update argument resolution to

This commit is contained in:
2026-06-28 07:05:36 +02:00
parent 93688ef59b
commit 858e4524c8
2 changed files with 26 additions and 12 deletions

View File

@@ -237,12 +237,14 @@ public class HeuristicBeanResolutionEngine implements BeanResolutionEngine {
org.eclipse.jdt.core.dom.TypeDeclaration td = context.getTypeDeclaration(machineName); org.eclipse.jdt.core.dom.TypeDeclaration td = context.getTypeDeclaration(machineName);
if (td != null) { if (td != null) {
org.eclipse.jdt.core.dom.Type superclass = td.getSuperclassType(); org.eclipse.jdt.core.dom.Type superclass = td.getSuperclassType();
return findTypeArgumentsRecursively(superclass, context, (org.eclipse.jdt.core.dom.CompilationUnit) td.getRoot()); Set<String> visited = new HashSet<>();
visited.add(machineName);
return findTypeArgumentsRecursively(superclass, context, (org.eclipse.jdt.core.dom.CompilationUnit) td.getRoot(), visited);
} }
return new String[]{null, null}; return new String[]{null, null};
} }
private String[] findTypeArgumentsRecursively(org.eclipse.jdt.core.dom.Type type, CodebaseContext context, org.eclipse.jdt.core.dom.CompilationUnit cu) { private String[] findTypeArgumentsRecursively(org.eclipse.jdt.core.dom.Type type, CodebaseContext context, org.eclipse.jdt.core.dom.CompilationUnit cu, Set<String> visited) {
if (type == null) return new String[]{null, null}; if (type == null) return new String[]{null, null};
if (type instanceof org.eclipse.jdt.core.dom.ParameterizedType pt) { if (type instanceof org.eclipse.jdt.core.dom.ParameterizedType pt) {
@@ -258,20 +260,28 @@ public class HeuristicBeanResolutionEngine implements BeanResolutionEngine {
} }
// Recurse into the raw type declaration's superclass // Recurse into the raw type declaration's superclass
org.eclipse.jdt.core.dom.TypeDeclaration td = context.getTypeDeclaration(rawTypeName, cu); org.eclipse.jdt.core.dom.AbstractTypeDeclaration td = context.getAbstractTypeDeclaration(rawTypeName, cu);
if (td != null) { if (td != null) {
String[] res = findTypeArgumentsRecursively(td.getSuperclassType(), context, (org.eclipse.jdt.core.dom.CompilationUnit) td.getRoot()); String fqn = context.getFqn(td);
if (visited.add(fqn)) {
org.eclipse.jdt.core.dom.Type superclass = (td instanceof org.eclipse.jdt.core.dom.TypeDeclaration) ? ((org.eclipse.jdt.core.dom.TypeDeclaration) td).getSuperclassType() : null;
String[] res = findTypeArgumentsRecursively(superclass, context, (org.eclipse.jdt.core.dom.CompilationUnit) td.getRoot(), visited);
if (res[0] != null || res[1] != null) return res; if (res[0] != null || res[1] != null) return res;
} }
}
} else { } else {
// It's a simple type (e.g. MyBaseConfig) // It's a simple type (e.g. MyBaseConfig)
String simpleName = type.toString(); String simpleName = type.toString();
org.eclipse.jdt.core.dom.TypeDeclaration td = context.getTypeDeclaration(simpleName, cu); org.eclipse.jdt.core.dom.AbstractTypeDeclaration td = context.getAbstractTypeDeclaration(simpleName, cu);
if (td != null) { if (td != null) {
String[] res = findTypeArgumentsRecursively(td.getSuperclassType(), context, (org.eclipse.jdt.core.dom.CompilationUnit) td.getRoot()); String fqn = context.getFqn(td);
if (visited.add(fqn)) {
org.eclipse.jdt.core.dom.Type superclass = (td instanceof org.eclipse.jdt.core.dom.TypeDeclaration) ? ((org.eclipse.jdt.core.dom.TypeDeclaration) td).getSuperclassType() : null;
String[] res = findTypeArgumentsRecursively(superclass, context, (org.eclipse.jdt.core.dom.CompilationUnit) td.getRoot(), visited);
if (res[0] != null || res[1] != null) return res; if (res[0] != null || res[1] != null) return res;
} }
} }
}
return new String[]{null, null}; return new String[]{null, null};
} }

View File

@@ -422,7 +422,7 @@ public class GenericEventDetector {
ITypeBinding binding = receiver.resolveTypeBinding(); ITypeBinding binding = receiver.resolveTypeBinding();
if (binding != null) { if (binding != null) {
ITypeBinding smBinding = findStateMachineSupertype(binding); ITypeBinding smBinding = findStateMachineSupertype(binding, new java.util.HashSet<>());
if (smBinding != null) { if (smBinding != null) {
ITypeBinding[] typeArgs = smBinding.getTypeArguments(); ITypeBinding[] typeArgs = smBinding.getTypeArguments();
if (typeArgs.length >= 2) { if (typeArgs.length >= 2) {
@@ -446,14 +446,18 @@ public class GenericEventDetector {
return new String[]{null, null}; return new String[]{null, null};
} }
private ITypeBinding findStateMachineSupertype(ITypeBinding binding) { private ITypeBinding findStateMachineSupertype(ITypeBinding binding, java.util.Set<String> visited) {
ITypeBinding current = binding; ITypeBinding current = binding;
while (current != null) { while (current != null) {
if (current.getErasure().getQualifiedName().equals("org.springframework.statemachine.StateMachine")) { String erasureName = current.getErasure().getQualifiedName();
if (erasureName != null && !visited.add(erasureName)) {
return null;
}
if ("org.springframework.statemachine.StateMachine".equals(erasureName)) {
return current; return current;
} }
for (ITypeBinding iface : current.getInterfaces()) { for (ITypeBinding iface : current.getInterfaces()) {
ITypeBinding res = findStateMachineSupertype(iface); ITypeBinding res = findStateMachineSupertype(iface, visited);
if (res != null) return res; if (res != null) return res;
} }
current = current.getSuperclass(); current = current.getSuperclass();