Java 类com.intellij.psi.stubs.StubIndex 实例源码
项目:reasonml-idea-plugin
文件:PsiVarNameReference.java
@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;
}
项目:reasonml-idea-plugin
文件:ModuleDotCompletionProvider.java
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))
);
}
}
}
}
项目:hybris-integration-intellij-idea-plugin
文件:TSMetaModelBuilder.java
@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;
}
项目:catberry-idea-plugin
文件:CatberryAttributeDescriptor.java
@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);
}
项目:intellij-neos
文件:ResolveEngine.java
@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;
}
项目:intellij-ce-playground
文件:PsiShortNamesCacheImpl.java
@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()]);
}
项目:intellij-ce-playground
文件:PsiShortNamesCacheImpl.java
@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()]);
}
项目:intellij-ce-playground
文件:PyClassNameCompletionContributor.java
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));
}
}
}
}
项目:intellij-ce-playground
文件:DomElementClassIndex.java
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();
}
项目:intellij-ce-playground
文件:DomNamespaceKeyIndex.java
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();
}
项目:intellij-ce-playground
文件:GroovyShortNamesCache.java
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;
}
项目:intellij-ce-playground
文件:GroovyDirectInheritorsSearcher.java
@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;
}
项目:intellij
文件:BlazeGoTestLocator.java
/**
* @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());
}
项目:intellij-ocaml
文件:StubIndexHelper.java
@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;
}
项目:robot-intellij-plugin
文件:RobotPsiUtil.java
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);
}
项目:robot-intellij-plugin
文件:RobotPsiUtil.java
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;
}
项目:robot-intellij-plugin
文件:RobotPsiUtil.java
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();
}
项目:tools-idea
文件:AnnotatedMembersSearcher.java
@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;
}
项目:tools-idea
文件:GroovyShortNamesCache.java
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;
}
项目:tools-idea
文件:GroovyDirectInheritorsSearcher.java
@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()]);
}
项目:consulo-csharp
文件:CSharpSymbolNameContributor.java
@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);
}
项目:idea-php-annotation-plugin
文件:PhpIndexUtil.java
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;
}
项目:consulo-xml
文件:DomElementClassIndex.java
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();
}
项目:consulo-xml
文件:DomNamespaceKeyIndex.java
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();
}
项目:consulo-javascript
文件:JavaScriptSymbolContributor.java
@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()]);
}
项目:consulo-java
文件:PsiShortNamesCacheImpl.java
@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()]);
}
项目:consulo-java
文件:PsiShortNamesCacheImpl.java
@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()]);
}
项目:intellij-nette-tester
文件:TesterTestLocator.java
@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;
}
项目:intellij-ce-playground
文件:PsiShortNamesCacheImpl.java
@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()]);
}
项目:intellij-ce-playground
文件:PsiShortNamesCacheImpl.java
@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);
}
项目:intellij-ce-playground
文件:PsiShortNamesCacheImpl.java
@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);
}
项目:intellij-ce-playground
文件:PsiShortNamesCacheImpl.java
@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);
}
项目:intellij-ce-playground
文件:JavaFunctionalExpressionSearcher.java
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;
}
});
}
项目:intellij-ce-playground
文件:PyGotoSymbolContributor.java
@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);
}
项目:intellij-ce-playground
文件:PyClassInheritorsSearchExecutor.java
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;
}
项目:intellij-ce-playground
文件:AnnotatedMembersSearcher.java
@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;
}
项目:intellij-ce-playground
文件:GroovyShortNamesCache.java
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;
}
项目:intellij-ce-playground
文件:GroovyShortNamesCache.java
@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);
}
项目:intellij-ce-playground
文件:GroovyShortNamesCache.java
@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);
}
项目:intellij-ce-playground
文件:GroovyShortNamesCache.java
@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);
}