diff --git a/state_machine_exporter/src/main/java/click/kamil/springstatemachineexporter/analysis/resolver/ConstantResolver.java b/state_machine_exporter/src/main/java/click/kamil/springstatemachineexporter/analysis/resolver/ConstantResolver.java index 9121d8e..71f1735 100644 --- a/state_machine_exporter/src/main/java/click/kamil/springstatemachineexporter/analysis/resolver/ConstantResolver.java +++ b/state_machine_exporter/src/main/java/click/kamil/springstatemachineexporter/analysis/resolver/ConstantResolver.java @@ -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()) { diff --git a/state_machine_exporter/src/main/java/click/kamil/springstatemachineexporter/analysis/service/AbstractCallGraphEngine.java b/state_machine_exporter/src/main/java/click/kamil/springstatemachineexporter/analysis/service/AbstractCallGraphEngine.java index 7f22480..adbca37 100644 --- a/state_machine_exporter/src/main/java/click/kamil/springstatemachineexporter/analysis/service/AbstractCallGraphEngine.java +++ b/state_machine_exporter/src/main/java/click/kamil/springstatemachineexporter/analysis/service/AbstractCallGraphEngine.java @@ -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";