KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.IClassFileAttribute;
15 import org.eclipse.jdt.core.util.IConstantPool;
16 import org.eclipse.jdt.core.util.IConstantPoolConstant;
17 import org.eclipse.jdt.core.util.IConstantPoolEntry;
18
19 /**
20  * Default implementation of IClassFileAttribute
21  */

22 public class ClassFileAttribute extends ClassFileStruct implements IClassFileAttribute {
23     public static final IClassFileAttribute[] NO_ATTRIBUTES = new IClassFileAttribute[0];
24     private long attributeLength;
25     private int attributeNameIndex;
26     private char[] attributeName;
27     
28     public ClassFileAttribute(byte[] classFileBytes, IConstantPool constantPool, int offset) throws ClassFormatException {
29         this.attributeNameIndex = u2At(classFileBytes, 0, offset);
30         this.attributeLength = u4At(classFileBytes, 2, offset);
31         IConstantPoolEntry constantPoolEntry = constantPool.decodeEntry(this.attributeNameIndex);
32         if (constantPoolEntry.getKind() != IConstantPoolConstant.CONSTANT_Utf8) {
33             throw new ClassFormatException(ClassFormatException.INVALID_CONSTANT_POOL_ENTRY);
34         }
35         this.attributeName = constantPoolEntry.getUtf8Value();
36     }
37
38     public int getAttributeNameIndex() {
39         return this.attributeNameIndex;
40     }
41
42     /**
43      * @see IClassFileAttribute#getAttributeName()
44      */

45     public char[] getAttributeName() {
46         return this.attributeName;
47     }
48
49     /**
50      * @see IClassFileAttribute#getAttributeLength()
51      */

52     public long getAttributeLength() {
53         return this.attributeLength;
54     }
55
56 }
57
Popular Tags