下面列出了怎么用com.intellij.psi.util.ClassUtil的API类实例代码及写法,或者点击链接到github查看源代码。
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;
}
@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();
}
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;
}
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;
}
public static String getSourceMethod(PsiMethod method) {
//TODO: check method signature
return method.getName() + ClassUtil.getAsmMethodSignature(method);
}
@NotNull
public String getClassSimpleName() {
return ClassUtil.extractClassName(className);
}