Java Code Examples for com.intellij.psi.JavaPsiFacade#findClass()

The following examples show how to use com.intellij.psi.JavaPsiFacade#findClass() . 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 vote down vote up
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: AbstractPropertiesProvider.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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 3
Source File: PsiTypeUtil.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 4
Source File: PsiConsultantImpl.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
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 5
Source File: SubscriberMetadata.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: PsiUtilsImpl.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public PsiClass findClass(Module module, String className) {
    JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject());
    return facade.findClass(className, GlobalSearchScope.allScope(module.getProject()));
}
 
Example 7
Source File: PsiQuarkusUtils.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
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 8
Source File: PsiTypeUtils.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
public static PsiClass findType(PsiManager manager, String name) {
    JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject());
    return facade.findClass(name, GlobalSearchScope.allScope(manager.getProject()));
}
 
Example 9
Source File: PsiTypeUtils.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
public static PsiClass findType(Module module, String name) {
    JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject());
    return facade.findClass(name, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module));
}
 
Example 10
Source File: JavaPsiUtil.java    From idea-android-studio-plugin with GNU General Public License v2.0 4 votes vote down vote up
@Nullable
public static PsiClass getClass(Project project, String qualifiedClassName) {
    JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
    return psiFacade.findClass(qualifiedClassName, GlobalSearchScope.allScope(project));
}
 
Example 11
Source File: OttoProjectHandler.java    From otto-intellij-plugin with Apache License 2.0 4 votes vote down vote up
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));
        }
      }
    });
  }
}