1 package joeq.Compiler.Analysis.IPSSA.Apps;
2
3 import joeq.Class.jq_Method;
4 import joeq.Compiler.Analysis.IPA.ProgramLocation;
5 import joeq.Compiler.Analysis.IPA.ProgramLocation.QuadProgramLocation;
6 import joeq.Compiler.Quad.ControlFlowGraph;
7 import joeq.Compiler.Quad.ControlFlowGraphVisitor;
8 import joeq.Compiler.Quad.Operator;
9 import joeq.Compiler.Quad.Quad;
10 import joeq.Compiler.Quad.QuadIterator;
11
12 public class AssertionAnalysis implements ControlFlowGraphVisitor {
13 public void visitCFG(ControlFlowGraph cfg) {
14 System.out.println("Processing method " + cfg.getMethod().toString());
15 for(QuadIterator iter = new QuadIterator(cfg); iter.hasNext(); ) {
16 Quad quad = (Quad)iter.next();
17
18 if(quad.getOperator() instanceof Operator.Invoke) {
19 processCall(cfg.getMethod(), quad);
20 }
21 }
22 }
23
24 private void processCall(jq_Method method, Quad quad) {
25 ProgramLocation loc = new QuadProgramLocation(method, quad);
26
27 if(!loc.isSingleTarget()) {
28
29 return;
30 }
31
32 jq_Method callee = loc.getTargetMethod();
33 System.out.println("\tProcessing a call to " + callee);
34 if(!isAssert(callee)) {
35 return;
36 }
37 }
38
39 public final static String ASSERT_NAME = "assert";
40 private static boolean isAssert(jq_Method callee) {
41 String name = callee.getName().toString();
42 return name.indexOf(ASSERT_NAME) != -1;
43 }
44 }