@Override
 @NotNull
 public String[] getAllMethodNames() {
   Collection<String> keys = StubIndex.getInstance().getAllKeys(GrMethodNameIndex.KEY, myProject);
   keys.addAll(StubIndex.getInstance().getAllKeys(GrAnnotationMethodNameIndex.KEY, myProject));
   return ArrayUtil.toStringArray(keys);
 }
 @Override
 public boolean processMethodsWithName(
     @NonNls @NotNull String name,
     @NotNull GlobalSearchScope scope,
     @NotNull Processor<PsiMethod> processor) {
   GrSourceFilterScope filterScope = new GrSourceFilterScope(scope);
   return StubIndex.getInstance()
           .process(GrMethodNameIndex.KEY, name, myProject, filterScope, processor)
       && StubIndex.getInstance()
           .process(GrAnnotationMethodNameIndex.KEY, name, myProject, filterScope, processor);
 }
 @Override
 @NotNull
 public PsiMethod[] getMethodsByName(
     @NonNls @NotNull String name, @NotNull GlobalSearchScope scope) {
   final Collection<? extends PsiMethod> methods =
       StubIndex.getInstance()
           .get(GrMethodNameIndex.KEY, name, myProject, new GrSourceFilterScope(scope));
   final Collection<? extends PsiMethod> annMethods =
       StubIndex.getInstance()
           .get(GrAnnotationMethodNameIndex.KEY, name, myProject, new GrSourceFilterScope(scope));
   if (methods.isEmpty() && annMethods.isEmpty()) return PsiMethod.EMPTY_ARRAY;
   return ArrayUtil.mergeCollections(annMethods, methods, PsiMethod.ARRAY_FACTORY);
 }
  public void getAllClassNames(@NotNull HashSet<String> dest) {
    if (!areClassesCompiled()) return;

    final Collection<String> classNames =
        StubIndex.getInstance().getAllKeys(ClojureClassNameIndex.KEY, myProject);
    dest.addAll(classNames);
  }
  public boolean hasStubElementsWithNamespaceKey(
      final DomFileElement domFileElement, final String namespaceKey) {
    final VirtualFile file = domFileElement.getFile().getVirtualFile();
    assert file instanceof VirtualFileWithId : file;

    final int virtualFileId = ((VirtualFileWithId) file).getId();
    CommonProcessors.FindFirstProcessor<String> processor =
        new CommonProcessors.FindFirstProcessor<String>() {
          @Override
          protected boolean accept(String s) {
            return namespaceKey.equals(s);
          }
        };
    StubIndex.getInstance()
        .processAllKeys(
            KEY,
            processor,
            GlobalSearchScope.fileScope(domFileElement.getFile()),
            new IdFilter() {
              @Override
              public boolean containsFileId(int id) {
                return id == virtualFileId;
              }
            });
    return processor.isFound();
  }
  private static Collection<PhpClass> getPhpClassInsideNamespace(
      Project project, PhpIndex phpIndex, String namespaceName, int maxDeep) {

    final Collection<PhpClass> phpClasses = new ArrayList<PhpClass>();

    if (maxDeep-- <= 0) {
      return phpClasses;
    }

    StubIndex.getInstance()
        .process(
            PhpNamespaceIndex.KEY,
            namespaceName.toLowerCase(),
            project,
            phpIndex.getSearchScope(),
            new Processor<PhpNamespace>() {
              @Override
              public boolean process(PhpNamespace phpNamespace) {
                phpClasses.addAll(
                    PsiTreeUtil.getChildrenOfTypeAsList(
                        phpNamespace.getStatements(), PhpClass.class));
                return true;
              }
            });

    for (String ns : phpIndex.getChildNamespacesByParentName(namespaceName + "\\")) {
      phpClasses.addAll(
          getPhpClassInsideNamespace(project, phpIndex, namespaceName + "\\" + ns, maxDeep));
    }

    return phpClasses;
  }
 @Override
 public Collection<PsiReferenceList> get(
     @NotNull final String s,
     @NotNull final Project project,
     @NotNull final GlobalSearchScope scope) {
   return StubIndex.getElements(
       getKey(), s, project, new JavaSourceFilterScope(scope), PsiReferenceList.class);
 }
  @NotNull
  public String[] getAllClassNames() {
    if (!areClassesCompiled()) return new String[0];

    final Collection<String> classNames =
        StubIndex.getInstance().getAllKeys(ClojureClassNameIndex.KEY, myProject);
    return classNames.toArray(new String[classNames.size()]);
  }
 @NotNull
 public PsiMethod[] getMethodsByName(
     @NonNls @NotNull String name, @NotNull GlobalSearchScope scope) {
   final Collection<? extends PsiMethod> methods =
       StubIndex.getInstance()
           .get(GosuMethodNameIndex.KEY, name, myProject, new GosuSourceFilterScope(scope));
   if (methods.isEmpty()) return PsiMethod.EMPTY_ARRAY;
   return methods.toArray(new PsiMethod[methods.size()]);
 }
 @NotNull
 public PsiField[] getFieldsByName(
     @NotNull @NonNls String name, @NotNull GlobalSearchScope scope) {
   final Collection<? extends PsiField> fields =
       StubIndex.getInstance()
           .get(GosuFieldNameIndex.KEY, name, myProject, new GosuSourceFilterScope(scope));
   if (fields.isEmpty()) return PsiField.EMPTY_ARRAY;
   return fields.toArray(new PsiField[fields.size()]);
 }
 private Collection<PsiClass> getAllScriptClasses(String shortName, GlobalSearchScope scope) {
   final ArrayList<PsiClass> result = CollectionFactory.arrayList();
   for (GosuFile file :
       StubIndex.getInstance()
           .get(GosuClassNameIndex.KEY, shortName, myProject, new GosuSourceFilterScope(scope))) {
     ContainerUtil.addIfNotNull(file.getPsiClass(), result);
   }
   return result;
 }
示例#12
0
 /**
  * Searching project files for global hash definitions by specific package and variable name
  *
  * @param project project to search in
  * @param canonicalName canonical variable name package::name
  * @return Collection of found definitions
  */
 public static Collection<PerlVariable> findGlobalHashDefinitions(
     Project project, String canonicalName) {
   assert canonicalName != null;
   return StubIndex.getElements(
       PerlVariableStubIndexKeys.KEY_HASH,
       canonicalName,
       project,
       GlobalSearchScope.allScope(project),
       PerlVariable.class);
 }
  public List<PsiClass> getScriptClassesByFQName(
      final String name, final GlobalSearchScope scope, final boolean srcOnly) {
    GlobalSearchScope actualScope = srcOnly ? new GrSourceFilterScope(scope) : scope;
    final Collection<GroovyFile> files =
        StubIndex.getInstance()
            .get(GrFullScriptNameIndex.KEY, name.hashCode(), myProject, actualScope);
    if (files.isEmpty()) {
      return Collections.emptyList();
    }

    final ArrayList<PsiClass> result = new ArrayList<PsiClass>();
    for (GroovyFile file : files) {
      if (file.isScript()) {
        final PsiClass scriptClass = file.getScriptClass();
        if (scriptClass != null && name.equals(scriptClass.getQualifiedName())) {
          result.add(scriptClass);
        }
      }
    }
    return result;
  }
  private Collection<PsiClass> getAllScriptClasses(String name, GlobalSearchScope scope) {
    if (!areClassesCompiled()) return new ArrayList<PsiClass>();

    Collection<ClojureFile> files =
        StubIndex.getInstance().get(ClojureClassNameIndex.KEY, name, myProject, scope);
    files =
        ContainerUtil.findAll(
            files,
            new Condition<ClojureFile>() {
              public boolean value(ClojureFile clojureFile) {
                return clojureFile.isClassDefiningFile();
              }
            });
    return ContainerUtil.map(
        files,
        new Function<ClojureFile, PsiClass>() {
          public PsiClass fun(ClojureFile clojureFile) {
            assert clojureFile.isClassDefiningFile();
            return clojureFile.getDefinedClass();
          }
        });
  }
  @NotNull
  public PsiClass[] getClassesByFQName(
      @NotNull @NonNls String name, @NotNull GlobalSearchScope scope) {
    final ArrayList<PsiClass> result = new ArrayList<PsiClass>();

    final Collection<? extends PsiElement> classes =
        StubIndex.getInstance()
            .get(
                GosuFullClassNameIndex.KEY,
                name.hashCode(),
                myProject,
                new GosuSourceFilterScope(scope));
    if (!classes.isEmpty()) {
      // hashcode doesn't guarantee equals
      for (PsiElement psiClass : classes) {
        if (!JavaFileManagerImpl.notClass(psiClass)
            && name.equals(((PsiClass) psiClass).getQualifiedName())) {
          result.add((PsiClass) psiClass);
        }
      }
    }

    return result.isEmpty() ? PsiClass.EMPTY_ARRAY : result.toArray(new PsiClass[result.size()]);
  }
 @NotNull
 @Override
 public Collection<KtProperty> get(
     @NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
   return StubIndex.getElements(KEY, s, project, scope, KtProperty.class);
 }
 public void getAllClassNames(@NotNull HashSet<String> dest) {
   dest.addAll(StubIndex.getInstance().getAllKeys(GosuClassNameIndex.KEY, myProject));
 }
 @NotNull
 public String[] getAllClassNames() {
   return ArrayUtil.toStringArray(
       StubIndex.getInstance().getAllKeys(GosuClassNameIndex.KEY, myProject));
 }
 public void getAllFieldNames(@NotNull HashSet<String> set) {
   set.addAll(StubIndex.getInstance().getAllKeys(GosuFieldNameIndex.KEY, myProject));
 }
 @NotNull
 public String[] getAllFieldNames() {
   Collection<String> fields =
       StubIndex.getInstance().getAllKeys(GosuFieldNameIndex.KEY, myProject);
   return ArrayUtil.toStringArray(fields);
 }
 @NotNull
 public String[] getAllMethodNames() {
   Collection<String> keys =
       StubIndex.getInstance().getAllKeys(GosuMethodNameIndex.KEY, myProject);
   return ArrayUtil.toStringArray(keys);
 }
示例#22
0
 /**
  * Returns list of defined global hashes
  *
  * @param project project to search in
  * @return collection of variable canonical names
  */
 public static Collection<String> listDefinedGlobalHahses(Project project) {
   return StubIndex.getInstance().getAllKeys(PerlVariableStubIndexKeys.KEY_HASH, project);
 }
    @Override
    public void run() {
      HierarchyService service = HierarchyService.instance(myProject);
      if (service.getSingleClassHierarchy() != null) {
        return;
      }
      LOG.info("BuildHierarchy started");
      final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();

      final double classes = 0.3;
      final double completeClasses = 0.1;
      final double sources = 0.3;
      final double collectPsiFilesFraction = 0.2;

      final UnitProcessor processor = new UnitProcessor(myProject, service);

      // 1. entering classes
      LOG.info("read classes start");
      indicator.setText("Reading classes");
      ApplicationManager.getApplication()
          .runReadAction(
              () -> {
                StubIndex.getInstance()
                    .processAllKeys(JavaStubIndexKeys.UNITS, myProject, processor);
              });
      indicator.setFraction(classes);
      testMemory("0");

      // 2. completing classes
      LOG.info("complete classes start");
      indicator.setText("Completing classes");
      service.connect1();
      indicator.setFraction(classes + completeClasses);
      testMemory("1");

      // 3. reading sources
      LOG.info("read sources start");
      indicator.setText("Reading sources");
      processor.isInSourceMode = true;
      ApplicationManager.getApplication()
          .runReadAction(
              () -> {
                StubIndex.getInstance()
                    .processAllKeys(JavaStubIndexKeys.UNITS, myProject, processor);
              });
      indicator.setFraction(classes + completeClasses + sources);

      // 4. reading PSI
      LOG.info("read PSI start");
      indicator.setText("Collecting PSI Files");
      final Set<VirtualFile> srcSet = new HashSet<VirtualFile>();
      collectFiles(srcSet, processor.myProcessedSet);

      double total = srcSet.size();
      LOG.info("Processing PSI");
      indicator.setText("Processing PSI Files");

      int loadedCound = 0;
      for (final VirtualFile vFile : srcSet) {
        String presentableUrl = vFile.getPresentableUrl();
        if (HierarchyService.PROCESS_PSI) {
          PsiFile psiFile =
              ApplicationManager.getApplication()
                  .runReadAction(
                      new Computable<PsiFile>() {
                        @Override
                        public PsiFile compute() {
                          return PsiManager.getInstance(myProject).findFile(vFile);
                        }
                      });
          if (psiFile instanceof PsiClassOwner) {
            service.processPsiClassOwner((PsiClassOwner) psiFile);
            LOG.info("PSI: " + presentableUrl);
          }
        }
        loadedCound++;
        indicator.setFraction(
            classes + completeClasses + sources + collectPsiFilesFraction * (loadedCound / total));
      }
      testMemory("2");

      // 5. completing sources + PSI
      indicator.setText("Completing sources + PSI");
      service.complete2();
      LOG.info("Complete end");
      testMemory("3");
      indicator.setFraction(0.9);

      // 6. connect subtypes
      indicator.setText("Connecting subtypes");
      service.connectSubtypes();
      LOG.info("Subtypes connected");
      indicator.setFraction(1);
    }
 @Override
 public Collection<PsiClass> get(
     final Integer integer, final Project project, @NotNull final GlobalSearchScope scope) {
   return StubIndex.getElements(
       getKey(), integer, project, new JavaSourceFilterScope(scope), PsiClass.class);
 }
 @Override
 public void getAllMethodNames(@NotNull HashSet<String> set) {
   set.addAll(StubIndex.getInstance().getAllKeys(GrMethodNameIndex.KEY, myProject));
 }