This commit is contained in:
2026-06-27 20:12:31 +02:00
parent 74a4e66a33
commit a75b7acfe4
2 changed files with 12 additions and 4 deletions

View File

@@ -70,6 +70,7 @@ public final class AstUtils {
} }
private static boolean isCollectionOrStreamType(org.eclipse.jdt.core.dom.ITypeBinding typeBinding) { private static boolean isCollectionOrStreamType(org.eclipse.jdt.core.dom.ITypeBinding typeBinding) {
if (typeBinding == null) return false;
String fqn = typeBinding.getErasure().getQualifiedName(); String fqn = typeBinding.getErasure().getQualifiedName();
if (fqn.startsWith("java.util.stream.") || if (fqn.startsWith("java.util.stream.") ||
fqn.equals("java.lang.Iterable") || fqn.equals("java.lang.Iterable") ||

View File

@@ -446,6 +446,7 @@ public class CodebaseContext {
} }
public String getSuperclassFqn(TypeDeclaration td) { public String getSuperclassFqn(TypeDeclaration td) {
if (td == null) return null;
ITypeBinding binding = td.resolveBinding(); ITypeBinding binding = td.resolveBinding();
if (binding != null) { if (binding != null) {
ITypeBinding superBinding = binding.getSuperclass(); ITypeBinding superBinding = binding.getSuperclass();
@@ -458,7 +459,7 @@ public class CodebaseContext {
if (superType == null) return null; if (superType == null) return null;
String superName = extractTypeName(superType); String superName = extractTypeName(superType);
CompilationUnit cu = (CompilationUnit) td.getRoot(); CompilationUnit cu = (td.getRoot() instanceof CompilationUnit) ? (CompilationUnit) td.getRoot() : null;
TypeDeclaration superTd = getTypeDeclaration(superName, cu); TypeDeclaration superTd = getTypeDeclaration(superName, cu);
return superTd != null ? getFqn(superTd) : superName; return superTd != null ? getFqn(superTd) : superName;
} }
@@ -475,10 +476,11 @@ public class CodebaseContext {
} }
public MethodDeclaration findMethodDeclaration(TypeDeclaration td, String methodName, boolean includeSuper) { public MethodDeclaration findMethodDeclaration(TypeDeclaration td, String methodName, boolean includeSuper) {
if (td == null) return null;
ITypeBinding binding = td.resolveBinding(); ITypeBinding binding = td.resolveBinding();
if (binding != null && includeSuper) { if (binding != null && includeSuper) {
IMethodBinding methodBinding = findMethodBinding(binding, methodName); IMethodBinding methodBinding = findMethodBinding(binding, methodName);
if (methodBinding != null) { if (methodBinding != null && methodBinding.getDeclaringClass() != null) {
CompilationUnit declaringCu = classes.get(methodBinding.getDeclaringClass().getErasure().getQualifiedName()); CompilationUnit declaringCu = classes.get(methodBinding.getDeclaringClass().getErasure().getQualifiedName());
if (declaringCu != null) { if (declaringCu != null) {
ASTNode declNode = declaringCu.findDeclaringNode(methodBinding.getKey()); ASTNode declNode = declaringCu.findDeclaringNode(methodBinding.getKey());
@@ -523,6 +525,7 @@ public class CodebaseContext {
} }
private MethodDeclaration findMethodDeclarationLegacy(TypeDeclaration td, String methodName, boolean includeSuper) { private MethodDeclaration findMethodDeclarationLegacy(TypeDeclaration td, String methodName, boolean includeSuper) {
if (td == null) return null;
for (MethodDeclaration method : td.getMethods()) { for (MethodDeclaration method : td.getMethods()) {
if (method.getName().getIdentifier().equals(methodName)) { if (method.getName().getIdentifier().equals(methodName)) {
return method; return method;
@@ -542,7 +545,7 @@ public class CodebaseContext {
for (Object interfaceTypeObj : td.superInterfaceTypes()) { for (Object interfaceTypeObj : td.superInterfaceTypes()) {
Type interfaceType = (Type) interfaceTypeObj; Type interfaceType = (Type) interfaceTypeObj;
String interfaceName = extractTypeName(interfaceType); 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) { if (interfaceTd != null) {
MethodDeclaration found = findMethodDeclarationLegacy(interfaceTd, methodName, true); MethodDeclaration found = findMethodDeclarationLegacy(interfaceTd, methodName, true);
if (found != null) return found; if (found != null) return found;
@@ -641,6 +644,7 @@ public class CodebaseContext {
} }
public String getFqn(AbstractTypeDeclaration atd) { public String getFqn(AbstractTypeDeclaration atd) {
if (atd == null) return null;
StringBuilder sb = new StringBuilder(atd.getName().getIdentifier()); StringBuilder sb = new StringBuilder(atd.getName().getIdentifier());
ASTNode current = atd.getParent(); ASTNode current = atd.getParent();
while (current instanceof AbstractTypeDeclaration parent) { while (current instanceof AbstractTypeDeclaration parent) {
@@ -648,7 +652,10 @@ public class CodebaseContext {
current = parent.getParent(); 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 packageName = cu.getPackage() != null ? cu.getPackage().getName().getFullyQualifiedName() : "";
String fqn = sb.toString(); String fqn = sb.toString();
return packageName.isEmpty() ? fqn : packageName + "." + fqn; return packageName.isEmpty() ? fqn : packageName + "." + fqn;