KickJava   Java API By Example, From Geeks To Geeks.

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


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.IConstantPool;
15 import org.eclipse.jdt.core.util.IConstantPoolConstant;
16 import org.eclipse.jdt.core.util.IConstantPoolEntry;
17 import org.eclipse.jdt.core.util.IEnclosingMethodAttribute;
18
19 /**
20  * Default implementation of EnclosingMethodAttribute.
21  *
22  * @since 3.0
23  */

24 public class EnclosingMethodAttribute extends ClassFileAttribute implements IEnclosingMethodAttribute {
25     
26     private int enclosingClassIndex;
27     private char[] enclosingClassName;
28     private int methodDescriptorIndex;
29     private char[] methodDescriptor;
30     private int methodNameIndex;
31     private char[] methodName;
32     private int methodNameAndTypeIndex;
33     
34     EnclosingMethodAttribute(byte[] classFileBytes, IConstantPool constantPool, int offset) throws ClassFormatException {
35         super(classFileBytes, constantPool, offset);
36         int index = u2At(classFileBytes, 6, offset);
37         this.enclosingClassIndex = index;
38         IConstantPoolEntry constantPoolEntry = constantPool.decodeEntry(index);
39         if (constantPoolEntry.getKind() != IConstantPoolConstant.CONSTANT_Class) {
40             throw new ClassFormatException(ClassFormatException.INVALID_CONSTANT_POOL_ENTRY);
41         }
42         this.enclosingClassName = constantPoolEntry.getClassInfoName();
43         this.methodNameAndTypeIndex = u2At(classFileBytes, 8, offset);
44         if (this.methodNameAndTypeIndex != 0) {
45             constantPoolEntry = constantPool.decodeEntry(this.methodNameAndTypeIndex);
46             if (constantPoolEntry.getKind() != IConstantPoolConstant.CONSTANT_NameAndType) {
47                 throw new ClassFormatException(ClassFormatException.INVALID_CONSTANT_POOL_ENTRY);
48             }
49             this.methodDescriptorIndex = constantPoolEntry.getNameAndTypeInfoDescriptorIndex();
50             this.methodNameIndex = constantPoolEntry.getNameAndTypeInfoNameIndex();
51             constantPoolEntry = constantPool.decodeEntry(this.methodDescriptorIndex);
52             if (constantPoolEntry.getKind() != IConstantPoolConstant.CONSTANT_Utf8) {
53                 throw new ClassFormatException(ClassFormatException.INVALID_CONSTANT_POOL_ENTRY);
54             }
55             this.methodDescriptor = constantPoolEntry.getUtf8Value();
56             constantPoolEntry = constantPool.decodeEntry(this.methodNameIndex);
57             if (constantPoolEntry.getKind() != IConstantPoolConstant.CONSTANT_Utf8) {
58                 throw new ClassFormatException(ClassFormatException.INVALID_CONSTANT_POOL_ENTRY);
59             }
60             this.methodName = constantPoolEntry.getUtf8Value();
61         }
62     }
63     /* (non-Javadoc)
64      * @see org.eclipse.jdt.core.util.IEnclosingMethodAttribute#getEnclosingClass()
65      */

66     public char[] getEnclosingClass() {
67         return this.enclosingClassName;
68     }
69     /* (non-Javadoc)
70      * @see org.eclipse.jdt.core.util.IEnclosingMethodAttribute#getMethodDeclaringClassDescriptorIndex()
71      */

72     public int getEnclosingClassIndex() {
73         return this.enclosingClassIndex;
74     }
75     /* (non-Javadoc)
76      * @see org.eclipse.jdt.core.util.IEnclosingMethodAttribute#getMethodDescriptor()
77      */

78     public char[] getMethodDescriptor() {
79         return this.methodDescriptor;
80     }
81     /* (non-Javadoc)
82      * @see org.eclipse.jdt.core.util.IEnclosingMethodAttribute#getMethodDescriptorIndex()
83      */

84     public int getMethodDescriptorIndex() {
85         return this.methodDescriptorIndex;
86     }
87     /* (non-Javadoc)
88      * @see org.eclipse.jdt.core.util.IEnclosingMethodAttribute#getMethodName()
89      */

90     public char[] getMethodName() {
91         return this.methodName;
92     }
93     /* (non-Javadoc)
94      * @see org.eclipse.jdt.core.util.IEnclosingMethodAttribute#getMethodNameIndex()
95      */

96     public int getMethodNameIndex() {
97         return this.methodNameIndex;
98     }
99     /* (non-Javadoc)
100      * @see org.eclipse.jdt.core.util.IEnclosingMethodAttribute#getMethodNameAndTypeIndex()
101      */

102     public int getMethodNameAndTypeIndex() {
103         return this.methodNameAndTypeIndex;
104     }
105 }
106
Popular Tags