diff options
author | Joe Onorato <joeo@android.com> | 2009-08-31 10:12:00 -0700 |
---|---|---|
committer | Joe Onorato <joeo@android.com> | 2009-08-31 10:12:00 -0700 |
commit | b72c5c2e5482cf10117b2b25f642f7616b2326c3 (patch) | |
tree | f02ba1bc29f4fe6853d9b7008eed37cdcfb96e81 /src/proguard/classfile/attribute | |
parent | a23344a828357fe4b6596f8af5fed467d72757ab (diff) | |
download | android_external_proguard-b72c5c2e5482cf10117b2b25f642f7616b2326c3.tar.gz android_external_proguard-b72c5c2e5482cf10117b2b25f642f7616b2326c3.tar.bz2 android_external_proguard-b72c5c2e5482cf10117b2b25f642f7616b2326c3.zip |
ProGuard 4.4
Diffstat (limited to 'src/proguard/classfile/attribute')
77 files changed, 7314 insertions, 0 deletions
diff --git a/src/proguard/classfile/attribute/Attribute.java b/src/proguard/classfile/attribute/Attribute.java new file mode 100644 index 0000000..2e16e22 --- /dev/null +++ b/src/proguard/classfile/attribute/Attribute.java @@ -0,0 +1,142 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +import proguard.classfile.*; +import proguard.classfile.attribute.visitor.AttributeVisitor; + +/** + * This abstract class represents an attribute that is attached to a class, + * a class member, or a code attribute. Specific types of attributes are + * subclassed from it. + * + * @author Eric Lafortune + * @noinspection AbstractClassWithoutAbstractMethods + */ +public abstract class Attribute implements VisitorAccepter +{ + public int u2attributeNameIndex; + //public int u4attributeLength; + //public byte info[]; + + /** + * An extra field in which visitors can store information. + */ + public Object visitorInfo; + + + /** + * Create an uninitialized Attribute. + */ + protected Attribute() + { + } + + + /** + * Create an initialized Attribute. + */ + protected Attribute(int u2attributeNameIndex) + { + this.u2attributeNameIndex = u2attributeNameIndex; + } + + + /** + * Returns the String name of the attribute. + */ + public String getAttributeName(Clazz clazz) + { + return clazz.getString(u2attributeNameIndex); + } + + + // Methods to be implemented by extensions, if applicable. + + /** + * Accepts the given visitor. + */ + public void accept(Clazz clazz, AttributeVisitor attributeVisitor) + { + throw new UnsupportedOperationException("Method must be overridden in ["+this.getClass().getName()+"] if ever called"); + } + + /** + * Accepts the given visitor in the context of the given field. + */ + public void accept(Clazz clazz, Field field, AttributeVisitor attributeVisitor) + { + // Delegate the default invocation if the field is null anyway. + if (field == null) + { + accept(clazz, attributeVisitor); + } + else + { + throw new UnsupportedOperationException("Method must be overridden in ["+this.getClass().getName()+"] if ever called"); + } + } + + /** + * Accepts the given visitor in the context of the given method. + */ + public void accept(Clazz clazz, Method method, AttributeVisitor attributeVisitor) + { + // Delegate the default invocation if the method is null anyway. + if (method == null) + { + accept(clazz, (Field)null, attributeVisitor); + } + else + { + throw new UnsupportedOperationException("Method must be overridden in ["+this.getClass().getName()+"] if ever called"); + } + } + + /** + * Accepts the given visitor in the context of the given code attribute. + */ + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, AttributeVisitor attributeVisitor) + { + // Delegate the default invocation if the code attribute is null anyway. + if (codeAttribute == null) + { + accept(clazz, method, attributeVisitor); + } + else + { + throw new UnsupportedOperationException("Method must be overridden in ["+this.getClass().getName()+"] if ever called"); + } + } + + + // Implementations for VisitorAccepter. + + public Object getVisitorInfo() + { + return visitorInfo; + } + + public void setVisitorInfo(Object visitorInfo) + { + this.visitorInfo = visitorInfo; + } +} diff --git a/src/proguard/classfile/attribute/CodeAttribute.java b/src/proguard/classfile/attribute/CodeAttribute.java new file mode 100644 index 0000000..92ff9ea --- /dev/null +++ b/src/proguard/classfile/attribute/CodeAttribute.java @@ -0,0 +1,202 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +import proguard.classfile.*; +import proguard.classfile.attribute.visitor.*; +import proguard.classfile.instruction.*; +import proguard.classfile.instruction.visitor.InstructionVisitor; + +/** + * This Attribute represents a code attribute. + * + * @author Eric Lafortune + */ +public class CodeAttribute extends Attribute +{ + public int u2maxStack; + public int u2maxLocals; + public int u4codeLength; + public byte[] code; + public int u2exceptionTableLength; + public ExceptionInfo[] exceptionTable; + public int u2attributesCount; + public Attribute[] attributes; + + + /** + * Creates an uninitialized CodeAttribute. + */ + public CodeAttribute() + { + } + + + /** + * Creates an initialized CodeAttribute. + */ + public CodeAttribute(int u2attributeNameIndex, + int u2maxStack, + int u2maxLocals, + int u4codeLength, + byte[] code, + int u2exceptionTableLength, + ExceptionInfo[] exceptionTable, + int u2attributesCount, + Attribute[] attributes) + { + super(u2attributeNameIndex); + + this.u2maxStack = u2maxStack; + this.u2maxLocals = u2maxLocals; + this.u4codeLength = u4codeLength; + this.code = code; + this.u2exceptionTableLength = u2exceptionTableLength; + this.exceptionTable = exceptionTable; + this.u2attributesCount = u2attributesCount; + this.attributes = attributes; + } + + + /** + * Returns the (first) attribute with the given name. + */ + public Attribute getAttribute(Clazz clazz, String name) + { + for (int index = 0; index < u2attributesCount; index++) + { + Attribute attribute = attributes[index]; + if (attribute.getAttributeName(clazz).equals(name)) + { + return attribute; + } + } + + return null; + } + + + // Implementations for Attribute. + + public void accept(Clazz clazz, Method method, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitCodeAttribute(clazz, method, this); + } + + + /** + * Applies the given instruction visitor to all instructions. + */ + public void instructionsAccept(Clazz clazz, Method method, InstructionVisitor instructionVisitor) + { + instructionsAccept(clazz, method, 0, u4codeLength, instructionVisitor); + } + + + /** + * Applies the given instruction visitor to the instruction at the specified + * offset. + */ + public void instructionAccept(Clazz clazz, Method method, int offset, InstructionVisitor instructionVisitor) + { + Instruction instruction = InstructionFactory.create(code, offset); + instruction.accept(clazz, method, this, offset, instructionVisitor); + } + + + /** + * Applies the given instruction visitor to all instructions in the + * specified range of offsets. + */ + public void instructionsAccept(Clazz clazz, Method method, int startOffset, int endOffset, InstructionVisitor instructionVisitor) + { + int offset = startOffset; + + while (offset < endOffset) + { + // Note that the instruction is only volatile. + Instruction instruction = InstructionFactory.create(code, offset); + int instructionLength = instruction.length(offset); + instruction.accept(clazz, method, this, offset, instructionVisitor); + offset += instructionLength; + } + } + + + /** + * Applies the given exception visitor to all exceptions. + */ + public void exceptionsAccept(Clazz clazz, Method method, ExceptionInfoVisitor exceptionInfoVisitor) + { + for (int index = 0; index < u2exceptionTableLength; index++) + { + // We don't need double dispatching here, since there is only one + // type of ExceptionInfo. + exceptionInfoVisitor.visitExceptionInfo(clazz, method, this, exceptionTable[index]); + } + } + + + /** + * Applies the given exception visitor to all exceptions that are applicable + * to the instruction at the specified offset. + */ + public void exceptionsAccept(Clazz clazz, Method method, int offset, ExceptionInfoVisitor exceptionInfoVisitor) + { + for (int index = 0; index < u2exceptionTableLength; index++) + { + ExceptionInfo exceptionInfo = exceptionTable[index]; + if (exceptionInfo.isApplicable(offset)) + { + exceptionInfoVisitor.visitExceptionInfo(clazz, method, this, exceptionInfo); + } + } + } + + + /** + * Applies the given exception visitor to all exceptions that are applicable + * to any of the instructions in the specified range of offsets. + */ + public void exceptionsAccept(Clazz clazz, Method method, int startOffset, int endOffset, ExceptionInfoVisitor exceptionInfoVisitor) + { + for (int index = 0; index < u2exceptionTableLength; index++) + { + ExceptionInfo exceptionInfo = exceptionTable[index]; + if (exceptionInfo.isApplicable(startOffset, endOffset)) + { + exceptionInfoVisitor.visitExceptionInfo(clazz, method, this, exceptionInfo); + } + } + } + + + /** + * Applies the given attribute visitor to all attributes. + */ + public void attributesAccept(Clazz clazz, Method method, AttributeVisitor attributeVisitor) + { + for (int index = 0; index < u2attributesCount; index++) + { + attributes[index].accept(clazz, method, this, attributeVisitor); + } + } +} diff --git a/src/proguard/classfile/attribute/ConstantValueAttribute.java b/src/proguard/classfile/attribute/ConstantValueAttribute.java new file mode 100644 index 0000000..3ae991e --- /dev/null +++ b/src/proguard/classfile/attribute/ConstantValueAttribute.java @@ -0,0 +1,62 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +import proguard.classfile.*; +import proguard.classfile.attribute.visitor.AttributeVisitor; + +/** + * This Attribute represents a constant value attribute. + * + * @author Eric Lafortune + */ +public class ConstantValueAttribute extends Attribute +{ + public int u2constantValueIndex; + + + /** + * Creates an uninitialized ConstantValueAttribute. + */ + public ConstantValueAttribute() + { + } + + + /** + * Creates an initialized ConstantValueAttribute. + */ + public ConstantValueAttribute(int u2attributeNameIndex, + int u2constantValueIndex) + { + super(u2attributeNameIndex); + + this.u2constantValueIndex = u2constantValueIndex; + } + + + // Implementations for Attribute. + + public void accept(Clazz clazz, Field field, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitConstantValueAttribute(clazz, field, this); + } +} diff --git a/src/proguard/classfile/attribute/DeprecatedAttribute.java b/src/proguard/classfile/attribute/DeprecatedAttribute.java new file mode 100644 index 0000000..4180950 --- /dev/null +++ b/src/proguard/classfile/attribute/DeprecatedAttribute.java @@ -0,0 +1,66 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +import proguard.classfile.*; +import proguard.classfile.attribute.visitor.AttributeVisitor; + +/** + * This Attribute represents a deprecated attribute. + * + * @author Eric Lafortune + */ +public class DeprecatedAttribute extends Attribute +{ + /** + * Creates an uninitialized DeprecatedAttribute. + */ + public DeprecatedAttribute() + { + } + + + /** + * Creates an initialized DeprecatedAttribute. + */ + public DeprecatedAttribute(int u2attributeNameIndex) + { + super(u2attributeNameIndex); + } + + + // Implementations for Attribute. + + public void accept(Clazz clazz, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitDeprecatedAttribute(clazz, this); + } + + public void accept(Clazz clazz, Field field, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitDeprecatedAttribute(clazz, field, this); + } + + public void accept(Clazz clazz, Method method, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitDeprecatedAttribute(clazz, method, this); + } +} diff --git a/src/proguard/classfile/attribute/EnclosingMethodAttribute.java b/src/proguard/classfile/attribute/EnclosingMethodAttribute.java new file mode 100644 index 0000000..9275b3a --- /dev/null +++ b/src/proguard/classfile/attribute/EnclosingMethodAttribute.java @@ -0,0 +1,132 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +import proguard.classfile.*; +import proguard.classfile.attribute.visitor.AttributeVisitor; +import proguard.classfile.visitor.*; + +/** + * This Attribute represents an enclosing method attribute. + * + * @author Eric Lafortune + */ +public class EnclosingMethodAttribute extends Attribute +{ + public int u2classIndex; + public int u2nameAndTypeIndex; + + /** + * An extra field pointing to the referenced Clazz object. + * This field is typically filled out by the <code>{@link + * proguard.classfile.util.ClassReferenceInitializer + * ClassReferenceInitializer}</code>. + */ + public Clazz referencedClass; + + /** + * An extra field optionally pointing to the referenced Method object. + * This field is typically filled out by the <code>{@link + * proguard.classfile.util.ClassReferenceInitializer + * ClassReferenceInitializer}</code>. + */ + public Method referencedMethod; + + + /** + * Creates an uninitialized EnclosingMethodAttribute. + */ + public EnclosingMethodAttribute() + { + } + + + /** + * Creates an initialized EnclosingMethodAttribute. + */ + public EnclosingMethodAttribute(int u2attributeNameIndex, + int u2classIndex, + int u2nameAndTypeIndex) + { + super(u2attributeNameIndex); + + this.u2classIndex = u2classIndex; + this.u2nameAndTypeIndex = u2nameAndTypeIndex; + } + + + /** + * Returns the class name. + */ + public String getClassName(Clazz clazz) + { + return clazz.getClassName(u2classIndex); + } + + /** + * Returns the method/field name. + */ + public String getName(Clazz clazz) + { + return clazz.getName(u2nameAndTypeIndex); + } + + /** + * Returns the type. + */ + public String getType(Clazz clazz) + { + return clazz.getType(u2nameAndTypeIndex); + } + + + /** + * Lets the referenced class accept the given visitor. + */ + public void referencedClassAccept(ClassVisitor classVisitor) + { + if (referencedClass != null) + { + referencedClass.accept(classVisitor); + } + } + + + /** + * Lets the referenced class member accept the given visitor. + */ + public void referencedMethodAccept(MemberVisitor memberVisitor) + { + if (referencedMethod != null) + { + referencedMethod.accept(referencedClass, + memberVisitor); + } + } + + + // Implementations for Attribute. + + public void accept(Clazz clazz, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitEnclosingMethodAttribute(clazz, this); + } +} diff --git a/src/proguard/classfile/attribute/ExceptionInfo.java b/src/proguard/classfile/attribute/ExceptionInfo.java new file mode 100644 index 0000000..082efab --- /dev/null +++ b/src/proguard/classfile/attribute/ExceptionInfo.java @@ -0,0 +1,100 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +import proguard.classfile.VisitorAccepter; + +/** + * Representation of an Exception table entry. + * + * @author Eric Lafortune + */ +public class ExceptionInfo implements VisitorAccepter +{ + public int u2startPC; + public int u2endPC; + public int u2handlerPC; + public int u2catchType; + + /** + * An extra field in which visitors can store information. + */ + public Object visitorInfo; + + + /** + * Creates an uninitialized ExceptionInfo. + */ + public ExceptionInfo() + { + this(0, 0, 0, 0); + } + + + /** + * Creates an ExceptionInfo with the given properties. + */ + public ExceptionInfo(int u2startPC, + int u2endPC, + int u2handlerPC, + int u2catchType) + { + this.u2startPC = u2startPC; + this.u2endPC = u2endPC; + this.u2handlerPC = u2handlerPC; + this.u2catchType = u2catchType; + } + + + /** + * Returns whether the exception's try block contains the instruction at the + * given offset. + */ + public boolean isApplicable(int instructionOffset) + { + return instructionOffset >= u2startPC && + instructionOffset < u2endPC; + } + + + /** + * Returns whether the exception's try block overlaps with the specified + * block of instructions. + */ + public boolean isApplicable(int startOffset, int endOffset) + { + return u2startPC < endOffset && + u2endPC > startOffset; + } + + + // Implementations for VisitorAccepter. + + public Object getVisitorInfo() + { + return visitorInfo; + } + + public void setVisitorInfo(Object visitorInfo) + { + this.visitorInfo = visitorInfo; + } +} diff --git a/src/proguard/classfile/attribute/ExceptionsAttribute.java b/src/proguard/classfile/attribute/ExceptionsAttribute.java new file mode 100644 index 0000000..d22c4a6 --- /dev/null +++ b/src/proguard/classfile/attribute/ExceptionsAttribute.java @@ -0,0 +1,80 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +import proguard.classfile.*; +import proguard.classfile.attribute.visitor.AttributeVisitor; +import proguard.classfile.constant.visitor.ConstantVisitor; + +/** + * This Attribute represents an exceptions attribute. + * + * @author Eric Lafortune + */ +public class ExceptionsAttribute extends Attribute +{ + public int u2exceptionIndexTableLength; + public int[] u2exceptionIndexTable; + + + /** + * Creates an uninitialized ExceptionsAttribute. + */ + public ExceptionsAttribute() + { + } + + + /** + * Creates an initialized ExceptionsAttribute. + */ + public ExceptionsAttribute(int u2attributeNameIndex, + int u2exceptionIndexTableLength, + int[] u2exceptionIndexTable) + { + super(u2attributeNameIndex); + + this.u2exceptionIndexTableLength = u2exceptionIndexTableLength; + this.u2exceptionIndexTable = u2exceptionIndexTable; + } + + + // Implementations for Attribute. + + public void accept(Clazz clazz, Method method, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitExceptionsAttribute(clazz, method, this); + } + + + /** + * Applies the given constant pool visitor to all exception class pool info + * entries. + */ + public void exceptionEntriesAccept(ProgramClass programClass, ConstantVisitor constantVisitor) + { + for (int index = 0; index < u2exceptionIndexTableLength; index++) + { + programClass.constantPoolEntryAccept(u2exceptionIndexTable[index], + constantVisitor); + } + } +} diff --git a/src/proguard/classfile/attribute/InnerClassesAttribute.java b/src/proguard/classfile/attribute/InnerClassesAttribute.java new file mode 100644 index 0000000..2f7e310 --- /dev/null +++ b/src/proguard/classfile/attribute/InnerClassesAttribute.java @@ -0,0 +1,80 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +import proguard.classfile.Clazz; +import proguard.classfile.attribute.visitor.*; + +/** + * This Attribute represents an inner classes attribute. + * + * @author Eric Lafortune + */ +public class InnerClassesAttribute extends Attribute +{ + public int u2classesCount; + public InnerClassesInfo[] classes; + + + /** + * Creates an uninitialized InnerClassesAttribute. + */ + public InnerClassesAttribute() + { + } + + + /** + * Creates an initialized InnerClassesAttribute. + */ + public InnerClassesAttribute(int u2attributeNameIndex, + int u2classesCount, + InnerClassesInfo[] classes) + { + super(u2attributeNameIndex); + + this.u2classesCount = u2classesCount; + this.classes = classes; + } + + // + + // Implementations for Attribute. + + public void accept(Clazz clazz, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitInnerClassesAttribute(clazz, this); + } + + + /** + * Applies the given visitor to all inner classes. + */ + public void innerClassEntriesAccept(Clazz clazz, InnerClassesInfoVisitor innerClassesInfoVisitor) + { + for (int index = 0; index < u2classesCount; index++) + { + // We don't need double dispatching here, since there is only one + // type of InnerClassesInfo. + innerClassesInfoVisitor.visitInnerClassesInfo(clazz, classes[index]); + } + } +} diff --git a/src/proguard/classfile/attribute/InnerClassesInfo.java b/src/proguard/classfile/attribute/InnerClassesInfo.java new file mode 100644 index 0000000..1bdd6c3 --- /dev/null +++ b/src/proguard/classfile/attribute/InnerClassesInfo.java @@ -0,0 +1,122 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +import proguard.classfile.*; +import proguard.classfile.constant.visitor.ConstantVisitor; + +/** + * Representation of an Inner Classes table entry. + * + * @author Eric Lafortune + */ +public class InnerClassesInfo implements VisitorAccepter +{ + public int u2innerClassIndex; + public int u2outerClassIndex; + public int u2innerNameIndex; + public int u2innerClassAccessFlags; + + /** + * An extra field in which visitors can store information. + */ + public Object visitorInfo; + + + /** + * Returns the inner class index. + */ + protected int getInnerClassIndex() + { + return u2innerClassIndex; + } + + /** + * Returns the name index. + */ + protected int getInnerNameIndex() + { + return u2innerNameIndex; + } + + /** + * Sets the name index. + */ + protected void setInnerNameIndex(int index) + { + u2innerNameIndex = index; + } + + + /** + * Applies the given constant pool visitor to the class constant of the + * inner class, if any. + */ + public void innerClassConstantAccept(Clazz clazz, ConstantVisitor constantVisitor) + { + if (u2innerClassIndex != 0) + { + clazz.constantPoolEntryAccept(u2innerClassIndex, + constantVisitor); + } + } + + + /** + * Applies the given constant pool visitor to the class constant of the + * outer class, if any. + */ + public void outerClassConstantAccept(Clazz clazz, ConstantVisitor constantVisitor) + { + if (u2outerClassIndex != 0) + { + clazz.constantPoolEntryAccept(u2outerClassIndex, + constantVisitor); + } + } + + + /** + * Applies the given constant pool visitor to the Utf8 constant of the + * inner name, if any. + */ + public void innerNameConstantAccept(Clazz clazz, ConstantVisitor constantVisitor) + { + if (u2innerNameIndex != 0) + { + clazz.constantPoolEntryAccept(u2innerNameIndex, + constantVisitor); + } + } + + + // Implementations for VisitorAccepter. + + public Object getVisitorInfo() + { + return visitorInfo; + } + + public void setVisitorInfo(Object visitorInfo) + { + this.visitorInfo = visitorInfo; + } +} diff --git a/src/proguard/classfile/attribute/LineNumberInfo.java b/src/proguard/classfile/attribute/LineNumberInfo.java new file mode 100644 index 0000000..f58083a --- /dev/null +++ b/src/proguard/classfile/attribute/LineNumberInfo.java @@ -0,0 +1,50 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +/** + * Representation of an Line Number table entry. + * + * @author Eric Lafortune + */ +public class LineNumberInfo +{ + public int u2startPC; + public int u2lineNumber; + + + /** + * Creates an uninitialized LineNumberInfo. + */ + public LineNumberInfo() + { + } + + + /** + * Creates an initialized LineNumberInfo. + */ + public LineNumberInfo(int u2startPC, int u2lineNumber) + { + this.u2startPC = u2startPC; + this.u2lineNumber = u2lineNumber; + } +} diff --git a/src/proguard/classfile/attribute/LineNumberTableAttribute.java b/src/proguard/classfile/attribute/LineNumberTableAttribute.java new file mode 100644 index 0000000..4d507d9 --- /dev/null +++ b/src/proguard/classfile/attribute/LineNumberTableAttribute.java @@ -0,0 +1,100 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +import proguard.classfile.*; +import proguard.classfile.attribute.visitor.*; + +/** + * This Attribute represents a line number table attribute. + * + * @author Eric Lafortune + */ +public class LineNumberTableAttribute extends Attribute +{ + public int u2lineNumberTableLength; + public LineNumberInfo[] lineNumberTable; + + + /** + * Creates an uninitialized LineNumberTableAttribute. + */ + public LineNumberTableAttribute() + { + } + + + /** + * Creates an initialized LineNumberTableAttribute. + */ + public LineNumberTableAttribute(int u2attributeNameIndex, + int u2lineNumberTableLength, + LineNumberInfo[] lineNumberTable) + { + super(u2attributeNameIndex); + + this.u2lineNumberTableLength = u2lineNumberTableLength; + this.lineNumberTable = lineNumberTable; + } + + + /** + * Returns the line number corresponding to the given byte code program + * counter. + */ + public int getLineNumber(int pc) + { + for (int index = u2lineNumberTableLength-1 ; index >= 0 ; index--) + { + LineNumberInfo info = lineNumberTable[index]; + if (pc >= info.u2startPC) + { + return info.u2lineNumber; + } + } + + return u2lineNumberTableLength > 0 ? + lineNumberTable[0].u2lineNumber : + 0; + } + + + // Implementations for Attribute. + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitLineNumberTableAttribute(clazz, method, codeAttribute, this); + } + + + /** + * Applies the given visitor to all line numbers. + */ + public void lineNumbersAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberInfoVisitor lineNumberInfoVisitor) + { + for (int index = 0; index < u2lineNumberTableLength; index++) + { + // We don't need double dispatching here, since there is only one + // type of LineNumberInfo. + lineNumberInfoVisitor.visitLineNumberInfo(clazz, method, codeAttribute, lineNumberTable[index]); + } + } +} diff --git a/src/proguard/classfile/attribute/LocalVariableInfo.java b/src/proguard/classfile/attribute/LocalVariableInfo.java new file mode 100644 index 0000000..4e54c22 --- /dev/null +++ b/src/proguard/classfile/attribute/LocalVariableInfo.java @@ -0,0 +1,83 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +import proguard.classfile.Clazz; +import proguard.classfile.visitor.ClassVisitor; + +/** + * Representation of an Local Variable table entry. + * + * @author Eric Lafortune + */ +public class LocalVariableInfo +{ + public int u2startPC; + public int u2length; + public int u2nameIndex; + public int u2descriptorIndex; + public int u2index; + + /** + * An extra field pointing to the referenced Clazz object. + * This field is typically filled out by the <code>{@link + * proguard.classfile.util.ClassReferenceInitializer + * ClassReferenceInitializer}</code>. + */ + public Clazz referencedClass; + + + /** + * Creates an uninitialized LocalVariableInfo. + */ + public LocalVariableInfo() + { + } + + + /** + * Creates an initialized LocalVariableInfo. + */ + public LocalVariableInfo(int u2startPC, + int u2length, + int u2nameIndex, + int u2descriptorIndex, + int u2index) + { + this.u2startPC = u2startPC; + this.u2length = u2length; + this.u2nameIndex = u2nameIndex; + this.u2descriptorIndex = u2descriptorIndex; + this.u2index = u2index; + } + + + /** + * Lets the referenced class accept the given visitor. + */ + public void referencedClassAccept(ClassVisitor classVisitor) + { + if (referencedClass != null) + { + referencedClass.accept(classVisitor); + } + } +} diff --git a/src/proguard/classfile/attribute/LocalVariableTableAttribute.java b/src/proguard/classfile/attribute/LocalVariableTableAttribute.java new file mode 100644 index 0000000..9c3f115 --- /dev/null +++ b/src/proguard/classfile/attribute/LocalVariableTableAttribute.java @@ -0,0 +1,79 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +import proguard.classfile.*; +import proguard.classfile.attribute.visitor.*; + +/** + * This Attribute represents a local variable table attribute. + * + * @author Eric Lafortune + */ +public class LocalVariableTableAttribute extends Attribute +{ + public int u2localVariableTableLength; + public LocalVariableInfo[] localVariableTable; + + + /** + * Creates an uninitialized LocalVariableTableAttribute. + */ + public LocalVariableTableAttribute() + { + } + + + /** + * Creates an initialized LocalVariableTableAttribute. + */ + public LocalVariableTableAttribute(int u2attributeNameIndex, + int u2localVariableTableLength, + LocalVariableInfo[] localVariableTable) + { + super(u2attributeNameIndex); + + this.u2localVariableTableLength = u2localVariableTableLength; + this.localVariableTable = localVariableTable; + } + + + // Implementations for Attribute. + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitLocalVariableTableAttribute(clazz, method, codeAttribute, this); + } + + + /** + * Applies the given visitor to all local variables. + */ + public void localVariablesAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableInfoVisitor localVariableInfoVisitor) + { + for (int index = 0; index < u2localVariableTableLength; index++) + { + // We don't need double dispatching here, since there is only one + // type of LocalVariableInfo. + localVariableInfoVisitor.visitLocalVariableInfo(clazz, method, codeAttribute, localVariableTable[index]); + } + } +} diff --git a/src/proguard/classfile/attribute/LocalVariableTypeInfo.java b/src/proguard/classfile/attribute/LocalVariableTypeInfo.java new file mode 100644 index 0000000..1b71f35 --- /dev/null +++ b/src/proguard/classfile/attribute/LocalVariableTypeInfo.java @@ -0,0 +1,91 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +import proguard.classfile.Clazz; +import proguard.classfile.visitor.ClassVisitor; + +/** + * Representation of an Local Variable table entry. + * + * @author Eric Lafortune + */ +public class LocalVariableTypeInfo +{ + public int u2startPC; + public int u2length; + public int u2nameIndex; + public int u2signatureIndex; + public int u2index; + + /** + * An extra field pointing to the Clazz objects referenced in the + * type string. This field is typically filled out by the <code>{@link + * proguard.classfile.util.ClassReferenceInitializer + * ClassReferenceInitializer}</code>. + * References to primitive types are ignored. + */ + public Clazz[] referencedClasses; + + + /** + * Creates an uninitialized LocalVariableTypeInfo. + */ + public LocalVariableTypeInfo() + { + } + + + /** + * Creates an initialized LocalVariableTypeInfo. + */ + public LocalVariableTypeInfo(int u2startPC, + int u2length, + int u2nameIndex, + int u2signatureIndex, + int u2index) + { + this.u2startPC = u2startPC; + this.u2length = u2length; + this.u2nameIndex = u2nameIndex; + this.u2signatureIndex = u2signatureIndex; + this.u2index = u2index; + } + + + /** + * Applies the given visitor to all referenced classes. + */ + public void referencedClassesAccept(ClassVisitor classVisitor) + { + if (referencedClasses != null) + { + for (int index = 0; index < referencedClasses.length; index++) + { + Clazz referencedClass = referencedClasses[index]; + if (referencedClass != null) + { + referencedClass.accept(classVisitor); + } + } + } + } +} diff --git a/src/proguard/classfile/attribute/LocalVariableTypeTableAttribute.java b/src/proguard/classfile/attribute/LocalVariableTypeTableAttribute.java new file mode 100644 index 0000000..fd856fe --- /dev/null +++ b/src/proguard/classfile/attribute/LocalVariableTypeTableAttribute.java @@ -0,0 +1,79 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +import proguard.classfile.*; +import proguard.classfile.attribute.visitor.*; + +/** + * This Attribute represents a local variable table type attribute. + * + * @author Eric Lafortune + */ +public class LocalVariableTypeTableAttribute extends Attribute +{ + public int u2localVariableTypeTableLength; + public LocalVariableTypeInfo[] localVariableTypeTable; + + + /** + * Creates an uninitialized LocalVariableTypeTableAttribute. + */ + public LocalVariableTypeTableAttribute() + { + } + + + /** + * Creates an initialized LocalVariableTypeTableAttribute. + */ + public LocalVariableTypeTableAttribute(int u2attributeNameIndex, + int u2localVariableTypeTableLength, + LocalVariableTypeInfo[] localVariableTypeTable) + { + super(u2attributeNameIndex); + + this.u2localVariableTypeTableLength = u2localVariableTypeTableLength; + this.localVariableTypeTable = localVariableTypeTable; + } + + + // Implementations for Attribute. + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitLocalVariableTypeTableAttribute(clazz, method, codeAttribute, this); + } + + + /** + * Applies the given visitor to all local variable types. + */ + public void localVariablesAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeInfoVisitor localVariableTypeInfoVisitor) + { + for (int index = 0; index < u2localVariableTypeTableLength; index++) + { + // We don't need double dispatching here, since there is only one + // type of LocalVariableTypeInfo. + localVariableTypeInfoVisitor.visitLocalVariableTypeInfo(clazz, method, codeAttribute, localVariableTypeTable[index]); + } + } +} diff --git a/src/proguard/classfile/attribute/SignatureAttribute.java b/src/proguard/classfile/attribute/SignatureAttribute.java new file mode 100644 index 0000000..c7585fe --- /dev/null +++ b/src/proguard/classfile/attribute/SignatureAttribute.java @@ -0,0 +1,100 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +import proguard.classfile.*; +import proguard.classfile.attribute.visitor.AttributeVisitor; +import proguard.classfile.visitor.ClassVisitor; + +/** + * This Attribute represents a signature attribute. + * + * @author Eric Lafortune + */ +public class SignatureAttribute extends Attribute +{ + public int u2signatureIndex; + + /** + * An extra field pointing to the Clazz objects referenced in the + * signature string. This field is filled out by the <code>{@link + * proguard.classfile.util.ClassReferenceInitializer ClassReferenceInitializer}</code>. + * References to primitive types are ignored. + */ + public Clazz[] referencedClasses; + + + /** + * Creates an uninitialized SignatureAttribute. + */ + public SignatureAttribute() + { + } + + + /** + * Creates an initialized SignatureAttribute. + */ + public SignatureAttribute(int u2attributeNameIndex, + int u2signatureIndex) + { + super(u2attributeNameIndex); + + this.u2signatureIndex = u2signatureIndex; + } + + + /** + * Lets the Clazz objects referenced in the signature string accept the + * given visitor. + */ + public void referencedClassesAccept(ClassVisitor classVisitor) + { + if (referencedClasses != null) + { + for (int index = 0; index < referencedClasses.length; index++) + { + if (referencedClasses[index] != null) + { + referencedClasses[index].accept(classVisitor); + } + } + } + } + + + // Implementations for Attribute. + + public void accept(Clazz clazz, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitSignatureAttribute(clazz, this); + } + + public void accept(Clazz clazz, Field field, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitSignatureAttribute(clazz, field, this); + } + + public void accept(Clazz clazz, Method method, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitSignatureAttribute(clazz, method, this); + } + } diff --git a/src/proguard/classfile/attribute/SourceDirAttribute.java b/src/proguard/classfile/attribute/SourceDirAttribute.java new file mode 100644 index 0000000..a26e8b1 --- /dev/null +++ b/src/proguard/classfile/attribute/SourceDirAttribute.java @@ -0,0 +1,62 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +import proguard.classfile.Clazz; +import proguard.classfile.attribute.visitor.AttributeVisitor; + +/** + * This Attribute represents a source directory attribute. + * + * @author Eric Lafortune + */ +public class SourceDirAttribute extends Attribute +{ + public int u2sourceDirIndex; + + + /** + * Creates an uninitialized SourceDirAttribute. + */ + public SourceDirAttribute() + { + } + + + /** + * Creates an initialized SourceDirAttribute. + */ + public SourceDirAttribute(int u2attributeNameIndex, + int u2sourceDirIndex) + { + super(u2attributeNameIndex); + + this.u2sourceDirIndex = u2sourceDirIndex; + } + + + // Implementations for Attribute. + + public void accept(Clazz clazz, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitSourceDirAttribute(clazz, this); + } +} diff --git a/src/proguard/classfile/attribute/SourceFileAttribute.java b/src/proguard/classfile/attribute/SourceFileAttribute.java new file mode 100644 index 0000000..24269b7 --- /dev/null +++ b/src/proguard/classfile/attribute/SourceFileAttribute.java @@ -0,0 +1,62 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +import proguard.classfile.Clazz; +import proguard.classfile.attribute.visitor.AttributeVisitor; + +/** + * This Attribute represents a source file attribute. + * + * @author Eric Lafortune + */ +public class SourceFileAttribute extends Attribute +{ + public int u2sourceFileIndex; + + + /** + * Creates an uninitialized SourceFileAttribute. + */ + public SourceFileAttribute() + { + } + + + /** + * Creates an initialized SourceFileAttribute. + */ + public SourceFileAttribute(int u2attributeNameIndex, + int u2sourceFileIndex) + { + super(u2attributeNameIndex); + + this.u2sourceFileIndex = u2sourceFileIndex; + } + + + // Implementations for Attribute. + + public void accept(Clazz clazz, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitSourceFileAttribute(clazz, this); + } +} diff --git a/src/proguard/classfile/attribute/SyntheticAttribute.java b/src/proguard/classfile/attribute/SyntheticAttribute.java new file mode 100644 index 0000000..6ccb1b5 --- /dev/null +++ b/src/proguard/classfile/attribute/SyntheticAttribute.java @@ -0,0 +1,66 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + +import proguard.classfile.*; +import proguard.classfile.attribute.visitor.AttributeVisitor; + +/** + * This Attribute represents a synthetic attribute. + * + * @author Eric Lafortune + */ +public class SyntheticAttribute extends Attribute +{ + /** + * Creates an uninitialized SyntheticAttribute. + */ + public SyntheticAttribute() + { + } + + + /** + * Creates an initialized SyntheticAttribute. + */ + public SyntheticAttribute(int u2attributeNameIndex) + { + super(u2attributeNameIndex); + } + + + // Implementations for Attribute. + + public void accept(Clazz clazz, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitSyntheticAttribute(clazz, this); + } + + public void accept(Clazz clazz, Field field, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitSyntheticAttribute(clazz, field, this); + } + + public void accept(Clazz clazz, Method method, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitSyntheticAttribute(clazz, method, this); + } +} diff --git a/src/proguard/classfile/attribute/UnknownAttribute.java b/src/proguard/classfile/attribute/UnknownAttribute.java new file mode 100644 index 0000000..2f138bd --- /dev/null +++ b/src/proguard/classfile/attribute/UnknownAttribute.java @@ -0,0 +1,82 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute; + + +import proguard.classfile.*; +import proguard.classfile.attribute.visitor.AttributeVisitor; + +/** + * This Attribute represents an unknown attribute. + * + * @author Eric Lafortune + */ +public class UnknownAttribute extends Attribute +{ + public final int u4attributeLength; + public byte[] info; + + + /** + * Creates an uninitialized UnknownAttribute with the given length. + */ + public UnknownAttribute(int attributeLength) + { + u4attributeLength = attributeLength; + } + + + /** + * Creates an initialized UnknownAttribute. + */ + public UnknownAttribute(int u2attributeNameIndex, + int u4attributeLength, + byte[] info) + { + super(u2attributeNameIndex); + + this.u4attributeLength = u4attributeLength; + this.info = info; + } + + + // Implementations for Attribute. + + public void accept(Clazz clazz, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitUnknownAttribute(clazz, this); + } + + public void accept(Clazz clazz, Field field, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitUnknownAttribute(clazz, this); + } + + public void accept(Clazz clazz, Method method, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitUnknownAttribute(clazz, this); + } + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitUnknownAttribute(clazz, this); + } +} diff --git a/src/proguard/classfile/attribute/annotation/Annotation.java b/src/proguard/classfile/attribute/annotation/Annotation.java new file mode 100644 index 0000000..41bb8e3 --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/Annotation.java @@ -0,0 +1,143 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation; + +import proguard.classfile.*; +import proguard.classfile.attribute.annotation.visitor.ElementValueVisitor; +import proguard.classfile.visitor.ClassVisitor; + +/** + * Representation of an annotation. + * + * @author Eric Lafortune + */ +public class Annotation implements VisitorAccepter +{ + public int u2typeIndex; + public int u2elementValuesCount; + public ElementValue[] elementValues; + + /** + * An extra field pointing to the Clazz objects referenced in the + * type string. This field is typically filled out by the <code>{@link + * proguard.classfile.util.ClassReferenceInitializer + * ClassReferenceInitializer}</code>. + * References to primitive types are ignored. + */ + public Clazz[] referencedClasses; + + /** + * An extra field in which visitors can store information. + */ + public Object visitorInfo; + + + /** + * Creates an uninitialized Annotation. + */ + public Annotation() + { + } + + + /** + * Creates an initialized Annotation. + */ + public Annotation(int u2typeIndex, + int u2elementValuesCount, + ElementValue[] elementValues) + { + this.u2typeIndex = u2typeIndex; + this.u2elementValuesCount = u2elementValuesCount; + this.elementValues = elementValues; + } + + + /** + * Returns the type. + */ + public String getType(Clazz clazz) + { + return clazz.getString(u2typeIndex); + } + + + + /** + * Applies the given visitor to the first referenced class. This is the + * main annotation class. + */ + public void referencedClassAccept(ClassVisitor classVisitor) + { + if (referencedClasses != null) + { + Clazz referencedClass = referencedClasses[0]; + if (referencedClass != null) + { + referencedClass.accept(classVisitor); + } + } + } + + + /** + * Applies the given visitor to all referenced classes. + */ + public void referencedClassesAccept(ClassVisitor classVisitor) + { + if (referencedClasses != null) + { + for (int index = 0; index < referencedClasses.length; index++) + { + Clazz referencedClass = referencedClasses[index]; + if (referencedClass != null) + { + referencedClass.accept(classVisitor); + } + } + } + } + + + /** + * Applies the given visitor to all element value pairs. + */ + public void elementValuesAccept(Clazz clazz, ElementValueVisitor elementValueVisitor) + { + for (int index = 0; index < u2elementValuesCount; index++) + { + elementValues[index].accept(clazz, this, elementValueVisitor); + } + } + + + // Implementations for VisitorAccepter. + + public Object getVisitorInfo() + { + return visitorInfo; + } + + public void setVisitorInfo(Object visitorInfo) + { + this.visitorInfo = visitorInfo; + } +} diff --git a/src/proguard/classfile/attribute/annotation/AnnotationDefaultAttribute.java b/src/proguard/classfile/attribute/annotation/AnnotationDefaultAttribute.java new file mode 100644 index 0000000..b378cd2 --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/AnnotationDefaultAttribute.java @@ -0,0 +1,73 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation; + +import proguard.classfile.*; +import proguard.classfile.attribute.Attribute; +import proguard.classfile.attribute.annotation.visitor.ElementValueVisitor; +import proguard.classfile.attribute.visitor.AttributeVisitor; + +/** + * This Attribute represents an annotation default attribute. + * + * @author Eric Lafortune + */ +public class AnnotationDefaultAttribute extends Attribute +{ + public ElementValue defaultValue; + + + /** + * Creates an uninitialized AnnotationDefaultAttribute. + */ + public AnnotationDefaultAttribute() + { + } + + + /** + * Creates an initialized AnnotationDefaultAttribute. + */ + public AnnotationDefaultAttribute(int u2attributeNameIndex, + ElementValue defaultValue) + { + super(u2attributeNameIndex); + + this.defaultValue = defaultValue; + } + + + /** + * Applies the given visitor to the default element value. + */ + public void defaultValueAccept(Clazz clazz, ElementValueVisitor elementValueVisitor) + { + defaultValue.accept(clazz, null, elementValueVisitor); + } + + + // Implementations for Attribute. + + public void accept(Clazz clazz, Method method, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitAnnotationDefaultAttribute(clazz, method, this); + } +} diff --git a/src/proguard/classfile/attribute/annotation/AnnotationElementValue.java b/src/proguard/classfile/attribute/annotation/AnnotationElementValue.java new file mode 100644 index 0000000..29129d0 --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/AnnotationElementValue.java @@ -0,0 +1,76 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation; + +import proguard.classfile.*; +import proguard.classfile.attribute.annotation.visitor.*; + +/** + * This ElementValue represents an annotation element value. + * + * @author Eric Lafortune + */ +public class AnnotationElementValue extends ElementValue +{ + public Annotation annotationValue; + + + /** + * Creates an uninitialized AnnotationElementValue. + */ + public AnnotationElementValue() + { + } + + + /** + * Creates an initialized AnnotationElementValue. + */ + public AnnotationElementValue(int u2elementNameIndex, + Annotation annotationValue) + { + super(u2elementNameIndex); + + this.annotationValue = annotationValue; + } + + + /** + * Applies the given visitor to the annotation. + */ + public void annotationAccept(Clazz clazz, AnnotationVisitor annotationVisitor) + { + annotationVisitor.visitAnnotation(clazz, annotationValue); + } + + + // Implementations for ElementValue. + + public int getTag() + { + return ClassConstants.ELEMENT_VALUE_ANNOTATION; + } + + public void accept(Clazz clazz, Annotation annotation, ElementValueVisitor elementValueVisitor) + { + elementValueVisitor.visitAnnotationElementValue(clazz, annotation, this); + } +} diff --git a/src/proguard/classfile/attribute/annotation/AnnotationsAttribute.java b/src/proguard/classfile/attribute/annotation/AnnotationsAttribute.java new file mode 100644 index 0000000..8117077 --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/AnnotationsAttribute.java @@ -0,0 +1,100 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation; + +import proguard.classfile.*; +import proguard.classfile.attribute.Attribute; +import proguard.classfile.attribute.annotation.visitor.AnnotationVisitor; + +/** + * This Attribute represents an annotations attribute. + * + * @author Eric Lafortune + */ +public abstract class AnnotationsAttribute extends Attribute +{ + public int u2annotationsCount; + public Annotation[] annotations; + + + /** + * Creates an uninitialized AnnotationsAttribute. + */ + protected AnnotationsAttribute() + { + } + + + /** + * Creates an initialized AnnotationsAttribute. + */ + protected AnnotationsAttribute(int u2attributeNameIndex, + int u2annotationsCount, + Annotation[] annotations) + { + super(u2attributeNameIndex); + + this.u2annotationsCount = u2annotationsCount; + this.annotations = annotations; + } + + + /** + * Applies the given visitor to all class annotations. + */ + public void annotationsAccept(Clazz clazz, AnnotationVisitor annotationVisitor) + { + for (int index = 0; index < u2annotationsCount; index++) + { + // We don't need double dispatching here, since there is only one + // type of Annotation. + annotationVisitor.visitAnnotation(clazz, annotations[index]); + } + } + + + /** + * Applies the given visitor to all field annotations. + */ + public void annotationsAccept(Clazz clazz, Field field, AnnotationVisitor annotationVisitor) + { + for (int index = 0; index < u2annotationsCount; index++) + { + // We don't need double dispatching here, since there is only one + // type of Annotation. + annotationVisitor.visitAnnotation(clazz, field, annotations[index]); + } + } + + + /** + * Applies the given visitor to all method annotations. + */ + public void annotationsAccept(Clazz clazz, Method method, AnnotationVisitor annotationVisitor) + { + for (int index = 0; index < u2annotationsCount; index++) + { + // We don't need double dispatching here, since there is only one + // type of Annotation. + annotationVisitor.visitAnnotation(clazz, method, annotations[index]); + } + } +} diff --git a/src/proguard/classfile/attribute/annotation/ArrayElementValue.java b/src/proguard/classfile/attribute/annotation/ArrayElementValue.java new file mode 100644 index 0000000..25b8b9f --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/ArrayElementValue.java @@ -0,0 +1,82 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation; + +import proguard.classfile.*; +import proguard.classfile.attribute.annotation.visitor.ElementValueVisitor; + +/** + * This ElementValue represents an array element value. + * + * @author Eric Lafortune + */ +public class ArrayElementValue extends ElementValue +{ + public int u2elementValuesCount; + public ElementValue[] elementValues; + + + /** + * Creates an uninitialized ArrayElementValue. + */ + public ArrayElementValue() + { + } + + + /** + * Creates an initialized ArrayElementValue. + */ + public ArrayElementValue(int u2elementNameIndex, + int u2elementValuesCount, + ElementValue[] elementValues) + { + super(u2elementNameIndex); + + this.u2elementValuesCount = u2elementValuesCount; + this.elementValues = elementValues; + } + + + // Implementations for ElementValue. + + public int getTag() + { + return ClassConstants.ELEMENT_VALUE_ARRAY; + } + + public void accept(Clazz clazz, Annotation annotation, ElementValueVisitor elementValueVisitor) + { + elementValueVisitor.visitArrayElementValue(clazz, annotation, this); + } + + + /** + * Applies the given visitor to all nested element values. + */ + public void elementValuesAccept(Clazz clazz, Annotation annotation, ElementValueVisitor elementValueVisitor) + { + for (int index = 0; index < u2elementValuesCount; index++) + { + elementValues[index].accept(clazz, annotation, elementValueVisitor); + } + } +} diff --git a/src/proguard/classfile/attribute/annotation/ClassElementValue.java b/src/proguard/classfile/attribute/annotation/ClassElementValue.java new file mode 100644 index 0000000..ba51641 --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/ClassElementValue.java @@ -0,0 +1,95 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation; + +import proguard.classfile.*; +import proguard.classfile.attribute.annotation.visitor.ElementValueVisitor; +import proguard.classfile.visitor.ClassVisitor; + +/** + * This ElementValue represents a class element value. + * + * @author Eric Lafortune + */ +public class ClassElementValue extends ElementValue +{ + public int u2classInfoIndex; + + /** + * An extra field pointing to the Clazz objects referenced in the + * type name string. This field is filled out by the <code>{@link + * proguard.classfile.util.ClassReferenceInitializer ClassReferenceInitializer}</code>. + * References to primitive types are ignored. + */ + public Clazz[] referencedClasses; + + + /** + * Creates an uninitialized ClassElementValue. + */ + public ClassElementValue() + { + } + + + /** + * Creates an initialized ClassElementValue. + */ + public ClassElementValue(int u2elementNameIndex, + int u2classInfoIndex) + { + super(u2elementNameIndex); + + this.u2classInfoIndex = u2classInfoIndex; + } + + + /** + * Applies the given visitor to all referenced classes. + */ + public void referencedClassesAccept(ClassVisitor classVisitor) + { + if (referencedClasses != null) + { + for (int index = 0; index < referencedClasses.length; index++) + { + Clazz referencedClass = referencedClasses[index]; + if (referencedClass != null) + { + referencedClass.accept(classVisitor); + } + } + } + } + + + // Implementations for ElementValue. + + public int getTag() + { + return ClassConstants.ELEMENT_VALUE_CLASS; + } + + public void accept(Clazz clazz, Annotation annotation, ElementValueVisitor elementValueVisitor) + { + elementValueVisitor.visitClassElementValue(clazz, annotation, this); + } +} diff --git a/src/proguard/classfile/attribute/annotation/ConstantElementValue.java b/src/proguard/classfile/attribute/annotation/ConstantElementValue.java new file mode 100644 index 0000000..3ebe5e5 --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/ConstantElementValue.java @@ -0,0 +1,71 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation; + +import proguard.classfile.Clazz; +import proguard.classfile.attribute.annotation.visitor.ElementValueVisitor; + +/** + * This ElementValue represents a constant element value. + * + * @author Eric Lafortune + */ +public class ConstantElementValue extends ElementValue +{ + public final int u1tag; + public int u2constantValueIndex; + + + /** + * Creates an uninitialized ConstantElementValue. + */ + public ConstantElementValue(int u1tag) + { + this.u1tag = u1tag; + } + + + /** + * Creates an initialized ConstantElementValue. + */ + public ConstantElementValue(int u1tag, + int u2elementNameIndex, + int u2constantValueIndex) + { + super(u2elementNameIndex); + + this.u1tag = u1tag; + this.u2constantValueIndex = u2constantValueIndex; + } + + + // Implementations for ElementValue. + + public int getTag() + { + return u1tag; + } + + public void accept(Clazz clazz, Annotation annotation, ElementValueVisitor elementValueVisitor) + { + elementValueVisitor.visitConstantElementValue(clazz, annotation, this); + } +} diff --git a/src/proguard/classfile/attribute/annotation/ElementValue.java b/src/proguard/classfile/attribute/annotation/ElementValue.java new file mode 100644 index 0000000..39f8953 --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/ElementValue.java @@ -0,0 +1,126 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation; + +import proguard.classfile.*; +import proguard.classfile.attribute.annotation.visitor.ElementValueVisitor; +import proguard.classfile.visitor.MemberVisitor; + +/** + * This abstract class represents an element value that is attached to an + * annotation or an annotation default. Specific types of element values are + * subclassed from it. + * + * @author Eric Lafortune + */ +public abstract class ElementValue implements VisitorAccepter +{ + /** + * An extra field for the optional element name. It is used in element value + * pairs of annotations. Otherwise, it is 0. + */ + public int u2elementNameIndex; + + /** + * An extra field pointing to the referenced <code>Clazz</code> + * object, if applicable. This field is typically filled out by the + * <code>{@link proguard.classfile.util.ClassReferenceInitializer}</code>. + */ + public Clazz referencedClass; + + /** + * An extra field pointing to the referenced <code>Method</code> + * object, if applicable. This field is typically filled out by the + * <code>{@link proguard.classfile.util.ClassReferenceInitializer}</code>. + */ + public Method referencedMethod; + + /** + * An extra field in which visitors can store information. + */ + public Object visitorInfo; + + + /** + * Creates an uninitialized ElementValue. + */ + protected ElementValue() + { + } + + + /** + * Creates an initialized ElementValue. + */ + protected ElementValue(int u2elementNameIndex) + { + this.u2elementNameIndex = u2elementNameIndex; + } + + + /** + * Returns the element name. + */ + public String getMethodName(Clazz clazz) + { + return clazz.getString(u2elementNameIndex); + } + + + // Abstract methods to be implemented by extensions. + + /** + * Returns the tag of this element value. + */ + public abstract int getTag(); + + + /** + * Accepts the given visitor. + */ + public abstract void accept(Clazz clazz, Annotation annotation, ElementValueVisitor elementValueVisitor); + + + + /** + * Applies the given visitor to the referenced method. + */ + public void referencedMethodAccept(MemberVisitor memberVisitor) + { + if (referencedMethod != null) + { + referencedMethod.accept(referencedClass, memberVisitor); + } + } + + + // Implementations for VisitorAccepter. + + public Object getVisitorInfo() + { + return visitorInfo; + } + + public void setVisitorInfo(Object visitorInfo) + { + this.visitorInfo = visitorInfo; + } +} diff --git a/src/proguard/classfile/attribute/annotation/EnumConstantElementValue.java b/src/proguard/classfile/attribute/annotation/EnumConstantElementValue.java new file mode 100644 index 0000000..d46bb7f --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/EnumConstantElementValue.java @@ -0,0 +1,99 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation; + +import proguard.classfile.*; +import proguard.classfile.attribute.annotation.visitor.ElementValueVisitor; +import proguard.classfile.visitor.ClassVisitor; + +/** + * This ElementValue represents an enumeration constant element value. + * + * @author Eric Lafortune + */ +public class EnumConstantElementValue extends ElementValue +{ + public int u2typeNameIndex; + public int u2constantNameIndex; + + /** + * An extra field pointing to the Clazz objects referenced in the + * type name string. This field is typically filled out by the <code>{@link + * proguard.classfile.util.ClassReferenceInitializer + * ClassReferenceInitializer}</code>. + * References to primitive types are ignored. + */ + public Clazz[] referencedClasses; + + + /** + * Creates an uninitialized EnumConstantElementValue. + */ + public EnumConstantElementValue() + { + } + + + /** + * Creates an initialized EnumConstantElementValue. + */ + public EnumConstantElementValue(int u2elementNameIndex, + int u2typeNameIndex, + int u2constantNameIndex) + { + super(u2elementNameIndex); + + this.u2typeNameIndex = u2typeNameIndex; + this.u2constantNameIndex = u2constantNameIndex; + } + + + /** + * Applies the given visitor to all referenced classes. + */ + public void referencedClassesAccept(ClassVisitor classVisitor) + { + if (referencedClasses != null) + { + for (int index = 0; index < referencedClasses.length; index++) + { + Clazz referencedClass = referencedClasses[index]; + if (referencedClass != null) + { + referencedClass.accept(classVisitor); + } + } + } + } + + + // Implementations for ElementValue. + + public int getTag() + { + return ClassConstants.ELEMENT_VALUE_ENUM_CONSTANT; + } + + public void accept(Clazz clazz, Annotation annotation, ElementValueVisitor elementValueVisitor) + { + elementValueVisitor.visitEnumConstantElementValue(clazz, annotation, this); + } +} diff --git a/src/proguard/classfile/attribute/annotation/ParameterAnnotationsAttribute.java b/src/proguard/classfile/attribute/annotation/ParameterAnnotationsAttribute.java new file mode 100644 index 0000000..3c700c8 --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/ParameterAnnotationsAttribute.java @@ -0,0 +1,83 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation; + +import proguard.classfile.*; +import proguard.classfile.attribute.Attribute; +import proguard.classfile.attribute.annotation.visitor.AnnotationVisitor; + +/** + * This Attribute represents a runtime parameter annotations attribute. + * + * @author Eric Lafortune + */ +public abstract class ParameterAnnotationsAttribute extends Attribute +{ + public int u2parametersCount; + public int[] u2parameterAnnotationsCount; + public Annotation[][] parameterAnnotations; + + + /** + * Creates an uninitialized ParameterAnnotationsAttribute. + */ + protected ParameterAnnotationsAttribute() + { + } + + + /** + * Creates an initialized ParameterAnnotationsAttribute. + */ + protected ParameterAnnotationsAttribute(int u2attributeNameIndex, + int u2parametersCount, + int[] u2parameterAnnotationsCount, + Annotation[][] parameterAnnotations) + { + super(u2attributeNameIndex); + + this.u2parametersCount = u2parametersCount; + this.u2parameterAnnotationsCount = u2parameterAnnotationsCount; + this.parameterAnnotations = parameterAnnotations; + } + + + /** + * Applies the given visitor to all annotations. + */ + public void annotationsAccept(Clazz clazz, Method method, AnnotationVisitor annotationVisitor) + { + // Loop over all parameters. + for (int parameterIndex = 0; parameterIndex < u2parametersCount; parameterIndex++) + { + int annotationsCount = u2parameterAnnotationsCount[parameterIndex]; + Annotation[] annotations = parameterAnnotations[parameterIndex]; + + // Loop over all parameter annotations. + for (int index = 0; index < annotationsCount; index++) + { + // We don't need double dispatching here, since there is only one + // type of Annotation. + annotationVisitor.visitAnnotation(clazz, method, parameterIndex, annotations[index]); + } + } + } +} diff --git a/src/proguard/classfile/attribute/annotation/RuntimeInvisibleAnnotationsAttribute.java b/src/proguard/classfile/attribute/annotation/RuntimeInvisibleAnnotationsAttribute.java new file mode 100644 index 0000000..9c8180c --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/RuntimeInvisibleAnnotationsAttribute.java @@ -0,0 +1,70 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation; + +import proguard.classfile.*; +import proguard.classfile.attribute.visitor.AttributeVisitor; + +/** + * This Attribute represents a runtime invisible annotations attribute. + * + * @author Eric Lafortune + */ +public class RuntimeInvisibleAnnotationsAttribute extends AnnotationsAttribute +{ + /** + * Creates an uninitialized RuntimeInvisibleAnnotationsAttribute. + */ + public RuntimeInvisibleAnnotationsAttribute() + { + } + + + /** + * Creates an initialized RuntimeInvisibleAnnotationsAttribute. + */ + public RuntimeInvisibleAnnotationsAttribute(int u2attributeNameIndex, + int u2annotationsCount, + Annotation[] annotations) + { + super(u2attributeNameIndex, u2annotationsCount, annotations); + } + + +// Implementations for Attribute. + + public void accept(Clazz clazz, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitRuntimeInvisibleAnnotationsAttribute(clazz, this); + } + + + public void accept(Clazz clazz, Field field, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitRuntimeInvisibleAnnotationsAttribute(clazz, field, this); + } + + + public void accept(Clazz clazz, Method method, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitRuntimeInvisibleAnnotationsAttribute(clazz, method, this); + } +} diff --git a/src/proguard/classfile/attribute/annotation/RuntimeInvisibleParameterAnnotationsAttribute.java b/src/proguard/classfile/attribute/annotation/RuntimeInvisibleParameterAnnotationsAttribute.java new file mode 100644 index 0000000..7e41656 --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/RuntimeInvisibleParameterAnnotationsAttribute.java @@ -0,0 +1,62 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation; + +import proguard.classfile.*; +import proguard.classfile.attribute.visitor.AttributeVisitor; + +/** + * This Attribute represents a runtime invisible parameter annotations attribute. + * + * @author Eric Lafortune + */ +public class RuntimeInvisibleParameterAnnotationsAttribute extends ParameterAnnotationsAttribute +{ + /** + * Creates an uninitialized RuntimeInvisibleParameterAnnotationsAttribute. + */ + public RuntimeInvisibleParameterAnnotationsAttribute() + { + } + + + /** + * Creates an initialized RuntimeInvisibleParameterAnnotationsAttribute. + */ + public RuntimeInvisibleParameterAnnotationsAttribute(int u2attributeNameIndex, + int u2parametersCount, + int[] u2parameterAnnotationsCount, + Annotation[][] parameterAnnotations) + { + super(u2attributeNameIndex, + u2parametersCount, + u2parameterAnnotationsCount, + parameterAnnotations); + } + + + // Implementations for Attribute. + + public void accept(Clazz clazz, Method method, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitRuntimeInvisibleParameterAnnotationsAttribute(clazz, method, this); + } +} diff --git a/src/proguard/classfile/attribute/annotation/RuntimeVisibleAnnotationsAttribute.java b/src/proguard/classfile/attribute/annotation/RuntimeVisibleAnnotationsAttribute.java new file mode 100644 index 0000000..380c52e --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/RuntimeVisibleAnnotationsAttribute.java @@ -0,0 +1,70 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation; + +import proguard.classfile.*; +import proguard.classfile.attribute.visitor.AttributeVisitor; + +/** + * This Attribute represents a runtime visible annotations attribute. + * + * @author Eric Lafortune + */ +public class RuntimeVisibleAnnotationsAttribute extends AnnotationsAttribute +{ + /** + * Creates an uninitialized RuntimeVisibleAnnotationsAttribute. + */ + public RuntimeVisibleAnnotationsAttribute() + { + } + + + /** + * Creates an initialized RuntimeVisibleAnnotationsAttribute. + */ + public RuntimeVisibleAnnotationsAttribute(int u2attributeNameIndex, + int u2annotationsCount, + Annotation[] annotations) + { + super(u2attributeNameIndex, u2annotationsCount, annotations); + } + + + // Implementations for Attribute. + + public void accept(Clazz clazz, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitRuntimeVisibleAnnotationsAttribute(clazz, this); + } + + + public void accept(Clazz clazz, Field field, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitRuntimeVisibleAnnotationsAttribute(clazz, field, this); + } + + + public void accept(Clazz clazz, Method method, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitRuntimeVisibleAnnotationsAttribute(clazz, method, this); + } +} diff --git a/src/proguard/classfile/attribute/annotation/RuntimeVisibleParameterAnnotationsAttribute.java b/src/proguard/classfile/attribute/annotation/RuntimeVisibleParameterAnnotationsAttribute.java new file mode 100644 index 0000000..626fbda --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/RuntimeVisibleParameterAnnotationsAttribute.java @@ -0,0 +1,62 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation; + +import proguard.classfile.*; +import proguard.classfile.attribute.visitor.AttributeVisitor; + +/** + * This Attribute represents a runtime visible parameter annotations attribute. + * + * @author Eric Lafortune + */ +public class RuntimeVisibleParameterAnnotationsAttribute extends ParameterAnnotationsAttribute +{ + /** + * Creates an uninitialized RuntimeVisibleParameterAnnotationsAttribute. + */ + public RuntimeVisibleParameterAnnotationsAttribute() + { + } + + + /** + * Creates an initialized RuntimeVisibleParameterAnnotationsAttribute. + */ + public RuntimeVisibleParameterAnnotationsAttribute(int u2attributeNameIndex, + int u2parametersCount, + int[] u2parameterAnnotationsCount, + Annotation[][] parameterAnnotations) + { + super(u2attributeNameIndex, + u2parametersCount, + u2parameterAnnotationsCount, + parameterAnnotations); + } + + + // Implementations for Attribute. + + public void accept(Clazz clazz, Method method, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitRuntimeVisibleParameterAnnotationsAttribute(clazz, method, this); + } +} diff --git a/src/proguard/classfile/attribute/annotation/package.html b/src/proguard/classfile/attribute/annotation/package.html new file mode 100644 index 0000000..6aacff3 --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/package.html @@ -0,0 +1,4 @@ +<body> +This package contains classes to represent the annotation attributes inside +class files. +</body> diff --git a/src/proguard/classfile/attribute/annotation/visitor/AllAnnotationVisitor.java b/src/proguard/classfile/attribute/annotation/visitor/AllAnnotationVisitor.java new file mode 100644 index 0000000..bce7170 --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/visitor/AllAnnotationVisitor.java @@ -0,0 +1,100 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.Attribute; +import proguard.classfile.attribute.annotation.*; +import proguard.classfile.attribute.visitor.AttributeVisitor; +import proguard.classfile.util.SimplifiedVisitor; + +/** + * This AttributeVisitor lets a given AnnotationVisitor visit all Annotation + * objects of the attributes it visits. + * + * @author Eric Lafortune + */ +public class AllAnnotationVisitor +extends SimplifiedVisitor +implements AttributeVisitor +{ + private final AnnotationVisitor annotationVisitor; + + + public AllAnnotationVisitor(AnnotationVisitor annotationVisitor) + { + this.annotationVisitor = annotationVisitor; + } + + + // Implementations for AttributeVisitor. + + public void visitAnyAttribute(Clazz clazz, Attribute attribute) {} + + + public void visitRuntimeVisibleAnnotationsAttribute(Clazz clazz, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute) + { + // Visit the annotations. + runtimeVisibleAnnotationsAttribute.annotationsAccept(clazz, annotationVisitor); + } + + + public void visitRuntimeVisibleAnnotationsAttribute(Clazz clazz, Field field, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute) + { + // Visit the annotations. + runtimeVisibleAnnotationsAttribute.annotationsAccept(clazz, field, annotationVisitor); + } + + + public void visitRuntimeVisibleAnnotationsAttribute(Clazz clazz, Method method, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute) + { + // Visit the annotations. + runtimeVisibleAnnotationsAttribute.annotationsAccept(clazz, method, annotationVisitor); + } + + + public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute) + { + // Visit the annotations. + runtimeInvisibleAnnotationsAttribute.annotationsAccept(clazz, annotationVisitor); + } + + + public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, Field field, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute) + { + // Visit the annotations. + runtimeInvisibleAnnotationsAttribute.annotationsAccept(clazz, field, annotationVisitor); + } + + + public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, Method method, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute) + { + // Visit the annotations. + runtimeInvisibleAnnotationsAttribute.annotationsAccept(clazz, method, annotationVisitor); + } + + + public void visitAnyParameterAnnotationsAttribute(Clazz clazz, Method method, ParameterAnnotationsAttribute parameterAnnotationsAttribute) + { + // Visit the annotations. + parameterAnnotationsAttribute.annotationsAccept(clazz, method, annotationVisitor); + } +} diff --git a/src/proguard/classfile/attribute/annotation/visitor/AnnotatedClassVisitor.java b/src/proguard/classfile/attribute/annotation/visitor/AnnotatedClassVisitor.java new file mode 100644 index 0000000..7a1d7c6 --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/visitor/AnnotatedClassVisitor.java @@ -0,0 +1,62 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation.visitor; + +import proguard.classfile.Clazz; +import proguard.classfile.attribute.annotation.Annotation; +import proguard.classfile.util.SimplifiedVisitor; +import proguard.classfile.visitor.ClassVisitor; + + +/** + * This AnnotationVisitor delegates all visits to a given ClassVisitor. + * The latter visits the class of each visited annotation, although + * never twice in a row. + * + * @author Eric Lafortune + */ +public class AnnotatedClassVisitor +extends SimplifiedVisitor +implements AnnotationVisitor +{ + private final ClassVisitor classVisitor; + + private Clazz lastVisitedClass; + + + public AnnotatedClassVisitor(ClassVisitor classVisitor) + { + this.classVisitor = classVisitor; + } + + + // Implementations for AnnotationVisitor. + + public void visitAnnotation(Clazz clazz, Annotation annotation) + { + if (!clazz.equals(lastVisitedClass)) + { + clazz.accept(classVisitor); + + lastVisitedClass = clazz; + } + } +} diff --git a/src/proguard/classfile/attribute/annotation/visitor/AnnotationToMemberVisitor.java b/src/proguard/classfile/attribute/annotation/visitor/AnnotationToMemberVisitor.java new file mode 100644 index 0000000..c206c16 --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/visitor/AnnotationToMemberVisitor.java @@ -0,0 +1,62 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.annotation.Annotation; +import proguard.classfile.util.SimplifiedVisitor; +import proguard.classfile.visitor.MemberVisitor; + + +/** + * This AnnotationVisitor delegates all visits to a given MemberVisitor. + * The latter visits the class member of each visited class member annotation + * or method parameter annotation, although never twice in a row. + * + * @author Eric Lafortune + */ +public class AnnotationToMemberVisitor +extends SimplifiedVisitor +implements AnnotationVisitor +{ + private final MemberVisitor memberVisitor; + + private Member lastVisitedMember; + + + public AnnotationToMemberVisitor(MemberVisitor memberVisitor) + { + this.memberVisitor = memberVisitor; + } + + + // Implementations for AnnotationVisitor. + + public void visitAnnotation(Clazz clazz, Member member, Annotation annotation) + { + if (!member.equals(lastVisitedMember)) + { + member.accept(clazz, memberVisitor); + + lastVisitedMember = member; + } + } +} diff --git a/src/proguard/classfile/attribute/annotation/visitor/AnnotationTypeFilter.java b/src/proguard/classfile/attribute/annotation/visitor/AnnotationTypeFilter.java new file mode 100644 index 0000000..d869fd2 --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/visitor/AnnotationTypeFilter.java @@ -0,0 +1,102 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.annotation.Annotation; +import proguard.classfile.util.SimplifiedVisitor; +import proguard.util.*; + +/** + * This <code>AnnotationVisitor</code> delegates its visits to another given + * <code>AnnotationVisitor</code>, but only when the visited annotation has + * a type that matches a given regular expression. + * + * @author Eric Lafortune + */ +public class AnnotationTypeFilter +extends SimplifiedVisitor +implements AnnotationVisitor +{ + private final StringMatcher regularExpressionMatcher; + private final AnnotationVisitor annotationVisitor; + + + /** + * Creates a new ClassNameFilter. + * @param regularExpression the regular expression against which annotation + * type names will be matched. + * @param annotationVisitor the <code>annotationVisitor</code> to which + * visits will be delegated. + */ + public AnnotationTypeFilter(String regularExpression, + AnnotationVisitor annotationVisitor) + { + this.regularExpressionMatcher = new ListParser(new ClassNameParser()).parse(regularExpression); + this.annotationVisitor = annotationVisitor; + } + + + // Implementations for AnnotationVisitor. + + public void visitAnnotation(Clazz clazz, Annotation annotation) + { + if (accepted(annotation.getType(clazz))) + { + annotationVisitor.visitAnnotation(clazz, annotation); + } + } + + + public void visitAnnotation(Clazz clazz, Field field, Annotation annotation) + { + if (accepted(annotation.getType(clazz))) + { + annotationVisitor.visitAnnotation(clazz, field, annotation); + } + } + + + public void visitAnnotation(Clazz clazz, Method method, Annotation annotation) + { + if (accepted(annotation.getType(clazz))) + { + annotationVisitor.visitAnnotation(clazz, method, annotation); + } + } + + + public void visitAnnotation(Clazz clazz, Method method, int parameterIndex, Annotation annotation) + { + if (accepted(annotation.getType(clazz))) + { + annotationVisitor.visitAnnotation(clazz, method, parameterIndex, annotation); + } + } + + + // Small utility methods. + + private boolean accepted(String name) + { + return regularExpressionMatcher.matches(name); + } +} diff --git a/src/proguard/classfile/attribute/annotation/visitor/AnnotationVisitor.java b/src/proguard/classfile/attribute/annotation/visitor/AnnotationVisitor.java new file mode 100644 index 0000000..16b2a56 --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/visitor/AnnotationVisitor.java @@ -0,0 +1,40 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.annotation.Annotation; + +/** + * This interface specifies the methods for a visitor of + * <code>Annotation</code> objects. Note that there is only a single + * implementation of <code>Annotation</code>, such that this interface + * is not strictly necessary as a visitor. + * + * @author Eric Lafortune + */ +public interface AnnotationVisitor +{ + public void visitAnnotation(Clazz clazz, Annotation annotation); + public void visitAnnotation(Clazz clazz, Field field, Annotation annotation); + public void visitAnnotation(Clazz clazz, Method method, Annotation annotation); + public void visitAnnotation(Clazz clazz, Method method, int parameterIndex, Annotation annotation); +} diff --git a/src/proguard/classfile/attribute/annotation/visitor/ElementValueVisitor.java b/src/proguard/classfile/attribute/annotation/visitor/ElementValueVisitor.java new file mode 100644 index 0000000..112084a --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/visitor/ElementValueVisitor.java @@ -0,0 +1,51 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.annotation.visitor; + +import proguard.classfile.Clazz; +import proguard.classfile.attribute.annotation.*; + +/** + * This interface specifies the methods for a visitor of <code>ElementValue</code> + * objects. + * + * @author Eric Lafortune + */ +public interface ElementValueVisitor +{ + public void visitConstantElementValue( Clazz clazz, Annotation annotation, ConstantElementValue constantElementValue); + public void visitEnumConstantElementValue(Clazz clazz, Annotation annotation, EnumConstantElementValue enumConstantElementValue); + public void visitClassElementValue( Clazz clazz, Annotation annotation, ClassElementValue classElementValue); + public void visitAnnotationElementValue( Clazz clazz, Annotation annotation, AnnotationElementValue annotationElementValue); + public void visitArrayElementValue( Clazz clazz, Annotation annotation, ArrayElementValue arrayElementValue); + +// public void visitConstantElementValue( Clazz clazz, Field field, Annotation annotation, ConstantElementValue constantElementValue); +// public void visitEnumConstantElementValue(Clazz clazz, Field field, Annotation annotation, EnumConstantElementValue enumConstantElementValue); +// public void visitClassElementValue( Clazz clazz, Field field, Annotation annotation, ClassElementValue classElementValue); +// public void visitAnnotationElementValue( Clazz clazz, Field field, Annotation annotation, AnnotationElementValue annotationElementValue); +// public void visitArrayElementValue( Clazz clazz, Field field, Annotation annotation, ArrayElementValue arrayElementValue); +// +// public void visitConstantElementValue( Clazz clazz, Method method, Annotation annotation, ConstantElementValue constantElementValue); +// public void visitEnumConstantElementValue(Clazz clazz, Method method, Annotation annotation, EnumConstantElementValue enumConstantElementValue); +// public void visitClassElementValue( Clazz clazz, Method method, Annotation annotation, ClassElementValue classElementValue); +// public void visitAnnotationElementValue( Clazz clazz, Method method, Annotation annotation, AnnotationElementValue annotationElementValue); +// public void visitArrayElementValue( Clazz clazz, Method method, Annotation annotation, ArrayElementValue arrayElementValue); +} diff --git a/src/proguard/classfile/attribute/annotation/visitor/package.html b/src/proguard/classfile/attribute/annotation/visitor/package.html new file mode 100644 index 0000000..10d0648 --- /dev/null +++ b/src/proguard/classfile/attribute/annotation/visitor/package.html @@ -0,0 +1,3 @@ +<body> +This package contains visitors for annotation attributes and their components. +</body> diff --git a/src/proguard/classfile/attribute/package.html b/src/proguard/classfile/attribute/package.html new file mode 100644 index 0000000..d17caaa --- /dev/null +++ b/src/proguard/classfile/attribute/package.html @@ -0,0 +1,3 @@ +<body> +This package contains classes to represent the attributes inside class files. +</body> diff --git a/src/proguard/classfile/attribute/preverification/DoubleType.java b/src/proguard/classfile/attribute/preverification/DoubleType.java new file mode 100644 index 0000000..d574dcb --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/DoubleType.java @@ -0,0 +1,66 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.attribute.preverification.visitor.VerificationTypeVisitor; + +/** + * This VerificationType represents a Double type. + * + * @author Eric Lafortune + */ +public class DoubleType extends VerificationType +{ + // Implementations for VerificationType. + + public int getTag() + { + return DOUBLE_TYPE; + } + + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitDoubleType(clazz, method, codeAttribute, instructionOffset, this); + } + + + public void stackAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int stackIndex, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitStackDoubleType(clazz, method, codeAttribute, instructionOffset, stackIndex, this); + } + + + public void variablesAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int variableIndex, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitVariablesDoubleType(clazz, method, codeAttribute, instructionOffset, variableIndex, this); + } + + + // Implementations for Object. + + public String toString() + { + return "d"; + } +} diff --git a/src/proguard/classfile/attribute/preverification/FloatType.java b/src/proguard/classfile/attribute/preverification/FloatType.java new file mode 100644 index 0000000..2f24720 --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/FloatType.java @@ -0,0 +1,66 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.attribute.preverification.visitor.VerificationTypeVisitor; + +/** + * This VerificationType represents a Float type. + * + * @author Eric Lafortune + */ +public class FloatType extends VerificationType +{ + // Implementations for VerificationType. + + public int getTag() + { + return FLOAT_TYPE; + } + + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitFloatType(clazz, method, codeAttribute, instructionOffset, this); + } + + + public void stackAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int stackIndex, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitStackFloatType(clazz, method, codeAttribute, instructionOffset, stackIndex, this); + } + + + public void variablesAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int variableIndex, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitVariablesFloatType(clazz, method, codeAttribute, instructionOffset, variableIndex, this); + } + + + // Implementations for Object. + + public String toString() + { + return "f"; + } +} diff --git a/src/proguard/classfile/attribute/preverification/FullFrame.java b/src/proguard/classfile/attribute/preverification/FullFrame.java new file mode 100644 index 0000000..adf5684 --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/FullFrame.java @@ -0,0 +1,202 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.attribute.preverification.visitor.*; + +/** + * This StackMapFrame represents a "full frame". + * + * @author Eric Lafortune + */ +public class FullFrame extends StackMapFrame +{ + public int variablesCount; + public VerificationType[] variables; + public int stackCount; + public VerificationType[] stack; + + + /** + * Creates an uninitialized FullFrame. + */ + public FullFrame() + { + } + + + /** + * Creates a FullFrame with the given variables and stack. + */ + public FullFrame(int offsetDelta, + VerificationType[] variables, + VerificationType[] stack) + { + this(offsetDelta, + variables.length, + variables, + stack.length, + stack); + } + + + /** + * Creates a FullFrame with the given variables and stack. + */ + public FullFrame(int offsetDelta, + int variablesCount, + VerificationType[] variables, + int stackCount, + VerificationType[] stack) + { + this.u2offsetDelta = offsetDelta; + this.variablesCount = variablesCount; + this.variables = variables; + this.stackCount = stackCount; + this.stack = stack; + } + + + /** + * Applies the given verification type visitor to all variables. + */ + public void variablesAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VerificationTypeVisitor verificationTypeVisitor) + { + for (int index = 0; index < variablesCount; index++) + { + variables[index].variablesAccept(clazz, method, codeAttribute, offset, index, verificationTypeVisitor); + } + } + + + /** + * Applies the given verification type visitor to all stack. + */ + public void stackAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VerificationTypeVisitor verificationTypeVisitor) + { + for (int index = 0; index < stackCount; index++) + { + stack[index].stackAccept(clazz, method, codeAttribute, offset, index, verificationTypeVisitor); + } + } + + + // Implementations for StackMapFrame. + + public int getTag() + { + return FULL_FRAME; + } + + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, StackMapFrameVisitor stackMapFrameVisitor) + { + stackMapFrameVisitor.visitFullFrame(clazz, method, codeAttribute, offset, this); + } + + + // Implementations for Object. + + public boolean equals(Object object) + { + if (!super.equals(object)) + { + return false; + } + + FullFrame other = (FullFrame)object; + + if (this.u2offsetDelta != other.u2offsetDelta || + this.variablesCount != other.variablesCount || + this.stackCount != other.stackCount) + { + return false; + } + + for (int index = 0; index < variablesCount; index++) + { + VerificationType thisType = this.variables[index]; + VerificationType otherType = other.variables[index]; + + if (!thisType.equals(otherType)) + { + return false; + } + } + + for (int index = 0; index < stackCount; index++) + { + VerificationType thisType = this.stack[index]; + VerificationType otherType = other.stack[index]; + + if (!thisType.equals(otherType)) + { + return false; + } + } + + return true; + } + + + public int hashCode() + { + int hashCode = super.hashCode(); + + for (int index = 0; index < variablesCount; index++) + { + hashCode ^= variables[index].hashCode(); + } + + for (int index = 0; index < stackCount; index++) + { + hashCode ^= stack[index].hashCode(); + } + + return hashCode; + } + + + public String toString() + { + StringBuffer buffer = new StringBuffer(super.toString()).append("Var: "); + + for (int index = 0; index < variablesCount; index++) + { + buffer = buffer.append('[') + .append(variables[index].toString()) + .append(']'); + } + + buffer.append(", Stack: "); + + for (int index = 0; index < stackCount; index++) + { + buffer = buffer.append('[') + .append(stack[index].toString()) + .append(']'); + } + + return buffer.toString(); + } +} diff --git a/src/proguard/classfile/attribute/preverification/IntegerType.java b/src/proguard/classfile/attribute/preverification/IntegerType.java new file mode 100644 index 0000000..55e3abe --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/IntegerType.java @@ -0,0 +1,66 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.attribute.preverification.visitor.VerificationTypeVisitor; + +/** + * This VerificationType represents a Integer type. + * + * @author Eric Lafortune + */ +public class IntegerType extends VerificationType +{ + // Implementations for VerificationType. + + public int getTag() + { + return INTEGER_TYPE; + } + + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitIntegerType(clazz, method, codeAttribute, instructionOffset, this); + } + + + public void stackAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int stackIndex, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitStackIntegerType(clazz, method, codeAttribute, instructionOffset, stackIndex, this); + } + + + public void variablesAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int variableIndex, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitVariablesIntegerType(clazz, method, codeAttribute, instructionOffset, variableIndex, this); + } + + + // Implementations for Object. + + public String toString() + { + return "i"; + } +} diff --git a/src/proguard/classfile/attribute/preverification/LessZeroFrame.java b/src/proguard/classfile/attribute/preverification/LessZeroFrame.java new file mode 100644 index 0000000..fcc8e0a --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/LessZeroFrame.java @@ -0,0 +1,103 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.attribute.preverification.visitor.StackMapFrameVisitor; + +/** + * This StackMapFrame represents an "chop frame". + * + * @author Eric Lafortune + */ +public class LessZeroFrame extends StackMapFrame +{ + public int choppedVariablesCount; + + + /** + * Creates an uninitialized LessZeroFrame. + */ + public LessZeroFrame() + { + } + + + /** + * Creates a LessZeroFrame with the given tag. + */ + public LessZeroFrame(int tag) + { + choppedVariablesCount = LESS_ZERO_FRAME + 3 - tag; + } + + + /** + * Creates a LessZeroFrame with the given number of chopped variables. + */ + public LessZeroFrame(byte choppedVariablesCount) + { + this.choppedVariablesCount = (int)choppedVariablesCount; + } + + + // Implementations for StackMapFrame. + + public int getTag() + { + return LESS_ZERO_FRAME + 3 - choppedVariablesCount; + } + + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, StackMapFrameVisitor stackMapFrameVisitor) + { + stackMapFrameVisitor.visitLessZeroFrame(clazz, method, codeAttribute, offset, this); + } + + + // Implementations for Object. + + public boolean equals(Object object) + { + if (!super.equals(object)) + { + return false; + } + + LessZeroFrame other = (LessZeroFrame)object; + + return this.u2offsetDelta == other.u2offsetDelta && + this.choppedVariablesCount != other.choppedVariablesCount; + } + + + public int hashCode() + { + return super.hashCode() ^ choppedVariablesCount; + } + + + public String toString() + { + return super.toString()+"Var: (chopped "+choppedVariablesCount+"), Stack: (empty)"; + } +} diff --git a/src/proguard/classfile/attribute/preverification/LongType.java b/src/proguard/classfile/attribute/preverification/LongType.java new file mode 100644 index 0000000..9b14dd6 --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/LongType.java @@ -0,0 +1,66 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.attribute.preverification.visitor.VerificationTypeVisitor; + +/** + * This VerificationType represents a Long type. + * + * @author Eric Lafortune + */ +public class LongType extends VerificationType +{ + // Implementations for VerificationType. + + public int getTag() + { + return LONG_TYPE; + } + + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitLongType(clazz, method, codeAttribute, instructionOffset, this); + } + + + public void stackAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int stackIndex, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitStackLongType(clazz, method, codeAttribute, instructionOffset, stackIndex, this); + } + + + public void variablesAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int variableIndex, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitVariablesLongType(clazz, method, codeAttribute, instructionOffset, variableIndex, this); + } + + + // Implementations for Object. + + public String toString() + { + return "l"; + } +} diff --git a/src/proguard/classfile/attribute/preverification/MoreZeroFrame.java b/src/proguard/classfile/attribute/preverification/MoreZeroFrame.java new file mode 100644 index 0000000..881f188 --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/MoreZeroFrame.java @@ -0,0 +1,161 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.attribute.preverification.visitor.*; + +/** + * This StackMapFrame represents an "append frame". + * + * @author Eric Lafortune + */ +public class MoreZeroFrame extends StackMapFrame +{ + public int additionalVariablesCount; + public VerificationType[] additionalVariables; + + + /** + * Creates an uninitialized MoreZeroFrame. + */ + public MoreZeroFrame() + { + } + + + /** + * Creates a MoreZeroFrame with the given tag. + */ + public MoreZeroFrame(int tag) + { + additionalVariablesCount = tag + 1 - MORE_ZERO_FRAME; + } + + + /** + * Creates a MoreZeroFrame with the given additional variables. + */ + public MoreZeroFrame(VerificationType[] additionalVariables) + { + this(additionalVariables.length, additionalVariables); + } + + + /** + * Creates a MoreZeroFrame with the given additional variables. + */ + public MoreZeroFrame(int additionalVariablesCount, + VerificationType[] additionalVariables) + { + this.additionalVariablesCount = additionalVariablesCount; + this.additionalVariables = additionalVariables; + } + + + /** + * Applies the given verification type visitor to all variables. + */ + public void additionalVariablesAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VerificationTypeVisitor verificationTypeVisitor) + { + for (int index = 0; index < additionalVariablesCount; index++) + { + additionalVariables[index].accept(clazz, method, codeAttribute, offset, verificationTypeVisitor); + } + } + + + // Implementations for StackMapFrame. + + public int getTag() + { + return MORE_ZERO_FRAME + additionalVariablesCount - 1; + } + + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, StackMapFrameVisitor stackMapFrameVisitor) + { + stackMapFrameVisitor.visitMoreZeroFrame(clazz, method, codeAttribute, offset, this); + } + + + // Implementations for Object. + + public boolean equals(Object object) + { + if (!super.equals(object)) + { + return false; + } + + MoreZeroFrame other = (MoreZeroFrame)object; + + if (this.u2offsetDelta != other.u2offsetDelta || + this.additionalVariablesCount != other.additionalVariablesCount) + { + return false; + } + + for (int index = 0; index < additionalVariablesCount; index++) + { + VerificationType thisType = this.additionalVariables[index]; + VerificationType otherType = other.additionalVariables[index]; + + if (!thisType.equals(otherType)) + { + return false; + } + } + + return true; + } + + + public int hashCode() + { + int hashCode = super.hashCode(); + + for (int index = 0; index < additionalVariablesCount; index++) + { + hashCode ^= additionalVariables[index].hashCode(); + } + + return hashCode; + } + + + public String toString() + { + StringBuffer buffer = new StringBuffer(super.toString()).append("Var: ..."); + + for (int index = 0; index < additionalVariablesCount; index++) + { + buffer = buffer.append('[') + .append(additionalVariables[index].toString()) + .append(']'); + } + + buffer.append(", Stack: (empty)"); + + return buffer.toString(); + } +} diff --git a/src/proguard/classfile/attribute/preverification/NullType.java b/src/proguard/classfile/attribute/preverification/NullType.java new file mode 100644 index 0000000..f35cefd --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/NullType.java @@ -0,0 +1,66 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.attribute.preverification.visitor.VerificationTypeVisitor; + +/** + * This VerificationType represents a Null type. + * + * @author Eric Lafortune + */ +public class NullType extends VerificationType +{ + // Implementations for VerificationType. + + public int getTag() + { + return NULL_TYPE; + } + + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitNullType(clazz, method, codeAttribute, instructionOffset, this); + } + + + public void stackAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int stackIndex, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitStackNullType(clazz, method, codeAttribute, instructionOffset, stackIndex, this); + } + + + public void variablesAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int variableIndex, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitVariablesNullType(clazz, method, codeAttribute, instructionOffset, variableIndex, this); + } + + + // Implementations for Object. + + public String toString() + { + return "n"; + } +} diff --git a/src/proguard/classfile/attribute/preverification/ObjectType.java b/src/proguard/classfile/attribute/preverification/ObjectType.java new file mode 100644 index 0000000..fbdeec7 --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/ObjectType.java @@ -0,0 +1,107 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.attribute.preverification.visitor.VerificationTypeVisitor; + +/** + * This VerificationType represents an Object type. + * + * @author Eric Lafortune + */ +public class ObjectType extends VerificationType +{ + public int u2classIndex; + + + + /** + * Creates an uninitialized ObjectType. + */ + public ObjectType() + { + } + + + /** + * Creates an ObjectType that points to the given class constant. + */ + public ObjectType(int u2classIndex) + { + this.u2classIndex = u2classIndex; + } + + + // Implementations for VerificationType. + + public int getTag() + { + return OBJECT_TYPE; + } + + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitObjectType(clazz, method, codeAttribute, instructionOffset, this); + } + + + public void stackAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int stackIndex, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitStackObjectType(clazz, method, codeAttribute, instructionOffset, stackIndex, this); + } + + + public void variablesAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int variableIndex, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitVariablesObjectType(clazz, method, codeAttribute, instructionOffset, variableIndex, this); + } + + + // Implementations for Object. + + public boolean equals(Object object) + { + if (!super.equals(object)) + { + return false; + } + + ObjectType other = (ObjectType)object; + + return this.u2classIndex == other.u2classIndex; + } + + + public int hashCode() + { + return super.hashCode() ^ + u2classIndex; + } + + + public String toString() + { + return "a:" + u2classIndex; + } +} diff --git a/src/proguard/classfile/attribute/preverification/SameOneFrame.java b/src/proguard/classfile/attribute/preverification/SameOneFrame.java new file mode 100644 index 0000000..db6747b --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/SameOneFrame.java @@ -0,0 +1,115 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.attribute.preverification.visitor.*; + +/** + * This StackMapFrame represents a "same locals 1 stack item frame" or a + * "same locals 1 stack item frame extended". + * + * @author Eric Lafortune + */ +public class SameOneFrame extends StackMapFrame +{ + public VerificationType stackItem; + + + /** + * Creates an uninitialized SameOneFrame. + */ + public SameOneFrame() + { + } + + + /** + * Creates a SameOneFrame with the given tag. + */ + public SameOneFrame(int tag) + { + u2offsetDelta = tag - SAME_ONE_FRAME; + } + + + /** + * Creates a SameOneFrame with the given stack verification type. + */ + public SameOneFrame(VerificationType stackItem) + { + this.stackItem = stackItem; + } + + + /** + * Applies the given verification type visitor to the stack item. + */ + public void stackItemAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VerificationTypeVisitor verificationTypeVisitor) + { + stackItem.accept(clazz, method, codeAttribute, offset, verificationTypeVisitor); + } + + + // Implementations for StackMapFrame. + + public int getTag() + { + return u2offsetDelta < 64 ? + SAME_ONE_FRAME + u2offsetDelta : + SAME_ONE_FRAME_EXTENDED; + } + + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, StackMapFrameVisitor stackMapFrameVisitor) + { + stackMapFrameVisitor.visitSameOneFrame(clazz, method, codeAttribute, offset, this); + } + + + // Implementations for Object. + + public boolean equals(Object object) + { + if (!super.equals(object)) + { + return false; + } + + SameOneFrame other = (SameOneFrame)object; + + return this.u2offsetDelta == other.u2offsetDelta && + this.stackItem.equals(other.stackItem); + } + + + public int hashCode() + { + return super.hashCode() ^ stackItem.hashCode(); + } + + + public String toString() + { + return super.toString()+"Var: ..., Stack: ["+stackItem.toString()+"]"; + } +} diff --git a/src/proguard/classfile/attribute/preverification/SameZeroFrame.java b/src/proguard/classfile/attribute/preverification/SameZeroFrame.java new file mode 100644 index 0000000..64b17f5 --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/SameZeroFrame.java @@ -0,0 +1,74 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.attribute.preverification.visitor.StackMapFrameVisitor; + +/** + * This StackMapFrame represents a "same frame" or a "same frame extended". + * + * @author Eric Lafortune + * @noinspection PointlessArithmeticExpression + */ +public class SameZeroFrame extends StackMapFrame +{ + /** + * Creates an uninitialized SameZeroFrame. + */ + public SameZeroFrame() + { + } + + + /** + * Creates a SameZeroFrame with the given tag. + */ + public SameZeroFrame(int tag) + { + u2offsetDelta = tag - SAME_ZERO_FRAME; + } + + + // Implementations for StackMapFrame. + + public int getTag() + { + return u2offsetDelta < 64 ? + SAME_ZERO_FRAME + u2offsetDelta : + SAME_ZERO_FRAME_EXTENDED; + } + + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, StackMapFrameVisitor stackMapFrameVisitor) + { + stackMapFrameVisitor.visitSameZeroFrame(clazz, method, codeAttribute, offset, this); + } + + + // Implementations for Object. + + public String toString() + { + return super.toString()+"Var: ..., Stack: (empty)"; + } +} diff --git a/src/proguard/classfile/attribute/preverification/StackMapAttribute.java b/src/proguard/classfile/attribute/preverification/StackMapAttribute.java new file mode 100644 index 0000000..db53ff1 --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/StackMapAttribute.java @@ -0,0 +1,91 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +import proguard.classfile.*; +import proguard.classfile.attribute.*; +import proguard.classfile.attribute.preverification.visitor.StackMapFrameVisitor; +import proguard.classfile.attribute.visitor.AttributeVisitor; + +/** + * This Attribute represents an exceptions attribute. + * + * @author Eric Lafortune + */ +public class StackMapAttribute extends Attribute +{ + public int u2stackMapFramesCount; + public FullFrame[] stackMapFrames; + + + /** + * Creates an uninitialized ExceptionsAttribute. + */ + public StackMapAttribute() + { + } + + + /** + * Creates a StackMapTableAttribute with the given stack map frames. + */ + public StackMapAttribute(FullFrame[] stackMapFrames) + { + this(stackMapFrames.length, stackMapFrames); + } + + + /** + * Creates a StackMapTableAttribute with the given stack map frames. + */ + public StackMapAttribute(int stackMapFramesCount, + FullFrame[] stackMapFrames) + { + this.u2stackMapFramesCount = stackMapFramesCount; + this.stackMapFrames = stackMapFrames; + } + + + + + // Implementations for Attribute. + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitStackMapAttribute(clazz, method, codeAttribute, this); + } + + + /** + * Applies the given stack map frame visitor to all stack map frames. + */ + public void stackMapFramesAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapFrameVisitor stackMapFrameVisitor) + { + for (int index = 0; index < u2stackMapFramesCount; index++) + { + FullFrame stackMapFrame = stackMapFrames[index]; + + // We don't need double dispatching here, since there is only one + // type of StackMapFrame. + stackMapFrameVisitor.visitFullFrame(clazz, method, codeAttribute, stackMapFrame.getOffsetDelta(), stackMapFrame); + } + } +} diff --git a/src/proguard/classfile/attribute/preverification/StackMapFrame.java b/src/proguard/classfile/attribute/preverification/StackMapFrame.java new file mode 100644 index 0000000..aa3e1f2 --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/StackMapFrame.java @@ -0,0 +1,117 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.attribute.preverification.visitor.StackMapFrameVisitor; + +/** + * This abstract class represents a stack map frame. Specific types + * of entries are subclassed from it. + * + * @author Eric Lafortune + */ +public abstract class StackMapFrame implements VisitorAccepter +{ + public static final int SAME_ZERO_FRAME = 0; + public static final int SAME_ONE_FRAME = 64; + public static final int SAME_ONE_FRAME_EXTENDED = 247; + public static final int LESS_ZERO_FRAME = 248; + public static final int SAME_ZERO_FRAME_EXTENDED = 251; + public static final int MORE_ZERO_FRAME = 252; + public static final int FULL_FRAME = 255; + + + public int u2offsetDelta; + + /** + * An extra field in which visitors can store information. + */ + public Object visitorInfo; + + + + /** + * Returns the bytecode offset delta relative to the previous stack map + * frame. + */ + public int getOffsetDelta() + { + return u2offsetDelta; + } + + + // Abstract methods to be implemented by extensions. + + /** + * Returns the stack map frame tag that specifies the entry type. + */ + public abstract int getTag(); + + + /** + * Accepts the given visitor. + */ + public abstract void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, StackMapFrameVisitor stackMapFrameVisitor); + + + // Implementations for VisitorAccepter. + + public Object getVisitorInfo() + { + return visitorInfo; + } + + public void setVisitorInfo(Object visitorInfo) + { + this.visitorInfo = visitorInfo; + } + + + // Implementations for Object. + + public boolean equals(Object object) + { + if (object == null || + this.getClass() != object.getClass()) + { + return false; + } + + StackMapFrame other = (StackMapFrame)object; + + return this.u2offsetDelta == other.u2offsetDelta; + } + + + public int hashCode() + { + return getClass().hashCode() ^ + u2offsetDelta; + } + + + public String toString() + { + return "[" + u2offsetDelta + "] "; + } +} diff --git a/src/proguard/classfile/attribute/preverification/StackMapTableAttribute.java b/src/proguard/classfile/attribute/preverification/StackMapTableAttribute.java new file mode 100644 index 0000000..0cddf70 --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/StackMapTableAttribute.java @@ -0,0 +1,93 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +import proguard.classfile.*; +import proguard.classfile.attribute.*; +import proguard.classfile.attribute.preverification.visitor.StackMapFrameVisitor; +import proguard.classfile.attribute.visitor.AttributeVisitor; + +/** + * This Attribute represents a stack map table attribute. + * + * @author Eric Lafortune + */ +public class StackMapTableAttribute extends Attribute +{ + public int u2stackMapFramesCount; + public StackMapFrame[] stackMapFrames; + + + /** + * Creates an uninitialized StackMapTableAttribute. + */ + public StackMapTableAttribute() + { + } + + + /** + * Creates a StackMapTableAttribute with the given stack map frames. + */ + public StackMapTableAttribute(StackMapFrame[] stackMapFrames) + { + this(stackMapFrames.length, stackMapFrames); + } + + + /** + * Creates a StackMapTableAttribute with the given stack map frames. + */ + public StackMapTableAttribute(int stackMapFramesCount, + StackMapFrame[] stackMapFrames) + { + this.u2stackMapFramesCount = stackMapFramesCount; + this.stackMapFrames = stackMapFrames; + } + + + // Implementations for Attribute. + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, AttributeVisitor attributeVisitor) + { + attributeVisitor.visitStackMapTableAttribute(clazz, method, codeAttribute, this); + } + + + /** + * Applies the given stack map frame visitor to all stack map frames. + */ + public void stackMapFramesAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapFrameVisitor stackMapFrameVisitor) + { + int offset = 0; + + for (int index = 0; index < u2stackMapFramesCount; index++) + { + StackMapFrame stackMapFrame = stackMapFrames[index]; + + // Note that the byte code offset is computed differently for the + // first stack map frame. + offset += stackMapFrame.getOffsetDelta() + (index == 0 ? 0 : 1); + + stackMapFrame.accept(clazz, method, codeAttribute, offset, stackMapFrameVisitor); + } + } +} diff --git a/src/proguard/classfile/attribute/preverification/TopType.java b/src/proguard/classfile/attribute/preverification/TopType.java new file mode 100644 index 0000000..bde8dda --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/TopType.java @@ -0,0 +1,66 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.attribute.preverification.visitor.VerificationTypeVisitor; + +/** + * This VerificationType represents a Top type. + * + * @author Eric Lafortune + */ +public class TopType extends VerificationType +{ + // Implementations for VerificationType. + + public int getTag() + { + return TOP_TYPE; + } + + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitTopType(clazz, method, codeAttribute, instructionOffset, this); + } + + + public void stackAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int stackIndex, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitStackTopType(clazz, method, codeAttribute, instructionOffset, stackIndex, this); + } + + + public void variablesAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int variableIndex, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitVariablesTopType(clazz, method, codeAttribute, instructionOffset, variableIndex, this); + } + + + // Implementations for Object. + + public String toString() + { + return "T"; + } +} diff --git a/src/proguard/classfile/attribute/preverification/UninitializedThisType.java b/src/proguard/classfile/attribute/preverification/UninitializedThisType.java new file mode 100644 index 0000000..dc4654f --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/UninitializedThisType.java @@ -0,0 +1,66 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.attribute.preverification.visitor.VerificationTypeVisitor; + +/** + * This VerificationType represents a UninitializedThis type. + * + * @author Eric Lafortune + */ +public class UninitializedThisType extends VerificationType +{ + // Implementations for VerificationType. + + public int getTag() + { + return UNINITIALIZED_THIS_TYPE; + } + + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitUninitializedThisType(clazz, method, codeAttribute, instructionOffset, this); + } + + + public void stackAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int stackIndex, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitStackUninitializedThisType(clazz, method, codeAttribute, instructionOffset, stackIndex, this); + } + + + public void variablesAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int variableIndex, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitVariablesUninitializedThisType(clazz, method, codeAttribute, instructionOffset, variableIndex, this); + } + + + // Implementations for Object. + + public String toString() + { + return "u:this"; + } +} diff --git a/src/proguard/classfile/attribute/preverification/UninitializedType.java b/src/proguard/classfile/attribute/preverification/UninitializedType.java new file mode 100644 index 0000000..a495f1f --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/UninitializedType.java @@ -0,0 +1,106 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.attribute.preverification.visitor.VerificationTypeVisitor; + +/** + * This VerificationType represents a Uninitialized type. + * + * @author Eric Lafortune + */ +public class UninitializedType extends VerificationType +{ + public int u2newInstructionOffset; + + + /** + * Creates an uninitialized UninitializedType. + */ + public UninitializedType() + { + } + + + /** + * Creates an UninitializedType pointing to the given 'new' instruction. + */ + public UninitializedType(int u2newInstructionOffset) + { + this.u2newInstructionOffset = u2newInstructionOffset; + } + + + // Implementations for VerificationType. + + public int getTag() + { + return UNINITIALIZED_TYPE; + } + + + public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitUninitializedType(clazz, method, codeAttribute, instructionOffset, this); + } + + + public void stackAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int stackIndex, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitStackUninitializedType(clazz, method, codeAttribute, instructionOffset, stackIndex, this); + } + + + public void variablesAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int variableIndex, VerificationTypeVisitor verificationTypeVisitor) + { + verificationTypeVisitor.visitVariablesUninitializedType(clazz, method, codeAttribute, instructionOffset, variableIndex, this); + } + + + // Implementations for Object. + + public boolean equals(Object object) + { + if (!super.equals(object)) + { + return false; + } + + UninitializedType other = (UninitializedType)object; + + return this.u2newInstructionOffset == other.u2newInstructionOffset; + } + + + public int hashCode() + { + return super.hashCode() ^ + u2newInstructionOffset; + } + + + public String toString() + { + return "u:" + u2newInstructionOffset; + } +} diff --git a/src/proguard/classfile/attribute/preverification/VerificationType.java b/src/proguard/classfile/attribute/preverification/VerificationType.java new file mode 100644 index 0000000..f33d511 --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/VerificationType.java @@ -0,0 +1,103 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.attribute.preverification.visitor.VerificationTypeVisitor; + +/** + * This abstract class represents a verification type of a local variable or + * a stack element. Specific verification types are subclassed from it. + * + * @author Eric Lafortune + */ +public abstract class VerificationType implements VisitorAccepter +{ + public static final int TOP_TYPE = 0; + public static final int INTEGER_TYPE = 1; + public static final int FLOAT_TYPE = 2; + public static final int DOUBLE_TYPE = 3; + public static final int LONG_TYPE = 4; + public static final int NULL_TYPE = 5; + public static final int UNINITIALIZED_THIS_TYPE = 6; + public static final int OBJECT_TYPE = 7; + public static final int UNINITIALIZED_TYPE = 8; + + + /** + * An extra field in which visitors can store information. + */ + public Object visitorInfo; + + + /** + * Returns the tag of the verification type. + */ + public abstract int getTag(); + + + /** + * Accepts the given visitor in the context of a method's code, either on + * a stack or as a variable. + */ + public abstract void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, VerificationTypeVisitor verificationTypeVisitor); + + + /** + * Accepts the given visitor in the context of a stack in a method's code . + */ + public abstract void stackAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int stackIndex, VerificationTypeVisitor verificationTypeVisitor); + + + /** + * Accepts the given visitor in the context of a variable in a method's code. + */ + public abstract void variablesAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int instructionOffset, int variableIndex, VerificationTypeVisitor verificationTypeVisitor); + + + // Implementations for VisitorAccepter. + + public Object getVisitorInfo() + { + return visitorInfo; + } + + public void setVisitorInfo(Object visitorInfo) + { + this.visitorInfo = visitorInfo; + } + + + // Implementations for Object. + + public boolean equals(Object object) + { + return object != null && + this.getClass() == object.getClass(); + } + + + public int hashCode() + { + return this.getClass().hashCode(); + } +} diff --git a/src/proguard/classfile/attribute/preverification/VerificationTypeFactory.java b/src/proguard/classfile/attribute/preverification/VerificationTypeFactory.java new file mode 100644 index 0000000..f8ef7e0 --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/VerificationTypeFactory.java @@ -0,0 +1,112 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification; + +/** + * This class provides methods to create and reuse IntegerType objects. + * + * @author Eric Lafortune + */ +public class VerificationTypeFactory +{ + // Shared copies of Type objects, to avoid creating a lot of objects. + static final IntegerType INTEGER_TYPE = new IntegerType(); + static final LongType LONG_TYPE = new LongType(); + static final FloatType FLOAT_TYPE = new FloatType(); + static final DoubleType DOUBLE_TYPE = new DoubleType(); + static final TopType TOP_TYPE = new TopType(); + static final NullType NULL_TYPE = new NullType(); + static final UninitializedThisType UNINITIALIZED_THIS_TYPE = new UninitializedThisType(); + + + /** + * Creates a new IntegerType. + */ + public static IntegerType createIntegerType() + { + return INTEGER_TYPE; + } + + /** + * Creates a new LongType. + */ + public static LongType createLongType() + { + return LONG_TYPE; + } + + /** + * Creates a new FloatType. + */ + public static FloatType createFloatType() + { + return FLOAT_TYPE; + } + + /** + * Creates a new DoubleType. + */ + public static DoubleType createDoubleType() + { + return DOUBLE_TYPE; + } + + /** + * Creates a new TopType. + */ + public static TopType createTopType() + { + return TOP_TYPE; + } + + /** + * Creates a new NullType. + */ + public static NullType createNullType() + { + return NULL_TYPE; + } + + /** + * Creates a new UninitializedThisType. + */ + public static UninitializedThisType createUninitializedThisType() + { + return UNINITIALIZED_THIS_TYPE; + } + + /** + * Creates a new UninitializedType for an instance that was created at + * the given offset. + */ + public static UninitializedType createUninitializedType(int newInstructionOffset) + { + return new UninitializedType(newInstructionOffset); + } + + /** + * Creates a new ObjectType of the given type. + */ + public static ObjectType createObjectType(int classIndex) + { + return new ObjectType(classIndex); + } +} diff --git a/src/proguard/classfile/attribute/preverification/visitor/StackMapFrameVisitor.java b/src/proguard/classfile/attribute/preverification/visitor/StackMapFrameVisitor.java new file mode 100644 index 0000000..7db246c --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/visitor/StackMapFrameVisitor.java @@ -0,0 +1,40 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.attribute.preverification.*; + +/** + * This interface specifies the methods for a visitor of + * <code>StackMapFrame</code> objects. + * + * @author Eric Lafortune + */ +public interface StackMapFrameVisitor +{ + public void visitSameZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SameZeroFrame sameZeroFrame); + public void visitSameOneFrame( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SameOneFrame sameOneFrame); + public void visitLessZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LessZeroFrame lessZeroFrame); + public void visitMoreZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, MoreZeroFrame moreZeroFrame); + public void visitFullFrame( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, FullFrame fullFrame); +} diff --git a/src/proguard/classfile/attribute/preverification/visitor/VerificationTypeVisitor.java b/src/proguard/classfile/attribute/preverification/visitor/VerificationTypeVisitor.java new file mode 100644 index 0000000..e9931f8 --- /dev/null +++ b/src/proguard/classfile/attribute/preverification/visitor/VerificationTypeVisitor.java @@ -0,0 +1,65 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.preverification.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.attribute.preverification.*; + +/** + * This interface specifies the methods for a visitor of + * <code>VerificationType</code> objects. There a methods for stack entries + * and methods for variable entries. + * + * @author Eric Lafortune + */ +public interface VerificationTypeVisitor +{ + public void visitIntegerType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, IntegerType integerType); + public void visitFloatType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, FloatType floatType); + public void visitLongType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LongType longType); + public void visitDoubleType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, DoubleType doubleType); + public void visitTopType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, TopType topType); + public void visitObjectType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ObjectType objectType); + public void visitNullType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, NullType nullType); + public void visitUninitializedType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, UninitializedType uninitializedType); + public void visitUninitializedThisType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, UninitializedThisType uninitializedThisType); + + public void visitStackIntegerType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int index, IntegerType integerType); + public void visitStackFloatType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int index, FloatType floatType); + public void visitStackLongType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int index, LongType longType); + public void visitStackDoubleType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int index, DoubleType doubleType); + public void visitStackTopType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int index, TopType topType); + public void visitStackObjectType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int index, ObjectType objectType); + public void visitStackNullType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int index, NullType nullType); + public void visitStackUninitializedType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int index, UninitializedType uninitializedType); + public void visitStackUninitializedThisType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int index, UninitializedThisType uninitializedThisType); + + public void visitVariablesIntegerType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int index, IntegerType integerType); + public void visitVariablesFloatType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int index, FloatType floatType); + public void visitVariablesLongType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int index, LongType longType); + public void visitVariablesDoubleType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int index, DoubleType doubleType); + public void visitVariablesTopType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int index, TopType topType); + public void visitVariablesObjectType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int index, ObjectType objectType); + public void visitVariablesNullType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int index, NullType nullType); + public void visitVariablesUninitializedType( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int index, UninitializedType uninitializedType); + public void visitVariablesUninitializedThisType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, int index, UninitializedThisType uninitializedThisType); +} diff --git a/src/proguard/classfile/attribute/visitor/AllAttributeVisitor.java b/src/proguard/classfile/attribute/visitor/AllAttributeVisitor.java new file mode 100644 index 0000000..61b0f1a --- /dev/null +++ b/src/proguard/classfile/attribute/visitor/AllAttributeVisitor.java @@ -0,0 +1,117 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.*; +import proguard.classfile.util.SimplifiedVisitor; +import proguard.classfile.visitor.*; + +/** + * This ClassVisitor, MemberVisitor, and AttributeVisitor lets a given + * AttributeVisitor visit all Attribute objects of the program classes, + * program class members, or code attributes, respectively, that it visits. + * + * @author Eric Lafortune + */ +public class AllAttributeVisitor +extends SimplifiedVisitor +implements ClassVisitor, + MemberVisitor, + AttributeVisitor +{ + private final boolean deep; + private final AttributeVisitor attributeVisitor; + + + /** + * Creates a new shallow AllAttributeVisitor. + * @param attributeVisitor the AttributeVisitor to which visits will be + * delegated. + */ + public AllAttributeVisitor(AttributeVisitor attributeVisitor) + { + this(false, attributeVisitor); + } + + + /** + * Creates a new optionally deep AllAttributeVisitor. + * @param deep specifies whether the attributes contained + * further down the class structure should be + * visited too. + * @param attributeVisitor the AttributeVisitor to which visits will be + * delegated. + */ + public AllAttributeVisitor(boolean deep, + AttributeVisitor attributeVisitor) + { + this.deep = deep; + this.attributeVisitor = attributeVisitor; + } + + + // Implementations for ClassVisitor. + + public void visitProgramClass(ProgramClass programClass) + { + programClass.attributesAccept(attributeVisitor); + + // Visit the attributes further down the class structure, if required. + if (deep) + { + programClass.fieldsAccept(this); + programClass.methodsAccept(this); + programClass.attributesAccept(this); + } + } + + + public void visitLibraryClass(LibraryClass libraryClass) {} + + + // Implementations for MemberVisitor. + + public void visitProgramMember(ProgramClass programClass, ProgramMember programMember) + { + programMember.attributesAccept(programClass, attributeVisitor); + + // Visit the attributes further down the member structure, if required. + if (deep) + { + programMember.attributesAccept(programClass, this); + } + } + + + public void visitLibraryMember(LibraryClass programClass, LibraryMember programMember) {} + + + // Implementations for AttributeVisitor. + + public void visitAnyAttribute(Clazz clazz, Attribute attribute) {} + + + public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) + { + codeAttribute.attributesAccept(clazz, method, attributeVisitor); + } +} diff --git a/src/proguard/classfile/attribute/visitor/AllExceptionInfoVisitor.java b/src/proguard/classfile/attribute/visitor/AllExceptionInfoVisitor.java new file mode 100644 index 0000000..839e104 --- /dev/null +++ b/src/proguard/classfile/attribute/visitor/AllExceptionInfoVisitor.java @@ -0,0 +1,55 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.*; +import proguard.classfile.util.SimplifiedVisitor; + +/** + * This AttributeVisitor lets a given ExceptionInfoVisitor visit all exceptions + * objects of the CodeAttribute objects it visits. + * + * @author Eric Lafortune + */ +public class AllExceptionInfoVisitor +extends SimplifiedVisitor +implements AttributeVisitor +{ + private final ExceptionInfoVisitor exceptionInfoVisitor; + + + public AllExceptionInfoVisitor(ExceptionInfoVisitor exceptionInfoVisitor) + { + this.exceptionInfoVisitor = exceptionInfoVisitor; + } + + + // Implementations for AttributeVisitor. + + public void visitAnyAttribute(Clazz clazz, Attribute attribute) {} + + + public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) + { + codeAttribute.exceptionsAccept(clazz, method, exceptionInfoVisitor); + } +} diff --git a/src/proguard/classfile/attribute/visitor/AttributeNameFilter.java b/src/proguard/classfile/attribute/visitor/AttributeNameFilter.java new file mode 100644 index 0000000..aa81ce0 --- /dev/null +++ b/src/proguard/classfile/attribute/visitor/AttributeNameFilter.java @@ -0,0 +1,345 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.*; +import proguard.classfile.attribute.annotation.*; +import proguard.classfile.attribute.preverification.*; +import proguard.util.StringMatcher; + +/** + * This AttributeVisitor delegates its visits another AttributeVisitor, but + * only when the visited attribute has a name that passes a given string + * matcher. + * + * @author Eric Lafortune + */ +public class AttributeNameFilter +implements AttributeVisitor +{ + private final StringMatcher stringMatcher; + private final AttributeVisitor attributeVisitor; + + + /** + * Creates a new AttributeNameFilter. + * @param stringMatcher the string matcher that will check the attribute + * names. + * @param attributeVisitor the <code>AttributeVisitor</code> to which + * visits will be delegated. + */ + public AttributeNameFilter(StringMatcher stringMatcher, + AttributeVisitor attributeVisitor) + { + this.stringMatcher = stringMatcher; + this.attributeVisitor = attributeVisitor; + } + + + // Implementations for AttributeVisitor. + + public void visitUnknownAttribute(Clazz clazz, UnknownAttribute unknownAttribute) + { + if (accepted(clazz, unknownAttribute)) + { + unknownAttribute.accept(clazz, attributeVisitor); + } + } + + + public void visitSourceFileAttribute(Clazz clazz, SourceFileAttribute sourceFileAttribute) + { + if (accepted(clazz, sourceFileAttribute)) + { + sourceFileAttribute.accept(clazz, attributeVisitor); + } + } + + + public void visitSourceDirAttribute(Clazz clazz, SourceDirAttribute sourceDirAttribute) + { + if (accepted(clazz, sourceDirAttribute)) + { + sourceDirAttribute.accept(clazz, attributeVisitor); + } + } + + + public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute) + { + if (accepted(clazz, innerClassesAttribute)) + { + innerClassesAttribute.accept(clazz, attributeVisitor); + } + } + + + public void visitEnclosingMethodAttribute(Clazz clazz, EnclosingMethodAttribute enclosingMethodAttribute) + { + if (accepted(clazz, enclosingMethodAttribute)) + { + enclosingMethodAttribute.accept(clazz, attributeVisitor); + } + } + + + public void visitDeprecatedAttribute(Clazz clazz, DeprecatedAttribute deprecatedAttribute) + { + if (accepted(clazz, deprecatedAttribute)) + { + deprecatedAttribute.accept(clazz, attributeVisitor); + } + } + + + public void visitDeprecatedAttribute(Clazz clazz, Field field, DeprecatedAttribute deprecatedAttribute) + { + if (accepted(clazz, deprecatedAttribute)) + { + deprecatedAttribute.accept(clazz, field, attributeVisitor); + } + } + + + public void visitDeprecatedAttribute(Clazz clazz, Method method, DeprecatedAttribute deprecatedAttribute) + { + if (accepted(clazz, deprecatedAttribute)) + { + deprecatedAttribute.accept(clazz, method, attributeVisitor); + } + } + + + public void visitSyntheticAttribute(Clazz clazz, SyntheticAttribute syntheticAttribute) + { + if (accepted(clazz, syntheticAttribute)) + { + syntheticAttribute.accept(clazz, attributeVisitor); + } + } + + + public void visitSyntheticAttribute(Clazz clazz, Field field, SyntheticAttribute syntheticAttribute) + { + if (accepted(clazz, syntheticAttribute)) + { + syntheticAttribute.accept(clazz, field, attributeVisitor); + } + } + + + public void visitSyntheticAttribute(Clazz clazz, Method method, SyntheticAttribute syntheticAttribute) + { + if (accepted(clazz, syntheticAttribute)) + { + syntheticAttribute.accept(clazz, method, attributeVisitor); + } + } + + + public void visitSignatureAttribute(Clazz clazz, SignatureAttribute signatureAttribute) + { + if (accepted(clazz, signatureAttribute)) + { + signatureAttribute.accept(clazz, attributeVisitor); + } + } + + + public void visitSignatureAttribute(Clazz clazz, Field field, SignatureAttribute signatureAttribute) + { + if (accepted(clazz, signatureAttribute)) + { + signatureAttribute.accept(clazz, field, attributeVisitor); + } + } + + + public void visitSignatureAttribute(Clazz clazz, Method method, SignatureAttribute signatureAttribute) + { + if (accepted(clazz, signatureAttribute)) + { + signatureAttribute.accept(clazz, method, attributeVisitor); + } + } + + + public void visitConstantValueAttribute(Clazz clazz, Field field, ConstantValueAttribute constantValueAttribute) + { + if (accepted(clazz, constantValueAttribute)) + { + constantValueAttribute.accept(clazz, field, attributeVisitor); + } + } + + + public void visitExceptionsAttribute(Clazz clazz, Method method, ExceptionsAttribute exceptionsAttribute) + { + if (accepted(clazz, exceptionsAttribute)) + { + exceptionsAttribute.accept(clazz, method, attributeVisitor); + } + } + + + public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) + { + if (accepted(clazz, codeAttribute)) + { + codeAttribute.accept(clazz, method, attributeVisitor); + } + } + + + public void visitStackMapAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapAttribute stackMapAttribute) + { + if (accepted(clazz, stackMapAttribute)) + { + stackMapAttribute.accept(clazz, method, codeAttribute, attributeVisitor); + } + } + + + public void visitStackMapTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapTableAttribute stackMapTableAttribute) + { + if (accepted(clazz, stackMapTableAttribute)) + { + stackMapTableAttribute.accept(clazz, method, codeAttribute, attributeVisitor); + } + } + + + public void visitLineNumberTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberTableAttribute lineNumberTableAttribute) + { + if (accepted(clazz, lineNumberTableAttribute)) + { + lineNumberTableAttribute.accept(clazz, method, codeAttribute, attributeVisitor); + } + } + + + public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute) + { + if (accepted(clazz, localVariableTableAttribute)) + { + localVariableTableAttribute.accept(clazz, method, codeAttribute, attributeVisitor); + } + } + + + public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute) + { + if (accepted(clazz, localVariableTypeTableAttribute)) + { + localVariableTypeTableAttribute.accept(clazz, method, codeAttribute, attributeVisitor); + } + } + + + public void visitRuntimeVisibleAnnotationsAttribute(Clazz clazz, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute) + { + if (accepted(clazz, runtimeVisibleAnnotationsAttribute)) + { + runtimeVisibleAnnotationsAttribute.accept(clazz, attributeVisitor); + } + } + + + public void visitRuntimeVisibleAnnotationsAttribute(Clazz clazz, Field field, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute) + { + if (accepted(clazz, runtimeVisibleAnnotationsAttribute)) + { + runtimeVisibleAnnotationsAttribute.accept(clazz, field, attributeVisitor); + } + } + + + public void visitRuntimeVisibleAnnotationsAttribute(Clazz clazz, Method method, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute) + { + if (accepted(clazz, runtimeVisibleAnnotationsAttribute)) + { + runtimeVisibleAnnotationsAttribute.accept(clazz, method, attributeVisitor); + } + } + + + public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute) + { + if (accepted(clazz, runtimeInvisibleAnnotationsAttribute)) + { + runtimeInvisibleAnnotationsAttribute.accept(clazz, attributeVisitor); + } + } + + + public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, Field field, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute) + { + if (accepted(clazz, runtimeInvisibleAnnotationsAttribute)) + { + runtimeInvisibleAnnotationsAttribute.accept(clazz, field, attributeVisitor); + } + } + + + public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, Method method, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute) + { + if (accepted(clazz, runtimeInvisibleAnnotationsAttribute)) + { + runtimeInvisibleAnnotationsAttribute.accept(clazz, method, attributeVisitor); + } + } + + + public void visitRuntimeVisibleParameterAnnotationsAttribute(Clazz clazz, Method method, RuntimeVisibleParameterAnnotationsAttribute runtimeVisibleParameterAnnotationsAttribute) + { + if (accepted(clazz, runtimeVisibleParameterAnnotationsAttribute)) + { + runtimeVisibleParameterAnnotationsAttribute.accept(clazz, method, attributeVisitor); + } + } + + + public void visitRuntimeInvisibleParameterAnnotationsAttribute(Clazz clazz, Method method, RuntimeInvisibleParameterAnnotationsAttribute runtimeInvisibleParameterAnnotationsAttribute) + { + if (accepted(clazz, runtimeInvisibleParameterAnnotationsAttribute)) + { + runtimeInvisibleParameterAnnotationsAttribute.accept(clazz, method, attributeVisitor); + } + } + + + public void visitAnnotationDefaultAttribute(Clazz clazz, Method method, AnnotationDefaultAttribute annotationDefaultAttribute) + { + if (accepted(clazz, annotationDefaultAttribute)) + { + annotationDefaultAttribute.accept(clazz, method, attributeVisitor); + } + } + + + // Small utility methods. + + private boolean accepted(Clazz clazz, Attribute attribute) + { + return stringMatcher.matches(attribute.getAttributeName(clazz)); + } +} diff --git a/src/proguard/classfile/attribute/visitor/AttributeVisitor.java b/src/proguard/classfile/attribute/visitor/AttributeVisitor.java new file mode 100644 index 0000000..e8f226b --- /dev/null +++ b/src/proguard/classfile/attribute/visitor/AttributeVisitor.java @@ -0,0 +1,89 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.*; +import proguard.classfile.attribute.annotation.*; +import proguard.classfile.attribute.preverification.*; + +/** + * This interface specifies the methods for a visitor of <code>Attribute</code> + * objects. + * + * @author Eric Lafortune + */ +public interface AttributeVisitor +{ + // Attributes that are attached to classes. + + public void visitUnknownAttribute( Clazz clazz, UnknownAttribute unknownAttribute); + public void visitSourceFileAttribute( Clazz clazz, SourceFileAttribute sourceFileAttribute); + public void visitSourceDirAttribute( Clazz clazz, SourceDirAttribute sourceDirAttribute); + public void visitInnerClassesAttribute( Clazz clazz, InnerClassesAttribute innerClassesAttribute); + public void visitEnclosingMethodAttribute( Clazz clazz, EnclosingMethodAttribute enclosingMethodAttribute); + + // Attributes that are attached to classes, fields, and methods. + + public void visitDeprecatedAttribute( Clazz clazz, DeprecatedAttribute deprecatedAttribute); + public void visitDeprecatedAttribute( Clazz clazz, Field field, DeprecatedAttribute deprecatedAttribute); + public void visitDeprecatedAttribute( Clazz clazz, Method method, DeprecatedAttribute deprecatedAttribute); + + public void visitSyntheticAttribute( Clazz clazz, SyntheticAttribute syntheticAttribute); + public void visitSyntheticAttribute( Clazz clazz, Field field, SyntheticAttribute syntheticAttribute); + public void visitSyntheticAttribute( Clazz clazz, Method method, SyntheticAttribute syntheticAttribute); + + public void visitSignatureAttribute( Clazz clazz, SignatureAttribute signatureAttribute); + public void visitSignatureAttribute( Clazz clazz, Field field, SignatureAttribute signatureAttribute); + public void visitSignatureAttribute( Clazz clazz, Method method, SignatureAttribute signatureAttribute); + + // Attributes that are attached to fields. + + public void visitConstantValueAttribute( Clazz clazz, Field field, ConstantValueAttribute constantValueAttribute); + + // Attributes that are attached to methods. + + public void visitExceptionsAttribute( Clazz clazz, Method method, ExceptionsAttribute exceptionsAttribute); + public void visitCodeAttribute( Clazz clazz, Method method, CodeAttribute codeAttribute); + + // Attributes that are attached to code attributes. + + public void visitStackMapAttribute( Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapAttribute stackMapAttribute); + public void visitStackMapTableAttribute( Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapTableAttribute stackMapTableAttribute); + public void visitLineNumberTableAttribute( Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberTableAttribute lineNumberTableAttribute); + public void visitLocalVariableTableAttribute( Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute); + public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute); + + // Annotation attributes. + + public void visitRuntimeVisibleAnnotationsAttribute( Clazz clazz, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute); + public void visitRuntimeVisibleAnnotationsAttribute( Clazz clazz, Field field, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute); + public void visitRuntimeVisibleAnnotationsAttribute( Clazz clazz, Method method, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute); + + public void visitRuntimeInvisibleAnnotationsAttribute( Clazz clazz, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute); + public void visitRuntimeInvisibleAnnotationsAttribute( Clazz clazz, Field field, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute); + public void visitRuntimeInvisibleAnnotationsAttribute( Clazz clazz, Method method, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute); + + public void visitRuntimeVisibleParameterAnnotationsAttribute( Clazz clazz, Method method, RuntimeVisibleParameterAnnotationsAttribute runtimeVisibleParameterAnnotationsAttribute); + public void visitRuntimeInvisibleParameterAnnotationsAttribute(Clazz clazz, Method method, RuntimeInvisibleParameterAnnotationsAttribute runtimeInvisibleParameterAnnotationsAttribute); + + public void visitAnnotationDefaultAttribute( Clazz clazz, Method method, AnnotationDefaultAttribute annotationDefaultAttribute); +} diff --git a/src/proguard/classfile/attribute/visitor/ExceptionInfoVisitor.java b/src/proguard/classfile/attribute/visitor/ExceptionInfoVisitor.java new file mode 100644 index 0000000..7c85e53 --- /dev/null +++ b/src/proguard/classfile/attribute/visitor/ExceptionInfoVisitor.java @@ -0,0 +1,37 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.*; + +/** + * This interface specifies the methods for a visitor of + * <code>ExceptionInfo</code> objects. Note that there is only a single + * implementation of <code>ExceptionInfo</code>, such that this interface + * is not strictly necessary as a visitor. + * + * @author Eric Lafortune + */ +public interface ExceptionInfoVisitor +{ + public void visitExceptionInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, ExceptionInfo exceptionInfo); +} diff --git a/src/proguard/classfile/attribute/visitor/InnerClassesInfoVisitor.java b/src/proguard/classfile/attribute/visitor/InnerClassesInfoVisitor.java new file mode 100644 index 0000000..91267b0 --- /dev/null +++ b/src/proguard/classfile/attribute/visitor/InnerClassesInfoVisitor.java @@ -0,0 +1,38 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.visitor; + +import proguard.classfile.Clazz; +import proguard.classfile.attribute.InnerClassesInfo; + + +/** + * This interface specifies the methods for a visitor of + * <code>InnerClassesInfo</code> objects. Note that there is only a single + * implementation of <code>InnerClassesInfo</code>, such that this interface + * is not strictly necessary as a visitor. + * + * @author Eric Lafortune + */ +public interface InnerClassesInfoVisitor +{ + public void visitInnerClassesInfo(Clazz clazz, InnerClassesInfo innerClassesInfo); +} diff --git a/src/proguard/classfile/attribute/visitor/LineNumberInfoVisitor.java b/src/proguard/classfile/attribute/visitor/LineNumberInfoVisitor.java new file mode 100644 index 0000000..e59ed7b --- /dev/null +++ b/src/proguard/classfile/attribute/visitor/LineNumberInfoVisitor.java @@ -0,0 +1,38 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.*; + + +/** + * This interface specifies the methods for a visitor of + * <code>LineNumberInfo</code> objects. Note that there is only a single + * implementation of <code>LineNumberInfo</code>, such that this interface + * is not strictly necessary as a visitor. + * + * @author Eric Lafortune + */ +public interface LineNumberInfoVisitor +{ + public void visitLineNumberInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberInfo lineNumberInfo); +} diff --git a/src/proguard/classfile/attribute/visitor/LocalVariableInfoVisitor.java b/src/proguard/classfile/attribute/visitor/LocalVariableInfoVisitor.java new file mode 100644 index 0000000..8647cb3 --- /dev/null +++ b/src/proguard/classfile/attribute/visitor/LocalVariableInfoVisitor.java @@ -0,0 +1,38 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.*; + + +/** + * This interface specifies the methods for a visitor of + * <code>LocalVariableInfo</code> objects. Note that there is only a single + * implementation of <code>LocalVariableInfo</code>, such that this interface + * is not strictly necessary as a visitor. + * + * @author Eric Lafortune + */ +public interface LocalVariableInfoVisitor +{ + public void visitLocalVariableInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableInfo localVariableInfo); +} diff --git a/src/proguard/classfile/attribute/visitor/LocalVariableTypeInfoVisitor.java b/src/proguard/classfile/attribute/visitor/LocalVariableTypeInfoVisitor.java new file mode 100644 index 0000000..9ad38e0 --- /dev/null +++ b/src/proguard/classfile/attribute/visitor/LocalVariableTypeInfoVisitor.java @@ -0,0 +1,38 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.*; + + +/** + * This interface specifies the methods for a visitor of + * <code>LocalVariableTypeInfo</code> objects. Note that there is only a single + * implementation of <code>LocalVariableTypeInfo</code>, such that this interface + * is not strictly necessary as a visitor. + * + * @author Eric Lafortune + */ +public interface LocalVariableTypeInfoVisitor +{ + public void visitLocalVariableTypeInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeInfo localVariableTypeInfo); +} diff --git a/src/proguard/classfile/attribute/visitor/MultiAttributeVisitor.java b/src/proguard/classfile/attribute/visitor/MultiAttributeVisitor.java new file mode 100644 index 0000000..870ba94 --- /dev/null +++ b/src/proguard/classfile/attribute/visitor/MultiAttributeVisitor.java @@ -0,0 +1,356 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.*; +import proguard.classfile.attribute.annotation.*; +import proguard.classfile.attribute.preverification.*; + +/** + * This AttributeVisitor delegates all visits to each AttributeVisitor + * in a given list. + * + * @author Eric Lafortune + */ +public class MultiAttributeVisitor implements AttributeVisitor +{ + private AttributeVisitor[] attributeVisitors; + + + public MultiAttributeVisitor() + { + } + + + public MultiAttributeVisitor(AttributeVisitor[] attributeVisitors) + { + this.attributeVisitors = attributeVisitors; + } + + + public void addAttributeVisitor(AttributeVisitor attributeVisitor) + { + incrementArraySize(); + + attributeVisitors[attributeVisitors.length - 1] = attributeVisitor; + } + + + private void incrementArraySize() + { + if (attributeVisitors == null) + { + attributeVisitors = new AttributeVisitor[1]; + } + else + { + AttributeVisitor[] newAttributeVisitors = + new AttributeVisitor[attributeVisitors.length + 1]; + System.arraycopy(attributeVisitors, 0, + newAttributeVisitors, 0, + attributeVisitors.length); + attributeVisitors = newAttributeVisitors; + } + } + + + // Implementations for AttributeVisitor. + + + public void visitUnknownAttribute(Clazz clazz, UnknownAttribute unknownAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitUnknownAttribute(clazz, unknownAttribute); + } + } + + + public void visitSourceFileAttribute(Clazz clazz, SourceFileAttribute sourceFileAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitSourceFileAttribute(clazz, sourceFileAttribute); + } + } + + + public void visitSourceDirAttribute(Clazz clazz, SourceDirAttribute sourceDirAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitSourceDirAttribute(clazz, sourceDirAttribute); + } + } + + + public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitInnerClassesAttribute(clazz, innerClassesAttribute); + } + } + + + public void visitEnclosingMethodAttribute(Clazz clazz, EnclosingMethodAttribute enclosingMethodAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitEnclosingMethodAttribute(clazz, enclosingMethodAttribute); + } + } + + + public void visitDeprecatedAttribute(Clazz clazz, DeprecatedAttribute deprecatedAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitDeprecatedAttribute(clazz, deprecatedAttribute); + } + } + + + public void visitSyntheticAttribute(Clazz clazz, SyntheticAttribute syntheticAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitSyntheticAttribute(clazz, syntheticAttribute); + } + } + + + public void visitSignatureAttribute(Clazz clazz, SignatureAttribute syntheticAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitSignatureAttribute(clazz, syntheticAttribute); + } + } + + + public void visitDeprecatedAttribute(Clazz clazz, Field field, DeprecatedAttribute deprecatedAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitDeprecatedAttribute(clazz, field, deprecatedAttribute); + } + } + + + public void visitSyntheticAttribute(Clazz clazz, Field field, SyntheticAttribute syntheticAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitSyntheticAttribute(clazz, field, syntheticAttribute); + } + } + + + public void visitSignatureAttribute(Clazz clazz, Field field, SignatureAttribute syntheticAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitSignatureAttribute(clazz, field, syntheticAttribute); + } + } + + + public void visitDeprecatedAttribute(Clazz clazz, Method method, DeprecatedAttribute deprecatedAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitDeprecatedAttribute(clazz, method, deprecatedAttribute); + } + } + + + public void visitSyntheticAttribute(Clazz clazz, Method method, SyntheticAttribute syntheticAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitSyntheticAttribute(clazz, method, syntheticAttribute); + } + } + + + public void visitSignatureAttribute(Clazz clazz, Method method, SignatureAttribute syntheticAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitSignatureAttribute(clazz, method, syntheticAttribute); + } + } + + + public void visitConstantValueAttribute(Clazz clazz, Field field, ConstantValueAttribute constantValueAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitConstantValueAttribute(clazz, field, constantValueAttribute); + } + } + + + public void visitExceptionsAttribute(Clazz clazz, Method method, ExceptionsAttribute exceptionsAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitExceptionsAttribute(clazz, method, exceptionsAttribute); + } + } + + + public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitCodeAttribute(clazz, method, codeAttribute); + } + } + + + public void visitStackMapAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapAttribute stackMapAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitStackMapAttribute(clazz, method, codeAttribute, stackMapAttribute); + } + } + + + public void visitStackMapTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapTableAttribute stackMapTableAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitStackMapTableAttribute(clazz, method, codeAttribute, stackMapTableAttribute); + } + } + + + public void visitLineNumberTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberTableAttribute lineNumberTableAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitLineNumberTableAttribute(clazz, method, codeAttribute, lineNumberTableAttribute); + } + } + + + public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitLocalVariableTableAttribute(clazz, method, codeAttribute, localVariableTableAttribute); + } + } + + + public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitLocalVariableTypeTableAttribute(clazz, method, codeAttribute, localVariableTypeTableAttribute); + } + } + + + public void visitRuntimeVisibleAnnotationsAttribute(Clazz clazz, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitRuntimeVisibleAnnotationsAttribute(clazz, runtimeVisibleAnnotationsAttribute); + } + } + + + public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitRuntimeInvisibleAnnotationsAttribute(clazz, runtimeInvisibleAnnotationsAttribute); + } + } + + + public void visitRuntimeVisibleAnnotationsAttribute(Clazz clazz, Field field, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitRuntimeVisibleAnnotationsAttribute(clazz, field, runtimeVisibleAnnotationsAttribute); + } + } + + + public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, Field field, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitRuntimeInvisibleAnnotationsAttribute(clazz, field, runtimeInvisibleAnnotationsAttribute); + } + } + + + public void visitRuntimeVisibleAnnotationsAttribute(Clazz clazz, Method method, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitRuntimeVisibleAnnotationsAttribute(clazz, method, runtimeVisibleAnnotationsAttribute); + } + } + + + public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, Method method, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitRuntimeInvisibleAnnotationsAttribute(clazz, method, runtimeInvisibleAnnotationsAttribute); + } + } + + + public void visitRuntimeVisibleParameterAnnotationsAttribute(Clazz clazz, Method method, RuntimeVisibleParameterAnnotationsAttribute runtimeVisibleParameterAnnotationsAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitRuntimeVisibleParameterAnnotationsAttribute(clazz, method, runtimeVisibleParameterAnnotationsAttribute); + } + } + + + public void visitRuntimeInvisibleParameterAnnotationsAttribute(Clazz clazz, Method method, RuntimeInvisibleParameterAnnotationsAttribute runtimeInvisibleParameterAnnotationsAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitRuntimeInvisibleParameterAnnotationsAttribute(clazz, method, runtimeInvisibleParameterAnnotationsAttribute); + } + } + + + public void visitAnnotationDefaultAttribute(Clazz clazz, Method method, AnnotationDefaultAttribute annotationDefaultAttribute) + { + for (int index = 0; index < attributeVisitors.length; index++) + { + attributeVisitors[index].visitAnnotationDefaultAttribute(clazz, method, annotationDefaultAttribute); + } + } +} diff --git a/src/proguard/classfile/attribute/visitor/RequiredAttributeFilter.java b/src/proguard/classfile/attribute/visitor/RequiredAttributeFilter.java new file mode 100644 index 0000000..92099f9 --- /dev/null +++ b/src/proguard/classfile/attribute/visitor/RequiredAttributeFilter.java @@ -0,0 +1,351 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.*; +import proguard.classfile.attribute.annotation.*; +import proguard.classfile.attribute.preverification.*; +import proguard.obfuscate.AttributeShrinker; + +/** + * This AttributeVisitor delegates its visits to one of two other + * AttributeVisitor instances, depending on whether the visited attribute + * is strictly required or not. + * + * @see AttributeShrinker + * + * @author Eric Lafortune + */ +public class RequiredAttributeFilter +implements AttributeVisitor +{ + private final AttributeVisitor requiredAttributeVisitor; + private final AttributeVisitor optionalAttributeVisitor; + + + /** + * Creates a new RequiredAttributeFilter for visiting required attributes. + * @param requiredAttributeVisitor the visitor that will visit required + * attributes. + */ + public RequiredAttributeFilter(AttributeVisitor requiredAttributeVisitor) + { + this(requiredAttributeVisitor, null); + } + + + /** + * Creates a new RequiredAttributeFilter for visiting required and + * optional attributes. + * @param requiredAttributeVisitor the visitor that will visit required + * attributes. + * @param optionalAttributeVisitor the visitor that will visit optional + * attributes. + */ + public RequiredAttributeFilter(AttributeVisitor requiredAttributeVisitor, + AttributeVisitor optionalAttributeVisitor) + { + this.requiredAttributeVisitor = requiredAttributeVisitor; + this.optionalAttributeVisitor = optionalAttributeVisitor; + } + + + // Implementations for AttributeVisitor. + + public void visitUnknownAttribute(Clazz clazz, UnknownAttribute unknownAttribute) + { + if (optionalAttributeVisitor != null) + { + unknownAttribute.accept(clazz, optionalAttributeVisitor); + } + } + + + public void visitSourceFileAttribute(Clazz clazz, SourceFileAttribute sourceFileAttribute) + { + if (optionalAttributeVisitor != null) + { + sourceFileAttribute.accept(clazz, optionalAttributeVisitor); + } + } + + + public void visitSourceDirAttribute(Clazz clazz, SourceDirAttribute sourceDirAttribute) + { + if (optionalAttributeVisitor != null) + { + sourceDirAttribute.accept(clazz, optionalAttributeVisitor); + } + } + + + public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute) + { + if (optionalAttributeVisitor != null) + { + innerClassesAttribute.accept(clazz, optionalAttributeVisitor); + } + } + + + public void visitEnclosingMethodAttribute(Clazz clazz, EnclosingMethodAttribute enclosingMethodAttribute) + { + if (optionalAttributeVisitor != null) + { + enclosingMethodAttribute.accept(clazz, optionalAttributeVisitor); + } + } + + + public void visitDeprecatedAttribute(Clazz clazz, DeprecatedAttribute deprecatedAttribute) + { + if (optionalAttributeVisitor != null) + { + deprecatedAttribute.accept(clazz, optionalAttributeVisitor); + } + } + + + public void visitDeprecatedAttribute(Clazz clazz, Field field, DeprecatedAttribute deprecatedAttribute) + { + if (optionalAttributeVisitor != null) + { + deprecatedAttribute.accept(clazz, field, optionalAttributeVisitor); + } + } + + + public void visitDeprecatedAttribute(Clazz clazz, Method method, DeprecatedAttribute deprecatedAttribute) + { + if (optionalAttributeVisitor != null) + { + deprecatedAttribute.accept(clazz, method, optionalAttributeVisitor); + } + } + + + public void visitSyntheticAttribute(Clazz clazz, SyntheticAttribute syntheticAttribute) + { + if (optionalAttributeVisitor != null) + { + syntheticAttribute.accept(clazz, optionalAttributeVisitor); + } + } + + + public void visitSyntheticAttribute(Clazz clazz, Field field, SyntheticAttribute syntheticAttribute) + { + if (optionalAttributeVisitor != null) + { + syntheticAttribute.accept(clazz, field, optionalAttributeVisitor); + } + } + + + public void visitSyntheticAttribute(Clazz clazz, Method method, SyntheticAttribute syntheticAttribute) + { + if (optionalAttributeVisitor != null) + { + syntheticAttribute.accept(clazz, method, optionalAttributeVisitor); + } + } + + + public void visitSignatureAttribute(Clazz clazz, SignatureAttribute signatureAttribute) + { + if (optionalAttributeVisitor != null) + { + signatureAttribute.accept(clazz, optionalAttributeVisitor); + } + } + + + public void visitSignatureAttribute(Clazz clazz, Field field, SignatureAttribute signatureAttribute) + { + if (optionalAttributeVisitor != null) + { + signatureAttribute.accept(clazz, field, optionalAttributeVisitor); + } + } + + + public void visitSignatureAttribute(Clazz clazz, Method method, SignatureAttribute signatureAttribute) + { + if (optionalAttributeVisitor != null) + { + signatureAttribute.accept(clazz, method, optionalAttributeVisitor); + } + } + + + public void visitConstantValueAttribute(Clazz clazz, Field field, ConstantValueAttribute constantValueAttribute) + { + if (requiredAttributeVisitor != null) + { + constantValueAttribute.accept(clazz, field, requiredAttributeVisitor); + } + } + + + public void visitExceptionsAttribute(Clazz clazz, Method method, ExceptionsAttribute exceptionsAttribute) + { + if (optionalAttributeVisitor != null) + { + exceptionsAttribute.accept(clazz, method, optionalAttributeVisitor); + } + } + + + public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) + { + if (requiredAttributeVisitor != null) + { + codeAttribute.accept(clazz, method, requiredAttributeVisitor); + } + } + + + public void visitStackMapAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapAttribute stackMapAttribute) + { + if (optionalAttributeVisitor != null) + { + stackMapAttribute.accept(clazz, method, codeAttribute, optionalAttributeVisitor); + } + } + + + public void visitStackMapTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapTableAttribute stackMapTableAttribute) + { + if (requiredAttributeVisitor != null) + { + stackMapTableAttribute.accept(clazz, method, codeAttribute, requiredAttributeVisitor); + } + } + + + public void visitLineNumberTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberTableAttribute lineNumberTableAttribute) + { + if (optionalAttributeVisitor != null) + { + lineNumberTableAttribute.accept(clazz, method, codeAttribute, optionalAttributeVisitor); + } + } + + + public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute) + { + if (optionalAttributeVisitor != null) + { + localVariableTableAttribute.accept(clazz, method, codeAttribute, optionalAttributeVisitor); + } + } + + + public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute) + { + if (optionalAttributeVisitor != null) + { + localVariableTypeTableAttribute.accept(clazz, method, codeAttribute, optionalAttributeVisitor); + } + } + + + public void visitRuntimeVisibleAnnotationsAttribute(Clazz clazz, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute) + { + if (optionalAttributeVisitor != null) + { + runtimeVisibleAnnotationsAttribute.accept(clazz, optionalAttributeVisitor); + } + } + + + public void visitRuntimeVisibleAnnotationsAttribute(Clazz clazz, Field field, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute) + { + if (optionalAttributeVisitor != null) + { + runtimeVisibleAnnotationsAttribute.accept(clazz, field, optionalAttributeVisitor); + } + } + + + public void visitRuntimeVisibleAnnotationsAttribute(Clazz clazz, Method method, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute) + { + if (optionalAttributeVisitor != null) + { + runtimeVisibleAnnotationsAttribute.accept(clazz, method, optionalAttributeVisitor); + } + } + + + public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute) + { + if (optionalAttributeVisitor != null) + { + runtimeInvisibleAnnotationsAttribute.accept(clazz, optionalAttributeVisitor); + } + } + + + public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, Field field, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute) + { + if (optionalAttributeVisitor != null) + { + runtimeInvisibleAnnotationsAttribute.accept(clazz, field, optionalAttributeVisitor); + } + } + + + public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, Method method, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute) + { + if (optionalAttributeVisitor != null) + { + runtimeInvisibleAnnotationsAttribute.accept(clazz, method, optionalAttributeVisitor); + } + } + + + public void visitRuntimeVisibleParameterAnnotationsAttribute(Clazz clazz, Method method, RuntimeVisibleParameterAnnotationsAttribute runtimeVisibleParameterAnnotationsAttribute) + { + if (optionalAttributeVisitor != null) + { + runtimeVisibleParameterAnnotationsAttribute.accept(clazz, method, optionalAttributeVisitor); + } + } + + + public void visitRuntimeInvisibleParameterAnnotationsAttribute(Clazz clazz, Method method, RuntimeInvisibleParameterAnnotationsAttribute runtimeInvisibleParameterAnnotationsAttribute) + { + if (optionalAttributeVisitor != null) + { + runtimeInvisibleParameterAnnotationsAttribute.accept(clazz, method, optionalAttributeVisitor); + } + } + + + public void visitAnnotationDefaultAttribute(Clazz clazz, Method method, AnnotationDefaultAttribute annotationDefaultAttribute) + { + if (optionalAttributeVisitor != null) + { + annotationDefaultAttribute.accept(clazz, method, optionalAttributeVisitor); + } + } +} diff --git a/src/proguard/classfile/attribute/visitor/StackSizeComputer.java b/src/proguard/classfile/attribute/visitor/StackSizeComputer.java new file mode 100644 index 0000000..401f188 --- /dev/null +++ b/src/proguard/classfile/attribute/visitor/StackSizeComputer.java @@ -0,0 +1,379 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.attribute.visitor; + +import proguard.classfile.*; +import proguard.classfile.visitor.ClassPrinter; +import proguard.classfile.attribute.*; +import proguard.classfile.instruction.*; +import proguard.classfile.instruction.visitor.InstructionVisitor; +import proguard.classfile.util.SimplifiedVisitor; + +/** + * This AttributeVisitor computes the stack sizes at all instruction offsets + * of the code attributes that it visits. + * + * @author Eric Lafortune + */ +public class StackSizeComputer +extends SimplifiedVisitor +implements AttributeVisitor, + InstructionVisitor, + ExceptionInfoVisitor +{ + //* + private static final boolean DEBUG = false; + /*/ + private static boolean DEBUG = true; + //*/ + + + private boolean[] evaluated = new boolean[ClassConstants.TYPICAL_CODE_LENGTH]; + private int[] stackSizes = new int[ClassConstants.TYPICAL_CODE_LENGTH]; + + private boolean exitInstructionBlock; + + private int stackSize; + private int maxStackSize; + + + /** + * Returns whether the instruction at the given offset is reachable in the + * most recently visited code attribute. + */ + public boolean isReachable(int instructionOffset) + { + return evaluated[instructionOffset]; + } + + + /** + * Returns the stack size at the given instruction offset of the most + * recently visited code attribute. + */ + public int getStackSize(int instructionOffset) + { + if (!evaluated[instructionOffset]) + { + throw new IllegalArgumentException("Unknown stack size at unreachable instruction offset ["+instructionOffset+"]"); + } + + return stackSizes[instructionOffset]; + } + + + /** + * Returns the maximum stack size of the most recently visited code attribute. + */ + public int getMaxStackSize() + { + return maxStackSize; + } + + + // Implementations for AttributeVisitor. + + public void visitAnyAttribute(Clazz clazz, Attribute attribute) {} + + + public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) + { +// DEBUG = +// clazz.getName().equals("abc/Def") && +// method.getName(clazz).equals("abc"); + + // TODO: Remove this when the code has stabilized. + // Catch any unexpected exceptions from the actual visiting method. + try + { + // Process the code. + visitCodeAttribute0(clazz, method, codeAttribute); + } + catch (RuntimeException ex) + { + System.err.println("Unexpected error while computing stack sizes:"); + System.err.println(" Class = ["+clazz.getName()+"]"); + System.err.println(" Method = ["+method.getName(clazz)+method.getDescriptor(clazz)+"]"); + System.err.println(" Exception = ["+ex.getClass().getName()+"] ("+ex.getMessage()+")"); + + if (DEBUG) + { + method.accept(clazz, new ClassPrinter()); + } + + throw ex; + } + } + + + public void visitCodeAttribute0(Clazz clazz, Method method, CodeAttribute codeAttribute) + { + if (DEBUG) + { + System.out.println("StackSizeComputer: "+clazz.getName()+"."+method.getName(clazz)+method.getDescriptor(clazz)); + } + + // Try to reuse the previous array. + int codeLength = codeAttribute.u4codeLength; + if (evaluated.length < codeLength) + { + evaluated = new boolean[codeLength]; + stackSizes = new int[codeLength]; + } + else + { + for (int index = 0; index < codeLength; index++) + { + evaluated[index] = false; + } + } + + // The initial stack is always empty. + stackSize = 0; + maxStackSize = 0; + + // Evaluate the instruction block starting at the entry point of the method. + evaluateInstructionBlock(clazz, method, codeAttribute, 0); + + // Evaluate the exception handlers. + codeAttribute.exceptionsAccept(clazz, method, this); + } + + + // Implementations for InstructionVisitor. + + public void visitSimpleInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SimpleInstruction simpleInstruction) + { + byte opcode = simpleInstruction.opcode; + + // Some simple instructions exit from the current instruction block. + exitInstructionBlock = + opcode == InstructionConstants.OP_IRETURN || + opcode == InstructionConstants.OP_LRETURN || + opcode == InstructionConstants.OP_FRETURN || + opcode == InstructionConstants.OP_DRETURN || + opcode == InstructionConstants.OP_ARETURN || + opcode == InstructionConstants.OP_RETURN || + opcode == InstructionConstants.OP_ATHROW; + } + + public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) + { + // Constant pool instructions never end the current instruction block. + exitInstructionBlock = false; + } + + public void visitVariableInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VariableInstruction variableInstruction) + { + byte opcode = variableInstruction.opcode; + + // The ret instruction end the current instruction block. + exitInstructionBlock = + opcode == InstructionConstants.OP_RET; + } + + public void visitBranchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, BranchInstruction branchInstruction) + { + byte opcode = branchInstruction.opcode; + + // Evaluate the target instruction blocks. + evaluateInstructionBlock(clazz, + method, + codeAttribute, + offset + + branchInstruction.branchOffset); + + // Evaluate the instructions after a subroutine branch. + if (opcode == InstructionConstants.OP_JSR || + opcode == InstructionConstants.OP_JSR_W) + { + // We assume subroutine calls (jsr and jsr_w instructions) don't + // change the stack, other than popping the return value. + stackSize -= 1; + + evaluateInstructionBlock(clazz, + method, + codeAttribute, + offset + branchInstruction.length(offset)); + } + + // Some branch instructions always end the current instruction block. + exitInstructionBlock = + opcode == InstructionConstants.OP_GOTO || + opcode == InstructionConstants.OP_GOTO_W || + opcode == InstructionConstants.OP_JSR || + opcode == InstructionConstants.OP_JSR_W; + } + + + public void visitAnySwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SwitchInstruction switchInstruction) + { + // Evaluate the target instruction blocks. + + // Loop over all jump offsets. + int[] jumpOffsets = switchInstruction.jumpOffsets; + + for (int index = 0; index < jumpOffsets.length; index++) + { + // Evaluate the jump instruction block. + evaluateInstructionBlock(clazz, + method, + codeAttribute, + offset + jumpOffsets[index]); + } + + // Also evaluate the default instruction block. + evaluateInstructionBlock(clazz, + method, + codeAttribute, + offset + switchInstruction.defaultOffset); + + // The switch instruction always ends the current instruction block. + exitInstructionBlock = true; + } + + + // Implementations for ExceptionInfoVisitor. + + public void visitExceptionInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, ExceptionInfo exceptionInfo) + { + if (DEBUG) + { + System.out.println("Exception:"); + } + + // The stack size when entering the exception handler is always 1. + stackSize = 1; + + // Evaluate the instruction block starting at the entry point of the + // exception handler. + evaluateInstructionBlock(clazz, + method, + codeAttribute, + exceptionInfo.u2handlerPC); + } + + + // Small utility methods. + + /** + * Evaluates a block of instructions that hasn't been handled before, + * starting at the given offset and ending at a branch instruction, a return + * instruction, or a throw instruction. Branch instructions are handled + * recursively. + */ + private void evaluateInstructionBlock(Clazz clazz, + Method method, + CodeAttribute codeAttribute, + int instructionOffset) + { + if (DEBUG) + { + if (evaluated[instructionOffset]) + { + System.out.println("-- (instruction block at "+instructionOffset+" already evaluated)"); + } + else + { + System.out.println("-- instruction block:"); + } + } + + // Remember the initial stack size. + int initialStackSize = stackSize; + + // Remember the maximum stack size. + if (maxStackSize < stackSize) + { + maxStackSize = stackSize; + } + + // Evaluate any instructions that haven't been evaluated before. + while (!evaluated[instructionOffset]) + { + // Mark the instruction as evaluated. + evaluated[instructionOffset] = true; + + Instruction instruction = InstructionFactory.create(codeAttribute.code, + instructionOffset); + + if (DEBUG) + { + int stackPushCount = instruction.stackPushCount(clazz); + int stackPopCount = instruction.stackPopCount(clazz); + System.out.println("["+instructionOffset+"]: "+ + stackSize+" - "+ + stackPopCount+" + "+ + stackPushCount+" = "+ + (stackSize+stackPushCount-stackPopCount)+": "+ + instruction.toString(instructionOffset)); + } + + // Compute the instruction's effect on the stack size. + stackSize -= instruction.stackPopCount(clazz); + + if (stackSize < 0) + { + throw new IllegalArgumentException("Stack size becomes negative after instruction "+ + instruction.toString(instructionOffset)+" in ["+ + clazz.getName()+"."+ + method.getName(clazz)+ + method.getDescriptor(clazz)+"]"); + } + + stackSizes[instructionOffset] = + stackSize += instruction.stackPushCount(clazz); + + // Remember the maximum stack size. + if (maxStackSize < stackSize) + { + maxStackSize = stackSize; + } + + // Remember the next instruction offset. + int nextInstructionOffset = instructionOffset + + instruction.length(instructionOffset); + + // Visit the instruction, in order to handle branches. + instruction.accept(clazz, method, codeAttribute, instructionOffset, this); + + // Stop evaluating after a branch. + if (exitInstructionBlock) + { + break; + } + + // Continue with the next instruction. + instructionOffset = nextInstructionOffset; + + if (DEBUG) + { + if (evaluated[instructionOffset]) + { + System.out.println("-- (instruction at "+instructionOffset+" already evaluated)"); + } + } + } + + // Restore the stack size for possible subsequent instruction blocks. + this.stackSize = initialStackSize; + } +} diff --git a/src/proguard/classfile/attribute/visitor/package.html b/src/proguard/classfile/attribute/visitor/package.html new file mode 100644 index 0000000..056244a --- /dev/null +++ b/src/proguard/classfile/attribute/visitor/package.html @@ -0,0 +1,3 @@ +<body> +This package contains visitors for attributes and their components. +</body> |