MethodGen.getMethod().
+ */
+ public void dispose() {
+ // Traverse in reverse order, because ih.next is overwritten
+ for (InstructionHandle ih = end; ih != null; ih = ih.prev) {
+ /*
+ * Causes BranchInstructions to release target and targeters, because it calls dispose() on the contained instruction.
+ */
+ ih.dispose();
+ }
+
+ clear();
+ }
+
+ /**
+ * @return start of list
+ */
+ public InstructionHandle getStart() {
+ return start;
+ }
+
+ /**
+ * @return end of list
+ */
+ public InstructionHandle getEnd() {
+ return end;
+ }
+
+ /**
+ * @return length of list (Number of instructions, not bytes)
+ */
+ public int getLength() {
+ return length;
+ }
+
+ /**
+ * @return length of list (Number of instructions, not bytes)
+ */
+ public int size() {
+ return length;
+ }
+
+ /**
+ * Redirect all references from old_target to new_target, i.e., update targets of branch instructions.
+ *
+ * @param old_target the old target instruction handle
+ * @param new_target the new target instruction handle
+ */
+ public void redirectBranches(InstructionHandle old_target, InstructionHandle new_target) {
+ for (InstructionHandle ih = start; ih != null; ih = ih.next) {
+ Instruction i = ih.getInstruction();
+
+ if (i instanceof InstructionBranch) {
+ InstructionBranch b = (InstructionBranch) i;
+ InstructionHandle target = b.getTarget();
+
+ if (target == old_target) {
+ b.setTarget(new_target);
+ }
+
+ if (b instanceof InstructionSelect) { // Either LOOKUPSWITCH or TABLESWITCH
+ InstructionHandle[] targets = ((InstructionSelect) b).getTargets();
+
+ for (int j = 0; j < targets.length; j++) {
+ if (targets[j] == old_target) {
+ ((InstructionSelect) b).setTarget(j, new_target);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Redirect all references of local variables from old_target to new_target.
+ *
+ * @param lg array of local variables
+ * @param old_target the old target instruction handle
+ * @param new_target the new target instruction handle
+ * @see MethodGen
+ */
+ public void redirectLocalVariables(LocalVariableGen[] lg, InstructionHandle old_target, InstructionHandle new_target) {
+ for (int i = 0; i < lg.length; i++) {
+ InstructionHandle start = lg[i].getStart();
+ InstructionHandle end = lg[i].getEnd();
+
+ if (start == old_target) {
+ lg[i].setStart(new_target);
+ }
+ if (end == old_target) {
+ lg[i].setEnd(new_target);
+ }
+ }
+ }
+
+ /**
+ * Redirect all references of exception handlers from old_target to new_target.
+ *
+ * @param exceptions array of exception handlers
+ * @param old_target the old target instruction handle
+ * @param new_target the new target instruction handle
+ * @see MethodGen
+ */
+ public void redirectExceptionHandlers(CodeExceptionGen[] exceptions, InstructionHandle old_target, InstructionHandle new_target) {
+ for (int i = 0; i < exceptions.length; i++) {
+ if (exceptions[i].getStartPC() == old_target) {
+ exceptions[i].setStartPC(new_target);
+ }
+
+ if (exceptions[i].getEndPC() == old_target) {
+ exceptions[i].setEndPC(new_target);
+ }
+
+ if (exceptions[i].getHandlerPC() == old_target) {
+ exceptions[i].setHandlerPC(new_target);
+ }
+ }
+ }
+
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/InstructionSelect.java bcel/src/java/org/aspectj/apache/bcel/generic/InstructionSelect.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/InstructionSelect.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/InstructionSelect.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,303 @@
+package org.apache.bcel.generic;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.bcel.util.ByteSequence;
+
+/**
+ * Select - Abstract super class for LOOKUPSWITCH and TABLESWITCH instructions.
+ *
+ * @version $Id: InstructionSelect.java,v 1.3 2008/08/28 00:05:41 aclement Exp $
+ * @author M. Dahm
+ * @see LOOKUPSWITCH
+ * @see TABLESWITCH
+ * @see InstructionList
+ */
+public abstract class InstructionSelect extends InstructionBranch {
+ protected int[] match; // matches, i.e., case 1: ...
+ protected int[] indices; // target offsets
+ protected InstructionHandle[] targets; // target objects in instruction list
+ protected int fixedLength; // fixed length defined by subclasses
+ protected int matchLength; // number of cases
+ protected int padding = 0; // number of pad bytes for alignment
+
+ protected short length;
+
+ /**
+ * (Match, target) pairs for switch. `Match' and `targets' must have the
+ * same length of course.
+ *
+ * @param match array of matching values
+ * @param targets instruction targets
+ * @param target default instruction target
+ */
+ InstructionSelect(short opcode, int[] match, InstructionHandle[] targets,
+ InstructionHandle target) {
+ super(opcode, target);
+
+ this.targets = targets;
+ for (int i = 0; i < targets.length; i++) {
+ notifyTarget(null, targets[i], this);
+ }
+
+ this.match = match;
+
+ if ((matchLength = match.length) != targets.length) {
+ throw new ClassGenException(
+ "Match and target array have not the same length");
+ }
+
+ indices = new int[matchLength];
+ }
+
+ protected int getTargetOffset(InstructionHandle target) {
+ if (target == null) {
+ throw new ClassGenException("Target of " + super.toString(true)
+ + " is invalid null handle");
+ }
+
+ int t = target.getPosition();
+
+ if (t < 0) {
+ throw new ClassGenException(
+ "Invalid branch target position offset for "
+ + super.toString(true) + ":" + t + ":" + target);
+ }
+
+ return t - positionOfThisInstruction;
+ }
+
+ /**
+ * Since this is a variable length instruction, it may shift the following
+ * instructions which then need to update their position.
+ *
+ * Called by InstructionList.setPositions when setting the position for
+ * every instruction. In the presence of variable length instructions
+ * `setPositions' performs multiple passes over the instruction list to
+ * calculate the correct (byte) positions and offsets by calling this
+ * function.
+ *
+ * @param offset additional offset caused by preceding (variable length)
+ * instructions
+ * @param max_offset the maximum offset that may be caused by these
+ * instructions
+ * @return additional offset caused by possible change of this instruction's
+ * length
+ */
+ protected int updatePosition(int offset, int max_offset) {
+ positionOfThisInstruction += offset; // Additional offset caused by
+ // preceding SWITCHs, GOTOs,
+ // etc.
+
+ short old_length = length;
+
+ /*
+ * Alignment on 4-byte-boundary, + 1, because of tag byte.
+ */
+ padding = (4 - (positionOfThisInstruction + 1) % 4) % 4;
+ length = (short) (fixedLength + padding); // Update length
+
+ return length - old_length;
+ }
+
+ /**
+ * Dump instruction as byte code to stream out.
+ *
+ * @param out Output stream
+ */
+ public void dump(DataOutputStream out) throws IOException {
+ out.writeByte(opcode);
+
+ for (int i = 0; i < padding; i++) {
+ out.writeByte(0);
+ }
+
+ targetIndex = getTargetOffset(); // Write default target offset
+ out.writeInt(targetIndex);
+ }
+
+ public InstructionSelect(short opcode, ByteSequence bytes)
+ throws IOException {
+ super(opcode);
+ padding = (4 - bytes.getIndex() % 4) % 4; // Compute number of pad bytes
+
+ for (int i = 0; i < padding; i++) {
+ bytes.readByte();
+ }
+
+ // Default branch target common for both cases (TABLESWITCH,
+ // LOOKUPSWITCH)
+ targetIndex = bytes.readInt();
+ }
+
+ /**
+ * @return mnemonic for instruction
+ */
+ public String toString(boolean verbose) {
+ StringBuffer buf = new StringBuffer(super.toString(verbose));
+
+ if (verbose) {
+ for (int i = 0; i < matchLength; i++) {
+ String s = "null";
+
+ if (targets[i] != null) {
+ s = targets[i].getInstruction().toString();
+ }
+
+ buf.append("(" + match[i] + ", " + s + " = {" + indices[i]
+ + "})");
+ }
+ } else {
+ buf.append(" ...");
+ }
+
+ return buf.toString();
+ }
+
+ /**
+ * Set branch target for `i'th case
+ */
+ public void setTarget(int i, InstructionHandle target) {
+ notifyTarget(targets[i], target, this);
+ targets[i] = target;
+ }
+
+ /**
+ * @param old_ih old target
+ * @param new_ih new target
+ */
+ public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) {
+ boolean targeted = false;
+
+ if (targetInstruction == old_ih) {
+ targeted = true;
+ setTarget(new_ih);
+ }
+
+ for (int i = 0; i < targets.length; i++) {
+ if (targets[i] == old_ih) {
+ targeted = true;
+ setTarget(i, new_ih);
+ }
+ }
+
+ if (!targeted) {
+ throw new ClassGenException("Not targeting " + old_ih);
+ }
+ }
+
+ /**
+ * @return true, if ih is target of this instruction
+ */
+ public boolean containsTarget(InstructionHandle ih) {
+ if (targetInstruction == ih) {
+ return true;
+ }
+
+ for (int i = 0; i < targets.length; i++) {
+ if (targets[i] == ih) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Inform targets that they're not targeted anymore.
+ */
+ void dispose() {
+ super.dispose();
+
+ for (int i = 0; i < targets.length; i++) {
+ targets[i].removeTargeter(this);
+ }
+ }
+
+ public boolean equals(Object other) {
+ return this == other;
+ }
+
+ public int hashCode() {
+ return opcode * 37;
+ }
+
+ /**
+ * @return array of match indices
+ */
+ public int[] getMatchs() {
+ return match;
+ }
+
+ /**
+ * @return array of match target offsets
+ */
+ public int[] getIndices() {
+ return indices;
+ }
+
+ /**
+ * @return array of match targets
+ */
+ public InstructionHandle[] getTargets() {
+ return targets;
+ }
+
+ public int getLength() {
+ return length;
+ }
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/InstructionShort.java bcel/src/java/org/aspectj/apache/bcel/generic/InstructionShort.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/InstructionShort.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/InstructionShort.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,80 @@
+package org.apache.bcel.generic;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+/**
+ * Instruction that needs one short
+ */
+public class InstructionShort extends Instruction {
+ private final short s;
+
+ public InstructionShort(short opcode, short s) {
+ super(opcode);
+ this.s = s;
+ }
+
+ public void dump(DataOutputStream out) throws IOException {
+ out.writeByte(opcode);
+ out.writeShort(s);
+ }
+
+ public String toString(boolean verbose) {
+ return super.toString(verbose) + " " + s;
+ }
+
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/InstructionTargeter.java bcel/src/java/org/aspectj/apache/bcel/generic/InstructionTargeter.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/InstructionTargeter.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/InstructionTargeter.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,70 @@
+package org.apache.bcel.generic;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+/**
+ * Denote that a class targets InstructionHandles within an InstructionList. Namely
+ * the following implementers:
+ *
+ * @see BranchHandle
+ * @see LocalVariableGen
+ * @see CodeExceptionGen
+ * @version $Id: InstructionTargeter.java,v 1.3 2008/05/28 23:52:57 aclement Exp $
+ * @author M. Dahm
+ */
+public interface InstructionTargeter {
+ public boolean containsTarget(InstructionHandle ih);
+ public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih);
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/InvokeInstruction.java bcel/src/java/org/aspectj/apache/bcel/generic/InvokeInstruction.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/InvokeInstruction.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/InvokeInstruction.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,132 @@
+package org.apache.bcel.generic;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+import java.util.StringTokenizer;
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.classfile.Constant;
+import org.apache.bcel.classfile.ConstantPool;
+
+/**
+ * Super class for the INVOKExxx family of instructions.
+ *
+ * @version $Id: InvokeInstruction.java,v 1.5 2008/05/28 23:52:54 aclement Exp $
+ * @author M. Dahm
+ */
+public class InvokeInstruction extends FieldOrMethod {
+
+ /**
+ * @param index to constant pool
+ */
+ public InvokeInstruction(short opcode, int index) {
+ super(opcode, index);
+ }
+
+ /**
+ * @return mnemonic for instruction with symbolic references resolved
+ */
+ public String toString(ConstantPool cp) {
+ Constant c = cp.getConstant(index);
+ StringTokenizer tok = new StringTokenizer(cp.constantToString(c));
+
+ return Constants.OPCODE_NAMES[opcode] + " " +
+ tok.nextToken().replace('.', '/') + tok.nextToken();
+ }
+
+ /**
+ * Also works for instructions whose stack effect depends on the
+ * constant pool entry they reference.
+ * @return Number of words consumed from stack by this instruction
+ */
+ public int consumeStack(ConstantPool cpg) {
+ String signature = getSignature(cpg);
+ int sum = Type.getArgumentSizes(signature);
+ if (opcode!=Constants.INVOKESTATIC) sum+=1;
+ return sum;
+ }
+
+ /**
+ * Also works for instructions whose stack effect depends on the
+ * constant pool entry they reference.
+ * @return Number of words produced onto stack by this instruction
+ */
+ public int produceStack(ConstantPool cpg) {
+ return getReturnType(cpg).getSize();
+ }
+
+ /** @return return type of referenced method.
+ */
+ public Type getType(ConstantPool cpg) {
+ return getReturnType(cpg);
+ }
+
+ /** @return name of referenced method.
+ */
+ public String getMethodName(ConstantPool cpg) {
+ return getName(cpg);
+ }
+
+ /** @return return type of referenced method.
+ */
+ public Type getReturnType(ConstantPool cpg) {
+ return Type.getReturnType(getSignature(cpg));
+ }
+
+ /** @return argument types of referenced method.
+ */
+ public Type[] getArgumentTypes(ConstantPool cpg) {
+ return Type.getArgumentTypes(getSignature(cpg));
+ }
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/LOOKUPSWITCH.java bcel/src/java/org/aspectj/apache/bcel/generic/LOOKUPSWITCH.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/LOOKUPSWITCH.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/LOOKUPSWITCH.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,115 @@
+package org.apache.bcel.generic;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.util.ByteSequence;
+
+import com.sun.org.apache.bcel.internal.generic.SWITCH;
+
+/**
+ * LOOKUPSWITCH - Switch with unordered set of values
+ *
+ * @version $Id: LOOKUPSWITCH.java,v 1.4 2008/08/28 00:05:29 aclement Exp $
+ * @author M. Dahm
+ * @see SWITCH
+ */
+public class LOOKUPSWITCH extends InstructionSelect {
+
+ public LOOKUPSWITCH(int[] match, InstructionHandle[] targets, InstructionHandle target) {
+ super(LOOKUPSWITCH, match, targets, target);
+ // Alignment remainer assumed 0 here, until dump time
+ length = (short) (9 + matchLength * 8);
+ fixedLength = length;
+ }
+
+ /**
+ * Dump instruction as byte code to stream out.
+ *
+ * @param out Output stream
+ */
+ public void dump(DataOutputStream out) throws IOException {
+ super.dump(out);
+ out.writeInt(matchLength); // npairs
+
+ for (int i = 0; i < matchLength; i++) {
+ out.writeInt(match[i]); // match-offset pairs
+ out.writeInt(indices[i] = getTargetOffset(targets[i]));
+ }
+ }
+
+ /**
+ * Read needed data (e.g. index) from file.
+ */
+ public LOOKUPSWITCH(ByteSequence bytes) throws IOException {
+ super(Constants.LOOKUPSWITCH, bytes); // reads padding
+
+ matchLength = bytes.readInt();
+ fixedLength = (short) (9 + matchLength * 8);
+ length = (short) (fixedLength + padding);
+
+ match = new int[matchLength];
+ indices = new int[matchLength];
+ targets = new InstructionHandle[matchLength];
+
+ for (int i = 0; i < matchLength; i++) {
+ match[i] = bytes.readInt();
+ indices[i] = bytes.readInt();
+ }
+ }
+
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/LineNumberGen.java bcel/src/java/org/aspectj/apache/bcel/generic/LineNumberGen.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/LineNumberGen.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/LineNumberGen.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,130 @@
+package org.apache.bcel.generic;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+import org.apache.bcel.classfile.LineNumber;
+
+/**
+ * This class represents a line number within a method, i.e., give an instruction
+ * a line number corresponding to the source code line.
+ *
+ * @version $Id: LineNumberGen.java,v 1.5 2008/05/28 23:53:00 aclement Exp $
+ * @author M. Dahm
+ * @see LineNumber
+ * @see MethodGen
+ */
+public class LineNumberGen
+ implements InstructionTargeter, Cloneable, java.io.Serializable
+{
+ private InstructionHandle ih;
+ private int src_line;
+
+ /**
+ * Create a line number.
+ *
+ * @param ih instruction handle to reference
+ */
+ public LineNumberGen(InstructionHandle ih, int src_line) {
+ setInstruction(ih);
+ setSourceLine(src_line);
+ }
+
+ /**
+ * @return true, if ih is target of this line number
+ */
+ public boolean containsTarget(InstructionHandle ih) {
+ return this.ih == ih;
+ }
+
+ /**
+ * @param old_ih old target
+ * @param new_ih new target
+ */
+ public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) {
+ if(old_ih != ih)
+ throw new ClassGenException("Not targeting " + old_ih + ", but " + ih + "}");
+ else
+ setInstruction(new_ih);
+ }
+
+ /**
+ * Get LineNumber attribute .
+ *
+ * This relies on that the instruction list has already been dumped to byte code or
+ * or that the `setPositions' methods has been called for the instruction list.
+ */
+ public LineNumber getLineNumber() {
+ return new LineNumber(ih.getPosition(), src_line);
+ }
+
+ public void setInstruction(InstructionHandle ih) {
+ InstructionBranch.notifyTarget(this.ih, ih, this);
+
+ this.ih = ih;
+ }
+
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch(CloneNotSupportedException e) {
+ System.err.println(e);
+ return null;
+ }
+ }
+
+ public InstructionHandle getInstruction() { return ih; }
+ public void setSourceLine(int src_line) { this.src_line = src_line; }
+ public int getSourceLine() { return src_line; }
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/LineNumberTag.java bcel/src/java/org/aspectj/apache/bcel/generic/LineNumberTag.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/LineNumberTag.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/LineNumberTag.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,44 @@
+/* *******************************************************************
+ * Copyright (c) 2002 Contributors
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * PARC initial implementation
+ * Andy Clement pushed down into bcel module
+ * ******************************************************************/
+
+
+package org.apache.bcel.generic;
+
+/**
+ * we don't actually target instructions, but instructions target us.
+ */
+public class LineNumberTag extends Tag {
+
+ private final int lineNumber;
+
+ public LineNumberTag(int lineNumber) {
+ this.lineNumber = lineNumber;
+ }
+
+ public int getLineNumber() {
+ return lineNumber;
+ }
+
+ public String toString() {
+ return "line " + lineNumber;
+ }
+
+ public boolean equals(Object other) {
+ if (!(other instanceof LineNumberTag)) return false;
+ return lineNumber == ((LineNumberTag)other).lineNumber;
+ }
+
+ public int hashCode() {
+ return lineNumber;
+ }
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/LocalVariableGen.java bcel/src/java/org/aspectj/apache/bcel/generic/LocalVariableGen.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/LocalVariableGen.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/LocalVariableGen.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,220 @@
+package org.apache.bcel.generic;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.classfile.ConstantPool;
+import org.apache.bcel.classfile.LocalVariable;
+
+/**
+ * This class represents a local variable within a method. It contains its scope, name and type. The generated LocalVariable object
+ * can be obtained with getLocalVariable which needs the instruction list and the constant pool as parameters.
+ *
+ * @version $Id: LocalVariableGen.java,v 1.7 2008/08/28 00:04:23 aclement Exp $
+ * @author M. Dahm
+ * @see LocalVariable
+ * @see MethodGen
+ */
+public class LocalVariableGen implements InstructionTargeter, Cloneable, java.io.Serializable {
+ private int index;
+ private String name;
+ private Type type;
+ private InstructionHandle start, end;
+
+ /**
+ * Generate a local variable that with index `index'. Note that double and long variables need two indexs. Index indices have to
+ * be provided by the user.
+ *
+ * @param index index of local variable
+ * @param name its name
+ * @param type its type
+ * @param start from where the instruction is valid (null means from the start)
+ * @param end until where the instruction is valid (null means to the end)
+ */
+ public LocalVariableGen(int index, String name, Type type, InstructionHandle start, InstructionHandle end) {
+ if (index < 0 || index > Constants.MAX_SHORT) {
+ throw new ClassGenException("Invalid index index: " + index);
+ }
+
+ this.name = name;
+ this.type = type;
+ this.index = index;
+ setStart(start);
+ setEnd(end);
+ }
+
+ /**
+ * Get LocalVariable object.
+ *
+ * This relies on that the instruction list has already been dumped to byte code or or that the `setPositions' methods has been
+ * called for the instruction list.
+ *
+ * Note that for local variables whose scope end at the last instruction of the method's code, the JVM specification is
+ * ambiguous: both a start_pc+length ending at the last instruction and start_pc+length ending at first index beyond the end of
+ * the code are valid.
+ *
+ * @param il instruction list (byte code) which this variable belongs to
+ * @param cp constant pool
+ */
+ public LocalVariable getLocalVariable(ConstantPool cp) {
+ int start_pc = start.getPosition();
+ int length = end.getPosition() - start_pc;
+
+ if (length > 0) {
+ length += end.getInstruction().getLength();
+ }
+
+ int name_index = cp.addUtf8(name);
+ int signature_index = cp.addUtf8(type.getSignature());
+
+ return new LocalVariable(start_pc, length, name_index, signature_index, index, cp);
+ }
+
+ public void setIndex(int index) {
+ this.index = index;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setType(Type type) {
+ this.type = type;
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public InstructionHandle getStart() {
+ return start;
+ }
+
+ public InstructionHandle getEnd() {
+ return end;
+ }
+
+ public void setStart(InstructionHandle start) {
+ InstructionBranch.notifyTarget(this.start, start, this);
+ this.start = start;
+ }
+
+ public void setEnd(InstructionHandle end) {
+ InstructionBranch.notifyTarget(this.end, end, this);
+ this.end = end;
+ }
+
+ /**
+ * @param old_ih old target, either start or end
+ * @param new_ih new target
+ */
+ public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) {
+ boolean targeted = false;
+
+ if (start == old_ih) {
+ targeted = true;
+ setStart(new_ih);
+ }
+
+ if (end == old_ih) {
+ targeted = true;
+ setEnd(new_ih);
+ }
+
+ if (!targeted) {
+ throw new ClassGenException("Not targeting " + old_ih + ", but {" + start + ", " + end + "}");
+ }
+ }
+
+ /**
+ * @return true, if ih is target of this variable
+ */
+ public boolean containsTarget(InstructionHandle ih) {
+ return start == ih || end == ih;
+ }
+
+ /**
+ * We consider to local variables to be equal, if the use the same index and are valid in the same range.
+ */
+ public boolean equals(Object o) {
+ if (!(o instanceof LocalVariableGen)) {
+ return false;
+ }
+
+ LocalVariableGen l = (LocalVariableGen) o;
+ return l.index == index && l.start == start && l.end == end;
+ }
+
+ public String toString() {
+ return "LocalVariableGen(" + name + ", " + type + ", " + start + ", " + end + ")";
+ }
+
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException e) {
+ System.err.println(e);
+ return null;
+ }
+ }
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/LocalVariableTag.java bcel/src/java/org/aspectj/apache/bcel/generic/LocalVariableTag.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/LocalVariableTag.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/LocalVariableTag.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,94 @@
+/* *******************************************************************
+ * Copyright (c) 2002 Contributors
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * PARC initial implementation
+ * Andy Clement pushed down into bcel module
+ * ******************************************************************/
+
+package org.apache.bcel.generic;
+
+public final class LocalVariableTag extends Tag {
+ private Type type; // not always known, in which case signature has to be used
+ private final String signature;
+ private String name;
+ private int slot;
+ private final int startPos;
+ boolean remapped = false;
+
+ // AMC - pr101047, two local vars with the same name can share the same slot, but must in that case
+ // have different start positions.
+ public LocalVariableTag(String sig, String name, int slot, int startPosition) {
+ this.signature = sig;
+ this.name = name;
+ this.slot = slot;
+ this.startPos = startPosition;
+ }
+
+ public LocalVariableTag(Type t, String sig, String name, int slot, int startPosition) {
+ this.type = t;
+ this.signature = sig;
+ this.name = name;
+ this.slot = slot;
+ this.startPos = startPosition;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getSlot() {
+ return slot;
+ }
+
+ public String getType() {
+ return signature;
+ }
+
+ public Type getRealType() {
+ return type;
+ }
+
+ public void updateSlot(int newSlot) {
+ this.slot = newSlot;
+ this.remapped = true;
+ }
+
+ public boolean isRemapped() {
+ return this.remapped;
+ }
+
+ public String toString() {
+ return "local " + slot + ": " + signature + " " + name;
+ }
+
+ public boolean equals(Object other) {
+ if (!(other instanceof LocalVariableTag))
+ return false;
+ LocalVariableTag o = (LocalVariableTag) other;
+ return o.slot == slot && o.startPos == startPos && o.signature.equals(signature) && o.name.equals(name);
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ private int hashCode = 0;
+
+ public int hashCode() {
+ if (hashCode == 0) {
+ int ret = 17;
+ ret = 37 * ret + signature.hashCode();
+ ret = 37 * ret + name.hashCode();
+ ret = 37 * ret + slot;
+ ret = 37 * ret + startPos;
+ hashCode = ret;
+ }
+ return hashCode;
+ }
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/MULTIANEWARRAY.java bcel/src/java/org/aspectj/apache/bcel/generic/MULTIANEWARRAY.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/MULTIANEWARRAY.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/MULTIANEWARRAY.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,161 @@
+package org.apache.bcel.generic;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+import java.io.*;
+import org.apache.bcel.classfile.ConstantPool;
+import org.apache.bcel.Constants;
+import org.apache.bcel.ExceptionConstants;
+
+/**
+ * MULTIANEWARRAY - Create new mutidimensional array of references
+ * Stack: ..., count1, [count2, ...] -> ..., arrayref
+ *
+ * @version $Id: MULTIANEWARRAY.java,v 1.3 2008/05/28 23:52:59 aclement Exp $
+ * @author M. Dahm
+ */
+public class MULTIANEWARRAY extends InstructionCP {
+ private short dimensions;
+
+ public MULTIANEWARRAY(int index, short dimensions) {
+ super(Constants.MULTIANEWARRAY, index);
+ this.dimensions = dimensions;
+ }
+
+ /**
+ * Dump instruction as byte code to stream out.
+ * @param out Output stream
+ */
+ public void dump(DataOutputStream out) throws IOException {
+ out.writeByte(opcode);
+ out.writeShort(index);
+ out.writeByte(dimensions);
+ }
+
+ /**
+ * Read needed data (i.e., no. dimension) from file.
+ */
+// protected void initFromFile(ByteSequence bytes, boolean wide)
+// throws IOException
+// {
+// super.initFromFile(bytes, wide);
+// dimensions = bytes.readByte();
+//// length = 4;
+// }
+
+ /**
+ * @return number of dimensions to be created
+ */
+ public final short getDimensions() { return dimensions; }
+
+ /**
+ * @return mnemonic for instruction
+ */
+ public String toString(boolean verbose) {
+ return super.toString(verbose) + " " + index + " " + dimensions;
+ }
+
+ /**
+ * @return mnemonic for instruction with symbolic references resolved
+ */
+ public String toString(ConstantPool cp) {
+ return super.toString(cp) + " " + dimensions;
+ }
+
+ /**
+ * Also works for instructions whose stack effect depends on the
+ * constant pool entry they reference.
+ * @return Number of words consumed from stack by this instruction
+ */
+ public int consumeStack(ConstantPool cpg) { return dimensions; }
+
+ public Class[] getExceptions() {
+ Class[] cs = new Class[2 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length];
+
+ System.arraycopy(ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0,
+ cs, 0, ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length);
+
+ cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length+1] = ExceptionConstants.NEGATIVE_ARRAY_SIZE_EXCEPTION;
+ cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length] = ExceptionConstants.ILLEGAL_ACCESS_ERROR;
+
+ return cs;
+ }
+
+ public ObjectType getLoadClassType(ConstantPool cpg) {
+ Type t = getType(cpg);
+
+ if (t instanceof ArrayType){
+ t = ((ArrayType) t).getBasicType();
+ }
+
+ return (t instanceof ObjectType)? (ObjectType) t : null;
+ }
+
+// /**
+// * Call corresponding visitor method(s). The order is:
+// * Call visitor methods of implemented interfaces first, then
+// * call methods according to the class hierarchy in descending order,
+// * i.e., the most specific visitXXX() call comes last.
+// *
+// * @param v Visitor object
+// */
+// public void accept(Visitor v) {
+// v.visitLoadClass(this);
+// v.visitAllocationInstruction(this);
+// v.visitExceptionThrower(this);
+// v.visitTypedInstruction(this);
+// v.visitCPInstruction(this);
+// v.visitMULTIANEWARRAY(this);
+// }
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/MethodGen.java bcel/src/java/org/aspectj/apache/bcel/generic/MethodGen.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/MethodGen.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/MethodGen.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,1131 @@
+package org.apache.bcel.generic;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Stack;
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.classfile.Attribute;
+import org.apache.bcel.classfile.Code;
+import org.apache.bcel.classfile.CodeException;
+import org.apache.bcel.classfile.ConstantPool;
+import org.apache.bcel.classfile.ExceptionTable;
+import org.apache.bcel.classfile.LineNumber;
+import org.apache.bcel.classfile.LineNumberTable;
+import org.apache.bcel.classfile.LocalVariable;
+import org.apache.bcel.classfile.LocalVariableTable;
+import org.apache.bcel.classfile.Method;
+import org.apache.bcel.classfile.Utility;
+import org.apache.bcel.classfile.annotation.AnnotationGen;
+import org.apache.bcel.classfile.annotation.RuntimeAnnotations;
+import org.apache.bcel.classfile.annotation.RuntimeParameterAnnotations;
+
+/**
+ * Template class for building up a method. This is done by defining exception handlers, adding thrown exceptions, local variables
+ * and attributes, whereas the 'LocalVariableTable' and 'LineNumberTable' attributes will be set automatically for the code. Use
+ * stripAttributes() if you don't like this.
+ *
+ * While generating code it may be necessary to insert NOP operations. You can use the `removeNOPs' method to get rid off them. The
+ * resulting method object can be obtained via the `getMethod()' method.
+ *
+ * @version $Id: MethodGen.java,v 1.11 2009/05/28 00:12:52 aclement Exp $
+ * @author M. Dahm
+ * @author Patrick C. Beard [setMaxStack()]
+ * @see InstructionList
+ * @see Method
+ */
+public class MethodGen extends FieldGenOrMethodGen {
+ private String classname;
+ private Type[] parameterTypes;
+ private String[] parameterNames;
+ private int maxLocals;
+ private int maxStack;
+ private InstructionList il;
+
+ // Indicates whether to produce code attributes for LineNumberTable and LocalVariableTable, like javac -O
+ private boolean stripAttributes;
+
+ private int highestLineNumber = 0;
+
+ private ArrayList localVariablesList = new ArrayList();
+ private ArrayList lineNumbersList = new ArrayList();
+ private ArrayList exceptionsList = new ArrayList();
+ private ArrayList throws_vec = new ArrayList();
+ private ArrayList codeAttributesList = new ArrayList();
+ private List[] param_annotations; // Array of lists containing AnnotationGen objects
+ private boolean hasParameterAnnotations = false;
+ private boolean haveUnpackedParameterAnnotations = false;
+
+ /**
+ * Declare method. If the method is non-static the constructor automatically declares a local variable `$this' in slot 0. The
+ * actual code is contained in the `il' parameter, which may further manipulated by the user. But he must take care not to
+ * remove any instruction (handles) that are still referenced from this object.
+ *
+ * For example one may not add a local variable and later remove the instructions it refers to without causing havoc. It is safe
+ * however if you remove that local variable, too.
+ *
+ * @param access_flags access qualifiers
+ * @param return_type method type
+ * @param arg_types argument types
+ * @param arg_names argument names (if this is null, default names will be provided for them)
+ * @param method_name name of method
+ * @param class_name class name containing this method (may be null, if you don't care)
+ * @param il instruction list associated with this method, may be null only for abstract or native methods
+ * @param cp constant pool
+ */
+ public MethodGen(int access_flags, Type return_type, Type[] arg_types, String[] arg_names, String method_name,
+ String class_name, InstructionList il, ConstantPool cp) {
+
+ this.modifiers = access_flags;
+ this.type = return_type;
+ this.parameterTypes = arg_types;
+ this.parameterNames = arg_names;
+ this.name = method_name;
+ this.classname = class_name;
+ this.il = il;
+ this.cp = cp;
+
+ // OPTIMIZE this code messes with the local variables - do we need it?
+ // boolean abstract_ = isAbstract() || isNative();
+ // InstructionHandle start = null;
+ // InstructionHandle end = null;
+ //
+ // if (!abstract_) {
+ // start = il.getStart();
+ // end = il.getEnd();
+ //
+ // /* Add local variables, namely the implicit `this' and the arguments
+ // */
+ // // if(!isStatic() && (class_name != null)) { // Instance method -> `this' is local var 0
+ // // addLocalVariable("this", new ObjectType(class_name), start, end);
+ // // }
+ // }
+
+ // if(arg_types != null) {
+ // int size = arg_types.length;
+ //
+ // for(int i=0; i < size; i++) {
+ // if(Type.VOID == arg_types[i]) {
+ // throw new ClassGenException("'void' is an illegal argument type for a method");
+ // }
+ // }
+ //
+ // if(arg_names != null) { // Names for variables provided?
+ // if(size != arg_names.length)
+ // throw new ClassGenException("Mismatch in argument array lengths: " +
+ // size + " vs. " + arg_names.length);
+ // } else { // Give them dummy names
+ // // arg_names = new String[size];
+ // //
+ // // for(int i=0; i < size; i++)
+ // // arg_names[i] = "arg" + i;
+ // //
+ // // setArgumentNames(arg_names);
+ // }
+
+ // if(!abstract_) {
+ // for(int i=0; i < size; i++) {
+ // // addLocalVariable(arg_names[i], arg_types[i], start, end);
+ // }
+ // }
+ // }
+ }
+
+ public int getHighestlinenumber() {
+ return highestLineNumber;
+ }
+
+ /**
+ * Instantiate from existing method.
+ *
+ * @param m method
+ * @param class_name class name containing this method
+ * @param cp constant pool
+ */
+
+ public MethodGen(Method m, String class_name, ConstantPool cp) {
+ this(m, class_name, cp, false);
+ }
+
+ // OPTIMIZE should always use tags and never anything else!
+ public MethodGen(Method m, String class_name, ConstantPool cp, boolean useTags) {
+ this(m.getModifiers(),
+ // OPTIMIZE implementation of getReturnType() and getArgumentTypes() on Method seems weak
+ m.getReturnType(), m.getArgumentTypes(), null /* may be overridden anyway */, m.getName(), class_name, ((m
+ .getModifiers() & (Constants.ACC_ABSTRACT | Constants.ACC_NATIVE)) == 0) ? new InstructionList(m.getCode()
+ .getCode()) : null, cp);
+
+ Attribute[] attributes = m.getAttributes();
+ for (int i = 0; i < attributes.length; i++) {
+ Attribute a = attributes[i];
+
+ if (a instanceof Code) {
+ Code c = (Code) a;
+ setMaxStack(c.getMaxStack());
+ setMaxLocals(c.getMaxLocals());
+
+ CodeException[] ces = c.getExceptionTable();
+
+ InstructionHandle[] arrayOfInstructions = il.getInstructionsAsArray();
+
+ // process the exception table
+ // -
+ if (ces != null) {
+ for (int j = 0; j < ces.length; j++) {
+ CodeException ce = ces[j];
+ int type = ce.getCatchType();
+ ObjectType c_type = null;
+
+ if (type > 0) {
+ String cen = m.getConstantPool().getConstantString_CONSTANTClass(type);
+ c_type = new ObjectType(cen);
+ }
+
+ int end_pc = ce.getEndPC();
+ int length = m.getCode().getCode().length;
+
+ InstructionHandle end;
+
+ if (length == end_pc) { // May happen, because end_pc is exclusive
+ end = il.getEnd();
+ } else {
+ end = il.findHandle(end_pc, arrayOfInstructions);// il.findHandle(end_pc);
+ end = end.getPrev(); // Make it inclusive
+ }
+
+ addExceptionHandler(il.findHandle(ce.getStartPC(), arrayOfInstructions), end, il.findHandle(ce
+ .getHandlerPC(), arrayOfInstructions), c_type);
+ }
+ }
+
+ Attribute[] codeAttrs = c.getAttributes();
+ for (int j = 0; j < codeAttrs.length; j++) {
+ a = codeAttrs[j];
+
+ if (a instanceof LineNumberTable) {
+ LineNumber[] ln = ((LineNumberTable) a).getLineNumberTable();
+ if (useTags) {
+ // abracadabra, lets create tags rather than linenumbergens.
+ for (int k = 0; k < ln.length; k++) {
+ LineNumber l = ln[k];
+ int lnum = l.getLineNumber();
+ if (lnum > highestLineNumber)
+ highestLineNumber = lnum;
+ LineNumberTag lt = new LineNumberTag(lnum);
+ il.findHandle(l.getStartPC(), arrayOfInstructions, true).addTargeter(lt);
+ }
+ } else {
+ for (int k = 0; k < ln.length; k++) {
+ LineNumber l = ln[k];
+ addLineNumber(il.findHandle(l.getStartPC(), arrayOfInstructions, true), l.getLineNumber());
+ }
+ }
+ } else if (a instanceof LocalVariableTable) {
+
+ // Lets have a go at creating Tags directly
+ if (useTags) {
+ LocalVariable[] lv = ((LocalVariableTable) a).getLocalVariableTable();
+
+ for (int k = 0; k < lv.length; k++) {
+ LocalVariable l = lv[k];
+ Type t = Type.getType(l.getSignature());
+ LocalVariableTag lvt = new LocalVariableTag(t, l.getSignature(), l.getName(), l.getIndex(), l
+ .getStartPC());
+ InstructionHandle start = il.findHandle(l.getStartPC(), arrayOfInstructions, true);
+ byte b = t.getType();
+ if (b != Constants.T_ADDRESS) {
+ int increment = t.getSize();
+ if (l.getIndex() + increment > maxLocals)
+ maxLocals = l.getIndex() + increment;
+ }
+ int end = l.getStartPC() + l.getLength();
+ do {
+ start.addTargeter(lvt);
+ start = start.getNext();
+ } while (start != null && start.getPosition() < end);
+ }
+ } else {
+
+ LocalVariable[] lv = ((LocalVariableTable) a).getLocalVariableTable();
+
+ removeLocalVariables();
+
+ for (int k = 0; k < lv.length; k++) {
+ LocalVariable l = lv[k];
+ InstructionHandle start = il.findHandle(l.getStartPC(), arrayOfInstructions);
+ InstructionHandle end = il.findHandle(l.getStartPC() + l.getLength(), arrayOfInstructions);
+ // AMC, this actually gives us the first instruction AFTER the range,
+ // so move back one... (findHandle can't cope with mid-instruction indices)
+ if (end != null)
+ end = end.getPrev();
+ // Repair malformed handles
+ if (null == start)
+ start = il.getStart();
+ if (null == end)
+ end = il.getEnd();
+
+ addLocalVariable(l.getName(), Type.getType(l.getSignature()), l.getIndex(), start, end);
+ }
+ }
+ } else
+ addCodeAttribute(a);
+ }
+ } else if (a instanceof ExceptionTable) {
+ String[] names = ((ExceptionTable) a).getExceptionNames();
+ for (int j = 0; j < names.length; j++)
+ addException(names[j]);
+ } else if (a instanceof RuntimeAnnotations) {
+ RuntimeAnnotations runtimeAnnotations = (RuntimeAnnotations) a;
+ List l = runtimeAnnotations.getAnnotations();
+ for (Iterator it = l.iterator(); it.hasNext();) {
+ AnnotationGen element = (AnnotationGen) it.next();
+ addAnnotation(new AnnotationGen(element, cp, false));
+ }
+ } else {
+ addAttribute(a);
+ }
+ }
+ }
+
+ /**
+ * Adds a local variable to this method.
+ *
+ * @param name variable name
+ * @param type variable type
+ * @param slot the index of the local variable, if type is long or double, the next available index is slot+2
+ * @param start from where the variable is valid
+ * @param end until where the variable is valid
+ * @return new local variable object
+ * @see LocalVariable
+ */
+ public LocalVariableGen addLocalVariable(String name, Type type, int slot, InstructionHandle start, InstructionHandle end) {
+ // byte t = type.getType();
+ // if (t != Constants.T_ADDRESS) {
+ int size = type.getSize();
+ if (slot + size > maxLocals)
+ maxLocals = slot + size;
+ LocalVariableGen l = new LocalVariableGen(slot, name, type, start, end);
+ int i = localVariablesList.indexOf(l);
+ if (i >= 0)
+ localVariablesList.set(i, l); // Overwrite if necessary
+ else
+ localVariablesList.add(l);
+ return l;
+ // } else {
+ // throw new IllegalArgumentException("Can not use " + type +
+ // " as type for local variable");
+ //
+ // }
+ }
+
+ /**
+ * Adds a local variable to this method and assigns an index automatically.
+ *
+ * @param name variable name
+ * @param type variable type
+ * @param start from where the variable is valid, if this is null, it is valid from the start
+ * @param end until where the variable is valid, if this is null, it is valid to the end
+ * @return new local variable object
+ * @see LocalVariable
+ */
+ public LocalVariableGen addLocalVariable(String name, Type type, InstructionHandle start, InstructionHandle end) {
+ return addLocalVariable(name, type, maxLocals, start, end);
+ }
+
+ /**
+ * Remove a local variable, its slot will not be reused, if you do not use addLocalVariable with an explicit index argument.
+ */
+ public void removeLocalVariable(LocalVariableGen l) {
+ localVariablesList.remove(l);
+ }
+
+ /**
+ * Remove all local variables.
+ */
+ public void removeLocalVariables() {
+ localVariablesList.clear();
+ }
+
+ /**
+ * Sort local variables by index
+ */
+ private static final void sort(LocalVariableGen[] vars, int l, int r) {
+ int i = l, j = r;
+ int m = vars[(l + r) / 2].getIndex();
+ LocalVariableGen h;
+
+ do {
+ while (vars[i].getIndex() < m)
+ i++;
+ while (m < vars[j].getIndex())
+ j--;
+
+ if (i <= j) {
+ h = vars[i];
+ vars[i] = vars[j];
+ vars[j] = h; // Swap elements
+ i++;
+ j--;
+ }
+ } while (i <= j);
+
+ if (l < j)
+ sort(vars, l, j);
+ if (i < r)
+ sort(vars, i, r);
+ }
+
+ /*
+ * If the range of the variable has not been set yet, it will be set to be valid from the start to the end of the instruction
+ * list.
+ *
+ * @return array of declared local variables sorted by index
+ */
+ public LocalVariableGen[] getLocalVariables() {
+ int size = localVariablesList.size();
+ LocalVariableGen[] lg = new LocalVariableGen[size];
+ localVariablesList.toArray(lg);
+
+ for (int i = 0; i < size; i++) {
+ if (lg[i].getStart() == null)
+ lg[i].setStart(il.getStart());
+
+ if (lg[i].getEnd() == null)
+ lg[i].setEnd(il.getEnd());
+ }
+
+ if (size > 1)
+ sort(lg, 0, size - 1);
+
+ return lg;
+ }
+
+ /**
+ * @return `LocalVariableTable' attribute of all the local variables of this method.
+ */
+ public LocalVariableTable getLocalVariableTable(ConstantPool cp) {
+ LocalVariableGen[] lg = getLocalVariables();
+ int size = lg.length;
+ LocalVariable[] lv = new LocalVariable[size];
+
+ for (int i = 0; i < size; i++)
+ lv[i] = lg[i].getLocalVariable(cp);
+
+ return new LocalVariableTable(cp.addUtf8("LocalVariableTable"), 2 + lv.length * 10, lv, cp);
+ }
+
+ /**
+ * Give an instruction a line number corresponding to the source code line.
+ *
+ * @param ih instruction to tag
+ * @return new line number object
+ * @see LineNumber
+ */
+ public LineNumberGen addLineNumber(InstructionHandle ih, int src_line) {
+ LineNumberGen l = new LineNumberGen(ih, src_line);
+ lineNumbersList.add(l);
+ return l;
+ }
+
+ /**
+ * Remove a line number.
+ */
+ public void removeLineNumber(LineNumberGen l) {
+ lineNumbersList.remove(l);
+ }
+
+ /**
+ * Remove all line numbers.
+ */
+ public void removeLineNumbers() {
+ lineNumbersList.clear();
+ }
+
+ /*
+ * @return array of line numbers
+ */
+ public LineNumberGen[] getLineNumbers() {
+ LineNumberGen[] lg = new LineNumberGen[lineNumbersList.size()];
+ lineNumbersList.toArray(lg);
+ return lg;
+ }
+
+ /**
+ * @return 'LineNumberTable' attribute for all the local variables of this method.
+ */
+ public LineNumberTable getLineNumberTable(ConstantPool cp) {
+ int size = lineNumbersList.size();
+ LineNumber[] ln = new LineNumber[size];
+
+ for (int i = 0; i < size; i++) {
+ ln[i] = ((LineNumberGen) lineNumbersList.get(i)).getLineNumber();
+ }
+
+ return new LineNumberTable(cp.addUtf8("LineNumberTable"), 2 + ln.length * 4, ln, cp);
+ }
+
+ /**
+ * Add an exception handler, i.e., specify region where a handler is active and an instruction where the actual handling is
+ * done.
+ *
+ * @param start_pc Start of region (inclusive)
+ * @param end_pc End of region (inclusive)
+ * @param handler_pc Where handling is done
+ * @param catch_type class type of handled exception or null if any exception is handled
+ * @return new exception handler object
+ */
+ public CodeExceptionGen addExceptionHandler(InstructionHandle start_pc, InstructionHandle end_pc, InstructionHandle handler_pc,
+ ObjectType catch_type) {
+ if ((start_pc == null) || (end_pc == null) || (handler_pc == null))
+ throw new ClassGenException("Exception handler target is null instruction");
+
+ CodeExceptionGen c = new CodeExceptionGen(start_pc, end_pc, handler_pc, catch_type);
+ exceptionsList.add(c);
+ return c;
+ }
+
+ /**
+ * Remove an exception handler.
+ */
+ public void removeExceptionHandler(CodeExceptionGen c) {
+ exceptionsList.remove(c);
+ }
+
+ /**
+ * Remove all line numbers.
+ */
+ public void removeExceptionHandlers() {
+ exceptionsList.clear();
+ }
+
+ /*
+ * @return array of declared exception handlers
+ */
+ public CodeExceptionGen[] getExceptionHandlers() {
+ CodeExceptionGen[] cg = new CodeExceptionGen[exceptionsList.size()];
+ exceptionsList.toArray(cg);
+ return cg;
+ }
+
+ /**
+ * @return code exceptions for `Code' attribute
+ */
+ private CodeException[] getCodeExceptions() {
+ int size = exceptionsList.size();
+ CodeException[] c_exc = new CodeException[size];
+
+ try {
+ for (int i = 0; i < size; i++) {
+ CodeExceptionGen c = (CodeExceptionGen) exceptionsList.get(i);
+ c_exc[i] = c.getCodeException(cp);
+ }
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
+
+ return c_exc;
+ }
+
+ /**
+ * Add an exception possibly thrown by this method.
+ *
+ * @param class_name (fully qualified) name of exception
+ */
+ public void addException(String class_name) {
+ throws_vec.add(class_name);
+ }
+
+ /**
+ * Remove an exception.
+ */
+ public void removeException(String c) {
+ throws_vec.remove(c);
+ }
+
+ /**
+ * Remove all exceptions.
+ */
+ public void removeExceptions() {
+ throws_vec.clear();
+ }
+
+ /*
+ * @return array of thrown exceptions
+ */
+ public String[] getExceptions() {
+ String[] e = new String[throws_vec.size()];
+ throws_vec.toArray(e);
+ return e;
+ }
+
+ /**
+ * @return `Exceptions' attribute of all the exceptions thrown by this method.
+ */
+ private ExceptionTable getExceptionTable(ConstantPool cp) {
+ int size = throws_vec.size();
+ int[] ex = new int[size];
+
+ try {
+ for (int i = 0; i < size; i++)
+ ex[i] = cp.addClass((String) throws_vec.get(i));
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
+
+ return new ExceptionTable(cp.addUtf8("Exceptions"), 2 + 2 * size, ex, cp);
+ }
+
+ /**
+ * Add an attribute to the code. Currently, the JVM knows about the LineNumberTable, LocalVariableTable and StackMap attributes,
+ * where the former two will be generated automatically and the latter is used for the MIDP only. Other attributes will be
+ * ignored by the JVM but do no harm.
+ *
+ * @param a attribute to be added
+ */
+ public void addCodeAttribute(Attribute a) {
+ codeAttributesList.add(a);
+ }
+
+ public void addParameterAnnotationsAsAttribute(ConstantPool cp) {
+ if (!hasParameterAnnotations)
+ return;
+ Attribute[] attrs = Utility.getParameterAnnotationAttributes(cp, param_annotations);
+ if (attrs != null) {
+ for (int i = 0; i < attrs.length; i++) {
+ addAttribute(attrs[i]);
+ }
+ }
+ }
+
+ /**
+ * Remove a code attribute.
+ */
+ public void removeCodeAttribute(Attribute a) {
+ codeAttributesList.remove(a);
+ }
+
+ /**
+ * Remove all code attributes.
+ */
+ public void removeCodeAttributes() {
+ codeAttributesList.clear();
+ }
+
+ /**
+ * @return all attributes of this method.
+ */
+ public Attribute[] getCodeAttributes() {
+ Attribute[] attributes = new Attribute[codeAttributesList.size()];
+ codeAttributesList.toArray(attributes);
+ return attributes;
+ }
+
+ /**
+ * Get method object. Never forget to call setMaxStack() or setMaxStack(max), respectively, before calling this method (the same
+ * applies for max locals).
+ *
+ * @return method object
+ */
+ public Method getMethod() {
+ String signature = getSignature();
+ int name_index = cp.addUtf8(name);
+ int signature_index = cp.addUtf8(signature);
+
+ /*
+ * Also updates positions of instructions, i.e., their indices
+ */
+ byte[] byte_code = null;
+
+ if (il != null)
+ byte_code = il.getByteCode();
+
+ LineNumberTable lnt = null;
+ LocalVariableTable lvt = null;
+ // J5TODO: LocalVariableTypeTable support!
+
+ /*
+ * Create LocalVariableTable and LineNumberTable attributes (for debuggers, e.g.)
+ */
+ if ((localVariablesList.size() > 0) && !stripAttributes)
+ addCodeAttribute(lvt = getLocalVariableTable(cp));
+
+ if ((lineNumbersList.size() > 0) && !stripAttributes)
+ addCodeAttribute(lnt = getLineNumberTable(cp));
+
+ Attribute[] code_attrs = getCodeAttributes();
+
+ /*
+ * Each attribute causes 6 additional header bytes
+ */
+ int attrs_len = 0;
+ for (int i = 0; i < code_attrs.length; i++)
+ attrs_len += (code_attrs[i].getLength() + 6);
+
+ CodeException[] c_exc = getCodeExceptions();
+ int exc_len = c_exc.length * 8; // Every entry takes 8 bytes
+
+ Code code = null;
+
+ if ((il != null) && !isAbstract()) {
+ // Remove any stale code attribute
+ List attributes = getAttributes();
+ for (int i = 0; i < attributes.size(); i++) {
+ Attribute a = (Attribute) attributes.get(i);
+ if (a instanceof Code)
+ removeAttribute(a);
+ }
+
+ code = new Code(cp.addUtf8("Code"), 8 + byte_code.length + // prologue byte code
+ 2 + exc_len + // exceptions
+ 2 + attrs_len, // attributes
+ maxStack, maxLocals, byte_code, c_exc, code_attrs, cp);
+
+ addAttribute(code);
+ }
+
+ addAnnotationsAsAttribute(cp);
+ addParameterAnnotationsAsAttribute(cp);
+
+ ExceptionTable et = null;
+
+ if (throws_vec.size() > 0)
+ addAttribute(et = getExceptionTable(cp)); // Add `Exceptions' if there are "throws" clauses
+
+ Method m = new Method(modifiers, name_index, signature_index, getAttributesImmutable(), cp);
+
+ // Undo effects of adding attributes
+ // OPTIMIZE why redo this? is there a better way to clean up?
+ if (lvt != null)
+ removeCodeAttribute(lvt);
+ if (lnt != null)
+ removeCodeAttribute(lnt);
+ if (code != null)
+ removeAttribute(code);
+ if (et != null)
+ removeAttribute(et);
+ // J5TODO: Remove the annotation attributes that may have been added
+ return m;
+ }
+
+ /**
+ * Set maximum number of local variables.
+ */
+ public void setMaxLocals(int m) {
+ maxLocals = m;
+ }
+
+ public int getMaxLocals() {
+ return maxLocals;
+ }
+
+ /**
+ * Set maximum stack size for this method.
+ */
+ public void setMaxStack(int m) {
+ maxStack = m;
+ }
+
+ public int getMaxStack() {
+ return maxStack;
+ }
+
+ /**
+ * @return class that contains this method
+ */
+ public String getClassName() {
+ return classname;
+ }
+
+ public void setClassName(String class_name) {
+ this.classname = class_name;
+ }
+
+ public void setReturnType(Type return_type) {
+ setType(return_type);
+ }
+
+ public Type getReturnType() {
+ return getType();
+ }
+
+ public void setArgumentTypes(Type[] arg_types) {
+ this.parameterTypes = arg_types;
+ }
+
+ public Type[] getArgumentTypes() {
+ return this.parameterTypes;
+ }// OPTIMIZE dont need clone here? (Type[])arg_types.clone(); }
+
+ public void setArgumentType(int i, Type type) {
+ parameterTypes[i] = type;
+ }
+
+ public Type getArgumentType(int i) {
+ return parameterTypes[i];
+ }
+
+ public void setArgumentNames(String[] arg_names) {
+ this.parameterNames = arg_names;
+ }
+
+ public String[] getArgumentNames() {
+ if (parameterNames != null)
+ return (String[]) parameterNames.clone();
+ else
+ return new String[0];
+ }
+
+ public void setArgumentName(int i, String name) {
+ parameterNames[i] = name;
+ }
+
+ public String getArgumentName(int i) {
+ return parameterNames[i];
+ }
+
+ public InstructionList getInstructionList() {
+ return il;
+ }
+
+ public void setInstructionList(InstructionList il) {
+ this.il = il;
+ }
+
+ public String getSignature() {
+ return Type.getMethodSignature(type, parameterTypes);
+ }
+
+ /**
+ * Computes max. stack size by performing control flow analysis.
+ */
+ public void setMaxStack() {
+ if (il != null)
+ maxStack = getMaxStack(cp, il, getExceptionHandlers());
+ else
+ maxStack = 0;
+ }
+
+ /**
+ * Compute maximum number of local variables.
+ */
+ public void setMaxLocals() {
+ if (il != null) {
+ int max = isStatic() ? 0 : 1;
+
+ if (parameterTypes != null)
+ for (int i = 0; i < parameterTypes.length; i++)
+ max += parameterTypes[i].getSize();
+
+ for (InstructionHandle ih = il.getStart(); ih != null; ih = ih.getNext()) {
+ Instruction ins = ih.getInstruction();
+
+ if ((ins instanceof InstructionLV) || (ins instanceof RET)) {
+ int index = ins.getIndex() + ins.getType(cp).getSize();
+
+ if (index > max)
+ max = index;
+ }
+ }
+
+ maxLocals = max;
+ } else
+ maxLocals = 0;
+ }
+
+ public void stripAttributes(boolean flag) {
+ stripAttributes = flag;
+ }
+
+ static final class BranchTarget {
+ InstructionHandle target;
+ int stackDepth;
+
+ BranchTarget(InstructionHandle target, int stackDepth) {
+ this.target = target;
+ this.stackDepth = stackDepth;
+ }
+ }
+
+ static final class BranchStack {
+ Stack branchTargets = new Stack();
+ Hashtable visitedTargets = new Hashtable();
+
+ public void push(InstructionHandle target, int stackDepth) {
+ if (visited(target))
+ return;
+
+ branchTargets.push(visit(target, stackDepth));
+ }
+
+ public BranchTarget pop() {
+ if (!branchTargets.empty()) {
+ BranchTarget bt = (BranchTarget) branchTargets.pop();
+ return bt;
+ }
+
+ return null;
+ }
+
+ private final BranchTarget visit(InstructionHandle target, int stackDepth) {
+ BranchTarget bt = new BranchTarget(target, stackDepth);
+ visitedTargets.put(target, bt);
+
+ return bt;
+ }
+
+ private final boolean visited(InstructionHandle target) {
+ return (visitedTargets.get(target) != null);
+ }
+ }
+
+ /**
+ * Computes stack usage of an instruction list by performing control flow analysis.
+ *
+ * @return maximum stack depth used by method
+ */
+ public static int getMaxStack(ConstantPool cp, InstructionList il, CodeExceptionGen[] et) {
+ BranchStack branchTargets = new BranchStack();
+
+ int stackDepth = 0, maxStackDepth = 0;
+ /*
+ * Initially, populate the branch stack with the exception handlers, because these aren't (necessarily) branched to
+ * explicitly. in each case, the stack will have depth 1, containing the exception object.
+ */
+ for (int i = 0; i < et.length; i++) {
+ InstructionHandle handler_pc = et[i].getHandlerPC();
+ if (handler_pc != null) {
+ // it must be at least 1 since there is an exception handler
+ maxStackDepth = 1;
+ branchTargets.push(handler_pc, 1);
+ }
+ }
+
+ InstructionHandle ih = il.getStart();
+ while (ih != null) {
+ Instruction instruction = ih.getInstruction();
+ short opcode = instruction.opcode;
+ int prod = instruction.produceStack(cp);
+ int con = instruction.consumeStack(cp);
+ int delta = prod - con;
+
+ stackDepth += delta;
+ if (stackDepth > maxStackDepth)
+ maxStackDepth = stackDepth;
+
+ // choose the next instruction based on whether current is a branch.
+ if (instruction instanceof InstructionBranch) {
+ InstructionBranch branch = (InstructionBranch) instruction;
+ if (instruction instanceof InstructionSelect) {
+ // explore all of the select's targets. the default target is handled below.
+ InstructionSelect select = (InstructionSelect) branch;
+ InstructionHandle[] targets = select.getTargets();
+ for (int i = 0; i < targets.length; i++)
+ branchTargets.push(targets[i], stackDepth);
+ // nothing to fall through to.
+ ih = null;
+ } else if (!(branch.isIfInstruction())) {
+ // if an instruction that comes back to following PC,
+ // push next instruction, with stack depth reduced by 1.
+ if (opcode == Constants.JSR || opcode == Constants.JSR_W)
+ branchTargets.push(ih.getNext(), stackDepth - 1);
+ ih = null;
+ }
+ // for all branches, the target of the branch is pushed on the branch stack.
+ // conditional branches have a fall through case, selects don't, and
+ // jsr/jsr_w return to the next instruction.
+ branchTargets.push(branch.getTarget(), stackDepth);
+ } else {
+ // check for instructions that terminate the method.
+ if (opcode == Constants.ATHROW || opcode == Constants.RET
+ || (opcode >= Constants.IRETURN && opcode <= Constants.RETURN))
+ ih = null;
+ }
+ // normal case, go to the next instruction.
+ if (ih != null)
+ ih = ih.getNext();
+ // if we have no more instructions, see if there are any deferred branches to explore.
+ if (ih == null) {
+ BranchTarget bt = branchTargets.pop();
+ if (bt != null) {
+ ih = bt.target;
+ stackDepth = bt.stackDepth;
+ }
+ }
+ }
+ return maxStackDepth;
+ }
+
+ /**
+ * Return string representation close to declaration format, `public static void main(String[]) throws IOException', e.g.
+ *
+ * @return String representation of the method.
+ */
+ public final String toString() {
+ String access = Utility.accessToString(modifiers);
+ String signature = Type.getMethodSignature(type, parameterTypes);
+
+ signature = Utility.methodSignatureToString(signature, name, access, true, getLocalVariableTable(cp));
+
+ StringBuffer buf = new StringBuffer(signature);
+
+ if (throws_vec.size() > 0) {
+ for (Iterator e = throws_vec.iterator(); e.hasNext();)
+ buf.append("\n\t\tthrows " + e.next());
+ }
+
+ return buf.toString();
+ }
+
+ /**
+ * @return deep copy of this method
+ */
+ public MethodGen copy(String class_name, ConstantPool cp) {
+ Method m = ((MethodGen) clone()).getMethod();
+ MethodGen mg = new MethodGen(m, class_name, this.cp);
+
+ if (this.cp != cp) {
+ mg.setConstantPool(cp);
+ mg.getInstructionList().replaceConstantPool(this.cp, cp);
+ }
+
+ return mg;
+ }
+
+ // J5TODO: Should param_annotations be an array of arrays? Rather than an array of lists, this
+ // is more likely to suggest to the caller it is readonly (which a List does not).
+ /**
+ * Return a list of AnnotationGen objects representing parameter annotations
+ */
+ public List getAnnotationsOnParameter(int i) {
+ ensureExistingParameterAnnotationsUnpacked();
+ if (!hasParameterAnnotations || i > parameterTypes.length)
+ return null;
+ return param_annotations[i];
+ }
+
+ /**
+ * Goes through the attributes on the method and identifies any that are RuntimeParameterAnnotations, extracting their contents
+ * and storing them as parameter annotations. There are two kinds of parameter annotation - visible and invisible. Once they
+ * have been unpacked, these attributes are deleted. (The annotations will be rebuilt as attributes when someone builds a Method
+ * object out of this MethodGen object).
+ */
+ private void ensureExistingParameterAnnotationsUnpacked() {
+ if (haveUnpackedParameterAnnotations)
+ return;
+ // Find attributes that contain parameter annotation data
+ List attrs = getAttributes();
+ RuntimeParameterAnnotations paramAnnVisAttr = null;
+ RuntimeParameterAnnotations paramAnnInvisAttr = null;
+ List accumulatedAnnotations = new ArrayList();
+ for (int i = 0; i < attrs.size(); i++) {
+ Attribute attribute = (Attribute) attrs.get(i);
+ if (attribute instanceof RuntimeParameterAnnotations) {
+
+ // Initialize param_annotations
+ if (!hasParameterAnnotations) {
+ param_annotations = new List[parameterTypes.length];
+ for (int j = 0; j < parameterTypes.length; j++)
+ param_annotations[j] = new ArrayList();
+ }
+
+ hasParameterAnnotations = true;
+ RuntimeParameterAnnotations rpa = (RuntimeParameterAnnotations) attribute;
+ if (rpa.areVisible())
+ paramAnnVisAttr = rpa;
+ else
+ paramAnnInvisAttr = rpa;
+ for (int j = 0; j < parameterTypes.length; j++) {
+ // This returns Annotation[] ...
+ AnnotationGen[] immutableArray = rpa.getAnnotationsOnParameter(j);
+ // ... which needs transforming into an AnnotationGen[] ...
+ List mutable = makeMutableVersion(immutableArray);
+ // ... then add these to any we already know about
+ param_annotations[j].addAll(mutable);
+ }
+ }
+ }
+ if (paramAnnVisAttr != null)
+ removeAttribute(paramAnnVisAttr);
+ if (paramAnnInvisAttr != null)
+ removeAttribute(paramAnnInvisAttr);
+ haveUnpackedParameterAnnotations = true;
+ }
+
+ private List /* AnnotationGen */makeMutableVersion(AnnotationGen[] mutableArray) {
+ List result = new ArrayList();
+ for (int i = 0; i < mutableArray.length; i++) {
+ result.add(new AnnotationGen(mutableArray[i], getConstantPool(), false));
+ }
+ return result;
+ }
+
+ public void addParameterAnnotation(int parameterIndex, AnnotationGen annotation) {
+ ensureExistingParameterAnnotationsUnpacked();
+ if (!hasParameterAnnotations) {
+ param_annotations = new List[parameterTypes.length];
+ hasParameterAnnotations = true;
+ }
+ List existingAnnotations = param_annotations[parameterIndex];
+ if (existingAnnotations != null) {
+ existingAnnotations.add(annotation);
+ } else {
+ List l = new ArrayList();
+ l.add(annotation);
+ param_annotations[parameterIndex] = l;
+ }
+ }
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/ObjectType.java bcel/src/java/org/aspectj/apache/bcel/generic/ObjectType.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/ObjectType.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/ObjectType.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,143 @@
+package org.apache.bcel.generic;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+import org.apache.bcel.Constants;
+import org.apache.bcel.Repository;
+import org.apache.bcel.classfile.JavaClass;
+
+/**
+ * Denotes reference such as java.lang.String.
+ *
+ * @version $Id: ObjectType.java,v 1.5 2008/06/23 04:01:28 aclement Exp $
+ * @author M. Dahm
+ */
+public class ObjectType extends ReferenceType {
+ private String class_name; // Class name of type
+
+ /**
+ * @param class_name fully qualified class name, e.g. java.lang.String
+ */
+ public ObjectType(String class_name) {
+ super(Constants.T_REFERENCE, toSignature(class_name));//"L" + class_name.replace('.', '/') + ";");
+ this.class_name = class_name;//.replace('/', '.');
+ }
+
+ private static String toSignature(String classname) {
+ StringBuffer sig = new StringBuffer();
+ sig.append("L").append(classname.replace('.','/'));
+ sig.append(";");
+ return sig.toString();
+ }
+
+ /** @return name of referenced class
+ */
+ public String getClassName() { return class_name; }
+
+ /** @return a hash code value for the object.
+ */
+ public int hashCode() { return class_name.hashCode(); }
+
+ /** @return true if both type objects refer to the same class.
+ */
+ public boolean equals(Object type) {
+ return (type instanceof ObjectType)?
+ ((ObjectType)type).class_name.equals(class_name) : false;
+ }
+
+ /**
+ * If "this" doesn't reference a class, it references an interface
+ * or a non-existant entity.
+ */
+ public boolean referencesClass(){
+ JavaClass jc = Repository.lookupClass(class_name);
+ if (jc == null)
+ return false;
+ else
+ return jc.isClass();
+ }
+
+ /**
+ * If "this" doesn't reference an interface, it references a class
+ * or a non-existant entity.
+ */
+ public boolean referencesInterface(){
+ JavaClass jc = Repository.lookupClass(class_name);
+ if (jc == null)
+ return false;
+ else
+ return !jc.isClass();
+ }
+
+ public boolean subclassOf(ObjectType superclass){
+ if (this.referencesInterface() || superclass.referencesInterface())
+ return false;
+
+ return Repository.instanceOf(this.class_name, superclass.class_name);
+ }
+
+ /**
+ * Java Virtual Machine Specification edition 2, ? 5.4.4 Access Control
+ */
+ public boolean accessibleTo(ObjectType accessor) {
+ JavaClass jc = Repository.lookupClass(class_name);
+
+ if(jc.isPublic()) {
+ return true;
+ } else {
+ JavaClass acc = Repository.lookupClass(accessor.class_name);
+ return acc.getPackageName().equals(jc.getPackageName());
+ }
+ }
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/RET.java bcel/src/java/org/aspectj/apache/bcel/generic/RET.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/RET.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/RET.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,106 @@
+package org.apache.bcel.generic;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+import java.io.*;
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.classfile.ConstantPool;
+
+/**
+ * RET - Return from subroutine
+ *
+ * Stack: ..., -> ..., address
+ *
+ * @version $Id: RET.java,v 1.3 2008/05/28 23:53:00 aclement Exp $
+ * @author M. Dahm
+ */
+public class RET extends Instruction {
+ private boolean wide;
+ private int index; // index to local variable containg the return address
+
+
+ public RET(int index,boolean wide) {
+ super(Constants.RET);
+ this.index = index;
+ this.wide = wide;
+ //this.wide = index > org.apache.bcel.Constants.MAX_BYTE;
+ }
+
+ public void dump(DataOutputStream out) throws IOException {
+ if (wide) out.writeByte(org.apache.bcel.Constants.WIDE);
+ out.writeByte(opcode);
+ if(wide) out.writeShort(index);
+ else out.writeByte(index);
+ }
+
+ public int getLength() {
+ if (wide) return 4; else return 2;
+ }
+
+ public final int getIndex() { return index; }
+ public final void setIndex(int index) {
+ this.index = index;
+ this.wide = index > org.apache.bcel.Constants.MAX_BYTE;
+ }
+
+ public String toString(boolean verbose) {
+ return super.toString(verbose) + " " + index;
+ }
+
+ public Type getType(ConstantPool cp) {
+ return ReturnaddressType.NO_TARGET;
+ }
+
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/ReferenceType.java bcel/src/java/org/aspectj/apache/bcel/generic/ReferenceType.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/ReferenceType.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/ReferenceType.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,365 @@
+package org.apache.bcel.generic;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.Repository;
+import org.apache.bcel.classfile.JavaClass;
+
+/**
+ * Super class for object and array types.
+ *
+ * @version $Id: ReferenceType.java,v 1.5 2008/08/28 15:36:59 aclement Exp $
+ * @author M. Dahm
+ */
+public abstract class ReferenceType extends Type {
+
+ protected ReferenceType(byte t, String s) {
+ super(t, s);
+ }
+
+ ReferenceType() {
+ super(Constants.T_OBJECT, "");
+ }
+
+ /**
+ * Return true iff this type is castable to another type t as defined in the JVM specification. The case where this is Type.NULL
+ * is not defined (see the CHECKCAST definition in the JVM specification). However, because e.g. CHECKCAST doesn't throw a
+ * ClassCastException when casting a null reference to any Object, true is returned in this case.
+ */
+ public boolean isCastableTo(Type t) {
+ if (this.equals(Type.NULL)) {
+ return true; // If this is ever changed in isAssignmentCompatible()
+ }
+
+ return isAssignmentCompatibleWith(t);
+ /*
+ * Yes, it's true: It's the same definition. See vmspec2 AASTORE / CHECKCAST definitions.
+ */
+ }
+
+ /**
+ * Return true iff this is assignment compatible with another type t as defined in the JVM specification; see the AASTORE
+ * definition there.
+ */
+ public boolean isAssignmentCompatibleWith(Type t) {
+ if (!(t instanceof ReferenceType)) {
+ return false;
+ }
+
+ ReferenceType T = (ReferenceType) t;
+
+ if (this.equals(Type.NULL)) {
+ return true; // This is not explicitely stated, but clear. Isn't it?
+ }
+
+ /*
+ * If this is a class type then
+ */
+ if (this instanceof ObjectType && ((ObjectType) this).referencesClass()) {
+ /*
+ * If T is a class type, then this must be the same class as T, or this must be a subclass of T;
+ */
+ if (T instanceof ObjectType && ((ObjectType) T).referencesClass()) {
+ if (this.equals(T)) {
+ return true;
+ }
+
+ if (Repository.instanceOf(((ObjectType) this).getClassName(), ((ObjectType) T).getClassName())) {
+ return true;
+ }
+ }
+
+ /*
+ * If T is an interface type, this must implement interface T.
+ */
+ if (T instanceof ObjectType && ((ObjectType) T).referencesInterface()) {
+ if (Repository.implementationOf(((ObjectType) this).getClassName(), ((ObjectType) T).getClassName())) {
+ return true;
+ }
+ }
+ }
+
+ /*
+ * If this is an interface type, then:
+ */
+ if (this instanceof ObjectType && ((ObjectType) this).referencesInterface()) {
+ /*
+ * If T is a class type, then T must be Object (?2.4.7).
+ */
+ if (T instanceof ObjectType && ((ObjectType) T).referencesClass()) {
+ if (T.equals(Type.OBJECT)) {
+ return true;
+ }
+ }
+
+ /*
+ * If T is an interface type, then T must be the same interface as this or a superinterface of this (?2.13.2).
+ */
+ if (T instanceof ObjectType && ((ObjectType) T).referencesInterface()) {
+ if (this.equals(T)) {
+ return true;
+ }
+ if (Repository.implementationOf(((ObjectType) this).getClassName(), ((ObjectType) T).getClassName())) {
+ return true;
+ }
+ }
+ }
+
+ /*
+ * If this is an array type, namely, the type SC[], that is, an array of components of type SC, then:
+ */
+ if (this instanceof ArrayType) {
+ /*
+ * If T is a class type, then T must be Object (?2.4.7).
+ */
+ if (T instanceof ObjectType && ((ObjectType) T).referencesClass()) {
+ if (T.equals(Type.OBJECT)) {
+ return true;
+ }
+ }
+
+ /*
+ * If T is an array type TC[], that is, an array of components of type TC, then one of the following must be true:
+ */
+ if (T instanceof ArrayType) {
+ /*
+ * TC and SC are the same primitive type (?2.4.1).
+ */
+ Type sc = ((ArrayType) this).getElementType();
+ Type tc = ((ArrayType) this).getElementType();
+
+ if (sc instanceof BasicType && tc instanceof BasicType && sc.equals(tc)) {
+ return true;
+ }
+
+ /*
+ * TC and SC are reference types (?2.4.6), and type SC is assignable to TC by these runtime rules.
+ */
+ if (tc instanceof ReferenceType && sc instanceof ReferenceType
+ && ((ReferenceType) sc).isAssignmentCompatibleWith(tc)) {
+ return true;
+ }
+ }
+
+ /* If T is an interface type, T must be one of the interfaces implemented by arrays (?2.15). */
+ // TODO: Check if this is still valid or find a way to dynamically find out which
+ // interfaces arrays implement. However, as of the JVM specification edition 2, there
+ // are at least two different pages where assignment compatibility is defined and
+ // on one of them "interfaces implemented by arrays" is exchanged with "'Cloneable' or
+ // 'java.io.Serializable'"
+ if (T instanceof ObjectType && ((ObjectType) T).referencesInterface()) {
+ for (int ii = 0; ii < Constants.INTERFACES_IMPLEMENTED_BY_ARRAYS.length; ii++) {
+ if (T.equals(new ObjectType(Constants.INTERFACES_IMPLEMENTED_BY_ARRAYS[ii]))) {
+ return true;
+ }
+ }
+ }
+ }
+ return false; // default.
+ }
+
+ /**
+ * This commutative operation returns the first common superclass (narrowest ReferenceType referencing a class, not an
+ * interface). If one of the types is a superclass of the other, the former is returned. If "this" is Type.NULL, then t is
+ * returned. If t is Type.NULL, then "this" is returned. If "this" equals t ['this.equals(t)'] "this" is returned. If "this" or
+ * t is an ArrayType, then Type.OBJECT is returned; unless their dimensions match. Then an ArrayType of the same number of
+ * dimensions is returned, with its basic type being the first common super class of the basic types of "this" and t. If "this"
+ * or t is a ReferenceType referencing an interface, then Type.OBJECT is returned. If not all of the two classes' superclasses
+ * cannot be found, "null" is returned. See the JVM specification edition 2, "?4.9.2 The Bytecode Verifier".
+ */
+ public ReferenceType getFirstCommonSuperclass(ReferenceType t) {
+ if (this.equals(Type.NULL)) {
+ return t;
+ }
+ if (t.equals(Type.NULL)) {
+ return this;
+ }
+ if (this.equals(t)) {
+ return this;
+ /*
+ * TODO: Above sounds a little arbitrary. On the other hand, there is no object referenced by Type.NULL so we can also
+ * say all the objects referenced by Type.NULL were derived from java.lang.Object. However, the Java Language's
+ * "instanceof" operator proves us wrong: "null" is not referring to an instance of java.lang.Object :)
+ */
+ }
+
+ /* This code is from a bug report by Konstantin Shagin */
+
+ if (this instanceof ArrayType && t instanceof ArrayType) {
+ ArrayType arrType1 = (ArrayType) this;
+ ArrayType arrType2 = (ArrayType) t;
+ if (arrType1.getDimensions() == arrType2.getDimensions() && arrType1.getBasicType() instanceof ObjectType
+ && arrType2.getBasicType() instanceof ObjectType) {
+ return new ArrayType(((ObjectType) arrType1.getBasicType()).getFirstCommonSuperclass((ObjectType) arrType2
+ .getBasicType()), arrType1.getDimensions());
+
+ }
+ }
+
+ if (this instanceof ArrayType || t instanceof ArrayType) {
+ return Type.OBJECT;
+ // TODO: Is there a proof of OBJECT being the direct ancestor of every ArrayType?
+ }
+
+ if (this instanceof ObjectType && ((ObjectType) this).referencesInterface() || t instanceof ObjectType
+ && ((ObjectType) t).referencesInterface()) {
+ return Type.OBJECT;
+ // TODO: The above line is correct comparing to the vmspec2. But one could
+ // make class file verification a bit stronger here by using the notion of
+ // superinterfaces or even castability or assignment compatibility.
+ }
+
+ // this and t are ObjectTypes, see above.
+ ObjectType thiz = (ObjectType) this;
+ ObjectType other = (ObjectType) t;
+ JavaClass[] thiz_sups = Repository.getSuperClasses(thiz.getClassName());
+ JavaClass[] other_sups = Repository.getSuperClasses(other.getClassName());
+
+ if (thiz_sups == null || other_sups == null) {
+ return null;
+ }
+
+ // Waaahh...
+ JavaClass[] this_sups = new JavaClass[thiz_sups.length + 1];
+ JavaClass[] t_sups = new JavaClass[other_sups.length + 1];
+ System.arraycopy(thiz_sups, 0, this_sups, 1, thiz_sups.length);
+ System.arraycopy(other_sups, 0, t_sups, 1, other_sups.length);
+ this_sups[0] = Repository.lookupClass(thiz.getClassName());
+ t_sups[0] = Repository.lookupClass(other.getClassName());
+
+ for (int i = 0; i < t_sups.length; i++) {
+ for (int j = 0; j < this_sups.length; j++) {
+ if (this_sups[j].equals(t_sups[i])) {
+ return new ObjectType(this_sups[j].getClassName());
+ }
+ }
+ }
+
+ // Huh? Did you ask for Type.OBJECT's superclass??
+ return null;
+ }
+
+ // /**
+ // * This commutative operation returns the first common superclass (narrowest ReferenceType referencing a class, not an
+ // * interface). If one of the types is a superclass of the other, the former is returned. If "this" is Type.NULL, then t is
+ // * returned. If t is Type.NULL, then "this" is returned. If "this" equals t ['this.equals(t)'] "this" is returned. If "this"
+ // or
+ // * t is an ArrayType, then Type.OBJECT is returned. If "this" or t is a ReferenceType referencing an interface, then
+ // Type.OBJECT
+ // * is returned. If not all of the two classes' superclasses cannot be found, "null" is returned. See the JVM specification
+ // * edition 2, "?4.9.2 The Bytecode Verifier".
+ // *
+ // * @deprecated use getFirstCommonSuperclass(ReferenceType t) which has slightly changed semantics.
+ // */
+ // public ReferenceType firstCommonSuperclass(ReferenceType t) {
+ // if (this.equals(Type.NULL)) {
+ // return t;
+ // }
+ // if (t.equals(Type.NULL)) {
+ // return this;
+ // }
+ // if (this.equals(t)) {
+ // return this;
+ // /*
+ // * TODO: Above sounds a little arbitrary. On the other hand, there is no object referenced by Type.NULL so we can also
+ // * say all the objects referenced by Type.NULL were derived from java.lang.Object. However, the Java Language's
+ // * "instanceof" operator proves us wrong: "null" is not referring to an instance of java.lang.Object :)
+ // */
+ // }
+ //
+ // if (this instanceof ArrayType || t instanceof ArrayType) {
+ // return Type.OBJECT;
+ // // TODO: Is there a proof of OBJECT being the direct ancestor of every ArrayType?
+ // }
+ //
+ // if (this instanceof ObjectType && ((ObjectType) this).referencesInterface() || t instanceof ObjectType
+ // && ((ObjectType) t).referencesInterface()) {
+ // return Type.OBJECT;
+ // // TODO: The above line is correct comparing to the vmspec2. But one could
+ // // make class file verification a bit stronger here by using the notion of
+ // // superinterfaces or even castability or assignment compatibility.
+ // }
+ //
+ // // this and t are ObjectTypes, see above.
+ // ObjectType thiz = (ObjectType) this;
+ // ObjectType other = (ObjectType) t;
+ // JavaClass[] thiz_sups = Repository.getSuperClasses(thiz.getClassName());
+ // JavaClass[] other_sups = Repository.getSuperClasses(other.getClassName());
+ //
+ // if (thiz_sups == null || other_sups == null) {
+ // return null;
+ // }
+ //
+ // // Waaahh...
+ // JavaClass[] this_sups = new JavaClass[thiz_sups.length + 1];
+ // JavaClass[] t_sups = new JavaClass[other_sups.length + 1];
+ // System.arraycopy(thiz_sups, 0, this_sups, 1, thiz_sups.length);
+ // System.arraycopy(other_sups, 0, t_sups, 1, other_sups.length);
+ // this_sups[0] = Repository.lookupClass(thiz.getClassName());
+ // t_sups[0] = Repository.lookupClass(other.getClassName());
+ //
+ // for (int i = 0; i < t_sups.length; i++) {
+ // for (int j = 0; j < this_sups.length; j++) {
+ // if (this_sups[j].equals(t_sups[i])) {
+ // return new ObjectType(this_sups[j].getClassName());
+ // }
+ // }
+ // }
+ //
+ // // Huh? Did you ask for Type.OBJECT's superclass??
+ // return null;
+ // }
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/ReturnaddressType.java bcel/src/java/org/aspectj/apache/bcel/generic/ReturnaddressType.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/ReturnaddressType.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/ReturnaddressType.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,102 @@
+package org.apache.bcel.generic;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+import org.apache.bcel.Constants;
+import org.apache.bcel.generic.InstructionHandle;
+
+/**
+ * Returnaddress, the type JSR or JSR_W instructions push upon the stack.
+ *
+ * see vmspec2 ?3.3.3
+ * @version $Id: ReturnaddressType.java,v 1.3 2008/05/28 23:52:56 aclement Exp $
+ * @author Enver Haase
+ */
+public class ReturnaddressType extends Type {
+
+ public static final ReturnaddressType NO_TARGET = new ReturnaddressType();
+ private InstructionHandle returnTarget;
+
+ /**
+ * A Returnaddress [that doesn't know where to return to].
+ */
+ private ReturnaddressType(){
+ super(Constants.T_ADDRESS, "");
+ }
+
+ /**
+ * Creates a ReturnaddressType object with a target.
+ */
+ public ReturnaddressType(InstructionHandle returnTarget) {
+ super(Constants.T_ADDRESS, "");
+ this.returnTarget = returnTarget;
+ }
+
+ /**
+ * Returns if the two Returnaddresses refer to the same target.
+ */
+ public boolean equals(Object rat){
+ if(!(rat instanceof ReturnaddressType))
+ return false;
+
+ return ((ReturnaddressType)rat).returnTarget.equals(this.returnTarget);
+ }
+
+ /**
+ * @return the target of this ReturnaddressType
+ */
+ public InstructionHandle getTarget(){
+ return returnTarget;
+ }
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/SwitchBuilder.java bcel/src/java/org/aspectj/apache/bcel/generic/SwitchBuilder.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/SwitchBuilder.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/SwitchBuilder.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,181 @@
+package org.apache.bcel.generic;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+/**
+ * SWITCH - Branch depending on int value, generates either LOOKUPSWITCH or
+ * TABLESWITCH instruction, depending on whether the match values (int[]) can be
+ * sorted with no gaps between the numbers.
+ *
+ * @version $Id: SwitchBuilder.java,v 1.2 2008/05/28 23:52:57 aclement Exp $
+ * @author M. Dahm
+ */
+public final class SwitchBuilder {
+ private int[] match;
+ private InstructionHandle[] targets;
+ private InstructionSelect instruction;
+ private int match_length;
+
+ /**
+ * Template for switch() constructs. If the match array can be
+ * sorted in ascending order with gaps no larger than max_gap
+ * between the numbers, a TABLESWITCH instruction is generated, and
+ * a LOOKUPSWITCH otherwise. The former may be more efficient, but
+ * needs more space.
+ *
+ * Note, that the key array always will be sorted, though we leave
+ * the original arrays unaltered.
+ *
+ * @param match array of match values (case 2: ... case 7: ..., etc.)
+ * @param targets the instructions to be branched to for each case
+ * @param target the default target
+ * @param max_gap maximum gap that may between case branches
+ */
+ public SwitchBuilder(int[] match, InstructionHandle[] targets,InstructionHandle target, int max_gap) {
+ this.match = (int[])match.clone();
+ this.targets = (InstructionHandle[])targets.clone();
+
+ if((match_length = match.length) < 2) // (almost) empty switch, or just default
+ if (match.length==0) {
+ instruction = new LOOKUPSWITCH(match,targets,target);
+ } else {
+ instruction = new TABLESWITCH(match,targets,target);
+ }
+ else {
+ sort(0, match_length - 1);
+
+ if(matchIsOrdered(max_gap)) {
+ fillup(max_gap, target);
+
+ instruction = new TABLESWITCH(this.match, this.targets, target);
+ }
+ else
+ instruction = new LOOKUPSWITCH(this.match, this.targets, target);
+ }
+ }
+
+ public SwitchBuilder(int[] match, InstructionHandle[] targets, InstructionHandle target) {
+ this(match, targets, target, 1);
+ }
+
+ private final void fillup(int max_gap, InstructionHandle target) {
+ int max_size = match_length + match_length * max_gap;
+ int[] m_vec = new int[max_size];
+ InstructionHandle[] t_vec = new InstructionHandle[max_size];
+ int count = 1;
+
+ m_vec[0] = match[0];
+ t_vec[0] = targets[0];
+
+ for(int i=1; i < match_length; i++) {
+ int prev = match[i-1];
+ int gap = match[i] - prev;
+
+ for(int j=1; j < gap; j++) {
+ m_vec[count] = prev + j;
+ t_vec[count] = target;
+ count++;
+ }
+
+ m_vec[count] = match[i];
+ t_vec[count] = targets[i];
+ count++;
+ }
+
+ match = new int[count];
+ targets = new InstructionHandle[count];
+
+ System.arraycopy(m_vec, 0, match, 0, count);
+ System.arraycopy(t_vec, 0, targets, 0, count);
+ }
+
+ /**
+ * Sort match and targets array with QuickSort.
+ */
+ private final void sort(int l, int r) {
+ int i = l, j = r;
+ int h, m = match[(l + r) / 2];
+ InstructionHandle h2;
+
+ do {
+ while(match[i] < m) i++;
+ while(m < match[j]) j--;
+
+ if(i <= j) {
+ h=match[i]; match[i]=match[j]; match[j]=h; // Swap elements
+ h2=targets[i]; targets[i]=targets[j]; targets[j]=h2; // Swap instructions, too
+ i++; j--;
+ }
+ } while(i <= j);
+
+ if(l < j) sort(l, j);
+ if(i < r) sort(i, r);
+ }
+
+ /**
+ * @return match is sorted in ascending order with no gap bigger than max_gap?
+ */
+ private final boolean matchIsOrdered(int max_gap) {
+ for(int i=1; i < match_length; i++) {
+ int diff = (match[i]-match[i-1]);
+ if(diff > max_gap || diff<0) return false;
+ }
+ return true;
+ }
+
+ public final InstructionSelect getInstruction() {
+ return instruction;
+ }
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/TABLESWITCH.java bcel/src/java/org/aspectj/apache/bcel/generic/TABLESWITCH.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/TABLESWITCH.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/TABLESWITCH.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,138 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+package org.apache.bcel.generic;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.util.ByteSequence;
+
+import com.sun.org.apache.bcel.internal.generic.SWITCH;
+
+/**
+ * TABLESWITCH - Switch within given range of values, i.e., low..high
+ *
+ * @version $Id: TABLESWITCH.java,v 1.5 2008/08/28 00:05:29 aclement Exp $
+ * @author M. Dahm
+ * @see SWITCH
+ */
+public class TABLESWITCH extends InstructionSelect {
+
+ /**
+ * @param match sorted array of match values, match[0] must be low value, match[match_length - 1] high value
+ * @param targets where to branch for matched values
+ * @param target default branch
+ */
+ public TABLESWITCH(int[] match, InstructionHandle[] targets, InstructionHandle target) {
+ super(org.apache.bcel.Constants.TABLESWITCH, match, targets, target);
+
+ // if (match_length==0) {
+ // throw new RuntimeException("A tableswitch with no targets should be represented as a LOOKUPSWITCH");
+ // }
+
+ // Alignment remainder assumed 0 here, until dump time
+ length = (short) (13 + matchLength * 4);
+ fixedLength = length;
+ }
+
+ /**
+ * Dump instruction as byte code to stream out.
+ *
+ * @param out Output stream
+ */
+ public void dump(DataOutputStream out) throws IOException {
+ super.dump(out);
+
+ int low = matchLength > 0 ? match[0] : 0;
+ out.writeInt(low);
+
+ int high = matchLength > 0 ? match[matchLength - 1] : 0;
+ out.writeInt(high);
+
+ // See aj bug pr104720
+ // if (match_length==0) out.writeInt(0); // following the switch you need to supply "HIGH-LOW+1" entries
+
+ for (int i = 0; i < matchLength; i++) {
+ out.writeInt(indices[i] = getTargetOffset(targets[i]));
+ }
+ }
+
+ /**
+ * Read needed data (e.g. index) from file.
+ */
+ public TABLESWITCH(ByteSequence bytes) throws IOException {
+ super(Constants.TABLESWITCH, bytes);
+
+ int low = bytes.readInt();
+ int high = bytes.readInt();
+
+ matchLength = high - low + 1;
+ fixedLength = (short) (13 + matchLength * 4);
+ length = (short) (fixedLength + padding);
+
+ match = new int[matchLength];
+ indices = new int[matchLength];
+ targets = new InstructionHandle[matchLength];
+
+ for (int i = low; i <= high; i++) {
+ match[i - low] = i;
+ }
+
+ for (int i = 0; i < matchLength; i++) {
+ indices[i] = bytes.readInt();
+ }
+ }
+
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/Tag.java bcel/src/java/org/aspectj/apache/bcel/generic/Tag.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/Tag.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/Tag.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,43 @@
+/* *******************************************************************
+ * Copyright (c) 2002 Contributors
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * PARC initial implementation
+ * Andy Clement pushed down into bcel module
+ * ******************************************************************/
+
+package org.apache.bcel.generic;
+
+/**
+ * A tag is an instruction-targeter that does not remember its target
+ */
+public abstract class Tag implements InstructionTargeter, Cloneable {
+
+ public Tag() {
+ }
+
+ // ---- from InstructionTargeter
+ public boolean containsTarget(InstructionHandle ih) {
+ return false;
+ }
+
+ public void updateTarget(InstructionHandle oldHandle, InstructionHandle newHandle) {
+ oldHandle.removeTargeter(this);
+ if (newHandle != null) {
+ newHandle.addTargeter(this);
+ }
+ }
+
+ public Tag copy() {
+ try {
+ return (Tag)clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeException("Sanity check, can't clone me");
+ }
+ }
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/TargetLostException.java bcel/src/java/org/aspectj/apache/bcel/generic/TargetLostException.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/TargetLostException.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/TargetLostException.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,101 @@
+package org.apache.bcel.generic;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+/**
+ * Thrown by InstructionList.remove() when one or multiple disposed instruction
+ * are still being referenced by a InstructionTargeter object. I.e. the
+ * InstructionTargeter has to be notified that (one of) the InstructionHandle it
+ * is referencing is being removed from the InstructionList and thus not valid anymore.
+ *
+ * Making this an exception instead of a return value forces the user to handle
+ * these case explicitely in a try { ... } catch. The following code illustrates
+ * how this may be done:
+ *
+ *
+ * ...
+ * try {
+ * il.delete(start_ih, end_ih);
+ * } catch(TargetLostException e) {
+ * InstructionHandle[] targets = e.getTargets();
+ * for(int i=0; i < targets.length; i++) {
+ * InstructionTargeter[] targeters = targets[i].getTargeters();
+ *
+ * for(int j=0; j < targeters.length; j++)
+ * targeters[j].updateTarget(targets[i], new_target);
+ * }
+ * }
+ *
+ *
+ * @see InstructionHandle
+ * @see InstructionList
+ * @see InstructionTargeter
+ * @version $Id: TargetLostException.java,v 1.3 2008/05/28 23:52:55 aclement Exp $
+ * @author M. Dahm
+ */
+// OPTIMIZE make unchecked, or get rid of it!
+public final class TargetLostException extends Exception {
+ private InstructionHandle[] targets;
+
+ TargetLostException(InstructionHandle[] t, String mesg) {
+ super(mesg);
+ targets = t;
+ }
+
+ /**
+ * @return list of instructions still being targeted.
+ */
+ public InstructionHandle[] getTargets() { return targets; }
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/generic/Type.java bcel/src/java/org/aspectj/apache/bcel/generic/Type.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/generic/Type.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/generic/Type.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,476 @@
+package org.apache.bcel.generic;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.classfile.ClassFormatException;
+import org.apache.bcel.classfile.Utility;
+
+
+/**
+ * Abstract super class for all possible java types, namely basic types
+ * such as int, object types like String and array types, e.g. int[]
+ *
+ * @version $Id: Type.java,v 1.10 2008/06/23 04:01:47 aclement Exp $
+ * @author M. Dahm
+ *
+ * modified:
+ * AndyClement 2-mar-05: Removed unnecessary static and optimized
+ */
+public abstract class Type implements java.io.Serializable {
+ protected byte type;
+ protected String signature; // signature for the type
+
+ /* Predefined constants */
+ public static final BasicType VOID = new BasicType(Constants.T_VOID);
+ public static final BasicType BOOLEAN = new BasicType(Constants.T_BOOLEAN);
+ public static final BasicType INT = new BasicType(Constants.T_INT);
+ public static final BasicType SHORT = new BasicType(Constants.T_SHORT);
+ public static final BasicType BYTE = new BasicType(Constants.T_BYTE);
+ public static final BasicType LONG = new BasicType(Constants.T_LONG);
+ public static final BasicType DOUBLE = new BasicType(Constants.T_DOUBLE);
+ public static final BasicType FLOAT = new BasicType(Constants.T_FLOAT);
+ public static final BasicType CHAR = new BasicType(Constants.T_CHAR);
+ public static final ObjectType OBJECT = new ObjectType("java.lang.Object");
+ public static final ObjectType STRING = new ObjectType("java.lang.String");
+ public static final ObjectType OBJECT_ARRAY = new ObjectType("java.lang.Object[]");
+ public static final ObjectType STRING_ARRAY = new ObjectType("java.lang.String[]");
+ public static final ObjectType STRINGBUFFER = new ObjectType("java.lang.StringBuffer");
+ public static final ObjectType STRINGBUILDER= new ObjectType("java.lang.StringBuilder");
+ public static final ObjectType THROWABLE = new ObjectType("java.lang.Throwable");
+ public static final ObjectType CLASS = new ObjectType("java.lang.Class");
+ public static final ObjectType INTEGER = new ObjectType("java.lang.Integer");
+ public static final ObjectType EXCEPTION = new ObjectType("java.lang.Exception");
+ public static final ObjectType LIST = new ObjectType("java.util.List");
+ public static final ObjectType ITERATOR = new ObjectType("java.util.Iterator");
+ public static final Type[] NO_ARGS = new Type[0];
+ public static final ReferenceType NULL = new ReferenceType(){};
+ public static final Type UNKNOWN = new Type(Constants.T_UNKNOWN,""){};
+ public static final Type[] STRINGARRAY1 = new Type[]{STRING};
+ public static final Type[] STRINGARRAY2 = new Type[]{STRING,STRING};
+ public static final Type[] STRINGARRAY3 = new Type[]{STRING,STRING,STRING};
+ public static final Type[] STRINGARRAY4 = new Type[]{STRING,STRING,STRING,STRING};
+ public static final Type[] STRINGARRAY5 = new Type[]{STRING,STRING,STRING,STRING,STRING};
+ public static final Type[] STRINGARRAY6 = new Type[]{STRING,STRING,STRING,STRING,STRING,STRING};
+ public static final Type[] STRINGARRAY7 = new Type[]{STRING,STRING,STRING,STRING,STRING,STRING,STRING};
+
+ private static Map commonTypes = new HashMap();
+
+ static {
+ commonTypes.put(STRING.getSignature(), STRING);
+ commonTypes.put(THROWABLE.getSignature(), THROWABLE);
+ commonTypes.put(VOID.getSignature(), VOID);
+ commonTypes.put(BOOLEAN.getSignature(), BOOLEAN);
+ commonTypes.put(BYTE.getSignature(), BYTE);
+ commonTypes.put(SHORT.getSignature(), SHORT);
+ commonTypes.put(CHAR.getSignature(), CHAR);
+ commonTypes.put(INT.getSignature(), INT);
+ commonTypes.put(LONG.getSignature(), LONG);
+ commonTypes.put(DOUBLE.getSignature(), DOUBLE);
+ commonTypes.put(FLOAT.getSignature(), FLOAT);
+ commonTypes.put(CLASS.getSignature(), CLASS);
+ commonTypes.put(OBJECT.getSignature(), OBJECT);
+ commonTypes.put(STRING_ARRAY.getSignature(), STRING_ARRAY);
+ commonTypes.put(OBJECT_ARRAY.getSignature(), OBJECT_ARRAY);
+ commonTypes.put(INTEGER.getSignature(), INTEGER);
+ commonTypes.put(EXCEPTION.getSignature(), EXCEPTION);
+ commonTypes.put(STRINGBUFFER.getSignature(), STRINGBUFFER);
+ commonTypes.put(STRINGBUILDER.getSignature(), STRINGBUILDER);
+ commonTypes.put(LIST.getSignature(), LIST);
+ commonTypes.put(ITERATOR.getSignature(), ITERATOR);
+
+ }
+
+ protected Type(byte t, String s) {
+ type = t;
+ signature = s;
+ }
+
+ /**
+ * @return signature for given type.
+ */
+ public String getSignature() { return signature; }
+
+ /**
+ * @return type as defined in Constants
+ */
+ public byte getType() { return type; }
+
+ /**
+ * @return stack size of this type (2 for long and double, 0 for void, 1 otherwise)
+ */
+ public int getSize() {
+ switch(type) {
+ case Constants.T_DOUBLE: case Constants.T_LONG:
+ return 2;
+ case Constants.T_VOID:
+ return 0;
+ default:
+ return 1;
+ }
+ }
+
+ /**
+ * @return Type string, e.g. 'int[]'
+ */
+ public String toString() {
+ return ((this.equals(Type.NULL) || (type >= Constants.T_UNKNOWN)))? signature :
+ Utility.signatureToString(signature, false);
+ }
+
+ /**
+ * Convert type to Java method signature, e.g. int[] f(java.lang.String x)
+ * becomes (Ljava/lang/String;)[I
+ *
+ * @param return_type what the method returns
+ * @param arg_types what are the argument types
+ * @return method signature for given type(s).
+ */
+ public static String getMethodSignature(Type return_type, Type[] arg_types) {
+ StringBuffer buf = new StringBuffer("(");
+ int length = (arg_types == null)? 0 : arg_types.length;
+ for(int i=0; i < length; i++) {
+ buf.append(arg_types[i].getSignature());
+ }
+ buf.append(')');
+ buf.append(return_type.getSignature());
+ return buf.toString();
+ }
+
+ public static final Type getType(String signature) {
+ Type t = (Type)commonTypes.get(signature);
+ if (t!=null) return t;
+ byte type = Utility.typeOfSignature(signature);
+ if (type <= Constants.T_VOID) {
+ return BasicType.getType(type);
+ } else if (type == Constants.T_ARRAY) {
+ int dim=0;
+ do { dim++; } while(signature.charAt(dim) == '[');
+ // Recurse, but just once, if the signature is ok
+ Type componentType = getType(signature.substring(dim));
+ return new ArrayType(componentType, dim);
+ } else { // type == T_REFERENCE
+ // generics awareness
+ int nextAngly = signature.indexOf('<');
+ // Format is 'Lblahblah;'
+ int index = signature.indexOf(';'); // Look for closing ';'
+
+ String typeString = null;
+ if (nextAngly==-1 || nextAngly>index) {
+ typeString = signature.substring(1,index).replace('/','.');
+ } else {
+ boolean endOfSigReached = false;
+ int posn = nextAngly;
+ int genericDepth=0;
+ while (!endOfSigReached) {
+ switch (signature.charAt(posn++)) {
+ case '<': genericDepth++;break;
+ case '>': genericDepth--;break;
+ case ';': if (genericDepth==0) endOfSigReached=true;break;
+ default:
+ }
+ }
+ index=posn-1;
+ typeString = signature.substring(1,nextAngly).replace('/','.');
+ }
+ // ObjectType doesn't currently store parameterized info
+ return new ObjectType(typeString);
+ }
+ }
+
+ /**
+ * Convert signature to a Type object.
+ * @param signature signature string such as Ljava/lang/String;
+ * @return type object
+ */
+ public static final TypeHolder getTypeInternal(String signature) throws StringIndexOutOfBoundsException {
+ byte type = Utility.typeOfSignature(signature);
+
+ if (type <= Constants.T_VOID) {
+ return new TypeHolder(BasicType.getType(type),1);
+ } else if (type == Constants.T_ARRAY) {
+ int dim=0;
+ do { dim++; } while(signature.charAt(dim) == '[');
+ // Recurse, but just once, if the signature is ok
+ TypeHolder th = getTypeInternal(signature.substring(dim));
+ return new TypeHolder(new ArrayType(th.getType(), dim),dim+th.getConsumed());
+ } else { // type == T_REFERENCE
+ // Format is 'Lblahblah;'
+ int index = signature.indexOf(';'); // Look for closing ';'
+ if (index < 0) throw new ClassFormatException("Invalid signature: " + signature);
+
+ // generics awareness
+ int nextAngly = signature.indexOf('<');
+ String typeString = null;
+ if (nextAngly==-1 || nextAngly>index) {
+ typeString = signature.substring(1,index).replace('/','.');
+ } else {
+ boolean endOfSigReached = false;
+ int posn = nextAngly;
+ int genericDepth=0;
+ while (!endOfSigReached) {
+ switch (signature.charAt(posn++)) {
+ case '<': genericDepth++;break;
+ case '>': genericDepth--;break;
+ case ';': if (genericDepth==0) endOfSigReached=true;break;
+ default:
+ }
+ }
+ index=posn-1;
+ typeString = signature.substring(1,nextAngly).replace('/','.');
+ }
+ // ObjectType doesn't currently store parameterized info
+ return new TypeHolder(new ObjectType(typeString),index+1);
+ }
+ }
+
+ /**
+ * Convert return value of a method (signature) to a Type object.
+ *
+ * @param signature signature string such as (Ljava/lang/String;)V
+ * @return return type
+ */
+ public static Type getReturnType(String signature) {
+ try {
+ // Read return type after `)'
+ int index = signature.lastIndexOf(')') + 1;
+ return getType(signature.substring(index));
+ } catch(StringIndexOutOfBoundsException e) { // Should never occur
+ throw new ClassFormatException("Invalid method signature: " + signature);
+ }
+ }
+
+ /**
+ * Convert arguments of a method (signature) to an array of Type objects.
+ * @param signature signature string such as (Ljava/lang/String;)V
+ * @return array of argument types
+ */
+ // OPTIMIZE crap impl
+ public static Type[] getArgumentTypes(String signature) {
+ ArrayList vec = new ArrayList();
+ int index;
+ Type[] types;
+
+ try { // Read all declarations between for `(' and `)'
+ if (signature.charAt(0) != '(')
+ throw new ClassFormatException("Invalid method signature: " + signature);
+
+ index = 1; // current string position
+
+ while(signature.charAt(index) != ')') {
+ TypeHolder th = getTypeInternal(signature.substring(index));
+ vec.add(th.getType());
+ index += th.getConsumed(); // update position
+ }
+ } catch(StringIndexOutOfBoundsException e) { // Should never occur
+ throw new ClassFormatException("Invalid method signature: " + signature);
+ }
+
+ types = new Type[vec.size()];
+ vec.toArray(types);
+ return types;
+ }
+
+ /**
+ * Work out the type of each argument in the signature and return the cumulative sizes of
+ * all the types (size means number of stack slots it consumes, eg double=2, int=1).
+ * Unlike the call above, this does minimal unpacking
+ */
+ public static int getArgumentSizes(String signature) {
+ int size = 0;
+ if (signature.charAt(0) != '(')
+ throw new ClassFormatException("Invalid method signature: " + signature);
+
+ int index = 1; // current string position
+ try {
+ while (signature.charAt(index) != ')') {
+ byte type = Utility.typeOfSignature(signature.charAt(index));
+ if (type<=Constants.T_VOID) {
+ size+=BasicType.getType(type).getSize();
+ index++;
+ } else if (type==Constants.T_ARRAY) {
+ int dim=0;
+ do { dim++; } while(signature.charAt(dim+index) == '[');
+ TypeHolder th = getTypeInternal(signature.substring(dim+index));
+ size+=1;
+ index+=dim+th.getConsumed();
+ } else { // type == T_REFERENCE
+ // Format is 'Lblahblah;'
+ int index2 = signature.indexOf(';',index); // Look for closing ';'
+
+ // generics awareness
+ int nextAngly = signature.indexOf('<',index);
+ if (nextAngly==-1 || nextAngly>index2) {
+ } else {
+ boolean endOfSigReached = false;
+ int posn = nextAngly;
+ int genericDepth=0;
+ while (!endOfSigReached) {
+ switch (signature.charAt(posn++)) {
+ case '<': genericDepth++;break;
+ case '>': genericDepth--;break;
+ case ';': if (genericDepth==0) endOfSigReached=true;break;
+ default:
+ }
+ }
+ index2=posn-1;
+ }
+ size++;
+ index=index2+1;
+ }
+ }
+ } catch(StringIndexOutOfBoundsException e) { // Should never occur
+ throw new ClassFormatException("Invalid method signature: " + signature);
+ }
+ return size;
+ }
+
+ /**
+ * Return the size of the type expressed in the signature. The signature should contain only one type.
+ */
+ public static int getTypeSize(String signature) {
+ byte type = Utility.typeOfSignature(signature.charAt(0));
+ if (type<=Constants.T_VOID) {
+ return BasicType.getType(type).getSize();
+ } else if (type==Constants.T_ARRAY) {
+ return 1;
+ } else { // type == T_REFERENCE
+ return 1;
+ }
+ }
+
+ /** Convert runtime java.lang.Class to BCEL Type object.
+ * @param cl Java class
+ * @return corresponding Type object
+ */
+ public static Type getType(java.lang.Class cl) {
+ if(cl == null) {
+ throw new IllegalArgumentException("Class must not be null");
+ }
+
+ /* That's an amazingly easy case, because getName() returns
+ * the signature. That's what we would have liked anyway.
+ */
+ if(cl.isArray()) {
+ return getType(cl.getName());
+ } else if(cl.isPrimitive()) {
+ if(cl == Integer.TYPE) {
+ return INT;
+ } else if(cl == Void.TYPE) {
+ return VOID;
+ } else if(cl == Double.TYPE) {
+ return DOUBLE;
+ } else if(cl == Float.TYPE) {
+ return FLOAT;
+ } else if(cl == Boolean.TYPE) {
+ return BOOLEAN;
+ } else if(cl == Byte.TYPE) {
+ return BYTE;
+ } else if(cl == Short.TYPE) {
+ return SHORT;
+ } else if(cl == Byte.TYPE) {
+ return BYTE;
+ } else if(cl == Long.TYPE) {
+ return LONG;
+ } else if(cl == Character.TYPE) {
+ return CHAR;
+ } else {
+ throw new IllegalStateException("Ooops, what primitive type is " + cl);
+ }
+ } else { // "Real" class
+ return new ObjectType(cl.getName());
+ }
+ }
+
+ public static String getSignature(java.lang.reflect.Method meth) {
+ StringBuffer sb = new StringBuffer("(");
+ Class[] params = meth.getParameterTypes(); // avoid clone
+
+ for(int j = 0; j < params.length; j++) {
+ sb.append(getType(params[j]).getSignature());
+ }
+
+ sb.append(")");
+ sb.append(getType(meth.getReturnType()).getSignature());
+ return sb.toString();
+ }
+
+ public static String getSignature(java.lang.reflect.Constructor cons) {
+ StringBuffer sb = new StringBuffer("(");
+ Class[] params = cons.getParameterTypes(); // avoid clone
+
+ for(int j = 0; j < params.length; j++) {
+ sb.append(getType(params[j]).getSignature());
+ }
+
+ sb.append(")V");
+ return sb.toString();
+ }
+
+ public static class TypeHolder {
+ private Type t;
+ private int consumed;
+
+ public Type getType() {return t;}
+ public int getConsumed() { return consumed;}
+
+ public TypeHolder(Type t,int i) { this.t=t;this.consumed = i;}
+ }
+
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/util/ByteSequence.java bcel/src/java/org/aspectj/apache/bcel/util/ByteSequence.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/util/ByteSequence.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/util/ByteSequence.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,82 @@
+package org.apache.bcel.util;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+import java.io.*;
+
+/**
+ * Utility class that implements a sequence of bytes which can be read
+ * via the `readByte()' method. This is used to implement a wrapper for the
+ * Java byte code stream to gain some more readability.
+ *
+ * @version $Id: ByteSequence.java,v 1.3 2008/05/28 23:52:53 aclement Exp $
+ * @author M. Dahm
+ */
+public final class ByteSequence extends DataInputStream {
+ private ByteArrayStream byte_stream;
+
+ public ByteSequence(byte[] bytes) {
+ super(new ByteArrayStream(bytes));
+ byte_stream = (ByteArrayStream)in;
+ }
+
+ public final int getIndex() { return byte_stream.getPosition(); }
+ final void unreadByte() { byte_stream.unreadByte(); }
+
+ private static final class ByteArrayStream extends ByteArrayInputStream {
+ ByteArrayStream(byte[] bytes) { super(bytes); }
+ final int getPosition() { return pos; } // is protected in ByteArrayInputStream
+ final void unreadByte() { if(pos > 0) pos--; }
+ }
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/util/ClassLoaderReference.java bcel/src/java/org/aspectj/apache/bcel/util/ClassLoaderReference.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/util/ClassLoaderReference.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/util/ClassLoaderReference.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,67 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+package org.apache.bcel.util;
+
+/**
+ * Implementors should provide access to a ClassLoader instance. The reference can be passed around and cached
+ * but will not cause the code that caches it to have a hard reference to the classloader, so it is easier
+ * to manage the classloader instance. The default implementation will just wrap a classloader object but
+ * more sophisticated implementations could keep a WeakReference to the loader.
+ */
+public interface ClassLoaderReference {
+
+ java.lang.ClassLoader getClassLoader();
+
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/util/ClassLoaderRepository.java bcel/src/java/org/aspectj/apache/bcel/util/ClassLoaderRepository.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/util/ClassLoaderRepository.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/util/ClassLoaderRepository.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,371 @@
+package org.apache.bcel.util;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.AbstractMap;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+import org.apache.bcel.classfile.ClassParser;
+import org.apache.bcel.classfile.JavaClass;
+
+/**
+ * The repository maintains information about which classes have
+ * been loaded.
+ *
+ * It loads its data from the ClassLoader implementation
+ * passed into its constructor.
+ *
+ * @see org.apache.bcel.Repository
+ *
+ * @version $Id: ClassLoaderRepository.java,v 1.12 2008/08/26 15:02:41 aclement Exp $
+ * @author M. Dahm
+ * @author David Dixon-Peugh
+ */
+public class ClassLoaderRepository implements Repository {
+ private static java.lang.ClassLoader bootClassLoader = null;
+ private ClassLoaderReference loaderRef;
+
+ // Choice of cache...
+ private WeakHashMap /**/localCache = new WeakHashMap();
+ private static SoftHashMap /**/sharedCache = new SoftHashMap(Collections.synchronizedMap(new HashMap()));
+
+ // For fast translation of the classname *intentionally not static*
+ private SoftHashMap /**/ nameMap = new SoftHashMap(new HashMap(), false);
+
+ public static boolean useSharedCache =
+ System.getProperty("org.apache.bcel.useSharedCache","true").equalsIgnoreCase("true");
+
+ private static int cacheHitsShared = 0;
+ private static int missSharedEvicted = 0; // Misses in shared cache access due to reference GC
+ private long timeManipulatingURLs = 0L;
+ private long timeSpentLoading = 0L;
+ private int classesLoadedCount = 0;
+ private int misses = 0;
+ private int cacheHitsLocal = 0;
+ private int missLocalEvicted = 0; // Misses in local cache access due to reference GC
+
+ public ClassLoaderRepository(java.lang.ClassLoader loader) {
+ this.loaderRef = new DefaultClassLoaderReference((loader != null) ? loader : getBootClassLoader());
+ }
+
+ public ClassLoaderRepository(ClassLoaderReference loaderRef) {
+ this.loaderRef = loaderRef;
+ }
+
+ private static synchronized java.lang.ClassLoader getBootClassLoader() {
+ if (bootClassLoader == null) {
+ bootClassLoader = new URLClassLoader(new URL[0]);
+ }
+ return bootClassLoader;
+ }
+
+ // Can track back to its key
+ public static class SoftHashMap extends AbstractMap {
+ private Map map;
+ boolean recordMiss = true; // only interested in recording miss stats sometimes
+ private ReferenceQueue rq = new ReferenceQueue();
+
+ public SoftHashMap(Map map) { this.map = map; }
+ public SoftHashMap() { this(new HashMap()); }
+ public SoftHashMap(Map map, boolean b) { this(map); this.recordMiss=b;}
+
+ class SpecialValue extends SoftReference {
+ private final Object key;
+ SpecialValue(Object k,Object v) {
+ super(v,rq);
+ this.key = k;
+ }
+ }
+
+ private void processQueue() {
+ SpecialValue sv = null;
+ while ((sv = (SpecialValue)rq.poll())!=null) {
+ map.remove(sv.key);
+ }
+ }
+
+ public Object get(Object key) {
+ SpecialValue value = (SpecialValue)map.get(key);
+ if (value==null) return null;
+ if (value.get()==null) {
+ // it got GC'd
+ map.remove(value.key);
+ if (recordMiss) missSharedEvicted++;
+ return null;
+ } else {
+ return value.get();
+ }
+ }
+
+ public Object put(Object k, Object v) {
+ processQueue();
+ return map.put(k, new SpecialValue(k,v));
+ }
+
+ public Set entrySet() {
+ return map.entrySet();
+ }
+
+ public void clear() {
+ processQueue();
+ map.clear();
+ }
+
+ public int size() {
+ processQueue();
+ return map.size();
+ }
+
+ public Object remove(Object k) {
+ processQueue();
+ SpecialValue value = (SpecialValue)map.remove(k);
+ if (value==null) return null;
+ if (value.get()!=null) {
+ return value.get();
+ }
+ return null;
+ }
+ }
+
+ /**
+ * Store a new JavaClass into this repository as a soft reference and return the reference
+ */
+ private void storeClassAsReference(URL url, JavaClass clazz ) {
+ if (useSharedCache) {
+ clazz.setRepository(null); // can't risk setting repository, we'll get in a pickle!
+ sharedCache.put(url, clazz);
+ } else {
+ clazz.setRepository(this);
+ localCache.put(url, new SoftReference(clazz));
+ }
+ }
+
+ /**
+ * Store a new JavaClass into this Repository.
+ */
+ public void storeClass( JavaClass clazz ) {
+ storeClassAsReference(toURL(clazz.getClassName()),clazz);
+ }
+
+ /**
+ * Remove class from repository
+ */
+ public void removeClass(JavaClass clazz) {
+ if (useSharedCache) sharedCache.remove(toURL(clazz.getClassName()));
+ else localCache.remove(toURL(clazz.getClassName()));
+ }
+
+ /**
+ * Find an already defined JavaClass in the local cache.
+ */
+ public JavaClass findClass( String className ) {
+ if (useSharedCache) return findClassShared(toURL(className));
+ else return findClassLocal(toURL(className));
+ }
+
+ private JavaClass findClassLocal( URL url ) {
+ Object o = localCache.get(url);
+ if (o != null) {
+ o = ((Reference)o).get();
+ if (o != null) {
+ return (JavaClass)o;
+ } else {
+ missLocalEvicted++;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Find an already defined JavaClass in the shared cache.
+ */
+ private JavaClass findClassShared(URL url) {
+ return (JavaClass)sharedCache.get(url);
+ }
+
+ private URL toURL(String className) {
+ URL url = (URL)nameMap.get(className);
+ if (url==null) {
+ String classFile = className.replace('.', '/');
+ url = loaderRef.getClassLoader().getResource(classFile + ".class");
+ nameMap.put(className, url);
+ }
+ return url;
+ }
+
+ /**
+ * Lookup a JavaClass object from the Class Name provided.
+ */
+ public JavaClass loadClass( String className ) throws ClassNotFoundException {
+
+ // translate to a URL
+ long time = System.currentTimeMillis();
+ java.net.URL url = toURL(className);
+ timeManipulatingURLs += (System.currentTimeMillis() - time);
+ if (url==null) throw new ClassNotFoundException(className + " not found - unable to determine URL");
+
+ JavaClass clazz = null;
+
+ // Look in the appropriate cache
+ if (useSharedCache) {
+ clazz = findClassShared(url);
+ if (clazz != null) { cacheHitsShared++; return clazz; }
+ } else {
+ clazz = findClassLocal(url);
+ if (clazz != null) { cacheHitsLocal++; return clazz; }
+ }
+
+ // Didn't find it in either cache
+ misses++;
+
+ try {
+ // Load it
+ String classFile = className.replace('.', '/');
+ InputStream is = (useSharedCache ? url.openStream() : loaderRef.getClassLoader().getResourceAsStream(classFile + ".class"));
+ if (is == null) {
+ throw new ClassNotFoundException(className + " not found using url "+url);
+ }
+ ClassParser parser = new ClassParser( is, className );
+ clazz = parser.parse();
+
+ // Cache it
+ storeClassAsReference(url, clazz );
+
+ timeSpentLoading += (System.currentTimeMillis() - time);
+ classesLoadedCount++;
+ return clazz;
+ } catch (IOException e) {
+ throw new ClassNotFoundException( e.toString() );
+ }
+ }
+
+ /**
+ * Produce a report on cache usage.
+ */
+ public String report() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("BCEL repository report.");
+ if (useSharedCache) sb.append(" (shared cache)");
+ else sb.append(" (local cache)");
+ sb.append(" Total time spent loading: "+timeSpentLoading+"ms.");
+ sb.append(" Time spent manipulating URLs: "+timeManipulatingURLs+"ms.");
+ sb.append(" Classes loaded: "+classesLoadedCount+".");
+ if (useSharedCache) {
+ sb.append(" Shared cache size: "+sharedCache.size());
+ sb.append(" Shared cache (hits/missDueToEviction): ("+cacheHitsShared+"/"+missSharedEvicted+").");
+ } else {
+ sb.append(" Local cache size: "+localCache.size());
+ sb.append(" Local cache (hits/missDueToEviction): ("+cacheHitsLocal+"/"+missLocalEvicted+").");
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Returns an array of the stats, for testing, the order is fixed:
+ * 0=time spent loading (static)
+ * 1=time spent manipulating URLs (static)
+ * 2=classes loaded (static)
+ * 3=cache hits shared (static)
+ * 4=misses in shared due to eviction (static)
+ * 5=cache hits local
+ * 6=misses in local due to eviction
+ * 7=shared cache size
+ */
+ public long[] reportStats() {
+ return new long[]{timeSpentLoading,timeManipulatingURLs,classesLoadedCount,
+ cacheHitsShared,missSharedEvicted,cacheHitsLocal,missLocalEvicted,
+ sharedCache.size()};
+ }
+
+ /**
+ * Reset statistics and clear all caches
+ */
+ public void reset() {
+ timeManipulatingURLs = 0L;
+ timeSpentLoading = 0L;
+ classesLoadedCount = 0;
+ cacheHitsLocal = 0;
+ cacheHitsShared = 0;
+ missSharedEvicted = 0;
+ missLocalEvicted = 0;
+ misses = 0;
+ clear();
+ }
+
+
+ public JavaClass loadClass(Class clazz) throws ClassNotFoundException {
+ return loadClass(clazz.getName());
+ }
+
+ /** Clear all entries from the local cache */
+ public void clear() {
+ if (useSharedCache) sharedCache.clear();
+ else localCache.clear();
+ }
+
+}
+
+
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/util/ClassPath.java bcel/src/java/org/aspectj/apache/bcel/util/ClassPath.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/util/ClassPath.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/util/ClassPath.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,378 @@
+package org.apache.bcel.util;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+import java.util.*;
+import java.util.zip.*;
+import java.io.*;
+
+/**
+ * Responsible for loading (class) files from the CLASSPATH. Inspired by
+ * sun.tools.ClassPath.
+ *
+ * @version $Id: ClassPath.java,v 1.4 2008/05/28 23:52:53 aclement Exp $
+ * @author M. Dahm
+ */
+public class ClassPath implements Serializable {
+ private static ClassPath SYSTEM_CLASS_PATH = null;
+
+ private PathEntry[] paths;
+ private String class_path;
+
+ public static ClassPath getSystemClassPath() {
+ if (SYSTEM_CLASS_PATH == null) {
+ SYSTEM_CLASS_PATH = new ClassPath();
+ }
+ return SYSTEM_CLASS_PATH;
+ }
+ /**
+ * Search for classes in given path.
+ */
+ public ClassPath(String class_path) {
+ this.class_path = class_path;
+
+ ArrayList vec = new ArrayList();
+
+ for(StringTokenizer tok=new StringTokenizer(class_path,
+ System.getProperty("path.separator"));
+ tok.hasMoreTokens();)
+ {
+ String path = tok.nextToken();
+
+ if(!path.equals("")) {
+ File file = new File(path);
+
+ try {
+ if(file.exists()) {
+ if(file.isDirectory())
+ vec.add(new Dir(path));
+ else
+ vec.add(new Zip(new ZipFile(file)));
+ }
+ } catch(IOException e) {
+ System.err.println("CLASSPATH component " + file + ": " + e);
+ }
+ }
+ }
+
+ paths = new PathEntry[vec.size()];
+ vec.toArray(paths);
+ }
+
+ /**
+ * Search for classes in CLASSPATH.
+ * @deprecated Use SYSTEM_CLASS_PATH constant
+ */
+ public ClassPath() {
+ this(getClassPath());
+ }
+
+ /** @return used class path string
+ */
+ public String toString() {
+ return class_path;
+ }
+
+ public int hashCode() {
+ return class_path.hashCode();
+ }
+
+ public boolean equals(Object o) {
+ if(o instanceof ClassPath) {
+ return class_path.equals(((ClassPath)o).class_path);
+ }
+
+ return false;
+ }
+
+ private static final void getPathComponents(String path, ArrayList list) {
+ if(path != null) {
+ StringTokenizer tok = new StringTokenizer(path, File.pathSeparator);
+
+ while(tok.hasMoreTokens()) {
+ String name = tok.nextToken();
+ File file = new File(name);
+
+ if(file.exists())
+ list.add(name);
+ }
+ }
+ }
+
+ /** Checks for class path components in the following properties:
+ * "java.class.path", "sun.boot.class.path", "java.ext.dirs"
+ *
+ * @return class path as used by default by BCEL
+ */
+ public static final String getClassPath() {
+ String class_path = System.getProperty("java.class.path");
+ String boot_path = System.getProperty("sun.boot.class.path");
+ String ext_path = System.getProperty("java.ext.dirs");
+
+ ArrayList list = new ArrayList();
+
+ getPathComponents(class_path, list);
+ getPathComponents(boot_path, list);
+
+ ArrayList dirs = new ArrayList();
+ getPathComponents(ext_path, dirs);
+
+ for(Iterator e = dirs.iterator(); e.hasNext(); ) {
+ File ext_dir = new File((String)e.next());
+ String[] extensions = ext_dir.list(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ name = name.toLowerCase();
+ return name.endsWith(".zip") || name.endsWith(".jar");
+ }
+ });
+
+ if(extensions != null)
+ for(int i=0; i < extensions.length; i++)
+ list.add(ext_path + File.separatorChar + extensions[i]);
+ }
+
+ StringBuffer buf = new StringBuffer();
+
+ for(Iterator e = list.iterator(); e.hasNext(); ) {
+ buf.append((String)e.next());
+
+ if(e.hasNext())
+ buf.append(File.pathSeparatorChar);
+ }
+
+ return buf.toString().intern();
+ }
+
+ /**
+ * @param name fully qualified class name, e.g. java.lang.String
+ * @return input stream for class
+ */
+ public InputStream getInputStream(String name) throws IOException {
+ return getInputStream(name, ".class");
+ }
+
+ /**
+ * Return stream for class or resource on CLASSPATH.
+ *
+ * @param name fully qualified file name, e.g. java/lang/String
+ * @param suffix file name ends with suff, e.g. .java
+ * @return input stream for file on class path
+ */
+ public InputStream getInputStream(String name, String suffix) throws IOException {
+ InputStream is = null;
+
+ try {
+ is = getClass().getClassLoader().getResourceAsStream(name + suffix);
+ } catch(Exception e) { }
+
+ if(is != null)
+ return is;
+
+ return getClassFile(name, suffix).getInputStream();
+ }
+
+ /**
+ * @param name fully qualified file name, e.g. java/lang/String
+ * @param suffix file name ends with suff, e.g. .java
+ * @return class file for the java class
+ */
+ public ClassFile getClassFile(String name, String suffix) throws IOException {
+ for(int i=0; i < paths.length; i++) {
+ ClassFile cf;
+
+ if((cf = paths[i].getClassFile(name, suffix)) != null)
+ return cf;
+ }
+
+ throw new IOException("Couldn't find: " + name + suffix);
+ }
+
+ /**
+ * @param name fully qualified class name, e.g. java.lang.String
+ * @return input stream for class
+ */
+ public ClassFile getClassFile(String name) throws IOException {
+ return getClassFile(name, ".class");
+ }
+
+ /**
+ * @param name fully qualified file name, e.g. java/lang/String
+ * @param suffix file name ends with suffix, e.g. .java
+ * @return byte array for file on class path
+ */
+ public byte[] getBytes(String name, String suffix) throws IOException {
+ InputStream is = getInputStream(name, suffix);
+
+ if(is == null)
+ throw new IOException("Couldn't find: " + name + suffix);
+
+ DataInputStream dis = new DataInputStream(is);
+ byte[] bytes = new byte[is.available()];
+ dis.readFully(bytes);
+ dis.close(); is.close();
+
+ return bytes;
+ }
+
+ /**
+ * @return byte array for class
+ */
+ public byte[] getBytes(String name) throws IOException {
+ return getBytes(name, ".class");
+ }
+
+ /**
+ * @param name name of file to search for, e.g. java/lang/String.java
+ * @return full (canonical) path for file
+ */
+ public String getPath(String name) throws IOException {
+ int index = name.lastIndexOf('.');
+ String suffix = "";
+
+ if(index > 0) {
+ suffix = name.substring(index);
+ name = name.substring(0, index);
+ }
+
+ return getPath(name, suffix);
+ }
+
+ /**
+ * @param name name of file to search for, e.g. java/lang/String
+ * @param suffix file name suffix, e.g. .java
+ * @return full (canonical) path for file, if it exists
+ */
+ public String getPath(String name, String suffix) throws IOException {
+ return getClassFile(name, suffix).getPath();
+ }
+
+ private static abstract class PathEntry implements Serializable {
+ abstract ClassFile getClassFile(String name, String suffix) throws IOException;
+ }
+
+ /** Contains information about file/ZIP entry of the Java class.
+ */
+ public interface ClassFile {
+ /** @return input stream for class file.
+ */
+ public abstract InputStream getInputStream() throws IOException;
+
+ /** @return canonical path to class file.
+ */
+ public abstract String getPath();
+
+ /** @return base path of found class, i.e. class is contained relative
+ * to that path, which may either denote a directory, or zip file
+ */
+ public abstract String getBase();
+
+ /** @return modification time of class file.
+ */
+ public abstract long getTime();
+
+ /** @return size of class file.
+ */
+ public abstract long getSize();
+ }
+
+ private static class Dir extends PathEntry {
+ private String dir;
+
+ Dir(String d) { dir = d; }
+
+ ClassFile getClassFile(String name, String suffix) throws IOException {
+ final File file = new File(dir + File.separatorChar +
+ name.replace('.', File.separatorChar) + suffix);
+
+ return file.exists()? new ClassFile() {
+ public InputStream getInputStream() throws IOException { return new FileInputStream(file); }
+
+ public String getPath() { try {
+ return file.getCanonicalPath();
+ } catch(IOException e) { return null; }
+
+ }
+ public long getTime() { return file.lastModified(); }
+ public long getSize() { return file.length(); }
+ public String getBase() { return dir; }
+
+ } : null;
+ }
+
+ public String toString() { return dir; }
+ }
+
+ private static class Zip extends PathEntry {
+ private ZipFile zip;
+
+ Zip(ZipFile z) { zip = z; }
+
+ ClassFile getClassFile(String name, String suffix) throws IOException {
+ final ZipEntry entry = zip.getEntry(name.replace('.', '/') + suffix);
+
+ return (entry != null)? new ClassFile() {
+ public InputStream getInputStream() throws IOException { return zip.getInputStream(entry); }
+ public String getPath() { return entry.toString(); }
+ public long getTime() { return entry.getTime(); }
+ public long getSize() { return entry.getSize(); }
+ public String getBase() {
+ return zip.getName();
+ }
+ } : null;
+ }
+ }
+}
+
+
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/util/ClassQueue.java bcel/src/java/org/aspectj/apache/bcel/util/ClassQueue.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/util/ClassQueue.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/util/ClassQueue.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,81 @@
+package org.apache.bcel.util;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+import java.util.LinkedList;
+import org.apache.bcel.classfile.JavaClass;
+
+/**
+ * Utility class implementing a (typesafe) queue of JavaClass
+ * objects.
+ *
+ * @version $Id: ClassQueue.java,v 1.3 2008/05/28 23:52:53 aclement Exp $
+ * @author M. Dahm
+ * @see ClassVector
+*/
+public class ClassQueue implements java.io.Serializable {
+ protected LinkedList vec = new LinkedList();
+
+ public void enqueue(JavaClass clazz) { vec.addLast(clazz); }
+
+ public JavaClass dequeue() {
+ return (JavaClass)vec.removeFirst();
+ }
+
+ public boolean empty() { return vec.isEmpty(); }
+
+ public String toString() {
+ return vec.toString();
+ }
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/util/ClassVector.java bcel/src/java/org/aspectj/apache/bcel/util/ClassVector.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/util/ClassVector.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/util/ClassVector.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,79 @@
+package org.apache.bcel.util;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+import java.util.ArrayList;
+import org.apache.bcel.classfile.JavaClass;
+
+/**
+ * Utility class implementing a (typesafe) collection of JavaClass
+ * objects. Contains the most important methods of a Vector.
+ *
+ * @version $Id: ClassVector.java,v 1.3 2008/05/28 23:52:53 aclement Exp $
+ * @author M. Dahm
+ * @see ClassQueue
+*/
+public class ClassVector implements java.io.Serializable {
+ protected ArrayList vec = new ArrayList();
+
+ public void addElement(JavaClass clazz) { vec.add(clazz); }
+ public JavaClass elementAt(int index) { return (JavaClass)vec.get(index); }
+ public void removeElementAt(int index) { vec.remove(index); }
+
+ public JavaClass[] toArray() {
+ JavaClass[] classes = new JavaClass[vec.size()];
+ vec.toArray(classes);
+ return classes;
+ }
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/util/DefaultClassLoaderReference.java bcel/src/java/org/aspectj/apache/bcel/util/DefaultClassLoaderReference.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/util/DefaultClassLoaderReference.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/util/DefaultClassLoaderReference.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,75 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+package org.apache.bcel.util;
+
+/**
+ * Simplistic ClassLoaderReference that merely delegates to a classloader. More sophisticated ones could allow for the
+ * loader to be weakly referenced.
+ *
+ * @author Andy Clement
+ */
+public class DefaultClassLoaderReference implements ClassLoaderReference {
+
+ private java.lang.ClassLoader loader;
+
+ public DefaultClassLoaderReference(java.lang.ClassLoader classLoader) {
+ this.loader = classLoader;
+ }
+
+ public java.lang.ClassLoader getClassLoader() {
+ return loader;
+ }
+
+}
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/util/NonCachingClassLoaderRepository.java bcel/src/java/org/aspectj/apache/bcel/util/NonCachingClassLoaderRepository.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/util/NonCachingClassLoaderRepository.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/util/NonCachingClassLoaderRepository.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,246 @@
+package org.apache.bcel.util;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.AbstractMap;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.bcel.classfile.ClassParser;
+import org.apache.bcel.classfile.JavaClass;
+
+/**
+ * The repository maintains information about which classes have
+ * been loaded.
+ *
+ * It loads its data from the ClassLoader implementation
+ * passed into its constructor.
+ *
+ * @see org.apache.bcel.Repository
+ *
+ * @version $Id: NonCachingClassLoaderRepository.java,v 1.4 2008/08/26 15:02:51 aclement Exp $
+ * @author M. Dahm
+ * @author David Dixon-Peugh
+ *
+ */
+public class NonCachingClassLoaderRepository
+ implements Repository
+{
+ private static java.lang.ClassLoader bootClassLoader = null;
+
+ private ClassLoaderReference loaderRef;
+ private Map loadedClasses =
+ new SoftHashMap(); // CLASSNAME X JAVACLASS
+
+ public static class SoftHashMap extends AbstractMap {
+ private Map map;
+ private ReferenceQueue rq = new ReferenceQueue();
+
+ public SoftHashMap(Map map) { this.map = map; }
+ public SoftHashMap() { this(new HashMap()); }
+ public SoftHashMap(Map map, boolean b) { this(map); }
+
+ class SpecialValue extends SoftReference {
+ private final Object key;
+ SpecialValue(Object k,Object v) {
+ super(v,rq);
+ this.key = k;
+ }
+ }
+
+ private void processQueue() {
+ SpecialValue sv = null;
+ while ((sv = (SpecialValue)rq.poll())!=null) {
+ map.remove(sv.key);
+ }
+ }
+
+ public Object get(Object key) {
+ SpecialValue value = (SpecialValue)map.get(key);
+ if (value==null) return null;
+ if (value.get()==null) {
+ // it got GC'd
+ map.remove(value.key);
+ return null;
+ } else {
+ return value.get();
+ }
+ }
+
+ public Object put(Object k, Object v) {
+ processQueue();
+ return map.put(k, new SpecialValue(k,v));
+ }
+
+ public Set entrySet() {
+ return map.entrySet();
+ }
+
+ public void clear() {
+ processQueue();
+ Set keys = map.keySet();
+ for (Iterator iterator = keys.iterator(); iterator.hasNext();) {
+ Object name = iterator.next();
+ map.remove(name);
+ }
+ }
+
+ public int size() {
+ processQueue();
+ return map.size();
+ }
+
+ public Object remove(Object k) {
+ processQueue();
+ SpecialValue value = (SpecialValue)map.remove(k);
+ if (value==null) return null;
+ if (value.get()!=null) {
+ return value.get();
+ }
+ return null;
+ }
+ }
+
+ public NonCachingClassLoaderRepository(java.lang.ClassLoader loader) {
+ this.loaderRef = new DefaultClassLoaderReference((loader != null) ? loader : getBootClassLoader());
+ }
+
+ public NonCachingClassLoaderRepository(ClassLoaderReference loaderRef) {
+ this.loaderRef = loaderRef;
+ }
+
+ private static synchronized java.lang.ClassLoader getBootClassLoader() {
+ if (bootClassLoader == null) {
+ bootClassLoader = new URLClassLoader(new URL[0]);
+ }
+ return bootClassLoader;
+ }
+
+ /**
+ * Store a new JavaClass into this Repository.
+ */
+ public void storeClass( JavaClass clazz ) {
+ loadedClasses.put( clazz.getClassName(),
+ clazz );
+ clazz.setRepository( this );
+ }
+
+ /**
+ * Remove class from repository
+ */
+ public void removeClass(JavaClass clazz) {
+ loadedClasses.remove(clazz.getClassName());
+ }
+
+ /**
+ * Find an already defined JavaClass.
+ */
+ public JavaClass findClass( String className ) {
+ if ( loadedClasses.containsKey( className )) {
+ return (JavaClass) loadedClasses.get( className );
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Lookup a JavaClass object from the Class Name provided.
+ */
+ public JavaClass loadClass( String className )
+ throws ClassNotFoundException
+ {
+ String classFile = className.replace('.', '/');
+
+ JavaClass RC = findClass( className );
+ if (RC != null) { return RC; }
+
+ try {
+ InputStream is =
+ loaderRef.getClassLoader().getResourceAsStream(classFile + ".class");
+
+ if(is == null) {
+ throw new ClassNotFoundException(className + " not found.");
+ }
+
+ ClassParser parser = new ClassParser( is, className );
+ RC = parser.parse();
+
+ storeClass( RC );
+
+ return RC;
+ } catch (IOException e) {
+ throw new ClassNotFoundException( e.toString() );
+ }
+ }
+
+ public JavaClass loadClass(Class clazz) throws ClassNotFoundException {
+ return loadClass(clazz.getName());
+ }
+
+ /** Clear all entries from cache.
+ */
+ public void clear() {
+ loadedClasses.clear();
+ }
+}
+
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/util/Repository.java bcel/src/java/org/aspectj/apache/bcel/util/Repository.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/util/Repository.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/util/Repository.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,105 @@
+package org.apache.bcel.util;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+import org.apache.bcel.classfile.JavaClass;
+
+/**
+ * Abstract definition of a class repository. Instances may be used
+ * to load classes from different sources and may be used in the
+ * Repository.setRepository method.
+ *
+ * @see org.apache.bcel.Repository
+ * @version $Id: Repository.java,v 1.4 2008/08/28 00:01:38 aclement Exp $
+ * @author M. Dahm
+ * @author David Dixon-Peugh
+ */
+public interface Repository {
+ /**
+ * Store the provided class under "clazz.getClassName()"
+ */
+ public void storeClass(JavaClass clazz);
+
+ /**
+ * Remove class from repository
+ */
+ public void removeClass(JavaClass clazz);
+
+ /**
+ * Find the class with the name provided, if the class
+ * isn't there, return NULL.
+ */
+ public JavaClass findClass(String className);
+
+ /**
+ * Find the class with the name provided, if the class
+ * isn't there, make an attempt to load it.
+ */
+ public JavaClass loadClass(String className)
+ throws java.lang.ClassNotFoundException;
+
+ /**
+ * Find the JavaClass instance for the given run-time class object
+ */
+ public JavaClass loadClass(Class clazz)
+ throws java.lang.ClassNotFoundException;
+
+ /** Clear all entries from cache.
+ */
+ public void clear();
+}
+
+
+
diff -N -a -u -r -b bcel-5.1/src/java/org/aspectj/apache/bcel/util/SyntheticRepository.java bcel/src/java/org/aspectj/apache/bcel/util/SyntheticRepository.java
--- bcel-5.1/src/java/org/aspectj/apache/bcel/util/SyntheticRepository.java 1970-01-01 01:00:00.000000000 +0100
+++ bcel/src/java/org/aspectj/apache/bcel/util/SyntheticRepository.java 2010-03-20 04:20:10.000000000 +0100
@@ -0,0 +1,205 @@
+package org.apache.bcel.util;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache BCEL" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache BCEL", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.WeakHashMap;
+
+import org.apache.bcel.classfile.ClassParser;
+import org.apache.bcel.classfile.JavaClass;
+
+/**
+ * This repository is used in situations where a Class is created
+ * outside the realm of a ClassLoader. Classes are loaded from
+ * the file systems using the paths specified in the given
+ * class path. By default, this is the value returned by
+ * ClassPath.getClassPath().
+ *
+ * It is designed to be used as a singleton, however it
+ * can also be used with custom classpaths.
+ *
+/**
+ * Abstract definition of a class repository. Instances may be used
+ * to load classes from different sources and may be used in the
+ * Repository.setRepository method.
+ *
+ * @see org.apache.bcel.Repository
+ *
+ * @version $Id: SyntheticRepository.java,v 1.7 2008/05/28 23:52:53 aclement Exp $
+ * @author M. Dahm
+ * @author David Dixon-Peugh
+ */
+public class SyntheticRepository implements Repository {
+ private static final String DEFAULT_PATH = ClassPath.getClassPath();
+
+ private static HashMap _instances = new HashMap(); // CLASSPATH X REPOSITORY
+
+ private ClassPath _path = null;
+ private WeakHashMap _loadedClasses = new WeakHashMap(); // CLASSNAME X JAVACLASS
+
+ private SyntheticRepository(ClassPath path) {
+ _path = path;
+ }
+
+ public static SyntheticRepository getInstance() {
+ return getInstance(ClassPath.getSystemClassPath());
+ }
+
+ public static SyntheticRepository getInstance(ClassPath classPath) {
+ SyntheticRepository rep = (SyntheticRepository)_instances.get(classPath);
+
+ if(rep == null) {
+ rep = new SyntheticRepository(classPath);
+ _instances.put(classPath, rep);
+ }
+
+ return rep;
+ }
+
+ /**
+ * Store a new JavaClass instance into this Repository.
+ */
+ public void storeClass(JavaClass clazz) {
+ _loadedClasses.put(clazz.getClassName(), clazz);
+ clazz.setRepository(this);
+ }
+
+ /**
+ * Remove class from repository
+ */
+ public void removeClass(JavaClass clazz) {
+ _loadedClasses.remove(clazz.getClassName());
+ }
+
+ /**
+ * Find an already defined (cached) JavaClass object by name.
+ */
+ public JavaClass findClass(String className) {
+ return (JavaClass)_loadedClasses.get(className);
+ }
+
+ /**
+ * Load a JavaClass object for the given class name using
+ * the CLASSPATH environment variable.
+ */
+ public JavaClass loadClass(String className)
+ throws ClassNotFoundException
+ {
+ if(className == null || className.equals("")) {
+ throw new IllegalArgumentException("Invalid class name " + className);
+ }
+
+ className = className.replace('/', '.'); // Just in case, canonical form
+
+ try {
+ return loadClass(_path.getInputStream(className), className);
+ } catch(IOException e) {
+ throw new ClassNotFoundException("Exception while looking for class " +
+ className + ": " + e.toString());
+ }
+ }
+
+ /**
+ * Try to find class source via getResourceAsStream().
+ * @see Class
+ * @return JavaClass object for given runtime class
+ */
+ public JavaClass loadClass(Class clazz) throws ClassNotFoundException {
+ String className = clazz.getName();
+ String name = className;
+ int i = name.lastIndexOf('.');
+
+ if(i > 0) {
+ name = name.substring(i + 1);
+ }
+
+ return loadClass(clazz.getResourceAsStream(name + ".class"), className);
+ }
+
+ private JavaClass loadClass(InputStream is, String className)
+ throws ClassNotFoundException
+ {
+ JavaClass clazz = findClass(className);
+
+ if(clazz != null) {
+ return clazz;
+ }
+
+ try {
+ if(is != null) {
+ ClassParser parser = new ClassParser(is, className);
+ clazz = parser.parse();
+
+ storeClass(clazz);
+
+ return clazz;
+ }
+ } catch(IOException e) {
+ throw new ClassNotFoundException("Exception while looking for class " +
+ className + ": " + e.toString());
+ }
+
+ throw new ClassNotFoundException("SyntheticRepository could not load " +
+ className);
+ }
+
+ /** Clear all entries from cache.
+ */
+ public void clear() {
+ _loadedClasses.clear();
+ }
+}