com.intellij.psi.search.PsiShortNamesCache Java Examples
The following examples show how to use
com.intellij.psi.search.PsiShortNamesCache.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClassHelper.java From MVPManager with MIT License | 6 votes |
/** * search class by class name. * * @param name * @param project * @return */ private static PsiClass searchClassByName(String name, Project project) { GlobalSearchScope searchScope = GlobalSearchScope.allScope(project); PsiClass[] psiClasses = PsiShortNamesCache.getInstance(project).getClassesByName(name, searchScope); if (psiClasses.length == 1) { return psiClasses[0]; } if (psiClasses.length > 1) { for (PsiClass pc : psiClasses) { PsiJavaFile psiJavaFile = (PsiJavaFile) pc.getContainingFile(); String packageName = psiJavaFile.getPackageName(); if (List.class.getPackage().getName().equals(packageName) || packageName.contains("io.xujiaji.xmvp")) { return pc; } } } return null; }
Example #2
Source File: LogDTemplate.java From android-postfix-plugin with Apache License 2.0 | 6 votes |
@Override public String getTemplateString(@NotNull PsiElement element) { Project project = element.getProject(); final GlobalSearchScope resolveScope = element.getResolveScope(); PsiClass[] buildConfigClasses = PsiShortNamesCache.getInstance(project).getClassesByName("BuildConfig", resolveScope); String buildConfigDebug = "BuildConfig.DEBUG"; if (buildConfigClasses.length != 0) { // Get BuildConfig QualifiedName PsiClass buildConfig = buildConfigClasses[0]; String qualifiedName = buildConfig.getQualifiedName(); buildConfigDebug = qualifiedName + ".DEBUG"; } return "if (" + buildConfigDebug + ") " + getStaticPrefix(LOG, "d", element) + "($TAG$, $expr$)$END$"; }
Example #3
Source File: BuckAutoDepsQuickFixProvider.java From buck with Apache License 2.0 | 6 votes |
private static Set<PsiClass> findPsiClasses(Project project, String className) { GlobalSearchScope scope = GlobalSearchScope.everythingScope(project); JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project); PsiShortNamesCache psiShortNamesCache = PsiShortNamesCache.getInstance(project); Set<PsiClass> results = new HashSet<>(); BuckAutoDepsSearchableClassNameContributor.EP_NAME.getExtensions(project).stream() .filter(contributor -> contributor.isApplicable(project, className)) .forEach( contributor -> contributor .getSearchableClassNames(project, className) .forEach( name -> Stream.concat( Stream.of(javaPsiFacade.findClasses(name, scope)), Stream.of(psiShortNamesCache.getClassesByName(name, scope))) .distinct() .forEach( psiClass -> { if (!results.contains(psiClass) && contributor.filter(project, className, psiClass)) { results.add(psiClass); } }))); return results; }
Example #4
Source File: ClassHelper.java From MVPManager with MIT License | 5 votes |
public static boolean isFileExists(AnActionEvent e, String name) { Project project = e.getProject(); GlobalSearchScope searchScope = GlobalSearchScope.allScope(project); PsiClass[] psiClasses = new PsiClass[0]; try { psiClasses = PsiShortNamesCache.getInstance(project).getClassesByName(name, searchScope); }catch (Exception ignored) { ignored.printStackTrace(); } return psiClasses.length > 0; }
Example #5
Source File: BlazeAndroidTestLocator.java From intellij with Apache License 2.0 | 5 votes |
private static List<PsiClass> findClasses( Project project, GlobalSearchScope scope, String className) { PsiClass psiClass = JavaPsiFacade.getInstance(project).findClass(className, scope); if (psiClass != null) { return ImmutableList.of(psiClass); } // handle unqualified class names return Arrays.stream(PsiShortNamesCache.getInstance(project).getClassesByName(className, scope)) .filter(JUnitUtil::isTestClass) .collect(Collectors.toList()); }
Example #6
Source File: PantsUnresolvedReferenceFixFinder.java From intellij-pants-plugin with Apache License 2.0 | 5 votes |
@NotNull public static List<PantsQuickFix> findMissingDependencies(@NotNull String referenceName, @NotNull PsiFile containingFile) { final VirtualFile containingClassFile = containingFile.getVirtualFile(); if (containingClassFile == null) return Collections.emptyList(); final Project project = containingFile.getProject(); final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); final Module containingModule = fileIndex.getModuleForFile(containingClassFile); final List<PantsTargetAddress> addresses = PantsUtil.getTargetAddressesFromModule(containingModule); if (addresses.size() != 1) return Collections.emptyList(); final PantsTargetAddress currentAddress = addresses.iterator().next(); final PsiClass[] classes = PsiShortNamesCache.getInstance(project).getClassesByName(referenceName, GlobalSearchScope.allScope(project)); final List<PsiClass> allowedDependencies = filterAllowedDependencies(containingFile, classes); final List<PantsQuickFix> result = new ArrayList<>(); for (PsiClass dependency : allowedDependencies) { final Module module = ModuleUtil.findModuleForPsiElement(dependency); for (PantsTargetAddress addressToAdd : PantsUtil.getTargetAddressesFromModule(module)) { result.add(new AddPantsTargetDependencyFix(currentAddress, addressToAdd)); } // todo(fkoroktov): handle jars } return result; }
Example #7
Source File: PsiSearchUtils.java From litho with Apache License 2.0 | 2 votes |
/** * Returns the list of all classes with the specified name in the specified scope * * @param project the project that includes scope. * @param searchScope the scope in which classes are searched. * @param name the non-qualified name of the classes to find. * @return the list of found classes. */ public static PsiClass[] findClassesByShortName( Project project, GlobalSearchScope searchScope, String name) { return PsiShortNamesCache.getInstance(project).getClassesByName(name, searchScope); }