Java Code Examples for com.intellij.psi.JavaPsiFacade#getInstance()
The following examples show how to use
com.intellij.psi.JavaPsiFacade#getInstance() .
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: PsiConsultantImpl.java From dagger-intellij-plugin with Apache License 2.0 | 6 votes |
public static Set<String> getQualifierAnnotations(PsiElement element) { Set<String> qualifiedClasses = new HashSet<String>(); if (element instanceof PsiModifierListOwner) { PsiModifierListOwner listOwner = (PsiModifierListOwner) element; PsiModifierList modifierList = listOwner.getModifierList(); if (modifierList != null) { for (PsiAnnotation psiAnnotation : modifierList.getAnnotations()) { if (psiAnnotation != null && psiAnnotation.getQualifiedName() != null) { JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(element.getProject()); PsiClass psiClass = psiFacade.findClass(psiAnnotation.getQualifiedName(), GlobalSearchScope.projectScope(element.getProject())); if (hasAnnotation(psiClass, CLASS_QUALIFIER)) { qualifiedClasses.add(psiAnnotation.getQualifiedName()); } } } } } return qualifiedClasses; }
Example 2
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 3
Source File: AbstractPropertiesProvider.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
/** * Create a search pattern for the given <code>className</code> class name. * * @param annotationName the class name to search. * @return a search pattern for the given <code>className</code> class name. */ protected static Query<PsiModifierListOwner> createAnnotationTypeDeclarationSearchPattern(SearchContext context, String annotationName) { JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(context.getModule().getProject()); PsiClass annotationClass = javaPsiFacade.findClass(annotationName, GlobalSearchScope.allScope(context.getModule().getProject())); if (annotationClass != null) { return new ArrayQuery<>(annotationClass); } else { return new EmptyQuery<>(); } }
Example 4
Source File: ProjectTestJvms.java From intellij-pants-plugin with Apache License 2.0 | 5 votes |
public static Stream<PsiClass> testClasses(Project project, String projectPath) throws IOException { JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); return testClassFiles(projectPath) .map(path -> path.getFileName().toString()) .map(name -> name.substring(0, name.length() - ".java".length())) .map(name -> PACKAGE_NAME + "." + name) .map(qualifiedName -> psiFacade.findClass(qualifiedName, GlobalSearchScope.allScope(project))); }
Example 5
Source File: PsiTypeUtil.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
@NotNull public static PsiType createCollectionType(@NotNull PsiManager psiManager, final String collectionQualifiedName, @NotNull PsiType... psiTypes) { final Project project = psiManager.getProject(); final GlobalSearchScope globalsearchscope = GlobalSearchScope.allScope(project); final JavaPsiFacade facade = JavaPsiFacade.getInstance(project); final PsiClass genericClass = facade.findClass(collectionQualifiedName, globalsearchscope); if (null != genericClass) { return JavaPsiFacade.getElementFactory(project).createType(genericClass, psiTypes); } else { return getJavaLangObject(psiManager); } }
Example 6
Source File: PsiConsultantImpl.java From dagger-intellij-plugin with Apache License 2.0 | 5 votes |
private static boolean isLazyOrProvider(PsiClass psiClass) { if (psiClass == null) { return false; } Project project = psiClass.getProject(); JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project); GlobalSearchScope globalSearchScope = GlobalSearchScope.allScope(project); PsiClass lazyClass = javaPsiFacade.findClass(CLASS_LAZY, globalSearchScope); PsiClass providerClass = javaPsiFacade.findClass(CLASS_PROVIDER, globalSearchScope); return psiClass.equals(lazyClass) || psiClass.equals(providerClass); }
Example 7
Source File: SubscriberMetadata.java From otto-intellij-plugin with Apache License 2.0 | 5 votes |
@Nullable public PsiMethod getBusPostMethod(Project project) { JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project); GlobalSearchScope globalSearchScope = GlobalSearchScope.allScope(project); PsiClass busClass = javaPsiFacade.findClass(getBusClassName(), globalSearchScope); if (busClass != null) { for (PsiMethod psiMethod : busClass.getMethods()) { if (psiMethod.getName().equals("post")) { return psiMethod; } } } return null; }
Example 8
Source File: PsiUtilsImpl.java From intellij-quarkus with Eclipse Public License 2.0 | 4 votes |
@Override public PsiClass findClass(Module module, String className) { JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject()); return facade.findClass(className, GlobalSearchScope.allScope(module.getProject())); }
Example 9
Source File: PsiQuarkusUtils.java From intellij-quarkus with Eclipse Public License 2.0 | 4 votes |
public static boolean isSupportNamingStrategy(Module javaProject) { JavaPsiFacade facade = JavaPsiFacade.getInstance(javaProject.getProject()); return facade.findClass(QuarkusConstants.CONFIG_PROPERTIES_NAMING_STRATEGY_ENUM, GlobalSearchScope.moduleWithLibrariesScope(javaProject)) != null; }
Example 10
Source File: PsiTypeUtils.java From intellij-quarkus with Eclipse Public License 2.0 | 4 votes |
public static PsiClass findType(PsiManager manager, String name) { JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject()); return facade.findClass(name, GlobalSearchScope.allScope(manager.getProject())); }
Example 11
Source File: PsiTypeUtils.java From intellij-quarkus with Eclipse Public License 2.0 | 4 votes |
public static PsiClass findType(Module module, String name) { JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject()); return facade.findClass(name, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module)); }
Example 12
Source File: SuggestionServiceImpl.java From component-runtime with Apache License 2.0 | 4 votes |
@Override public List<LookupElement> computeKeySuggestions(final Project project, final Module module, final String packageName, final List<String> containerElements, final String query) { final JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project); final PsiPackage pkg = javaPsiFacade.findPackage(packageName); if (pkg == null) { return Collections.emptyList(); } final String defaultFamily = getFamilyFromPackageInfo(pkg, module); return Stream .concat(Stream .concat(of(pkg.getClasses()) .flatMap(this::unwrapInnerClasses) .filter(c -> AnnotationUtil .findAnnotation(c, PARTITION_MAPPER, PROCESSOR, EMITTER) != null) .flatMap(clazz -> fromComponent(clazz, defaultFamily)), of(pkg.getClasses()) .flatMap(this::unwrapInnerClasses) .filter(c -> of(c.getAllFields()) .anyMatch(f -> AnnotationUtil.findAnnotation(f, OPTION) != null)) .flatMap(c -> fromConfiguration(defaultFamily, c.getName(), c))), of(pkg.getClasses()) .flatMap(this::unwrapInnerClasses) .flatMap(c -> of(c.getMethods()) .filter(m -> ACTIONS .stream() .anyMatch(action -> AnnotationUtil.findAnnotation(m, action) != null))) .map(m -> ACTIONS .stream() .map(action -> AnnotationUtil.findAnnotation(m, action)) .filter(Objects::nonNull) .findFirst() .get()) .map(action -> fromAction(action, defaultFamily)) .filter(Optional::isPresent) .map(Optional::get)) .filter(s -> containerElements.isEmpty() || !containerElements.contains(s.getKey())) .filter(s -> query == null || query.isEmpty() || s.getKey().startsWith(query)) .map(s -> s.newLookupElement(withPriority(s.getType()))) .collect(toList()); }
Example 13
Source File: JavaPsiUtil.java From idea-android-studio-plugin with GNU General Public License v2.0 | 4 votes |
@Nullable public static PsiClass getClass(Project project, String qualifiedClassName) { JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); return psiFacade.findClass(qualifiedClassName, GlobalSearchScope.allScope(project)); }
Example 14
Source File: OttoProjectHandler.java From otto-intellij-plugin with Apache License 2.0 | 4 votes |
private void performSearch(final SearchScope searchScope, final String subscribeClassName) { JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(myProject); PsiClass subscribePsiClass = javaPsiFacade.findClass(subscribeClassName, GlobalSearchScope.allScope(myProject)); if (subscribePsiClass == null) { // the guava or otto library isn't available in this project so do nothing return; } FindUsagesHandler handler = findUsagesManager.getNewFindUsagesHandler(subscribePsiClass, false); if (handler != null) { UsageInfoToUsageConverter.TargetElementsDescriptor descriptor = new UsageInfoToUsageConverter.TargetElementsDescriptor(handler.getPrimaryElements(), handler.getSecondaryElements()); final long startTime = System.currentTimeMillis(); Processor<Usage> processor = new Processor<Usage>() { @Override public boolean process(Usage usage) { if (usage instanceof UsageInfo2UsageAdapter) { PsiElement element = ((UsageInfo2UsageAdapter) usage).getElement(); if ((element = element.getContext()) instanceof PsiAnnotation) { if ((element = element.getContext()) instanceof PsiModifierList) { if ((element = element.getContext()) instanceof PsiMethod) { if (PsiConsultantImpl.hasAnnotation((PsiMethod) element, subscribeClassName)) { maybeAddSubscriberMethod((PsiMethod) element); } } } } } return true; } }; JavaClassFindUsagesOptions options = new JavaClassFindUsagesOptions(myProject); options.searchScope = searchScope; FindUsagesManager.startProcessUsages(handler, handler.getPrimaryElements(), handler.getSecondaryElements(), processor, options, new Runnable() { @Override public void run() { int eventClassCount = optimizeEventClassIndex(); if (eventClassCount > 0) { scheduleRefreshOfEventFiles(); } else { maybeScheduleAnotherSearch(); } if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("Searched for @Subscribe in %s in %dms", searchScope, System.currentTimeMillis() - startTime)); } } }); } }