Java 类com.intellij.psi.impl.java.stubs.index.JavaFullClassNameIndex 实例源码

项目:intellij-ce-playground    文件:JavaFileManagerImpl.java   
@NotNull
@Override
public PsiClass[] findClasses(@NotNull String qName, @NotNull final GlobalSearchScope scope) {
  final Collection<PsiClass> classes = JavaFullClassNameIndex.getInstance().get(qName.hashCode(), myManager.getProject(), scope);
  if (classes.isEmpty()) return PsiClass.EMPTY_ARRAY;
  List<PsiClass> result = new ArrayList<PsiClass>(classes.size());
  for (PsiClass aClass : classes) {
    final String qualifiedName = aClass.getQualifiedName();
    if (qualifiedName == null || !qualifiedName.equals(qName)) continue;

    PsiUtilCore.ensureValid(aClass);
    PsiFile file = aClass.getContainingFile();
    if (file == null) {
      throw new AssertionError("No file for class: " + aClass + " of " + aClass.getClass());
    }

    VirtualFile vFile = file.getVirtualFile();
    if (!hasAcceptablePackage(vFile)) continue;

    result.add(aClass);
  }

  int count = result.size();
  if (count == 0) return PsiClass.EMPTY_ARRAY;
  if (count == 1) return new PsiClass[] {result.get(0)};

  ContainerUtil.quickSort(result, new Comparator<PsiClass>() {
    @Override
    public int compare(PsiClass o1, PsiClass o2) {
      return scope.compare(o2.getContainingFile().getVirtualFile(), o1.getContainingFile().getVirtualFile());
    }
  });

  return result.toArray(new PsiClass[count]);
}
项目:intellij-ce-playground    文件:JavaFileManagerImpl.java   
@Nullable
private PsiClass findClassInIndex(String qName, GlobalSearchScope scope) {
  VirtualFile bestFile = null;
  PsiClass bestClass = null;
  final Collection<PsiClass> classes = JavaFullClassNameIndex.getInstance().get(qName.hashCode(), myManager.getProject(), scope);

  for (PsiClass aClass : classes) {
    PsiFile file = aClass.getContainingFile();
    if (file == null) {
      LOG.error("aClass=" + aClass + " of class " + aClass.getClass() + "; valid=" + aClass.isValid());
      continue;
    }
    final boolean valid = aClass.isValid();
    VirtualFile vFile = file.getVirtualFile();
    if (!valid) {
      LOG.error("Invalid class " + aClass + "; " +
                file + (file.isValid() ? "" : " (invalid)") +
                "; virtualFile:" + vFile +
                (vFile != null && !vFile.isValid() ? " (invalid)" : "") +
                "; id=" + (vFile == null ? 0 : ((VirtualFileWithId)vFile).getId()),
                new PsiInvalidElementAccessException(aClass));
      continue;
    }

    final String qualifiedName = aClass.getQualifiedName();
    if (qualifiedName == null || !qualifiedName.equals(qName)) continue;


    if (!hasAcceptablePackage(vFile)) continue;
    if (bestFile == null || scope.compare(vFile, bestFile) > 0) {
      bestFile = vFile;
      bestClass = aClass;
    }
  }
  return bestClass;
}
项目:tools-idea    文件:JavaFileManagerBase.java   
@Override
public PsiClass[] findClasses(@NotNull String qName, @NotNull final GlobalSearchScope scope) {
  final Collection<PsiClass> classes = JavaFullClassNameIndex.getInstance().get(qName.hashCode(), myManager.getProject(), scope);
  if (classes.isEmpty()) return PsiClass.EMPTY_ARRAY;
  List<PsiClass> result = new ArrayList<PsiClass>(classes.size());
  int count = 0;
  PsiClass aClass = null;
  for (PsiClass found : classes) {
    aClass = found;
    final String qualifiedName = aClass.getQualifiedName();
    if (qualifiedName == null || !qualifiedName.equals(qName)) continue;

    PsiUtilCore.ensureValid(aClass);
    PsiFile file = aClass.getContainingFile();
    if (file == null) {
      throw new AssertionError("No file for class: " + aClass + " of " + aClass.getClass());
    }

    VirtualFile vFile = file.getVirtualFile();
    if (!hasAcceptablePackage(vFile)) continue;

    result.add(aClass);
    count++;
  }

  if (count == 0) return PsiClass.EMPTY_ARRAY;
  if (count == 1) return new PsiClass[] {aClass};

  ContainerUtil.quickSort(result, new Comparator<PsiClass>() {
    @Override
    public int compare(PsiClass o1, PsiClass o2) {
      return scope.compare(o2.getContainingFile().getVirtualFile(), o1.getContainingFile().getVirtualFile());
    }
  });

  return result.toArray(new PsiClass[count]);
}
项目:tools-idea    文件:JavaFileManagerBase.java   
@Nullable
private PsiClass findClassInIndex(String qName, GlobalSearchScope scope) {
  VirtualFile bestFile = null;
  PsiClass bestClass = null;
  final Collection<PsiClass> classes = JavaFullClassNameIndex.getInstance().get(qName.hashCode(), myManager.getProject(), scope);

  for (PsiClass aClass : classes) {
    PsiFile file = aClass.getContainingFile();
    if (file == null) {
      LOG.error("aClass=" + aClass + " of class " + aClass.getClass() + "; valid=" + aClass.isValid());
      continue;
    }
    final boolean valid = aClass.isValid();
    VirtualFile vFile = file.getVirtualFile();
    if (!valid) {
      LOG.error("Invalid class " + aClass + "; " +
                file + (file.isValid() ? "" : " (invalid)") +
                "; virtualFile:" + vFile +
                (vFile != null && !vFile.isValid() ? " (invalid)" : "") +
                "; id=" + (vFile == null ? 0 : ((VirtualFileWithId)vFile).getId()),
                new PsiInvalidElementAccessException(aClass));
      continue;
    }

    final String qualifiedName = aClass.getQualifiedName();
    if (qualifiedName == null || !qualifiedName.equals(qName)) continue;


    if (!hasAcceptablePackage(vFile)) continue;
    if (bestFile == null || scope.compare(vFile, bestFile) > 0) {
      bestFile = vFile;
      bestClass = aClass;
    }
  }
  return bestClass;
}
项目:consulo-java    文件:JavaFileManagerImpl.java   
@NotNull
private List<Pair<PsiClass, VirtualFile>> doFindClasses(@NotNull String qName, @NotNull final GlobalSearchScope scope)
{
    final Collection<PsiClass> classes = JavaFullClassNameIndex.getInstance().get(qName.hashCode(), myManager.getProject(), scope);
    if(classes.isEmpty())
    {
        return Collections.emptyList();
    }
    List<Pair<PsiClass, VirtualFile>> result = new ArrayList<>(classes.size());
    for(PsiClass aClass : classes)
    {
        final String qualifiedName = aClass.getQualifiedName();
        if(qualifiedName == null || !qualifiedName.equals(qName))
        {
            continue;
        }

        PsiFile file = aClass.getContainingFile();
        if(file == null)
        {
            throw new AssertionError("No file for class: " + aClass + " of " + aClass.getClass());
        }
        final boolean valid = file.isValid();
        VirtualFile vFile = file.getVirtualFile();
        if(!valid)
        {
            LOG.error("Invalid file " +
                    file + "; virtualFile:" + vFile +
                    (vFile != null && !vFile.isValid() ? " (invalid)" : "") +
                    "; id=" + (vFile == null ? 0 : ((VirtualFileWithId) vFile).getId()), new PsiInvalidElementAccessException(aClass));
            continue;
        }
        if(!hasAcceptablePackage(vFile))
        {
            continue;
        }

        result.add(Pair.create(aClass, vFile));
    }

    return result;
}