Skip to content

Commit 2ab0f3d

Browse files
committed
re
1 parent 1ffc25c commit 2ab0f3d

File tree

5 files changed

+22
-54
lines changed

5 files changed

+22
-54
lines changed

mirror-common/src/main/java/cn/com/mirror/analyser/visitor/ControlEdgeVisitor.java

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import lombok.Getter;
88
import lombok.extern.slf4j.Slf4j;
99
import org.eclipse.jdt.core.dom.*;
10-
import org.neo4j.cypher.internal.compiler.v2_3.commands.AstNode;
1110

1211
import java.util.Arrays;
1312
import java.util.HashMap;
@@ -26,7 +25,6 @@
2625
public class ControlEdgeVisitor extends ASTVisitor {
2726
private String targetPath;
2827

29-
private Map<Integer, Integer> controlEdges = new HashMap<>();
3028
private Map<Vertex, Vertex> ctrlEdges = new HashMap<>();
3129

3230
public ControlEdgeVisitor(String targetPath) {
@@ -44,8 +42,6 @@ private ASTNode searchDirectParentControlNode(ASTNode astNode) {
4442
// mark the s between astNode and statements and return
4543
int currentLine = AstUtils.getSpecificStartLine(astNode);
4644
int directParentStartLine = AstUtils.getSpecificStartLine(parent);
47-
markEdges(currentLine, directParentStartLine);
48-
4945
markCtrlEdge(currentLine, astNode, directParentStartLine, parent);
5046
return parent;
5147
}
@@ -98,52 +94,29 @@ private boolean markCtrlEdge(int curLine,
9894
return false;
9995
}
10096

101-
VertexTypeEnum headType = null;
102-
if (astNode instanceof MethodDeclaration) {
103-
headType = VertexTypeEnum.METHOD;
104-
} else {
105-
headType = VertexTypeEnum.STATEMENT;
106-
}
107-
108-
Vertex head = new Vertex(this.targetPath, curLine, headType);
109-
110-
VertexTypeEnum tailType = null;
111-
if (parent instanceof MethodDeclaration) {
112-
tailType = VertexTypeEnum.METHOD;
113-
} else {
114-
tailType = VertexTypeEnum.STATEMENT;
115-
}
116-
Vertex tail = new Vertex(this.targetPath, parentLine, tailType);
97+
Vertex head = new Vertex(this.targetPath, curLine, checkVertexType(astNode), null, -1);
98+
Vertex tail = new Vertex(this.targetPath, parentLine, checkVertexType(parent), null, -1);
11799
ctrlEdges.put(head, tail);
118100

119101
return true;
120102
}
121103

122-
private boolean markEdges(int curLine, int parentLine) {
123-
if (-1 != parentLine &&
124-
curLine != parentLine) {
125-
controlEdges.put(curLine, parentLine);
126-
return true;
127-
}
128-
129-
return false;
104+
private VertexTypeEnum checkVertexType(ASTNode node) {
105+
if (node instanceof TypeDeclaration) return VertexTypeEnum.CLASS;
106+
if (node instanceof MethodDeclaration) return VertexTypeEnum.METHOD;
107+
if (node instanceof FieldDeclaration) return VertexTypeEnum.FIELD;
108+
return VertexTypeEnum.STATEMENT;
130109
}
131110

132-
// @Override
133-
// public boolean visit(SimpleName node) {
134-
// searchDirectParentControlNode(node);
135-
// return super.visit(node);
136-
// }
137-
138111
@Override
139112
public boolean visit(TypeDeclaration node) {
140113
int typeDecLine = AstUtils.getStartLine(node.getName());
141114
Arrays.stream(node.getFields()).forEach(fieldDeclaration -> {
142-
markEdges(AstUtils.getSpecificStartLine(fieldDeclaration.getType()), typeDecLine);
115+
markCtrlEdge(AstUtils.getSpecificStartLine(fieldDeclaration), fieldDeclaration, typeDecLine, node);
143116
});
144117

145118
Arrays.stream(node.getMethods()).forEach(methodDeclaration -> {
146-
markEdges(AstUtils.getSpecificStartLine(methodDeclaration.getName()), typeDecLine);
119+
markCtrlEdge(AstUtils.getSpecificStartLine(methodDeclaration), methodDeclaration, typeDecLine, node);
147120
});
148121

149122
return super.visit(node);

mirror-common/src/main/java/cn/com/mirror/project/pair/Vertex.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,20 @@ public class Vertex implements Serializable {
1616
private String targetPath;
1717
private int lineNum;
1818
private VertexTypeEnum vertexType;
19+
private String host;
20+
private int port;
21+
22+
public Vertex(String targetPath,
23+
int lineNum,
24+
VertexTypeEnum vertexType,
25+
String host,
26+
int port) {
1927

20-
public Vertex(String targetPath, int lineNum, VertexTypeEnum vertexType) {
2128
this.targetPath = targetPath;
2229
this.lineNum = lineNum;
2330
this.vertexType = vertexType;
31+
this.host = host;
32+
this.port = port;
2433
}
2534

2635
@Override

mirror-common/src/main/java/cn/com/mirror/project/pair/VertexTypeEnum.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
@Getter
1111
public enum VertexTypeEnum {
1212
STATEMENT(1, "statement"),
13-
METHOD(2, "method");
13+
FIELD(2, "field"),
14+
METHOD(3, "method"),
15+
CLASS(4, "class");
1416

1517
private Integer key;
1618
private String desc;

mirror-common/src/main/java/cn/com/mirror/project/pair/factory/PairFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public Pair newPair(String repositoryUrl) {
2323
ControlEdgeVisitor controlEdgeVisitor = new ControlEdgeVisitor(targetPath);
2424
CompilationUnit compilationUnit = AstUtils.getCompUnitResolveBinding(targetPath);
2525
compilationUnit.accept(controlEdgeVisitor);
26-
pair.addDirectCtrlEdges(targetPath, controlEdgeVisitor.getControlEdges());
2726
pair.addCtrlEdge(targetPath, controlEdgeVisitor.getCtrlEdges());
2827
});
2928

mirror-common/src/test/cn/com/mirror/analyser/UnitAnalyserTests.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package cn.com.mirror.analyser;
22

3-
import cn.com.mirror.analyser.visitor.ControlEdgeVisitor;
43
import cn.com.mirror.project.unit.Unit;
54
import cn.com.mirror.project.unit.element.Class;
65
import cn.com.mirror.project.unit.element.Method;
76
import cn.com.mirror.project.unit.element.Statement;
87
import lombok.extern.slf4j.Slf4j;
9-
import org.eclipse.jdt.core.dom.CompilationUnit;
108
import org.junit.Test;
119

1210
import java.util.Map;
@@ -27,19 +25,6 @@ public void init() {
2725
this.unit = unitAnalyser.analyze();
2826
}
2927

30-
@Test
31-
public void testControlDependenceVisitor() {
32-
init();
33-
34-
unit.getTargets().stream().forEach(targetPah -> {
35-
ControlEdgeVisitor controlDependenceVisitor = new ControlEdgeVisitor(targetPah);
36-
CompilationUnit compilationUnit = unit.getCompilationUnits().get(targetPah);
37-
compilationUnit.accept(controlDependenceVisitor);
38-
log.info("Target path: {}", targetPah);
39-
log.info("Control edges: {}", controlDependenceVisitor.getControlEdges());
40-
});
41-
}
42-
4328
@Test
4429
public void testCls() {
4530
init();

0 commit comments

Comments
 (0)