本文整理汇总了Java中com.intellij.psi.stubs.StubIndex.getElements方法的典型用法代码示例。如果您正苦于以下问题:Java StubIndex.getElements方法的具体用法?Java StubIndex.getElements怎么用?Java StubIndex.getElements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.stubs.StubIndex
的用法示例。
在下文中一共展示了StubIndex.getElements方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolve
import com.intellij.psi.stubs.StubIndex; //导入方法依赖的package包/类
@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;
}
示例2: complete
import com.intellij.psi.stubs.StubIndex; //导入方法依赖的package包/类
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))
);
}
}
}
}
示例3: getScriptClassesByFQName
import com.intellij.psi.stubs.StubIndex; //导入方法依赖的package包/类
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;
}
示例4: findNamespaceByAlias
import com.intellij.psi.stubs.StubIndex; //导入方法依赖的package包/类
@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;
}
示例5: findTestFunction
import com.intellij.psi.stubs.StubIndex; //导入方法依赖的package包/类
/**
* @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());
}
示例6: getDerivingClassCandidates
import com.intellij.psi.stubs.StubIndex; //导入方法依赖的package包/类
@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;
}
示例7: addVariantsFromIndex
import com.intellij.psi.stubs.StubIndex; //导入方法依赖的package包/类
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));
}
}
}
}
示例8: findFirstMatchInEmbeddedArgsIndex
import com.intellij.psi.stubs.StubIndex; //导入方法依赖的package包/类
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();
}
示例9: addClasses
import com.intellij.psi.stubs.StubIndex; //导入方法依赖的package包/类
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;
}
示例10: getFieldsByName
import com.intellij.psi.stubs.StubIndex; //导入方法依赖的package包/类
@Override
@NotNull
public PsiField[] getFieldsByName(@NotNull @NonNls String name, @NotNull GlobalSearchScope scope) {
final Collection<? extends PsiField> fields = StubIndex.getElements(GrFieldNameIndex.KEY, name, myProject,
new GrSourceFilterScope(scope), GrField.class);
if (fields.isEmpty()) return PsiField.EMPTY_ARRAY;
return fields.toArray(new PsiField[fields.size()]);
}
示例11: processDirectInheritors
import com.intellij.psi.stubs.StubIndex; //导入方法依赖的package包/类
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;
}
示例12: findAllRobotKeywordDefsInRobotFiles
import com.intellij.psi.stubs.StubIndex; //导入方法依赖的package包/类
public static void findAllRobotKeywordDefsInRobotFiles(Project project, List<PsiElement> results) {
final StubIndex STUB_INDEX = StubIndex.getInstance();
Collection<String> keys = STUB_INDEX.getAllKeys(RobotKeywordTitleNormalizedNameIndex.KEY, project);
for (String key : keys) {
Collection<RobotKeywordTitle> defsForKey = StubIndex.getElements(RobotKeywordTitleNormalizedNameIndex.KEY, key,
project, GlobalSearchScope.allScope(project), RobotKeywordTitle.class);
results.addAll(defsForKey);
}
}
示例13: findUniqueJavaKeywordForRobotKeyword
import com.intellij.psi.stubs.StubIndex; //导入方法依赖的package包/类
@NotNull
public static Optional<PsiMethod> findUniqueJavaKeywordForRobotKeyword(Project project, String robotKeywordName, boolean wrapPsiMethods) {
//First attempt to find the Java method with the exact name using the Method stub index:
final String methodName = RobotPsiUtil.robotKeywordToMethodFast(robotKeywordName);
final String normalizedName = RobotPsiUtil.normalizeKeywordForIndex(robotKeywordName);
Collection<PsiMethod> methods = StubIndex.getElements(JavaStubIndexKeys.METHODS, methodName, project, GlobalSearchScope.allScope(project), PsiMethod.class);
for (PsiMethod method : methods) {
if (!isPsiMethodRobotKeyword(method)) {
continue;
}
String methodNameLower = method.getName().toLowerCase();
if (methodNameLower.equals(normalizedName)) {
return Optional.of(wrap(method, wrapPsiMethods));
}
}
GlobalSearchScope javaFilesInProject = GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), JavaFileType.INSTANCE);
List<PsiElement> results = Lists.newArrayList();
//If no results are found, attempt to search the words index by the method name (since it is case insensitive, we might get results that we didn't get above.)
RobotJavaFileProcessor processor = new RobotJavaFileProcessor(results, SearchType.FIRST_EXACT_MATCH, Optional.of(normalizedName), wrapPsiMethods);
PsiSearchHelper.SERVICE.getInstance(project).processAllFilesWithWord(methodName, javaFilesInProject, processor, false);
if (results.size() > 0) {
return Optional.of((PsiMethod)results.get(0));
}
//If still no results are found, assume the Java method has the "underscore" style and search with words index again
final String underscoreMethod = RobotPsiUtil.robotKeywordToUnderscoreStyleMethod(robotKeywordName);
if (!underscoreMethod.equals(normalizedName)) {
RobotJavaFileProcessor underscoreProcessor = new RobotJavaFileProcessor(results, SearchType.FIRST_EXACT_MATCH, Optional.of(underscoreMethod), wrapPsiMethods);
PsiSearchHelper.SERVICE.getInstance(project).processAllFilesWithWord(underscoreMethod, javaFilesInProject, underscoreProcessor, false);
if (results.size() > 0) {
return Optional.of((PsiMethod) results.get(0));
}
}
return Optional.absent();
}
示例14: findUsagesOfVariableFromVariablesTable
import com.intellij.psi.stubs.StubIndex; //导入方法依赖的package包/类
private static List<PsiElement> findUsagesOfVariableFromVariablesTable(PsiElement sourceVariable, String normalName) {
final Project project = sourceVariable.getProject();
List<PsiElement> usages = Lists.newArrayList();
Collection<RobotScalarVariable> scalarVariablesWithSameName = StubIndex.getElements(RobotVariableNormalizedNameIndex.KEY, normalName, project,
GlobalSearchScope.allScope(project), RobotScalarVariable.class);
for (RobotScalarVariable robotScalarVariable: scalarVariablesWithSameName) {
if (isVariableUsage(sourceVariable, robotScalarVariable, normalName)) {
usages.add(robotScalarVariable);
}
}
return usages;
}
示例15: getItemsByName
import com.intellij.psi.stubs.StubIndex; //导入方法依赖的package包/类
@NotNull
@Override
public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) {
GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
Collection<HaskellNamedElement> result = StubIndex.getElements(HaskellAllNameIndex.KEY, name, project, scope, HaskellNamedElement.class);
List<NavigationItem> items = ContainerUtil.newArrayListWithCapacity(result.size());
for (HaskellNamedElement element : result) {
items.add(element);
}
return items.toArray(new NavigationItem[items.size()]);
}