Skip to content

Commit 96f2314

Browse files
author
Niklas
committed
Generalize MethodAndClass to support other languages
1 parent 3fd69bd commit 96f2314

File tree

2 files changed

+122
-93
lines changed

2 files changed

+122
-93
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package soot.jimple.infoflow.data;
2+
3+
import java.util.List;
4+
5+
/**
6+
* Abstract class for all MethodAndClass containers.
7+
*
8+
* @author Steven Arzt
9+
* @author Niklas Vogel
10+
*
11+
*/
12+
public abstract class AbstractMethodAndClass {
13+
protected final String methodName;
14+
protected final String className;
15+
protected final String returnType;
16+
protected final List<String> parameters;
17+
18+
private String subSignature = null;
19+
private String signature = null;
20+
21+
public AbstractMethodAndClass(String methodName, String className, String returnType, List<String> parameters) {
22+
this.methodName = methodName;
23+
this.className = className;
24+
this.returnType = returnType;
25+
this.parameters = parameters;
26+
}
27+
28+
public String getMethodName() {
29+
return this.methodName;
30+
}
31+
32+
public String getClassName() {
33+
return this.className;
34+
}
35+
36+
public String getReturnType() {
37+
return this.returnType;
38+
}
39+
40+
public List<String> getParameters() {
41+
return this.parameters;
42+
}
43+
44+
/**
45+
* Get subsignature of stored method and class
46+
*
47+
* @return Subsignature
48+
*/
49+
public String getSubSignature() {
50+
if (subSignature != null)
51+
return subSignature;
52+
53+
StringBuilder sb = new StringBuilder(
54+
10 + this.returnType.length() + this.methodName.length() + (this.parameters.size() * 30));
55+
if (!this.returnType.isEmpty()) {
56+
sb.append(this.returnType);
57+
sb.append(" ");
58+
}
59+
sb.append(this.methodName);
60+
sb.append("(");
61+
62+
for (int i = 0; i < this.parameters.size(); i++) {
63+
if (i > 0)
64+
sb.append(",");
65+
sb.append(this.parameters.get(i).trim());
66+
}
67+
sb.append(")");
68+
this.subSignature = sb.toString();
69+
70+
return this.subSignature;
71+
}
72+
73+
/**
74+
* Get the signature of the stored method and class
75+
*
76+
* @return Signature
77+
*/
78+
public String getSignature() {
79+
if (signature != null)
80+
return signature;
81+
82+
StringBuilder sb = new StringBuilder(10 + this.className.length() + this.returnType.length()
83+
+ this.methodName.length() + (this.parameters.size() * 30));
84+
sb.append("<");
85+
sb.append(this.className);
86+
sb.append(": ");
87+
if (!this.returnType.isEmpty()) {
88+
sb.append(this.returnType);
89+
sb.append(" ");
90+
}
91+
sb.append(this.methodName);
92+
sb.append("(");
93+
94+
for (int i = 0; i < this.parameters.size(); i++) {
95+
if (i > 0)
96+
sb.append(",");
97+
sb.append(this.parameters.get(i).trim());
98+
}
99+
sb.append(")>");
100+
this.signature = sb.toString();
101+
102+
return this.signature;
103+
}
104+
}

soot-infoflow/src/soot/jimple/infoflow/data/SootMethodAndClass.java

Lines changed: 18 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -20,117 +20,42 @@
2020
* Data container which stores the string representation of a SootMethod and its
2121
* corresponding class
2222
*/
23-
public class SootMethodAndClass {
24-
private final String methodName;
25-
private final String className;
26-
private final String returnType;
27-
private final List<String> parameters;
23+
public class SootMethodAndClass extends AbstractMethodAndClass {
2824

29-
private String subSignature = null;
30-
private String signature = null;
3125
private int hashCode = 0;
3226

3327
public SootMethodAndClass(String methodName, String className, String returnType, List<String> parameters) {
34-
this.methodName = methodName;
35-
this.className = className;
36-
this.returnType = returnType;
37-
this.parameters = parameters;
28+
super(methodName, className, returnType, parameters);
3829
}
3930

4031
public SootMethodAndClass(String methodName, String className, String returnType, String parameters) {
41-
this.methodName = methodName;
42-
this.className = className;
43-
this.returnType = returnType;
32+
super(methodName, className, returnType, parameterFromString(parameters));
33+
}
4434

45-
this.parameters = new ArrayList<>();
46-
if (parameters != null && !parameters.isEmpty()) {
35+
private static List<String> parameterFromString(String parameters) {
36+
List<String> paras = new ArrayList<>();
37+
if (paras != null && !paras.isEmpty()) {
4738
String[] params = parameters.split(",");
4839
for (String s : params)
49-
this.parameters.add(s);
40+
paras.add(s);
5041
}
42+
return paras;
5143
}
5244

5345
public SootMethodAndClass(SootMethod sm) {
54-
this.methodName = sm.getName();
55-
this.className = sm.getDeclaringClass().getName();
56-
this.returnType = sm.getReturnType().toString();
57-
this.parameters = new ArrayList<String>();
58-
for (Type p : sm.getParameterTypes())
59-
this.parameters.add(p.toString());
60-
}
61-
62-
public SootMethodAndClass(SootMethodAndClass methodAndClass) {
63-
this.methodName = methodAndClass.methodName;
64-
this.className = methodAndClass.className;
65-
this.returnType = methodAndClass.returnType;
66-
this.parameters = new ArrayList<String>(methodAndClass.parameters);
67-
}
68-
69-
public String getMethodName() {
70-
return this.methodName;
71-
}
72-
73-
public String getClassName() {
74-
return this.className;
75-
}
76-
77-
public String getReturnType() {
78-
return this.returnType;
79-
}
80-
81-
public List<String> getParameters() {
82-
return this.parameters;
46+
super(sm.getName(), sm.getDeclaringClass().getName(), sm.getReturnType().toString(), parameterFromMethod(sm));
8347
}
8448

85-
public String getSubSignature() {
86-
if (subSignature != null)
87-
return subSignature;
88-
89-
StringBuilder sb = new StringBuilder(
90-
10 + this.returnType.length() + this.methodName.length() + (this.parameters.size() * 30));
91-
if (!this.returnType.isEmpty()) {
92-
sb.append(this.returnType);
93-
sb.append(" ");
94-
}
95-
sb.append(this.methodName);
96-
sb.append("(");
97-
98-
for (int i = 0; i < this.parameters.size(); i++) {
99-
if (i > 0)
100-
sb.append(",");
101-
sb.append(this.parameters.get(i).trim());
102-
}
103-
sb.append(")");
104-
this.subSignature = sb.toString();
105-
106-
return this.subSignature;
49+
private static List<String> parameterFromMethod(SootMethod sm) {
50+
ArrayList<String> parameters = new ArrayList<String>();
51+
for (Type p : sm.getParameterTypes())
52+
parameters.add(p.toString());
53+
return parameters;
10754
}
10855

109-
public String getSignature() {
110-
if (signature != null)
111-
return signature;
112-
113-
StringBuilder sb = new StringBuilder(10 + this.className.length() + this.returnType.length()
114-
+ this.methodName.length() + (this.parameters.size() * 30));
115-
sb.append("<");
116-
sb.append(this.className);
117-
sb.append(": ");
118-
if (!this.returnType.isEmpty()) {
119-
sb.append(this.returnType);
120-
sb.append(" ");
121-
}
122-
sb.append(this.methodName);
123-
sb.append("(");
124-
125-
for (int i = 0; i < this.parameters.size(); i++) {
126-
if (i > 0)
127-
sb.append(",");
128-
sb.append(this.parameters.get(i).trim());
129-
}
130-
sb.append(")>");
131-
this.signature = sb.toString();
132-
133-
return this.signature;
56+
public SootMethodAndClass(SootMethodAndClass methodAndClass) {
57+
super(methodAndClass.methodName, methodAndClass.className, methodAndClass.returnType,
58+
new ArrayList<String>(methodAndClass.parameters));
13459
}
13560

13661
@Override

0 commit comments

Comments
 (0)