update tranistions 3

This commit is contained in:
2026-06-28 10:33:08 +02:00
parent 96fc975170
commit f4188f4384

View File

@@ -258,7 +258,7 @@ public class VariableTracer {
for (Expression expr : initializers) { for (Expression expr : initializers) {
Expression traced = traceVariable(expr); Expression traced = traceVariable(expr);
if (traced instanceof MethodInvocation mi) { if (traced instanceof MethodInvocation mi) {
Expression innerMost = unwrapMethodInvocation(mi, 0, methodFqn); Expression innerMost = unwrapMethodInvocation(mi, 0);
stringified.add(innerMost.toString()); stringified.add(innerMost.toString());
} else if (traced instanceof ArrayInitializer) { } else if (traced instanceof ArrayInitializer) {
stringified.add("new Object[]" + traced.toString()); stringified.add("new Object[]" + traced.toString());
@@ -513,61 +513,13 @@ public class VariableTracer {
return (TypeDeclaration) parent; return (TypeDeclaration) parent;
} }
private int getReturnedParameterIndex(MethodDeclaration md) { private Expression unwrapMethodInvocation(MethodInvocation mi, int depth) {
if (md.getBody() == null) return -1;
List<?> parameters = md.parameters();
if (parameters.isEmpty()) return -1;
final List<String> returnedExprs = new ArrayList<>();
md.getBody().accept(new ASTVisitor() {
@Override
public boolean visit(ReturnStatement node) {
if (node.getExpression() != null) {
returnedExprs.add(node.getExpression().toString());
}
return super.visit(node);
}
});
if (returnedExprs.size() == 1) {
String retStr = returnedExprs.get(0);
for (int i = 0; i < parameters.size(); i++) {
if (parameters.get(i) instanceof SingleVariableDeclaration svd) {
if (svd.getName().getIdentifier().equals(retStr)) {
return i;
}
}
}
}
return -1;
}
private Expression unwrapMethodInvocation(MethodInvocation mi, int depth, String methodFqn) {
if (depth > 5) return mi; if (depth > 5) return mi;
if (mi.getExpression() != null) { if (mi.getExpression() != null) {
String exprStr = mi.getExpression().toString(); String exprStr = mi.getExpression().toString();
if (!exprStr.equals("Optional") && !exprStr.equals("Stream") && !exprStr.equals("List") && !exprStr.equals("Set") && !exprStr.equals("Arrays") && !exprStr.equals("Objects") && !exprStr.equals("Mono") && !exprStr.equals("Flux")) { if (!exprStr.equals("Optional") && !exprStr.equals("Stream") && !exprStr.equals("List") && !exprStr.equals("Set") && !exprStr.equals("Arrays") && !exprStr.equals("Objects") && !exprStr.equals("Mono") && !exprStr.equals("Flux")) {
return mi; return mi;
} }
} else {
if (methodFqn != null && methodFqn.contains(".")) {
String className = methodFqn.substring(0, methodFqn.lastIndexOf('.'));
TypeDeclaration td = context.getTypeDeclaration(className);
if (td != null) {
MethodDeclaration localMd = context.findMethodDeclaration(td, mi.getName().getIdentifier(), true);
if (localMd != null) {
int paramIdx = getReturnedParameterIndex(localMd);
if (paramIdx >= 0 && paramIdx < mi.arguments().size()) {
Expression arg = (Expression) mi.arguments().get(paramIdx);
if (arg instanceof MethodInvocation innerMi) {
return unwrapMethodInvocation(innerMi, depth + 1, methodFqn);
}
return arg;
}
}
}
}
return mi;
} }
if (!mi.arguments().isEmpty()) { if (!mi.arguments().isEmpty()) {
@@ -582,13 +534,13 @@ public class VariableTracer {
lowerName.startsWith("derive") || lowerName.startsWith("determine") || lowerName.startsWith("derive") || lowerName.startsWith("determine") ||
lowerName.startsWith("calculate") || lowerName.startsWith("decode") || lowerName.startsWith("calculate") || lowerName.startsWith("decode") ||
lowerName.startsWith("extract") || lowerName.startsWith("get") || lowerName.startsWith("extract") || lowerName.startsWith("get") ||
lowerName.startsWith("find")) { lowerName.startsWith("find") || lowerName.startsWith("validate")) {
return mi; return mi;
} }
Expression arg = (Expression) mi.arguments().get(0); Expression arg = (Expression) mi.arguments().get(0);
if (arg instanceof MethodInvocation innerMi) { if (arg instanceof MethodInvocation innerMi) {
return unwrapMethodInvocation(innerMi, depth + 1, methodFqn); return unwrapMethodInvocation(innerMi, depth + 1);
} }
return arg; return arg;
} }