|
20 | 20 | * Data container which stores the string representation of a SootMethod and its |
21 | 21 | * corresponding class |
22 | 22 | */ |
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 { |
28 | 24 |
|
29 | | - private String subSignature = null; |
30 | | - private String signature = null; |
31 | 25 | private int hashCode = 0; |
32 | 26 |
|
33 | 27 | 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); |
38 | 29 | } |
39 | 30 |
|
40 | 31 | 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 | + } |
44 | 34 |
|
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()) { |
47 | 38 | String[] params = parameters.split(","); |
48 | 39 | for (String s : params) |
49 | | - this.parameters.add(s); |
| 40 | + paras.add(s); |
50 | 41 | } |
| 42 | + return paras; |
51 | 43 | } |
52 | 44 |
|
53 | 45 | 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)); |
83 | 47 | } |
84 | 48 |
|
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; |
107 | 54 | } |
108 | 55 |
|
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)); |
134 | 59 | } |
135 | 60 |
|
136 | 61 | @Override |
|
0 commit comments