KickJava   Java API By Example, From Geeks To Geeks.

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


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.IAnnotation;
15 import org.eclipse.jdt.core.util.IConstantPool;
16 import org.eclipse.jdt.core.util.IParameterAnnotation;
17
18 /**
19  * Default implementation of IParameterAnnotation
20  */

21 public class ParameterAnnotation extends ClassFileStruct implements IParameterAnnotation {
22
23     private static final IAnnotation[] NO_ENTRIES = new IAnnotation[0];
24     
25     private int annotationsNumber;
26     private IAnnotation[] annotations;
27     private int readOffset;
28     
29     /**
30      * Constructor for Annotation.
31      *
32      * @param classFileBytes
33      * @param constantPool
34      * @param offset
35      * @throws ClassFormatException
36      */

37     public ParameterAnnotation(
38             byte[] classFileBytes,
39             IConstantPool constantPool,
40             int offset) throws ClassFormatException {
41         
42         final int length = u2At(classFileBytes, 0, offset);
43         this.readOffset = 2;
44         this.annotationsNumber = length;
45         if (length != 0) {
46             this.annotations = new IAnnotation[length];
47             for (int i = 0; i < length; i++) {
48                 Annotation annotation = new Annotation(classFileBytes, constantPool, offset + readOffset);
49                 this.annotations[i] = annotation;
50                 this.readOffset += annotation.sizeInBytes();
51             }
52         } else {
53             this.annotations = NO_ENTRIES;
54         }
55     }
56     
57     int sizeInBytes() {
58         return this.readOffset;
59     }
60     /* (non-Javadoc)
61      * @see org.eclipse.jdt.core.util.IParameterAnnotation#getAnnotations()
62      */

63     public IAnnotation[] getAnnotations() {
64         return this.annotations;
65     }
66     /* (non-Javadoc)
67      * @see org.eclipse.jdt.core.util.IParameterAnnotation#getAnnotationsNumber()
68      */

69     public int getAnnotationsNumber() {
70         return this.annotationsNumber;
71     }
72 }
73
Popular Tags