Skip to content

Commit 7a587cf

Browse files
committed
Implement Spring DI extraction and FieldNode annotation modeling
1 parent a1a5f35 commit 7a587cf

9 files changed

Lines changed: 347 additions & 25 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.neuvem.java2graph.models;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class AnnotationInfo {
7+
public String name;
8+
public Map<String, String> attributes = new HashMap<>();
9+
10+
public AnnotationInfo() {}
11+
12+
public AnnotationInfo(String name) {
13+
this.name = name;
14+
}
15+
}

src/main/java/com/neuvem/java2graph/models/ClassNode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class ClassNode {
1010
private boolean isInterface;
1111
private String declarationCode;
1212
private String filePath;
13-
private List<String> annotations;
13+
private List<AnnotationInfo> annotations;
1414
private boolean isExternal;
1515

1616
public ClassNode() {}
@@ -33,11 +33,11 @@ public ClassNode() {}
3333
public String getFilePath() { return filePath; }
3434
public void setFilePath(String filePath) { this.filePath = filePath; }
3535

36-
public List<String> getAnnotations() {
36+
public List<AnnotationInfo> getAnnotations() {
3737
if (annotations == null) annotations = new ArrayList<>();
3838
return annotations;
3939
}
40-
public void setAnnotations(List<String> annotations) { this.annotations = annotations; }
40+
public void setAnnotations(List<AnnotationInfo> annotations) { this.annotations = annotations; }
4141

4242
public boolean isExternal() { return isExternal; }
4343
public void setExternal(boolean isExternal) { this.isExternal = isExternal; }
@@ -52,7 +52,7 @@ public static class Builder {
5252
public Builder isInterface(boolean isInterface) { node.isInterface = isInterface; return this; }
5353
public Builder declarationCode(String code) { node.declarationCode = code; return this; }
5454
public Builder filePath(String filePath) { node.filePath = filePath; return this; }
55-
public Builder annotations(List<String> annotations) { node.annotations = annotations; return this; }
55+
public Builder annotations(List<AnnotationInfo> annotations) { node.annotations = annotations; return this; }
5656
public Builder isExternal(boolean isExternal) { node.isExternal = isExternal; return this; }
5757
public ClassNode build() { return node; }
5858
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.neuvem.java2graph.models;
2+
3+
import java.util.Objects;
4+
5+
public class DependencyEdge {
6+
private String sourceFqn;
7+
private String targetFqn;
8+
private String injectionType;
9+
10+
public DependencyEdge() {}
11+
12+
public String getSourceFqn() { return sourceFqn; }
13+
public void setSourceFqn(String sourceFqn) { this.sourceFqn = sourceFqn; }
14+
15+
public String getTargetFqn() { return targetFqn; }
16+
public void setTargetFqn(String targetFqn) { this.targetFqn = targetFqn; }
17+
18+
public String getInjectionType() { return injectionType; }
19+
public void setInjectionType(String injectionType) { this.injectionType = injectionType; }
20+
21+
@Override
22+
public boolean equals(Object o) {
23+
if (this == o) return true;
24+
if (o == null || getClass() != o.getClass()) return false;
25+
DependencyEdge that = (DependencyEdge) o;
26+
return Objects.equals(sourceFqn, that.sourceFqn) &&
27+
Objects.equals(targetFqn, that.targetFqn) &&
28+
Objects.equals(injectionType, that.injectionType);
29+
}
30+
31+
@Override
32+
public int hashCode() {
33+
return Objects.hash(sourceFqn, targetFqn, injectionType);
34+
}
35+
36+
public static Builder builder() { return new Builder(); }
37+
38+
public static class Builder {
39+
private DependencyEdge edge = new DependencyEdge();
40+
public Builder sourceFqn(String sourceFqn) { edge.sourceFqn = sourceFqn; return this; }
41+
public Builder targetFqn(String targetFqn) { edge.targetFqn = targetFqn; return this; }
42+
public Builder injectionType(String injectionType) { edge.injectionType = injectionType; return this; }
43+
public DependencyEdge build() { return edge; }
44+
}
45+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.neuvem.java2graph.models;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class FieldNode {
7+
private String id;
8+
private String fqn;
9+
private String name;
10+
private String typeFqn;
11+
private String containingClassFqn;
12+
private List<AnnotationInfo> annotations;
13+
private String filePath;
14+
15+
public FieldNode() {}
16+
17+
public String getId() { return id; }
18+
public void setId(String id) { this.id = id; }
19+
20+
public String getFqn() { return fqn; }
21+
public void setFqn(String fqn) { this.fqn = fqn; }
22+
23+
public String getName() { return name; }
24+
public void setName(String name) { this.name = name; }
25+
26+
public String getTypeFqn() { return typeFqn; }
27+
public void setTypeFqn(String typeFqn) { this.typeFqn = typeFqn; }
28+
29+
public String getContainingClassFqn() { return containingClassFqn; }
30+
public void setContainingClassFqn(String containingClassFqn) { this.containingClassFqn = containingClassFqn; }
31+
32+
public List<AnnotationInfo> getAnnotations() {
33+
if (annotations == null) annotations = new ArrayList<>();
34+
return annotations;
35+
}
36+
public void setAnnotations(List<AnnotationInfo> annotations) { this.annotations = annotations; }
37+
38+
public String getFilePath() { return filePath; }
39+
public void setFilePath(String filePath) { this.filePath = filePath; }
40+
41+
public static Builder builder() { return new Builder(); }
42+
43+
public static class Builder {
44+
private FieldNode node = new FieldNode();
45+
public Builder id(String id) { node.id = id; return this; }
46+
public Builder fqn(String fqn) { node.fqn = fqn; return this; }
47+
public Builder name(String name) { node.name = name; return this; }
48+
public Builder typeFqn(String typeFqn) { node.typeFqn = typeFqn; return this; }
49+
public Builder containingClassFqn(String containingClassFqn) { node.containingClassFqn = containingClassFqn; return this; }
50+
public Builder annotations(List<AnnotationInfo> annotations) { node.annotations = annotations; return this; }
51+
public Builder filePath(String filePath) { node.filePath = filePath; return this; }
52+
public FieldNode build() { return node; }
53+
}
54+
}

src/main/java/com/neuvem/java2graph/models/GraphContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
public class GraphContext {
77
public final ConcurrentHashMap<String, ClassNode> classes = new ConcurrentHashMap<>();
88
public final ConcurrentHashMap<String, MethodNode> methods = new ConcurrentHashMap<>();
9+
public final ConcurrentHashMap<String, FieldNode> fields = new ConcurrentHashMap<>();
910

1011
public final java.util.Set<InheritanceEdge> inheritanceEdges = ConcurrentHashMap.newKeySet();
1112
public final java.util.Set<MethodCallEdge> callEdges = ConcurrentHashMap.newKeySet();
13+
public final java.util.Set<DependencyEdge> dependencyEdges = ConcurrentHashMap.newKeySet();
1214

1315
// Store the type solver for use across passes (symbol-solver resolution)
1416
public Object typeSolver;

src/main/java/com/neuvem/java2graph/models/MethodNode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class MethodNode {
1212
private String containingClassFqn;
1313
private boolean isLambda;
1414
private String filePath;
15-
private List<String> annotations;
15+
private List<AnnotationInfo> annotations;
1616
private boolean isExternal;
1717

1818
public MethodNode() {}
@@ -41,11 +41,11 @@ public MethodNode() {}
4141
public String getFilePath() { return filePath; }
4242
public void setFilePath(String filePath) { this.filePath = filePath; }
4343

44-
public List<String> getAnnotations() {
44+
public List<AnnotationInfo> getAnnotations() {
4545
if (annotations == null) annotations = new ArrayList<>();
4646
return annotations;
4747
}
48-
public void setAnnotations(List<String> annotations) { this.annotations = annotations; }
48+
public void setAnnotations(List<AnnotationInfo> annotations) { this.annotations = annotations; }
4949

5050
public boolean isExternal() { return isExternal; }
5151
public void setExternal(boolean isExternal) { this.isExternal = isExternal; }
@@ -62,7 +62,7 @@ public static class Builder {
6262
public Builder containingClassFqn(String containingClassFqn) { node.containingClassFqn = containingClassFqn; return this; }
6363
public Builder isLambda(boolean isLambda) { node.isLambda = isLambda; return this; }
6464
public Builder filePath(String filePath) { node.filePath = filePath; return this; }
65-
public Builder annotations(List<String> annotations) { node.annotations = annotations; return this; }
65+
public Builder annotations(List<AnnotationInfo> annotations) { node.annotations = annotations; return this; }
6666
public Builder isExternal(boolean isExternal) { node.isExternal = isExternal; return this; }
6767
public MethodNode build() { return node; }
6868
}

0 commit comments

Comments
 (0)