001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.core.util;
011:
012: import org.eclipse.jdt.core.util.ClassFormatException;
013: import org.eclipse.jdt.core.util.IConstantPool;
014: import org.eclipse.jdt.core.util.IConstantPoolConstant;
015: import org.eclipse.jdt.core.util.IConstantPoolEntry;
016: import org.eclipse.jdt.core.util.IEnclosingMethodAttribute;
017:
018: /**
019: * Default implementation of EnclosingMethodAttribute.
020: *
021: * @since 3.0
022: */
023: public class EnclosingMethodAttribute extends ClassFileAttribute
024: implements IEnclosingMethodAttribute {
025:
026: private int enclosingClassIndex;
027: private char[] enclosingClassName;
028: private int methodDescriptorIndex;
029: private char[] methodDescriptor;
030: private int methodNameIndex;
031: private char[] methodName;
032: private int methodNameAndTypeIndex;
033:
034: EnclosingMethodAttribute(byte[] classFileBytes,
035: IConstantPool constantPool, int offset)
036: throws ClassFormatException {
037: super (classFileBytes, constantPool, offset);
038: int index = u2At(classFileBytes, 6, offset);
039: this .enclosingClassIndex = index;
040: IConstantPoolEntry constantPoolEntry = constantPool
041: .decodeEntry(index);
042: if (constantPoolEntry.getKind() != IConstantPoolConstant.CONSTANT_Class) {
043: throw new ClassFormatException(
044: ClassFormatException.INVALID_CONSTANT_POOL_ENTRY);
045: }
046: this .enclosingClassName = constantPoolEntry.getClassInfoName();
047: this .methodNameAndTypeIndex = u2At(classFileBytes, 8, offset);
048: if (this .methodNameAndTypeIndex != 0) {
049: constantPoolEntry = constantPool
050: .decodeEntry(this .methodNameAndTypeIndex);
051: if (constantPoolEntry.getKind() != IConstantPoolConstant.CONSTANT_NameAndType) {
052: throw new ClassFormatException(
053: ClassFormatException.INVALID_CONSTANT_POOL_ENTRY);
054: }
055: this .methodDescriptorIndex = constantPoolEntry
056: .getNameAndTypeInfoDescriptorIndex();
057: this .methodNameIndex = constantPoolEntry
058: .getNameAndTypeInfoNameIndex();
059: constantPoolEntry = constantPool
060: .decodeEntry(this .methodDescriptorIndex);
061: if (constantPoolEntry.getKind() != IConstantPoolConstant.CONSTANT_Utf8) {
062: throw new ClassFormatException(
063: ClassFormatException.INVALID_CONSTANT_POOL_ENTRY);
064: }
065: this .methodDescriptor = constantPoolEntry.getUtf8Value();
066: constantPoolEntry = constantPool
067: .decodeEntry(this .methodNameIndex);
068: if (constantPoolEntry.getKind() != IConstantPoolConstant.CONSTANT_Utf8) {
069: throw new ClassFormatException(
070: ClassFormatException.INVALID_CONSTANT_POOL_ENTRY);
071: }
072: this .methodName = constantPoolEntry.getUtf8Value();
073: }
074: }
075:
076: /* (non-Javadoc)
077: * @see org.eclipse.jdt.core.util.IEnclosingMethodAttribute#getEnclosingClass()
078: */
079: public char[] getEnclosingClass() {
080: return this .enclosingClassName;
081: }
082:
083: /* (non-Javadoc)
084: * @see org.eclipse.jdt.core.util.IEnclosingMethodAttribute#getMethodDeclaringClassDescriptorIndex()
085: */
086: public int getEnclosingClassIndex() {
087: return this .enclosingClassIndex;
088: }
089:
090: /* (non-Javadoc)
091: * @see org.eclipse.jdt.core.util.IEnclosingMethodAttribute#getMethodDescriptor()
092: */
093: public char[] getMethodDescriptor() {
094: return this .methodDescriptor;
095: }
096:
097: /* (non-Javadoc)
098: * @see org.eclipse.jdt.core.util.IEnclosingMethodAttribute#getMethodDescriptorIndex()
099: */
100: public int getMethodDescriptorIndex() {
101: return this .methodDescriptorIndex;
102: }
103:
104: /* (non-Javadoc)
105: * @see org.eclipse.jdt.core.util.IEnclosingMethodAttribute#getMethodName()
106: */
107: public char[] getMethodName() {
108: return this .methodName;
109: }
110:
111: /* (non-Javadoc)
112: * @see org.eclipse.jdt.core.util.IEnclosingMethodAttribute#getMethodNameIndex()
113: */
114: public int getMethodNameIndex() {
115: return this .methodNameIndex;
116: }
117:
118: /* (non-Javadoc)
119: * @see org.eclipse.jdt.core.util.IEnclosingMethodAttribute#getMethodNameAndTypeIndex()
120: */
121: public int getMethodNameAndTypeIndex() {
122: return this.methodNameAndTypeIndex;
123: }
124: }
|