|
15 | 15 | * one |
16 | 16 | * |
17 | 17 | * @author Steven Arzt, Siegfried Rasthofer |
18 | | - * |
19 | 18 | */ |
20 | 19 | public class MethodCallsMethodFeature extends AbstractSootFeature { |
21 | 20 |
|
22 | | - private final String className; |
23 | | - private final String methodName; |
24 | | - private final boolean substringMatch; |
| 21 | + private final String className; |
| 22 | + private final String methodName; |
| 23 | + private final boolean substringMatch; |
25 | 24 |
|
26 | | - public MethodCallsMethodFeature(String cp, String methodName) { |
27 | | - this(cp, "", methodName); |
28 | | - } |
| 25 | + public MethodCallsMethodFeature(String methodName) { |
| 26 | + this("", methodName); |
| 27 | + } |
29 | 28 |
|
30 | | - public MethodCallsMethodFeature(String cp, String className, |
31 | | - String methodName) { |
32 | | - this(cp, className, methodName, false); |
33 | | - } |
| 29 | + public MethodCallsMethodFeature(String className, String methodName) { |
| 30 | + this(className, methodName, false); |
| 31 | + } |
34 | 32 |
|
35 | | - public MethodCallsMethodFeature(String cp, String className, |
36 | | - String methodName, boolean substringMatch) { |
37 | | - super(cp); |
38 | | - this.className = className; |
39 | | - this.methodName = methodName; |
40 | | - this.substringMatch = substringMatch; |
41 | | - } |
| 33 | + public MethodCallsMethodFeature(String className, String methodName, boolean substringMatch) { |
| 34 | + super(); |
| 35 | + this.className = className; |
| 36 | + this.methodName = methodName; |
| 37 | + this.substringMatch = substringMatch; |
| 38 | + } |
42 | 39 |
|
43 | | - @Override |
44 | | - public Type appliesInternal(Method method) { |
45 | | - try { |
46 | | - SootMethod sm = getSootMethod(method); |
47 | | - if (sm == null) { |
48 | | - return Type.NOT_SUPPORTED; |
49 | | - } |
50 | | - return checkMethod(sm, new ArrayList<SootMethod>()); |
51 | | - } catch (Exception ex) { |
52 | | - System.err.println("Something went wrong:"); |
53 | | - ex.printStackTrace(); |
54 | | - return Type.NOT_SUPPORTED; |
| 40 | + @Override |
| 41 | + public Type appliesInternal(Method method) { |
| 42 | + try { |
| 43 | + |
| 44 | + if (method.getSootMethod() == null) { |
| 45 | + return Type.NOT_SUPPORTED; |
| 46 | + } |
| 47 | + return checkMethod(method.getSootMethod(), new ArrayList<>()); |
| 48 | + } catch (Exception ex) { |
| 49 | + System.err.println("Something went wrong:"); |
| 50 | + ex.printStackTrace(); |
| 51 | + return Type.NOT_SUPPORTED; |
| 52 | + } |
55 | 53 | } |
56 | | - } |
57 | 54 |
|
58 | | - public Type checkMethod(SootMethod method, List<SootMethod> doneList) { |
59 | | - if (doneList.contains(method)) |
60 | | - return Type.NOT_SUPPORTED; |
61 | | - if (!method.isConcrete()) |
62 | | - return Type.NOT_SUPPORTED; |
63 | | - doneList.add(method); |
| 55 | + public Type checkMethod(SootMethod method, List<SootMethod> doneList) { |
| 56 | + if (doneList.contains(method)) |
| 57 | + return Type.NOT_SUPPORTED; |
| 58 | + if (!method.isConcrete()) |
| 59 | + return Type.NOT_SUPPORTED; |
| 60 | + doneList.add(method); |
64 | 61 |
|
65 | | - try { |
66 | | - Body body = null; |
67 | | - try { |
68 | | - body = method.retrieveActiveBody(); |
69 | | - } catch (Exception ex) { |
70 | | - return Type.NOT_SUPPORTED; |
71 | | - } |
| 62 | + try { |
| 63 | + Body body; |
| 64 | + try { |
| 65 | + body = method.retrieveActiveBody(); |
| 66 | + } catch (Exception ex) { |
| 67 | + return Type.NOT_SUPPORTED; |
| 68 | + } |
72 | 69 |
|
73 | | - for (Unit u : body.getUnits()) { |
74 | | - if (!(u instanceof Stmt)) |
75 | | - continue; |
76 | | - Stmt stmt = (Stmt) u; |
77 | | - if (!stmt.containsInvokeExpr()) |
78 | | - continue; |
| 70 | + for (Unit u : body.getUnits()) { |
| 71 | + if (!(u instanceof Stmt)) |
| 72 | + continue; |
| 73 | + Stmt stmt = (Stmt) u; |
| 74 | + if (!stmt.containsInvokeExpr()) |
| 75 | + continue; |
79 | 76 |
|
80 | | - InvokeExpr inv = stmt.getInvokeExpr(); |
81 | | - if ((substringMatch |
82 | | - && inv.getMethod().getName().contains(this.methodName)) |
83 | | - || inv.getMethod().getName().startsWith(this.methodName)) { |
84 | | - if (this.className.isEmpty() || this.className |
85 | | - .equals(inv.getMethod().getDeclaringClass().getName())) |
86 | | - return Type.TRUE; |
87 | | - } else if (checkMethod(inv.getMethod(), doneList) == Type.TRUE) |
88 | | - return Type.TRUE; |
89 | | - } |
90 | | - return Type.FALSE; |
91 | | - } catch (Exception ex) { |
92 | | - System.err.println("Oops: " + ex); |
93 | | - return Type.NOT_SUPPORTED; |
| 77 | + InvokeExpr inv = stmt.getInvokeExpr(); |
| 78 | + if ((substringMatch |
| 79 | + && inv.getMethod().getName().contains(this.methodName)) |
| 80 | + || inv.getMethod().getName().startsWith(this.methodName)) { |
| 81 | + if (this.className.isEmpty() || this.className |
| 82 | + .equals(inv.getMethod().getDeclaringClass().getName())) |
| 83 | + return Type.TRUE; |
| 84 | + } else if (checkMethod(inv.getMethod(), doneList) == Type.TRUE) |
| 85 | + return Type.TRUE; |
| 86 | + } |
| 87 | + return Type.FALSE; |
| 88 | + } catch (Exception ex) { |
| 89 | + System.err.println("Oops: " + ex); |
| 90 | + return Type.NOT_SUPPORTED; |
| 91 | + } |
94 | 92 | } |
95 | | - } |
96 | | - |
97 | | - @Override |
98 | | - public String toString() { |
99 | | - return "Method starting with '" + this.methodName + "' invoked"; |
100 | | - } |
101 | 93 |
|
| 94 | + @Override |
| 95 | + public String toString() { |
| 96 | + return "Method starting with '" + this.methodName + "' invoked"; |
| 97 | + } |
102 | 98 | } |
0 commit comments