1 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 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 66 public char[] getEnclosingClass() { 67 return this.enclosingClassName; 68 } 69 72 public int getEnclosingClassIndex() { 73 return this.enclosingClassIndex; 74 } 75 78 public char[] getMethodDescriptor() { 79 return this.methodDescriptor; 80 } 81 84 public int getMethodDescriptorIndex() { 85 return this.methodDescriptorIndex; 86 } 87 90 public char[] getMethodName() { 91 return this.methodName; 92 } 93 96 public int getMethodNameIndex() { 97 return this.methodNameIndex; 98 } 99 102 public int getMethodNameAndTypeIndex() { 103 return this.methodNameAndTypeIndex; 104 } 105 } 106 | Popular Tags |