| 1 19 20 package soot.jimple.toolkits.annotation.nullcheck; 21 22 import soot.*; 23 import soot.tagkit.*; 24 import soot.toolkits.graph.*; 25 import java.util.*; 26 import soot.toolkits.scalar.*; 27 import soot.jimple.*; 28 29 public class NullPointerColorer extends BodyTransformer { 30 31 public NullPointerColorer( Singletons.Global g ) {} 32 public static NullPointerColorer v() { return G.v().soot_jimple_toolkits_annotation_nullcheck_NullPointerColorer(); } 33 34 protected void internalTransform (Body b, String phaseName, Map options) { 35 36 BranchedRefVarsAnalysis analysis = new BranchedRefVarsAnalysis ( 37 new ExceptionalUnitGraph(b)); 38 39 Iterator it = b.getUnits().iterator(); 40 41 while (it.hasNext()) { 42 Stmt s = (Stmt)it.next(); 43 44 Iterator usesIt = s.getUseBoxes().iterator(); 45 FlowSet beforeSet = (FlowSet)analysis.getFlowBefore(s); 46 47 while (usesIt.hasNext()) { 48 ValueBox vBox = (ValueBox)usesIt.next(); 49 addColorTags(vBox, beforeSet, s, analysis); 50 } 51 52 Iterator defsIt = s.getDefBoxes().iterator(); 53 FlowSet afterSet = (FlowSet)analysis.getFallFlowAfter(s); 54 55 while (defsIt.hasNext()){ 56 ValueBox vBox = (ValueBox)defsIt.next(); 57 addColorTags(vBox, afterSet, s, analysis); 58 } 59 } 60 61 Iterator keysIt = b.getMethod().getDeclaringClass().getTags().iterator(); 62 boolean keysAdded = false; 63 while (keysIt.hasNext()){ 64 Object next = keysIt.next(); 65 if (next instanceof KeyTag){ 66 if (((KeyTag)next).analysisType().equals("NullCheckTag")){ 67 keysAdded = true; 68 } 69 } 70 } 71 if (!keysAdded){ 72 b.getMethod().getDeclaringClass().addTag(new KeyTag(ColorTag.RED, "Nullness: Null", "NullCheckTag")); 73 b.getMethod().getDeclaringClass().addTag(new KeyTag(ColorTag.GREEN, "Nullness: Not Null", "NullCheckTag")); 74 b.getMethod().getDeclaringClass().addTag(new KeyTag(ColorTag.BLUE, "Nullness: Nullness Unknown", "NullCheckTag")); 75 } 76 } 77 78 private void addColorTags(ValueBox vBox, FlowSet set, Stmt s, BranchedRefVarsAnalysis analysis){ 79 80 Value val = vBox.getValue(); 81 if (val.getType() instanceof RefLikeType) { 82 84 int vInfo = analysis.anyRefInfo(val, set); 85 86 switch (vInfo) { 87 case 1 : { 88 s.addTag(new StringTag(val+": Null", "NullCheckTag")); 90 vBox.addTag(new ColorTag(ColorTag.RED, "NullCheckTag")); 91 break; 92 } 93 case 2 : { 94 s.addTag(new StringTag(val+": NonNull", "NullCheckTag")); 96 vBox.addTag(new ColorTag(ColorTag.GREEN, "NullCheckTag")); 97 break; 98 } 99 case 99 : { 100 s.addTag(new StringTag(val+": Nullness Unknown", "NullCheckTag")); 102 vBox.addTag(new ColorTag(ColorTag.BLUE, "NullCheckTag")); 103 break; 104 } 105 case 0 : { 106 s.addTag(new StringTag(val+": Nullness Unknown", "NullCheckTag")); 108 vBox.addTag(new ColorTag(ColorTag.BLUE, "NullCheckTag")); 109 break; 110 } 111 } 112 } 113 else { 114 115 } 116 } 117 } 118 | Popular Tags |