update
This commit is contained in:
@@ -70,6 +70,7 @@ public final class AstUtils {
|
||||
}
|
||||
|
||||
private static boolean isCollectionOrStreamType(org.eclipse.jdt.core.dom.ITypeBinding typeBinding) {
|
||||
if (typeBinding == null) return false;
|
||||
String fqn = typeBinding.getErasure().getQualifiedName();
|
||||
if (fqn.startsWith("java.util.stream.") ||
|
||||
fqn.equals("java.lang.Iterable") ||
|
||||
|
||||
@@ -446,6 +446,7 @@ public class CodebaseContext {
|
||||
}
|
||||
|
||||
public String getSuperclassFqn(TypeDeclaration td) {
|
||||
if (td == null) return null;
|
||||
ITypeBinding binding = td.resolveBinding();
|
||||
if (binding != null) {
|
||||
ITypeBinding superBinding = binding.getSuperclass();
|
||||
@@ -458,7 +459,7 @@ public class CodebaseContext {
|
||||
if (superType == null) return null;
|
||||
|
||||
String superName = extractTypeName(superType);
|
||||
CompilationUnit cu = (CompilationUnit) td.getRoot();
|
||||
CompilationUnit cu = (td.getRoot() instanceof CompilationUnit) ? (CompilationUnit) td.getRoot() : null;
|
||||
TypeDeclaration superTd = getTypeDeclaration(superName, cu);
|
||||
return superTd != null ? getFqn(superTd) : superName;
|
||||
}
|
||||
@@ -475,10 +476,11 @@ public class CodebaseContext {
|
||||
}
|
||||
|
||||
public MethodDeclaration findMethodDeclaration(TypeDeclaration td, String methodName, boolean includeSuper) {
|
||||
if (td == null) return null;
|
||||
ITypeBinding binding = td.resolveBinding();
|
||||
if (binding != null && includeSuper) {
|
||||
IMethodBinding methodBinding = findMethodBinding(binding, methodName);
|
||||
if (methodBinding != null) {
|
||||
if (methodBinding != null && methodBinding.getDeclaringClass() != null) {
|
||||
CompilationUnit declaringCu = classes.get(methodBinding.getDeclaringClass().getErasure().getQualifiedName());
|
||||
if (declaringCu != null) {
|
||||
ASTNode declNode = declaringCu.findDeclaringNode(methodBinding.getKey());
|
||||
@@ -523,6 +525,7 @@ public class CodebaseContext {
|
||||
}
|
||||
|
||||
private MethodDeclaration findMethodDeclarationLegacy(TypeDeclaration td, String methodName, boolean includeSuper) {
|
||||
if (td == null) return null;
|
||||
for (MethodDeclaration method : td.getMethods()) {
|
||||
if (method.getName().getIdentifier().equals(methodName)) {
|
||||
return method;
|
||||
@@ -542,7 +545,7 @@ public class CodebaseContext {
|
||||
for (Object interfaceTypeObj : td.superInterfaceTypes()) {
|
||||
Type interfaceType = (Type) interfaceTypeObj;
|
||||
String interfaceName = extractTypeName(interfaceType);
|
||||
TypeDeclaration interfaceTd = getTypeDeclaration(interfaceName, (CompilationUnit) td.getRoot());
|
||||
TypeDeclaration interfaceTd = getTypeDeclaration(interfaceName, (td.getRoot() instanceof CompilationUnit) ? (CompilationUnit) td.getRoot() : null);
|
||||
if (interfaceTd != null) {
|
||||
MethodDeclaration found = findMethodDeclarationLegacy(interfaceTd, methodName, true);
|
||||
if (found != null) return found;
|
||||
@@ -641,6 +644,7 @@ public class CodebaseContext {
|
||||
}
|
||||
|
||||
public String getFqn(AbstractTypeDeclaration atd) {
|
||||
if (atd == null) return null;
|
||||
StringBuilder sb = new StringBuilder(atd.getName().getIdentifier());
|
||||
ASTNode current = atd.getParent();
|
||||
while (current instanceof AbstractTypeDeclaration parent) {
|
||||
@@ -648,7 +652,10 @@ public class CodebaseContext {
|
||||
current = parent.getParent();
|
||||
}
|
||||
|
||||
CompilationUnit cu = (CompilationUnit) atd.getRoot();
|
||||
CompilationUnit cu = (atd.getRoot() instanceof CompilationUnit) ? (CompilationUnit) atd.getRoot() : null;
|
||||
if (cu == null) {
|
||||
return sb.toString();
|
||||
}
|
||||
String packageName = cu.getPackage() != null ? cu.getPackage().getName().getFullyQualifiedName() : "";
|
||||
String fqn = sb.toString();
|
||||
return packageName.isEmpty() ? fqn : packageName + "." + fqn;
|
||||
|
||||
Reference in New Issue
Block a user