1 11 package org.eclipse.jdt.internal.core.util; 12 13 import org.eclipse.jdt.core.util.ClassFormatException; 14 import org.eclipse.jdt.core.util.IAnnotation; 15 import org.eclipse.jdt.core.util.IAnnotationComponent; 16 import org.eclipse.jdt.core.util.IConstantPool; 17 import org.eclipse.jdt.core.util.IConstantPoolConstant; 18 import org.eclipse.jdt.core.util.IConstantPoolEntry; 19 20 23 public class Annotation extends ClassFileStruct implements IAnnotation { 24 25 private static final IAnnotationComponent[] NO_ENTRIES = new IAnnotationComponent[0]; 26 27 private int typeIndex; 28 private char[] typeName; 29 private int componentsNumber; 30 private IAnnotationComponent[] components; 31 private int readOffset; 32 33 41 public Annotation( 42 byte[] classFileBytes, 43 IConstantPool constantPool, 44 int offset) throws ClassFormatException { 45 46 final int index = u2At(classFileBytes, 0, offset); 47 this.typeIndex = index; 48 if (index != 0) { 49 IConstantPoolEntry constantPoolEntry = constantPool.decodeEntry(index); 50 if (constantPoolEntry.getKind() != IConstantPoolConstant.CONSTANT_Utf8) { 51 throw new ClassFormatException(ClassFormatException.INVALID_CONSTANT_POOL_ENTRY); 52 } 53 this.typeName = constantPoolEntry.getUtf8Value(); 54 } else { 55 throw new ClassFormatException(ClassFormatException.INVALID_CONSTANT_POOL_ENTRY); 56 } 57 final int length = u2At(classFileBytes, 2, offset); 58 this.componentsNumber = length; 59 this.readOffset = 4; 60 if (length != 0) { 61 this.components = new IAnnotationComponent[length]; 62 for (int i = 0; i < length; i++) { 63 AnnotationComponent component = new AnnotationComponent(classFileBytes, constantPool, offset + readOffset); 64 this.components[i] = component; 65 this.readOffset += component.sizeInBytes(); 66 } 67 } else { 68 this.components = NO_ENTRIES; 69 } 70 } 71 72 75 public int getTypeIndex() { 76 return this.typeIndex; 77 } 78 81 public int getComponentsNumber() { 82 return this.componentsNumber; 83 } 84 87 public IAnnotationComponent[] getComponents() { 88 return this.components; 89 } 90 91 int sizeInBytes() { 92 return this.readOffset; 93 } 94 97 public char[] getTypeName() { 98 return this.typeName; 99 } 100 } 101 | Popular Tags |