com.intellij.psi.util.ClassUtil Java Examples

The following examples show how to use com.intellij.psi.util.ClassUtil. 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: JavaCamelIdeaUtils.java    From camel-idea-plugin with Apache License 2.0 6 votes vote down vote up
private List<PsiElement> findEndpoints(Module module, Predicate<String> uriCondition, Predicate<PsiLiteral> elementCondition) {
    PsiManager manager = PsiManager.getInstance(module.getProject());
    //TODO: use IdeaUtils.ROUTE_BUILDER_OR_EXPRESSION_CLASS_QUALIFIED_NAME somehow
    PsiClass routeBuilderClass = ClassUtil.findPsiClass(manager, "org.apache.camel.builder.RouteBuilder");

    List<PsiElement> results = new ArrayList<>();
    if (routeBuilderClass != null) {
        Collection<PsiClass> routeBuilders = ClassInheritorsSearch.search(routeBuilderClass, module.getModuleScope(), true)
            .findAll();
        for (PsiClass routeBuilder : routeBuilders) {
            Collection<PsiLiteralExpression> literals = PsiTreeUtil.findChildrenOfType(routeBuilder, PsiLiteralExpression.class);
            for (PsiLiteralExpression literal : literals) {
                Object val = literal.getValue();
                if (val instanceof String) {
                    String endpointUri = (String) val;
                    if (uriCondition.test(endpointUri) && elementCondition.test(literal)) {
                        results.add(literal);
                    }
                }
            }
        }
    }
    return results;
}
 
Example #2
Source File: BlazeScalaTestLocator.java    From intellij with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
private List<Location> findTestCase(Project project, String path) {
  String[] parts = path.split(SmRunnerUtils.TEST_NAME_PARTS_SPLITTER, 2);
  if (parts.length < 2) {
    return ImmutableList.of();
  }
  String className = parts[0];
  String testName = parts[1];
  PsiClass testClass = ClassUtil.findPsiClass(PsiManager.getInstance(project), className);
  for (ScInfixExpr testCase : PsiTreeUtil.findChildrenOfType(testClass, ScInfixExpr.class)) {
    if (TestNodeProvider.isSpecs2TestExpr(testCase)
        && Objects.equal(Specs2Utils.getSpecs2ScopedTestName(testCase), testName)) {
      return ImmutableList.of(new PsiLocation<>(testCase));
    }
  }
  return ImmutableList.of();
}
 
Example #3
Source File: JavaImportsUtil.java    From KodeBeagle with Apache License 2.0 6 votes vote down vote up
private Map<String, Set<String>> getImportsAndMethodsAfterValidation(
        final PsiJavaFile javaFile, final Map<String, Set<String>> importsVsMethods) {
    Map<String, Set<String>> finalImportsWithMethods =
            getFullyQualifiedImportsWithMethods(javaFile, importsVsMethods);
    Set<String> imports = importsVsMethods.keySet();
    Set<PsiPackage> importedPackages = getOnDemandImports(javaFile);
    if (!importedPackages.isEmpty()) {
        for (PsiPackage psiPackage : importedPackages) {
            for (String psiImport : imports) {
                if (psiPackage.containsClassNamed(ClassUtil.extractClassName(psiImport))) {
                    finalImportsWithMethods.put(psiImport, importsVsMethods.get(psiImport));
                }
            }
        }
    }
    return finalImportsWithMethods;
}
 
Example #4
Source File: PsiTypeUtils.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
public static String getSourceType(PsiModifierListOwner psiElement) {
    if (psiElement instanceof PsiField || psiElement instanceof PsiMethod) {
        return ClassUtil.getJVMClassName(((PsiMember)psiElement).getContainingClass());
    } else if (psiElement instanceof PsiParameter) {
        return ClassUtil.getJVMClassName(((PsiMethod)((PsiParameter)psiElement).getDeclarationScope()).getContainingClass());
    }
    return null;
}
 
Example #5
Source File: PsiTypeUtils.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
public static String getSourceMethod(PsiMethod method) {
    //TODO: check method signature
    return method.getName() + ClassUtil.getAsmMethodSignature(method);
}
 
Example #6
Source File: ReferencedClass.java    From camel-idea-plugin with Apache License 2.0 4 votes vote down vote up
@NotNull
public String getClassSimpleName() {
    return ClassUtil.extractClassName(className);
}