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