01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.core.util;
11:
12: import org.eclipse.jdt.core.util.ClassFormatException;
13: import org.eclipse.jdt.core.util.IClassFileAttribute;
14: import org.eclipse.jdt.core.util.IConstantPool;
15: import org.eclipse.jdt.core.util.IConstantPoolConstant;
16: import org.eclipse.jdt.core.util.IConstantPoolEntry;
17:
18: /**
19: * Default implementation of IClassFileAttribute
20: */
21: public class ClassFileAttribute extends ClassFileStruct implements
22: 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,
29: IConstantPool constantPool, int offset)
30: throws ClassFormatException {
31: this .attributeNameIndex = u2At(classFileBytes, 0, offset);
32: this .attributeLength = u4At(classFileBytes, 2, offset);
33: IConstantPoolEntry constantPoolEntry = constantPool
34: .decodeEntry(this .attributeNameIndex);
35: if (constantPoolEntry.getKind() != IConstantPoolConstant.CONSTANT_Utf8) {
36: throw new ClassFormatException(
37: ClassFormatException.INVALID_CONSTANT_POOL_ENTRY);
38: }
39: this .attributeName = constantPoolEntry.getUtf8Value();
40: }
41:
42: public int getAttributeNameIndex() {
43: return this .attributeNameIndex;
44: }
45:
46: /**
47: * @see IClassFileAttribute#getAttributeName()
48: */
49: public char[] getAttributeName() {
50: return this .attributeName;
51: }
52:
53: /**
54: * @see IClassFileAttribute#getAttributeLength()
55: */
56: public long getAttributeLength() {
57: return this.attributeLength;
58: }
59:
60: }
|