@Nullable @Override public PsiElement resolve() { PsiElement parent = PsiTreeUtil.getParentOfType(myElement, PsiLet.class); // If name is used in a let definition, it's already the reference if (parent instanceof PsiLet && ((PsiLet) parent).getNameIdentifier() == myElement) { return myElement; } // Find the name in the index Collection<PsiLet> elements = StubIndex.getElements(IndexKeys.LETS, m_referenceName, myElement.getProject(), GlobalSearchScope.allScope(myElement.getProject()), PsiLet.class); if (!elements.isEmpty()) { // TODO: only let with correct QN PsiLet let = elements.iterator().next(); return let.getNameIdentifier(); } return null; }
static void complete(Project project, PsiModuleName name, @NotNull CompletionResultSet resultSet) { // Get the correct module Collection<PsiModule> modules = StubIndex.getElements(IndexKeys.MODULES, name.getName(), project, GlobalSearchScope.allScope(project), PsiModule.class); if (!modules.isEmpty()) { for (PsiModule module : modules) { Collection<PsiNamedElement> expressions = module.getExpressions(); for (PsiNamedElement expression : expressions) { resultSet.addElement( LookupElementBuilder.create(expression). withIcon(PsiIconUtil.getProvidersIcon(expression, 0)). withTypeText(PsiInferredTypeUtil.getTypeInfo(expression)) ); } } } }
@NotNull public TSMetaModelImpl buildModel() { myResult = new TSMetaModelImpl(); myFiles.clear(); StubIndex.getInstance().processElements( DomElementClassIndex.KEY, Items.class.getName(), myProject, ProjectScope.getAllScope(myProject), PsiFile.class, this ); final TSMetaModelImpl result = myResult; myResult = null; return result; }
@Override public PsiElement getValueDeclaration(XmlElement xmlElement, String value) { CatberryProjectConfigurationManager configurationManager = CatberryProjectConfigurationManager.getInstance(project); PsiDirectory directory = configurationManager.getStoresDirectory(); if(directory == null) return super.getValueDeclaration(xmlElement, value); final String requiredPath = directory.getVirtualFile().getPath() + "/" + value+".js"; int index = value.lastIndexOf('/'); String className = index == -1 ? value : value.substring(index+1); Collection<JSElement> elements = StubIndex.getElements(JSClassIndex.KEY, className, project, GlobalSearchScope.allScope(project), JSElement.class); for(JSElement element : elements) { if (element instanceof JSClass && element.getContainingFile().getVirtualFile().getPath().equals(requiredPath)) return element; } return super.getValueDeclaration(xmlElement, value); }
@Nullable private static String findNamespaceByAlias(Project project, String alias) { Collection<FusionNamespaceDeclaration> namespaces = StubIndex.getElements( FusionNamespaceDeclarationIndex.KEY, alias, project, GlobalSearchScope.projectScope(project), FusionNamespaceDeclaration.class); if (!namespaces.isEmpty()) { FusionNamespace namespace = namespaces.iterator().next().getNamespace(); if (namespace != null) { return namespace.getText(); } } return null; }
@Override @NotNull public PsiMethod[] getMethodsByNameIfNotMoreThan(@NonNls @NotNull final String name, @NotNull final GlobalSearchScope scope, final int maxCount) { final List<PsiMethod> methods = new SmartList<PsiMethod>(); StubIndex.getInstance().processElements(JavaStubIndexKeys.METHODS, name, myManager.getProject(), scope, PsiMethod.class, new CommonProcessors.CollectProcessor < PsiMethod > (methods){ @Override public boolean process(PsiMethod method) { return methods.size() != maxCount && super.process(method); } }); if (methods.isEmpty()) return PsiMethod.EMPTY_ARRAY; List<PsiMethod> list = filterMembers(methods, scope); return list.toArray(new PsiMethod[list.size()]); }
@Override @NotNull public PsiField[] getFieldsByNameIfNotMoreThan(@NotNull String name, @NotNull final GlobalSearchScope scope, final int maxCount) { final List<PsiField> methods = new SmartList<PsiField>(); StubIndex.getInstance().processElements(JavaStubIndexKeys.FIELDS, name, myManager.getProject(), scope, PsiField.class, new CommonProcessors.CollectProcessor < PsiField > (methods){ @Override public boolean process(PsiField method) { return methods.size() != maxCount && super.process(method); } }); if (methods.isEmpty()) return PsiField.EMPTY_ARRAY; List<PsiField> list = filterMembers(methods, scope); return list.toArray(new PsiField[list.size()]); }
private static <T extends PsiNamedElement> void addVariantsFromIndex(final CompletionResultSet resultSet, final PsiFile targetFile, final StubIndexKey<String, T> key, final InsertHandler<LookupElement> insertHandler, final Condition<? super T> condition, Class<T> elementClass) { final Project project = targetFile.getProject(); GlobalSearchScope scope = PyProjectScopeBuilder.excludeSdkTestsScope(targetFile); Collection<String> keys = StubIndex.getInstance().getAllKeys(key, project); for (final String elementName : CompletionUtil.sortMatching(resultSet.getPrefixMatcher(), keys)) { for (T element : StubIndex.getElements(key, elementName, project, scope, elementClass)) { if (condition.value(element)) { resultSet.addElement(LookupElementBuilder.createWithIcon(element) .withTailText(" " + ((NavigationItem)element).getPresentation().getLocationString(), true) .withInsertHandler(insertHandler)); } } } }
public boolean hasStubElementsOfType(final DomFileElement domFileElement, final Class<? extends DomElement> clazz) { final VirtualFile file = domFileElement.getFile().getVirtualFile(); if (!(file instanceof VirtualFileWithId)) return false; final String clazzName = clazz.getName(); final int virtualFileId = ((VirtualFileWithId)file).getId(); CommonProcessors.FindFirstProcessor<? super PsiFile> processor = new CommonProcessors.FindFirstProcessor<PsiFile>(); StubIndex.getInstance().processElements(KEY, clazzName, domFileElement.getFile().getProject(), GlobalSearchScope.fileScope(domFileElement.getFile()), new IdFilter() { @Override public boolean containsFileId(int id) { return id == virtualFileId; } }, PsiFile.class, processor ); return processor.isFound(); }
public boolean hasStubElementsWithNamespaceKey(final DomFileElement domFileElement, final String namespaceKey) { final VirtualFile file = domFileElement.getFile().getVirtualFile(); if (!(file instanceof VirtualFileWithId)) return false; final int virtualFileId = ((VirtualFileWithId)file).getId(); CommonProcessors.FindFirstProcessor<PsiFile> processor = new CommonProcessors.FindFirstProcessor<PsiFile>(); StubIndex.getInstance().processElements( KEY, namespaceKey, domFileElement.getFile().getProject(), GlobalSearchScope.fileScope(domFileElement.getFile()), new IdFilter() { @Override public boolean containsFileId(int id) { return id == virtualFileId; } }, PsiFile.class, processor ); return processor.isFound(); }
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.getElements(GrFullScriptNameIndex.KEY, name.hashCode(), myProject, actualScope, GroovyFile.class); 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; }
@NotNull private static List<PsiClass> getDerivingClassCandidates(PsiClass clazz, GlobalSearchScope scope, boolean includeAnonymous) { final String name = clazz.getName(); if (name == null) return Collections.emptyList(); final ArrayList<PsiClass> inheritors = new ArrayList<PsiClass>(); for (GrReferenceList list : StubIndex.getElements(GrDirectInheritorsIndex.KEY, name, clazz.getProject(), scope, GrReferenceList.class)) { final PsiElement parent = list.getParent(); if (parent instanceof GrTypeDefinition) { inheritors.add((PsiClass)parent); } } if (includeAnonymous) { final Collection<GrAnonymousClassDefinition> classes = StubIndex.getElements(GrAnonymousClassIndex.KEY, name, clazz.getProject(), scope, GrAnonymousClassDefinition.class); for (GrAnonymousClassDefinition aClass : classes) { inheritors.add(aClass); } } return inheritors; }
/** * @param path for function "TestFoo" in target "//foo/bar:baz" would be "foo/bar/baz::TestFoo". * See {@link BlazeGoTestEventsHandler#testLocationUrl}. */ @SuppressWarnings("rawtypes") private static List<Location> findTestFunction(Project project, String path) { String[] parts = path.split(SmRunnerUtils.TEST_NAME_PARTS_SPLITTER); if (parts.length != 2) { return ImmutableList.of(); } String functionName = parts[1]; TargetIdeInfo target = getGoTestTarget(project, parts[0]); List<VirtualFile> goFiles = getGoFiles(project, target); if (goFiles.isEmpty()) { return ImmutableList.of(); } GlobalSearchScope scope = FilesScope.filesScope(project, goFiles); Collection<GoFunctionDeclaration> functions = StubIndex.getElements( GoFunctionIndex.KEY, functionName, project, scope, GoFunctionDeclaration.class); return functions.stream().map(PsiLocation::new).collect(Collectors.toList()); }
@NotNull public Collection<Key> getAllKeysInScope(@NotNull final Project project, @NotNull final GlobalSearchScope scope) { final StubIndex stubIndex = StubIndex.getInstance(); final Collection<Key> allKeys = new HashSet<Key>(); allKeys.addAll(stubIndex.getAllKeys(myIndexKey, project)); final Iterator<Key> iterator = allKeys.iterator(); while (iterator.hasNext()) { final Key key = iterator.next(); if (stubIndex.get(myIndexKey, key, project, scope).isEmpty()) { iterator.remove(); } } return allKeys; }
public static void findAllRobotKeywordDefsInRobotFilesStartingWith(Project project, List<PsiElement> results, String startsWith) { final StubIndex STUB_INDEX = StubIndex.getInstance(); final String normalizedStartsWith = RobotPsiUtil.normalizeRobotDefinedKeywordForIndex(startsWith); String keyValue; StubIndexKey<String, RobotKeywordTitle> indexKey; if (normalizedStartsWith.length() >= 3) { keyValue = normalizedStartsWith.substring(0, 3); indexKey = RobotKeywordDefFirstThreeCharsIndex.KEY; } else if (normalizedStartsWith.length() >= 2) { keyValue = normalizedStartsWith.substring(0, 2); indexKey = RobotKeywordTitleFirstTwoCharsIndex.KEY; } else if (normalizedStartsWith.length() >= 1) { keyValue = normalizedStartsWith.substring(0, 1); indexKey = RobotKeywordDefFirstCharIndex.KEY; } else { findAllRobotKeywordDefsInRobotFiles(project, results); return; } GlobalSearchScope robotFilesScope = GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.projectScope(project), RobotFileType.INSTANCE); RobotKeywordDefProcessor processor = new RobotKeywordDefProcessor(results, SearchType.STARTS_WITH, startsWith); STUB_INDEX.processElements(indexKey, keyValue, project, robotFilesScope, RobotKeywordTitle.class, processor); }
public static List<RobotKeywordTitle> findMatchingKeywordDefsByName(String name, Project project, boolean isSearchTextFromRobotFile) { final StubIndex STUB_INDEX = StubIndex.getInstance(); final String normalizedName = normalizeRobotDefinedKeywordForIndex(name); List<PsiElement> results = Lists.newArrayList(); RobotKeywordDefProcessor processor = new RobotKeywordDefProcessor(results, SearchType.FIND_ALL_EXACT_MATCHES, name); STUB_INDEX.processElements(RobotKeywordTitleNormalizedNameIndex.KEY, normalizedName, project, GlobalSearchScope.allScope(project), RobotKeywordTitle.class, processor); if (isSearchTextFromRobotFile) { Optional<RobotKeywordTitle> embeddedKeywordTitle = findFirstMatchInEmbeddedArgsIndex(name, project); if (embeddedKeywordTitle.isPresent()) { results.add(embeddedKeywordTitle.get()); } } List<RobotKeywordTitle> keywordTitleResults = Lists.newArrayList(); for (PsiElement result: results) { if (result instanceof RobotKeywordTitle) { keywordTitleResults.add((RobotKeywordTitle)result); } } return keywordTitleResults; }
private static Optional<RobotKeywordTitle> findFirstMatchInEmbeddedArgsIndex(String name, Project project) { final String normalizedKeyword = normalizeEmbeddedArgKeyword(name); final StubIndex STUB_INDEX = StubIndex.getInstance(); final Collection<String> KEYS = STUB_INDEX.getAllKeys(RobotKeywordTitleEmbeddedArgsIndex.KEY, project); for (String key: KEYS) { Collection<RobotKeywordTitle> keywordsWithEmbeddedArgs = StubIndex.getElements(RobotKeywordTitleEmbeddedArgsIndex.KEY, key, project, GlobalSearchScope.allScope(project), RobotKeywordTitle.class); for (RobotKeywordTitle keyword: keywordsWithEmbeddedArgs) { String regex = keyword.getRegex(); Pattern pattern = Pattern.compile(regex); if (pattern.matcher(normalizedKeyword).matches()) { return Optional.of(keyword); } } } return Optional.absent(); }
@NotNull private static List<PsiModifierListOwner> getAnnotatedMemberCandidates(final PsiClass clazz, final GlobalSearchScope scope) { final String name = clazz.getName(); if (name == null) return Collections.emptyList(); final Collection<PsiElement> members = ApplicationManager.getApplication().runReadAction(new Computable<Collection<PsiElement>>() { @Override public Collection<PsiElement> compute() { return StubIndex.getInstance().get(GrAnnotatedMemberIndex.KEY, name, clazz.getProject(), scope); } }); if (members.isEmpty()) { return Collections.emptyList(); } final ArrayList<PsiModifierListOwner> result = new ArrayList<PsiModifierListOwner>(); for (PsiElement element : members) { if (element instanceof GroovyFile) { element = ((GroovyFile)element).getPackageDefinition(); } if (element instanceof PsiModifierListOwner) { result.add((PsiModifierListOwner)element); } } return result; }
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; }
@NotNull private static PsiClass[] getDeriverCandidates(PsiClass clazz, GlobalSearchScope scope) { final String name = clazz.getName(); if (name == null) return GrTypeDefinition.EMPTY_ARRAY; final ArrayList<PsiClass> inheritors = new ArrayList<PsiClass>(); for (GrReferenceList list : StubIndex.getInstance().safeGet(GrDirectInheritorsIndex.KEY, name, clazz.getProject(), scope, GrReferenceList.class)) { final PsiElement parent = list.getParent(); if (parent instanceof GrTypeDefinition) { inheritors.add(GrClassSubstitutor.getSubstitutedClass(((GrTypeDefinition)parent))); } } final Collection<GrAnonymousClassDefinition> classes = StubIndex.getInstance().get(GrAnonymousClassIndex.KEY, name, clazz.getProject(), scope); for (GrAnonymousClassDefinition aClass : classes) { inheritors.add(aClass); } return inheritors.toArray(new PsiClass[inheritors.size()]); }
@Override public void processElementsWithName( @NotNull String name, @NotNull Processor<NavigationItem> navigationItemProcessor, @NotNull FindSymbolParameters findSymbolParameters) { Project project = findSymbolParameters.getProject(); IdFilter idFilter = findSymbolParameters.getIdFilter(); GlobalSearchScope searchScope = findSymbolParameters.getSearchScope(); StubIndex.getInstance().processElements(CSharpIndexKeys.METHOD_INDEX, name, project, searchScope, idFilter, DotNetLikeMethodDeclaration.class, (Processor) navigationItemProcessor); StubIndex.getInstance().processElements(CSharpIndexKeys.EVENT_INDEX, name, project, searchScope, idFilter, DotNetEventDeclaration.class, (Processor) navigationItemProcessor); StubIndex.getInstance().processElements(CSharpIndexKeys.PROPERTY_INDEX, name, project, searchScope, idFilter, DotNetPropertyDeclaration.class, (Processor) navigationItemProcessor); StubIndex.getInstance().processElements(CSharpIndexKeys.FIELD_INDEX, name, project, searchScope, idFilter, DotNetFieldDeclaration.class, (Processor) navigationItemProcessor); }
private static Collection<PhpClass> getPhpClassInsideNamespace(Project project, PhpIndex phpIndex, String namespaceName, int maxDeep) { final Collection<PhpClass> phpClasses = new ArrayList<>(); if(maxDeep-- <= 0) { return phpClasses; } StubIndex.getInstance().processElements(PhpNamespaceIndex.KEY, namespaceName.toLowerCase(), project, phpIndex.getSearchScope(), PhpNamespace.class, 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; }
public boolean hasStubElementsOfType(final DomFileElement domFileElement, final Class<? extends DomElement> clazz) { final VirtualFile file = domFileElement.getFile().getVirtualFile(); if(!(file instanceof VirtualFileWithId)) { return false; } final String clazzName = clazz.getName(); final int virtualFileId = ((VirtualFileWithId) file).getId(); CommonProcessors.FindFirstProcessor<? super PsiFile> processor = new CommonProcessors.FindFirstProcessor<PsiFile>(); StubIndex.getInstance().process(KEY, clazzName, domFileElement.getFile().getProject(), GlobalSearchScope.fileScope(domFileElement.getFile()) , new IdFilter() { @Override public boolean containsFileId(int id) { return id == virtualFileId; } }, processor); return processor.isFound(); }
public boolean hasStubElementsWithNamespaceKey(final DomFileElement domFileElement, final String namespaceKey) { final VirtualFile file = domFileElement.getFile().getVirtualFile(); if(!(file instanceof VirtualFileWithId)) { return false; } final int virtualFileId = ((VirtualFileWithId) file).getId(); CommonProcessors.FindFirstProcessor<PsiFile> processor = new CommonProcessors.FindFirstProcessor<PsiFile>(); StubIndex.getInstance().process(KEY, namespaceKey, domFileElement.getFile().getProject(), GlobalSearchScope.fileScope(domFileElement.getFile ()), new IdFilter() { @Override public boolean containsFileId(int id) { return id == virtualFileId; } }, processor); return processor.isFound(); }
@NotNull @Override public String[] getNames(Project project, boolean includeNonProjectItems) { final Set<String> result = new HashSet<String>(); result.addAll(StubIndex.getInstance().getAllKeys(JavaScriptIndexKeys.ELEMENTS_BY_NAME, project)); FileBasedIndex.getInstance().processAllKeys(FilenameIndex.NAME, new Processor<String>() { @Override public boolean process(String s) { if(JavaScriptSupportLoader.isFlexMxmFile(s)) { result.add(FileUtil.getNameWithoutExtension(s)); } return true; } }, project); return result.toArray(new String[result.size()]); }
@Override @NotNull public PsiMethod[] getMethodsByNameIfNotMoreThan(@NonNls @NotNull final String name, @NotNull final GlobalSearchScope scope, final int maxCount) { final List<PsiMethod> methods = new SmartList<PsiMethod>(); StubIndex.getInstance().process(JavaStubIndexKeys.METHODS, name, myManager.getProject(), scope, new CommonProcessors.CollectProcessor<PsiMethod>(methods) { @Override public boolean process(PsiMethod method) { return methods.size() != maxCount && super.process(method); } }); if(methods.isEmpty()) { return PsiMethod.EMPTY_ARRAY; } List<PsiMethod> list = filterMembers(methods, scope); return list.toArray(new PsiMethod[list.size()]); }
@Override @NotNull public PsiField[] getFieldsByNameIfNotMoreThan(@NotNull String name, @NotNull final GlobalSearchScope scope, final int maxCount) { final List<PsiField> methods = new SmartList<PsiField>(); StubIndex.getInstance().process(JavaStubIndexKeys.FIELDS, name, myManager.getProject(), scope, new CommonProcessors.CollectProcessor<PsiField>(methods) { @Override public boolean process(PsiField method) { return methods.size() != maxCount && super.process(method); } }); if(methods.isEmpty()) { return PsiField.EMPTY_ARRAY; } List<PsiField> list = filterMembers(methods, scope); return list.toArray(new PsiField[list.size()]); }
@Nullable private Method findMethod(String path, Project project) { String[] location = path.split("#"); int tokensNumber = location.length; if (tokensNumber == 2) { String filePath = location[0]; String methodName = location[1]; if (filePath == null) { return null; } else { PsiFile file = findFile(filePath, project); if (file == null) { return null; } GlobalSearchScope scope = GlobalSearchScope.fileScope(project, file.getVirtualFile()); Collection<Method> methods = StubIndex.getElements(PhpMethodIndex.KEY, methodName, project, scope, Method.class); if (methods.size() == 1) { return methods.iterator().next(); } } } return null; }
@Override @NotNull public PsiMethod[] getMethodsByName(@NotNull String name, @NotNull final GlobalSearchScope scope) { Collection<PsiMethod> methods = StubIndex.getElements(JavaStubIndexKeys.METHODS, name, myManager.getProject(), new JavaSourceFilterScope(scope), PsiMethod.class); if (methods.isEmpty()) return PsiMethod.EMPTY_ARRAY; List<PsiMethod> list = filterMembers(methods, scope); return list.toArray(new PsiMethod[list.size()]); }
@Override public boolean processFieldsWithName(@NotNull String name, @NotNull Processor<? super PsiField> processor, @NotNull GlobalSearchScope scope, @Nullable IdFilter filter) { return StubIndex.getInstance().processElements(JavaStubIndexKeys.FIELDS, name, myManager.getProject(), new JavaSourceFilterScope(scope), filter, PsiField.class, processor); }
@Override public boolean processMethodsWithName(@NonNls @NotNull String name, @NotNull Processor<? super PsiMethod> processor, @NotNull GlobalSearchScope scope, @Nullable IdFilter filter) { return StubIndex.getInstance().processElements(JavaStubIndexKeys.METHODS, name, myManager.getProject(), new JavaSourceFilterScope(scope), filter, PsiMethod.class, processor); }
@Override public boolean processClassesWithName(@NotNull String name, @NotNull Processor<? super PsiClass> processor, @NotNull GlobalSearchScope scope, @Nullable IdFilter filter) { return StubIndex.getInstance().processElements(JavaStubIndexKeys.CLASS_SHORT_NAMES, name, myManager.getProject(), new JavaSourceFilterScope(scope), filter, PsiClass.class, processor); }
private static Collection<PsiMethod> getCandidateMethodsWithSuitableParams(final PsiClass aClass, final Project project, final GlobalSearchScope useScope, final Set<VirtualFile> candidateFiles, final GlobalSearchScope candidateScope) { return ApplicationManager.getApplication().runReadAction(new Computable<Collection<PsiMethod>>() { @Override public Collection<PsiMethod> compute() { if (!aClass.isValid()) return Collections.emptyList(); GlobalSearchScope visibleFromCandidates = combineResolveScopes(project, candidateFiles); final Set<String> usedMethodNames = newHashSet(); FileBasedIndex.getInstance().processAllKeys(JavaFunctionalExpressionIndex.JAVA_FUNCTIONAL_EXPRESSION_INDEX_ID, new CommonProcessors.CollectProcessor<String>(usedMethodNames), candidateScope, null); final LinkedHashSet<PsiMethod> methods = newLinkedHashSet(); Processor<PsiMethod> methodProcessor = new Processor<PsiMethod>() { @Override public boolean process(PsiMethod method) { if (usedMethodNames.contains(method.getName())) { methods.add(method); } return true; } }; StubIndexKey<String, PsiMethod> key = JavaMethodParameterTypesIndex.getInstance().getKey(); StubIndex index = StubIndex.getInstance(); index.processElements(key, aClass.getName(), project, useScope.intersectWith(visibleFromCandidates), PsiMethod.class, methodProcessor); index.processElements(key, JavaMethodElementType.TYPE_PARAMETER_PSEUDO_NAME, project, visibleFromCandidates, PsiMethod.class, methodProcessor); LOG.info("#methods: " + methods.size()); return methods; } }); }
@NotNull public String[] getNames(final Project project, final boolean includeNonProjectItems) { Set<String> symbols = new HashSet<String>(); symbols.addAll(PyClassNameIndex.allKeys(project)); symbols.addAll(PyModuleNameIndex.getAllKeys(project)); symbols.addAll(StubIndex.getInstance().getAllKeys(PyFunctionNameIndex.KEY, project)); symbols.addAll(StubIndex.getInstance().getAllKeys(PyVariableNameIndex.KEY, project)); return ArrayUtil.toStringArray(symbols); }
private static boolean processDirectInheritors( final PyClass superClass, final Processor<PyClass> consumer, final boolean checkDeep, final Set<PyClass> processed ) { AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); try { final String superClassName = superClass.getName(); if (superClassName == null || IGNORED_BASES.contains(superClassName)) return true; // we don't want to look for inheritors of overly general classes if (processed.contains(superClass)) return true; processed.add(superClass); Project project = superClass.getProject(); final Collection<PyClass> candidates = StubIndex.getElements(PySuperClassIndex.KEY, superClassName, project, ProjectScope.getAllScope(project), PyClass.class); for (PyClass candidate : candidates) { final PyClass[] classes = candidate.getSuperClasses(); for (PyClass superClassCandidate : classes) { if (superClassCandidate.isEquivalentTo(superClass)) { if (!consumer.process(candidate)) { return false; } if (checkDeep && !processDirectInheritors(candidate, consumer, checkDeep, processed)) return false; break; } } } } finally { accessToken.finish(); } return true; }
@NotNull private static List<PsiModifierListOwner> getAnnotatedMemberCandidates(final PsiClass clazz, final GlobalSearchScope scope) { final String name = ApplicationManager.getApplication().runReadAction(new Computable<String>() { @Override public String compute() { return clazz.getName(); } }); if (name == null) return Collections.emptyList(); final Collection<PsiElement> members = ApplicationManager.getApplication().runReadAction(new Computable<Collection<PsiElement>>() { @Override public Collection<PsiElement> compute() { return StubIndex.getElements(GrAnnotatedMemberIndex.KEY, name, clazz.getProject(), scope, PsiElement.class); } }); if (members.isEmpty()) { return Collections.emptyList(); } final List<PsiModifierListOwner> result = new ArrayList<PsiModifierListOwner>(); for (final PsiElement element : members) { ApplicationManager.getApplication().runReadAction(new Runnable() { @Override public void run() { PsiElement e = element instanceof GroovyFile ? ((GroovyFile)element).getPackageDefinition() : element; if (e instanceof PsiModifierListOwner) { result.add((PsiModifierListOwner)e); } } }); } return result; }
private List<PsiClass> addClasses(String name, GlobalSearchScope scope, boolean inSource) { final List<PsiClass> result = new ArrayList<PsiClass>(getScriptClassesByFQName(name, scope, inSource)); for (PsiElement psiClass : StubIndex.getElements(GrFullClassNameIndex.KEY, name.hashCode(), myProject, inSource ? new GrSourceFilterScope(scope) : scope, PsiClass.class)) { //hashcode doesn't guarantee equals if (name.equals(((PsiClass)psiClass).getQualifiedName())) { result.add((PsiClass)psiClass); } } return result; }
@Override @NotNull public PsiMethod[] getMethodsByName(@NonNls @NotNull String name, @NotNull GlobalSearchScope scope) { final Collection<? extends PsiMethod> methods = StubIndex.getElements(GrMethodNameIndex.KEY, name, myProject, new GrSourceFilterScope(scope), GrMethod.class); final Collection<? extends PsiMethod> annMethods = StubIndex.getElements(GrAnnotationMethodNameIndex.KEY, name, myProject, new GrSourceFilterScope(scope), GrAnnotationMethod.class); if (methods.isEmpty() && annMethods.isEmpty()) return PsiMethod.EMPTY_ARRAY; return ArrayUtil.mergeCollections(annMethods, methods, PsiMethod.ARRAY_FACTORY); }
@Override public boolean processMethodsWithName(@NonNls @NotNull String name, @NotNull Processor<? super PsiMethod> processor, @NotNull GlobalSearchScope scope, @Nullable IdFilter filter) { GrSourceFilterScope filterScope = new GrSourceFilterScope(scope); return StubIndex.getInstance().processElements(GrMethodNameIndex.KEY, name, myProject, filterScope, filter, GrMethod.class, processor) && StubIndex.getInstance().processElements(GrAnnotationMethodNameIndex.KEY, name, myProject, filterScope, filter, GrAnnotationMethod.class, processor); }
@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); }