1 19 20 package jode.decompiler; 21 import jode.type.Type; 22 import jode.bytecode.FieldInfo; 23 import jode.expr.Expression; 24 import jode.expr.ThisOperator; 25 import jode.expr.LocalLoadOperator; 26 import jode.expr.ConstOperator; 27 import jode.expr.OuterLocalOperator; 28 29 import java.lang.reflect.Modifier ; 30 import java.io.IOException ; 31 32 import java.util.Set ; 33 34 public class FieldAnalyzer implements Analyzer { 35 ClassAnalyzer clazz; 36 ImportHandler imports; 37 int modifiers; 38 Type type; 39 String fieldName; 40 Expression constant; 41 boolean isSynthetic; 42 boolean isDeprecated; 43 boolean analyzedSynthetic = false; 44 45 public FieldAnalyzer(ClassAnalyzer cla, FieldInfo fd, 46 ImportHandler i) 47 { 48 clazz = cla; 49 imports = i; 50 51 modifiers = fd.getModifiers(); 52 type = Type.tType(fd.getType()); 53 fieldName = fd.getName(); 54 constant = null; 55 this.isSynthetic = fd.isSynthetic(); 56 this.isDeprecated = fd.isDeprecated(); 57 if (fd.getConstant() != null) { 58 constant = new ConstOperator(fd.getConstant()); 59 constant.setType(type); 60 constant.makeInitializer(type); 61 } 62 } 63 64 public String getName() { 65 return fieldName; 66 } 67 68 public Type getType() { 69 return type; 70 } 71 72 public ClassAnalyzer getClassAnalyzer() { 73 return clazz; 74 } 75 76 public Expression getConstant() { 77 return constant; 78 } 79 80 public boolean isSynthetic() { 81 return isSynthetic; 82 } 83 84 public boolean isFinal() { 85 return Modifier.isFinal(modifiers); 86 } 87 88 public void analyzedSynthetic() { 89 analyzedSynthetic = true; 90 } 91 92 public boolean setInitializer(Expression expr) { 93 if (constant != null) 94 return constant.equals(expr); 95 96 100 if (isSynthetic 101 && (fieldName.startsWith("this$") 102 || fieldName.startsWith("val$"))) { 103 if (fieldName.startsWith("val$") && fieldName.length() > 4 104 && expr instanceof OuterLocalOperator) { 105 LocalInfo li = ((OuterLocalOperator) expr).getLocalInfo(); 106 li.addHint(fieldName.substring(4), type); 107 } 108 analyzedSynthetic(); 109 } else 110 expr.makeInitializer(type); 111 112 constant = expr; 113 return true; 114 } 115 116 public boolean setClassConstant(String clazzName) { 117 if (constant != null) 118 return false; 119 if (clazzName.charAt(0) == '[') { 120 if (clazzName.charAt(clazzName.length()-1) == ';') 121 clazzName = clazzName.substring(0, clazzName.length()-1); 122 123 if (fieldName.equals("array"+ (clazzName.replace('[', '$') 124 .replace('.', '$')))) { 125 analyzedSynthetic(); 126 return true; 127 } 128 } else { 129 if (fieldName.equals("class$" + clazzName.replace('.', '$')) 130 || fieldName.equals("class$L" + clazzName.replace('.', '$'))) { 131 analyzedSynthetic(); 132 return true; 133 } 134 } 135 return false; 136 } 137 138 public void analyze() { 139 imports.useType(type); 140 } 141 142 public void makeDeclaration(Set done) { 143 if (constant != null) { 144 constant.makeDeclaration(done); 145 constant = constant.simplify(); 146 } 147 } 148 149 public boolean skipWriting() { 150 return analyzedSynthetic; 151 } 152 153 public void dumpSource(TabbedPrintWriter writer) throws IOException 154 { 155 if (isDeprecated) { 156 writer.println("/**"); 157 writer.println(" * @deprecated"); 158 writer.println(" */"); 159 } 160 if (isSynthetic) 161 writer.print("/*synthetic*/ "); 162 int modifiedModifiers = modifiers; 163 179 writer.startOp(writer.NO_PAREN, 0); 180 String modif = Modifier.toString(modifiedModifiers); 181 if (modif.length() > 0) 182 writer.print(modif+" "); 183 184 writer.printType(type); 185 writer.print(" " + fieldName); 186 if (constant != null) { 187 writer.breakOp(); 188 writer.print(" = "); 189 constant.dumpExpression(writer.IMPL_PAREN, writer); 190 } 191 writer.endOp(); 192 writer.println(";"); 193 } 194 195 public String toString() { 196 return getClass().getName()+"["+clazz.getClazz()+"."+getName()+"]"; 197 } 198 } 199 200 | Popular Tags |