1 32 33 package com.jeantessier.classreader; 34 35 import java.io.*; 36 import java.util.*; 37 38 import org.apache.log4j.*; 39 40 public abstract class Feature_info implements Deprecatable, Visitable { 41 public static final int ACC_PUBLIC = 0x0001; 42 public static final int ACC_PRIVATE = 0x0002; 43 public static final int ACC_PROTECTED = 0x0004; 44 public static final int ACC_STATIC = 0x0008; 45 public static final int ACC_FINAL = 0x0010; 46 47 private Classfile classfile; 48 private int accessFlag; 49 private int nameIndex; 50 private int descriptorIndex; 51 private Collection attributes = new LinkedList(); 52 53 public Feature_info(Classfile classfile, DataInputStream in) throws IOException { 54 this.classfile = classfile; 55 56 accessFlag = in.readUnsignedShort(); 57 Logger.getLogger(getClass()).debug(getFeatureType() + " access flag: " + accessFlag); 58 59 nameIndex = in.readUnsignedShort(); 60 Logger.getLogger(getClass()).debug(getFeatureType() + " name: " + nameIndex + " (" + getName() + ")"); 61 62 descriptorIndex = in.readUnsignedShort(); 63 Logger.getLogger(getClass()).debug(getFeatureType() + " Descriptor: " + descriptorIndex + " (" + getDescriptor() + ")"); 64 65 int attributeCount = in.readUnsignedShort(); 66 Logger.getLogger(getClass()).debug("Reading " + attributeCount + " " + getFeatureType() + " attribute(s)"); 67 for (int i=0; i<attributeCount; i++) { 68 Logger.getLogger(getClass()).debug(getFeatureType() + " attribute " + i + ":"); 69 attributes.add(AttributeFactory.create(getClassfile(), this, in)); 70 } 71 } 72 73 public Classfile getClassfile() { 74 return classfile; 75 } 76 77 public int getAccessFlag() { 78 return accessFlag; 79 } 80 81 public boolean isPublic() { 82 return (getAccessFlag() & ACC_PUBLIC) != 0; 83 } 84 85 public boolean isProtected() { 86 return (getAccessFlag() & ACC_PROTECTED) != 0; 87 } 88 89 public boolean isPrivate() { 90 return (getAccessFlag() & ACC_PRIVATE) != 0; 91 } 92 93 public boolean isPackage() { 94 return (getAccessFlag() & (ACC_PUBLIC | ACC_PROTECTED | ACC_PRIVATE)) == 0; 95 } 96 97 public boolean isStatic() { 98 return (getAccessFlag() & ACC_STATIC) != 0; 99 } 100 101 public boolean isFinal() { 102 return (getAccessFlag() & ACC_FINAL) != 0; 103 } 104 105 public int getNameIndex() { 106 return nameIndex; 107 } 108 109 public UTF8_info getRawName() { 110 return (UTF8_info) getClassfile().getConstantPool().get(nameIndex); 111 } 112 113 public String getName() { 114 return getRawName().toString(); 115 } 116 117 public String getFullName() { 118 return getClassfile().getClassName() + "." + getName(); 119 } 120 121 public int getDescriptorIndex() { 122 return descriptorIndex; 123 } 124 125 public UTF8_info getRawDescriptor() { 126 return (UTF8_info) getClassfile().getConstantPool().get(descriptorIndex); 127 } 128 129 public String getDescriptor() { 130 return getRawDescriptor().toString(); 131 } 132 133 public Collection getAttributes() { 134 return attributes; 135 } 136 137 public boolean isSynthetic() { 138 boolean result = false; 139 140 Iterator i = getAttributes().iterator(); 141 while (!result && i.hasNext()) { 142 result = i.next() instanceof Synthetic_attribute; 143 } 144 145 return result; 146 } 147 148 public boolean isDeprecated() { 149 boolean result = false; 150 151 Iterator i = getAttributes().iterator(); 152 while (!result && i.hasNext()) { 153 result = i.next() instanceof Deprecated_attribute; 154 } 155 156 return result; 157 } 158 159 public String toString() { 160 return getFullName(); 161 } 162 163 public abstract String getFeatureType(); 164 public abstract String getDeclaration(); 165 public abstract String getSignature(); 166 167 public String getFullSignature() { 168 return getClassfile().getClassName() + "." + getSignature(); 169 } 170 } 171 | Popular Tags |