update number 4

This commit is contained in:
2026-07-05 15:11:09 +02:00
parent 3988864494
commit bcdbbffa13
3 changed files with 94 additions and 1 deletions

View File

@@ -194,6 +194,30 @@ public abstract class AbstractCallGraphEngine implements CallGraphEngine {
if (paramIndex < edge.getArguments().size()) {
String arg = edge.getArguments().get(paramIndex);
if (arg != null) {
if (arg.contains("(") && !arg.startsWith("new ")) {
org.eclipse.jdt.core.dom.ASTParser argParser = org.eclipse.jdt.core.dom.ASTParser.newParser(org.eclipse.jdt.core.dom.AST.JLS17);
argParser.setKind(org.eclipse.jdt.core.dom.ASTParser.K_EXPRESSION);
argParser.setSource(arg.toCharArray());
org.eclipse.jdt.core.dom.ASTNode argNode = argParser.createAST(null);
if (argNode instanceof org.eclipse.jdt.core.dom.MethodInvocation miArg && !miArg.arguments().isEmpty()) {
boolean shouldUnpack = false;
org.eclipse.jdt.core.dom.Expression recv = miArg.getExpression();
if (recv == null || recv instanceof org.eclipse.jdt.core.dom.ThisExpression) {
shouldUnpack = true;
} else if (recv instanceof org.eclipse.jdt.core.dom.SimpleName sn) {
shouldUnpack = !Character.isLowerCase(sn.getIdentifier().charAt(0));
} else if (recv instanceof org.eclipse.jdt.core.dom.QualifiedName qn) {
shouldUnpack = !Character.isLowerCase(qn.getName().getIdentifier().charAt(0));
}
if (shouldUnpack) {
org.eclipse.jdt.core.dom.Expression innerArg = (org.eclipse.jdt.core.dom.Expression) miArg.arguments().get(0);
if (miArg.getName().getIdentifier().equals("valueOf") && miArg.arguments().size() == 2) {
innerArg = (org.eclipse.jdt.core.dom.Expression) miArg.arguments().get(1);
}
arg = innerArg.toString();
}
}
}
String receiver = edge.getReceiver();
String actualReceiver = null;
if ("this".equals(arg) || arg.startsWith("this.") || "super".equals(arg) || arg.startsWith("super.")) {

View File

@@ -164,6 +164,10 @@ public class JdtCallGraphEngine extends AbstractCallGraphEngine {
List<String> allResolved = new ArrayList<>();
if (node.getExpression() == null) {
return Collections.singletonList(baseCalled);
}
if (baseCalled.contains(".")) {
String className = baseCalled.substring(0, baseCalled.lastIndexOf('.'));
String methodName = baseCalled.substring(baseCalled.lastIndexOf('.') + 1);
@@ -177,7 +181,8 @@ public class JdtCallGraphEngine extends AbstractCallGraphEngine {
if (td != null) {
isAbstractOrInterface = td.isInterface() || (td.modifiers() != null && td.modifiers().toString().contains("abstract"));
}
if (!isAbstractOrInterface) {
boolean isImplicitThis = node.getExpression() == null || node.getExpression() instanceof ThisExpression;
if (!isAbstractOrInterface || isImplicitThis) {
allResolved.add(baseCalled);
}
for (String impl : impls) {