1 19 20 package ca.mcgill.sable.soot.editors.parser; 21 22 import java.util.*; 23 24 import ca.mcgill.sable.soot.editors.JimpleOutlineObject; 25 26 27 public class JimpleMethod { 28 29 30 private String val; 31 private String label; 32 private String type; 33 private ArrayList modifiers; 34 private int imageType; 35 36 public static boolean isMethod(String val){ 37 if ((val.indexOf("(") != -1) && (val.indexOf(")") != -1)) return true; 38 return false; 39 } 40 41 public JimpleMethod(String val){ 42 setVal(val); 43 } 44 45 public void parseMethod(){ 46 StringTokenizer st = new StringTokenizer(getVal()); 47 int numTokens = st.countTokens(); 48 String tempLabel = ""; 49 boolean addLabel = false; 50 while (st.hasMoreTokens()){ 51 String next = st.nextToken(); 52 if (JimpleModifier.isModifier(next)) { 53 if (getModifiers() == null){ 54 setModifiers(new ArrayList()); 55 } 56 getModifiers().add(next); 57 } 58 if (next.indexOf("(") != -1){ 59 addLabel = true; 60 } 61 if (addLabel){ 62 tempLabel = tempLabel + next; 63 tempLabel = tempLabel + " "; 64 } 65 66 } 67 setLabel(tempLabel); 68 } 69 70 public void findImageType(){ 71 if (getModifiers() == null){ 72 setImageType(JimpleOutlineObject.NONE_METHOD); 73 return; 74 } 75 if (getModifiers().contains("public")) { 76 setImageType(JimpleOutlineObject.PUBLIC_METHOD); 77 } 78 else if (getModifiers().contains("protected")) { 79 setImageType(JimpleOutlineObject.PROTECTED_METHOD); 80 } 81 else if (getModifiers().contains("private")) { 82 setImageType(JimpleOutlineObject.PRIVATE_METHOD); 83 } 84 else { 85 setImageType(JimpleOutlineObject.NONE_METHOD); 86 } 87 } 88 89 public BitSet findDecorators() { 90 BitSet bits = new BitSet(); 91 if (getModifiers() == null) return bits; 92 if (getModifiers().contains("abstract")){ 93 bits.set(JimpleOutlineObject.ABSTRACT_DEC); 94 } 95 if (getModifiers().contains("final")){ 96 bits.set(JimpleOutlineObject.FINAL_DEC); 97 } 98 if (getModifiers().contains("static")){ 99 bits.set(JimpleOutlineObject.STATIC_DEC); 100 } 101 if (getModifiers().contains("synchronized")){ 102 bits.set(JimpleOutlineObject.SYNCHRONIZED_DEC); 103 } 104 return bits; 105 } 106 107 110 public int getImageType() { 111 return imageType; 112 } 113 114 117 public String getLabel() { 118 return label; 119 } 120 121 124 public ArrayList getModifiers() { 125 return modifiers; 126 } 127 128 131 public String getType() { 132 return type; 133 } 134 135 138 public String getVal() { 139 return val; 140 } 141 142 145 public void setImageType(int i) { 146 imageType = i; 147 } 148 149 152 public void setLabel(String string) { 153 label = string; 154 } 155 156 159 public void setModifiers(ArrayList list) { 160 modifiers = list; 161 } 162 163 166 public void setType(String string) { 167 type = string; 168 } 169 170 173 public void setVal(String string) { 174 val = string; 175 } 176 177 } 178 | Popular Tags |