001 package AST; 002 003 import java.util.HashSet; 004 import java.io.File; 005 import java.util.*; 006 import beaver.*; 007 import java.util.ArrayList; 008 import java.util.zip.*; 009 import java.io.*; 010 import java.io.FileNotFoundException; 011 import java.util.Collection; 012 /** 013 * @ast class 014 * 015 */ 016 public class FieldInfo extends java.lang.Object { 017 018 private BytecodeParser p; 019 020 021 String name; 022 023 024 int flags; 025 026 027 private FieldDescriptor fieldDescriptor; 028 029 030 private Attributes.FieldAttributes attributes; 031 032 033 034 public FieldInfo(BytecodeParser parser) { 035 p = parser; 036 flags = p.u2(); 037 if(BytecodeParser.VERBOSE) 038 p.print("Flags: " + flags); 039 int name_index = p.u2(); 040 name = ((CONSTANT_Utf8_Info) p.constantPool[name_index]).string(); 041 042 fieldDescriptor = new FieldDescriptor(p, name); 043 attributes = new Attributes.FieldAttributes(p); 044 } 045 046 047 048 public BodyDecl bodyDecl() { 049 FieldDeclaration f; 050 if((flags & Flags.ACC_ENUM) != 0) 051 //EnumConstant : FieldDeclaration ::= Modifiers <ID:String> Arg:Expr* BodyDecl* /TypeAccess:Access/ /[Init:Expr]/; 052 f = new EnumConstant( 053 BytecodeParser.modifiers(flags), 054 name, 055 new List(), 056 new List() 057 ); 058 else { 059 Signatures.FieldSignature s = attributes.fieldSignature; 060 Access type = s != null ? s.fieldTypeAccess() : fieldDescriptor.type(); 061 f = new FieldDeclaration( 062 BytecodeParser.modifiers(flags), 063 type, 064 name, 065 new Opt() 066 ); 067 } 068 if(attributes.constantValue() != null) 069 if(fieldDescriptor.isBoolean()) { 070 f.setInit(attributes.constantValue().exprAsBoolean()); 071 } 072 else { 073 f.setInit(attributes.constantValue().expr()); 074 } 075 076 if(attributes.annotations != null) 077 for(Iterator iter = attributes.annotations.iterator(); iter.hasNext(); ) 078 f.getModifiersNoTransform().addModifier((Modifier)iter.next()); 079 080 return f; 081 } 082 083 084 085 public boolean isSynthetic() { 086 return attributes.isSynthetic(); 087 } 088 089 090 }