another ai fix

This commit is contained in:
2026-07-06 22:09:23 +02:00
parent 4f8c35adef
commit a7bf07e8b2
2 changed files with 66 additions and 1 deletions

View File

@@ -798,11 +798,50 @@ public class ConstantResolver {
}
}
}
// Check superclass
if (td.getSuperclassType() != null) {
String superclassName = click.kamil.springstatemachineexporter.ast.common.AstUtils.extractSimpleTypeName(td.getSuperclassType());
String resolvedSuperclass = resolveTypeFqn(superclassName, context, td);
if (resolvedSuperclass != null) {
TypeDeclaration superTd = context.getTypeDeclaration(resolvedSuperclass);
if (superTd != null) {
String result = resolveFieldInType(superTd, fieldName, resolvedSuperclass, context, visited);
if (result != null) return result;
}
}
}
// Check superinterfaces
for (Object intfObj : td.superInterfaceTypes()) {
Type intfType = (Type) intfObj;
String intfName = click.kamil.springstatemachineexporter.ast.common.AstUtils.extractSimpleTypeName(intfType);
String resolvedIntf = resolveTypeFqn(intfName, context, td);
if (resolvedIntf != null) {
TypeDeclaration intfTd = context.getTypeDeclaration(resolvedIntf);
if (intfTd != null) {
String result = resolveFieldInType(intfTd, fieldName, resolvedIntf, context, visited);
if (result != null) return result;
}
}
}
} finally {
visited.remove(fieldId);
}
return null;
}
private String resolveTypeFqn(String simpleName, CodebaseContext context, TypeDeclaration td) {
CompilationUnit cu = (CompilationUnit) td.getRoot();
for (Object impObj : cu.imports()) {
ImportDeclaration imp = (ImportDeclaration) impObj;
String name = imp.getName().getFullyQualifiedName();
if (name.endsWith("." + simpleName)) {
return name;
}
}
return cu.getPackage().getName().getFullyQualifiedName() + "." + simpleName;
}
private String findValueFromAnnotation(FieldDeclaration fd) {
for (Object mod : fd.modifiers()) {

View File

@@ -372,7 +372,32 @@ public abstract class AbstractCallGraphEngine implements CallGraphEngine {
if (exprNode instanceof MethodInvocation mi) {
methodName = mi.getName().getIdentifier();
if (mi.getExpression() instanceof SimpleName sn) {
boolean handledStaticEnum = false;
if (methodName.equals("valueOf") && mi.arguments().size() == 1) {
Object arg = mi.arguments().get(0);
if (arg instanceof StringLiteral sl) {
polymorphicEvents.add(sl.getLiteralValue());
methodName = null;
handledStaticEnum = true;
} else if (arg instanceof QualifiedName qn) {
polymorphicEvents.add(qn.getName().getIdentifier());
methodName = null;
handledStaticEnum = true;
}
} else if (methodName.equals("name") && mi.arguments().isEmpty()) {
if (mi.getExpression() instanceof QualifiedName qn) {
polymorphicEvents.add(qn.getName().getIdentifier());
methodName = null;
handledStaticEnum = true;
} else if (mi.getExpression() instanceof SimpleName sn) {
polymorphicEvents.add(sn.getIdentifier());
methodName = null;
handledStaticEnum = true;
}
}
if (!handledStaticEnum) {
if (mi.getExpression() instanceof SimpleName sn) {
varName = sn.getIdentifier();
} else if (mi.getExpression() instanceof ParenthesizedExpression pe &&
pe.getExpression() instanceof CastExpression ce &&
@@ -449,6 +474,7 @@ public abstract class AbstractCallGraphEngine implements CallGraphEngine {
varName = exprStr;
}
}
}
} else if (exprNode instanceof ClassInstanceCreation cic) {
declaredType = click.kamil.springstatemachineexporter.ast.common.AstUtils.extractSimpleTypeName(cic.getType());
sourceMethod = "inline-instantiation";