KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > util > AnnotationComponent


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
21  * Default implementation of IAnnotationComponent
22  */

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     /* (non-Javadoc)
50      * @see org.eclipse.jdt.core.util.IAnnotationComponent#getComponentNameIndex()
51      */

52     public int getComponentNameIndex() {
53         return this.componentNameIndex;
54     }
55     /* (non-Javadoc)
56      * @see org.eclipse.jdt.core.util.IAnnotationComponent#getComponentName()
57      */

58     public char[] getComponentName() {
59         return this.componentName;
60     }
61     /* (non-Javadoc)
62      * @see org.eclipse.jdt.core.util.IAnnotationComponent#getComponentValue()
63      */

64     public IAnnotationComponentValue getComponentValue() {
65         return this.componentValue;
66     }
67     
68     int sizeInBytes() {
69         return this.readOffset;
70     }
71 }
72
Popular Tags