adding java parsing but it should be bytecode to java and parsing that
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package click.kamil.callgraphexporter;
|
||||
|
||||
import click.kamil.callgraphexporter.domain.MethodMetadata;
|
||||
import click.kamil.callgraphexporter.domain.MethodSignature;
|
||||
import click.kamil.callgraphexporter.domain.Modifiers;
|
||||
import org.eclipse.jdt.core.JavaCore;
|
||||
import org.eclipse.jdt.core.dom.*;
|
||||
|
||||
@@ -93,9 +96,8 @@ public class JdtResolvedCallGraph {
|
||||
});
|
||||
}
|
||||
|
||||
// Fixed: matches your MethodSignature record with only methodName and paramTypes
|
||||
private static MethodSignature toSignature(IMethodBinding binding) {
|
||||
String packageName = binding.getDeclaringClass().getPackage().getName();
|
||||
String className = binding.getDeclaringClass().getName();
|
||||
String methodName = binding.getName();
|
||||
|
||||
List<String> paramTypes = new ArrayList<>();
|
||||
@@ -103,7 +105,7 @@ public class JdtResolvedCallGraph {
|
||||
paramTypes.add(param.getName());
|
||||
}
|
||||
|
||||
return new MethodSignature(packageName, className, methodName, paramTypes);
|
||||
return new MethodSignature(methodName, paramTypes);
|
||||
}
|
||||
|
||||
private static MethodMetadata toMetadata(IMethodBinding binding, MethodDeclaration method) {
|
||||
@@ -123,18 +125,25 @@ public class JdtResolvedCallGraph {
|
||||
private static void generateDotFile(String filename) throws IOException {
|
||||
StringBuilder sb = new StringBuilder("digraph G {\n");
|
||||
for (MethodSignature caller : callGraph.keySet()) {
|
||||
String callerLabel = formatSignature(caller);
|
||||
for (MethodSignature callee : callGraph.get(caller)) {
|
||||
sb.append(" \"").append(caller).append("\" -> \"").append(callee).append("\";\n");
|
||||
String calleeLabel = formatSignature(callee);
|
||||
sb.append(" \"").append(callerLabel).append("\" -> \"").append(calleeLabel).append("\";\n");
|
||||
}
|
||||
}
|
||||
sb.append("}");
|
||||
Files.writeString(new File(filename).toPath(), sb.toString());
|
||||
}
|
||||
|
||||
private static String formatSignature(MethodSignature sig) {
|
||||
// Build a readable label (methodName + param list)
|
||||
return sig.methodName() + sig.parameterTypes();
|
||||
}
|
||||
|
||||
private static Set<Modifiers> extractModifiers(IMethodBinding binding, MethodDeclaration method) {
|
||||
Set<Modifiers> result = new HashSet<>();
|
||||
int mods = binding.getModifiers();
|
||||
|
||||
// 1. From bitmask
|
||||
if (Modifier.isPublic(mods)) result.add(Modifiers.PUBLIC);
|
||||
if (Modifier.isPrivate(mods)) result.add(Modifiers.PRIVATE);
|
||||
if (Modifier.isProtected(mods)) result.add(Modifiers.PROTECTED);
|
||||
@@ -145,13 +154,10 @@ public class JdtResolvedCallGraph {
|
||||
if (Modifier.isSynchronized(mods)) result.add(Modifiers.SYNCHRONIZED);
|
||||
if (Modifier.isStrictfp(mods)) result.add(Modifiers.STRICTFP);
|
||||
|
||||
// 2. From modifiers list for special cases
|
||||
for (Object mod : method.modifiers()) {
|
||||
if (mod instanceof Modifier keyword) {
|
||||
if (keyword.isDefault()) result.add(Modifiers.DEFAULT);
|
||||
// NOTE: isSealed and isNonSealed are class-level only
|
||||
}
|
||||
// If needed, check for annotation modifiers here
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package click.kamil.callgraphexporter;
|
||||
package click.kamil.callgraphexporter.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -1,4 +1,4 @@
|
||||
package click.kamil.callgraphexporter;
|
||||
package click.kamil.callgraphexporter.domain;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -1,10 +1,8 @@
|
||||
package click.kamil.callgraphexporter;
|
||||
package click.kamil.callgraphexporter.domain;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record MethodSignature(
|
||||
String packageName,
|
||||
String className,
|
||||
String methodName,
|
||||
List<String> parameterTypes
|
||||
) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package click.kamil.callgraphexporter;
|
||||
package click.kamil.callgraphexporter.domain;
|
||||
|
||||
public enum Modifiers {
|
||||
PUBLIC,
|
||||
@@ -16,4 +16,3 @@ public enum Modifiers {
|
||||
SEALED,
|
||||
NON_SEALED,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package click.kamil.callgraphexporter.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TypeGroup {
|
||||
private String packageName;
|
||||
private String typeName;
|
||||
private TypeKind typeKind;
|
||||
private EnumSet<Modifiers> modifiers = EnumSet.noneOf(Modifiers.class);
|
||||
private List<Method> methods = new ArrayList<>();
|
||||
|
||||
public void addMethod(Method method) {
|
||||
methods.add(method);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package click.kamil.callgraphexporter.domain;
|
||||
|
||||
public enum TypeKind {
|
||||
CLASS,
|
||||
INTERFACE,
|
||||
RECORD,
|
||||
ENUM,
|
||||
ANNOTATION
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import java.util.*;
|
||||
public class JavaConcatenator {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
Path sourceDir = Path.of("./src/main/java/click/kamil/springstatemachineexporter/ast");
|
||||
Path sourceDir = Path.of("./src/main/java/click/kamil/callgraphexporter/domain");
|
||||
Path outputFile = Path.of("./Combined.java");
|
||||
|
||||
String targetPackage = "click.kamil";
|
||||
|
||||
Reference in New Issue
Block a user