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.IAnnotationComponent; 15 import org.eclipse.jdt.core.util.IAnnotationComponentValue; 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 AnnotationComponent extends ClassFileStruct implements IAnnotationComponent { 24 25 private int componentNameIndex; 26 private char[] componentName; 27 private IAnnotationComponentValue componentValue; 28 private int readOffset; 29 30 public AnnotationComponent( 31 byte[] classFileBytes, 32 IConstantPool constantPool, 33 int offset) throws ClassFormatException { 34 final int nameIndex = u2At(classFileBytes, 0, offset); 35 this.componentNameIndex = nameIndex; 36 if (nameIndex != 0) { 37 IConstantPoolEntry constantPoolEntry = constantPool.decodeEntry(nameIndex); 38 if (constantPoolEntry.getKind() != IConstantPoolConstant.CONSTANT_Utf8) { 39 throw new ClassFormatException(ClassFormatException.INVALID_CONSTANT_POOL_ENTRY); 40 } 41 this.componentName = constantPoolEntry.getUtf8Value(); 42 } 43 this.readOffset = 2; 44 AnnotationComponentValue value = new AnnotationComponentValue(classFileBytes, constantPool, offset + readOffset); 45 this.componentValue = value; 46 this.readOffset += value.sizeInBytes(); 47 } 48 49 52 public int getComponentNameIndex() { 53 return this.componentNameIndex; 54 } 55 58 public char[] getComponentName() { 59 return this.componentName; 60 } 61 64 public IAnnotationComponentValue getComponentValue() { 65 return this.componentValue; 66 } 67 68 int sizeInBytes() { 69 return this.readOffset; 70 } 71 } 72 | Popular Tags |