-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAbstractGraphEdge.java
More file actions
121 lines (107 loc) · 2.93 KB
/
AbstractGraphEdge.java
File metadata and controls
121 lines (107 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
Copyright IBM Corporation 2023, 2024
Licensed under the Apache Public License 2.0, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.ibm.cldk.entities;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.slicer.Statement;
import com.ibm.wala.shrike.shrikeCT.InvalidClassFileException;
import com.ibm.wala.ssa.IR;
import com.ibm.wala.ssa.SSAInstruction;
import org.jgrapht.nio.Attribute;
import java.io.Serializable;
import java.util.Map;
/**
* The type Abstract graph edge.
*/
public abstract class AbstractGraphEdge implements Serializable {
/**
* The Context.
*/
public final String context;
/**
* The Weight.
*/
public Integer weight = 1;
/**
* Instantiates a new Abstract graph edge.
*/
protected AbstractGraphEdge() {
this(null);
}
/**
* Instantiates a new Abstract graph edge.
*
* @param context the context
*/
protected AbstractGraphEdge(String context) {
this.context = context;
}
/**
* Increment weight.
*/
public void incrementWeight() {
this.weight += 1;
}
/**
* Gets context.
*
* @return the context
*/
public String getContext() {
return this.context;
}
/**
* Gets id.
*
* @return the id
*/
public Integer getId() {
return this.hashCode();
}
/**
* Gets weight.
*
* @return the weight
*/
public Integer getWeight() {
return this.weight;
}
/**
* Gets statement position.
*
* @param statement the statement
* @return the statement position
*/
Integer getStatementPosition(Statement statement) {
CGNode statementNode = statement.getNode();
IR statementIR = statementNode.getIR();
Integer pos = null;
// TODO: check this assumption: the same source instruction maps to several
// SSAInstructions,
// therefore it is sufficient to return the position of the first statement.
for (SSAInstruction inst : statementNode.getIR().getInstructions()) {
try {
pos = statementIR.getMethod().getSourcePosition(inst.iIndex()).getLastLine();
return pos;
} catch (InvalidClassFileException e) {
throw new RuntimeException(e);
} catch (NullPointerException npe) {
return -1;
}
}
return pos;
}
/**
* Gets attributes.
*
* @return the attributes
*/
public abstract Map<String, Attribute> getAttributes();
}