001: /*
002: * ProGuard -- shrinking, optimization, obfuscation, and preverification
003: * of Java bytecode.
004: *
005: * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
006: *
007: * This library is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the Free
009: * Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This library is distributed in the hope that it will be useful, but WITHOUT
013: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public License
018: * along with this library; if not, write to the Free Software Foundation,
019: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: package proguard.classfile.attribute;
022:
023: import proguard.classfile.*;
024: import proguard.classfile.attribute.visitor.AttributeVisitor;
025: import proguard.classfile.visitor.*;
026:
027: /**
028: * This Attribute represents an enclosing method attribute.
029: *
030: * @author Eric Lafortune
031: */
032: public class EnclosingMethodAttribute extends Attribute {
033: public int u2classIndex;
034: public int u2nameAndTypeIndex;
035:
036: /**
037: * An extra field pointing to the referenced Clazz object.
038: * This field is typically filled out by the <code>{@link
039: * proguard.classfile.util.ClassReferenceInitializer
040: * ClassReferenceInitializer}</code>.
041: */
042: public Clazz referencedClass;
043:
044: /**
045: * An extra field optionally pointing to the referenced Method object.
046: * This field is typically filled out by the <code>{@link
047: * proguard.classfile.util.ClassReferenceInitializer
048: * ClassReferenceInitializer}</code>.
049: */
050: public Method referencedMethod;
051:
052: /**
053: * Creates an uninitialized EnclosingMethodAttribute.
054: */
055: public EnclosingMethodAttribute() {
056: }
057:
058: /**
059: * Returns the class name.
060: */
061: public String getClassName(Clazz clazz) {
062: return clazz.getClassName(u2classIndex);
063: }
064:
065: /**
066: * Returns the method/field name.
067: */
068: public String getName(Clazz clazz) {
069: return clazz.getName(u2nameAndTypeIndex);
070: }
071:
072: /**
073: * Returns the type.
074: */
075: public String getType(Clazz clazz) {
076: return clazz.getType(u2nameAndTypeIndex);
077: }
078:
079: /**
080: * Lets the referenced class accept the given visitor.
081: */
082: public void referencedClassAccept(ClassVisitor classVisitor) {
083: if (referencedClass != null) {
084: referencedClass.accept(classVisitor);
085: }
086: }
087:
088: /**
089: * Lets the referenced class member accept the given visitor.
090: */
091: public void referencedMethodAccept(MemberVisitor memberVisitor) {
092: if (referencedMethod != null) {
093: referencedMethod.accept(referencedClass, memberVisitor);
094: }
095: }
096:
097: // Implementations for Attribute.
098:
099: public void accept(Clazz clazz, AttributeVisitor attributeVisitor) {
100: attributeVisitor.visitEnclosingMethodAttribute(clazz, this);
101: }
102: }
|