abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r419720 [4/5] - in /incubator/abdera/java/trunk/build: ./ tools/ tools/retroweaver/ tools/retroweaver/docs/ tools/retroweaver/docs/guide/ tools/retroweaver/docs/images/ tools/retroweaver/lib/ tools/retroweaver/release/ tools/retroweaver/src...
Date Thu, 06 Jul 2006 22:08:33 GMT
Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/gui/RetroWeaverGui.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/gui/RetroWeaverGui.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/gui/RetroWeaverGui.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/gui/RetroWeaverGui.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,369 @@
+package com.rc.retroweaver.gui;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Cursor;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.Toolkit;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JFileChooser;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+
+import org.objectweb.asm.commons.EmptyVisitor;
+
+import com.rc.retroweaver.RefVerifier;
+import com.rc.retroweaver.RetroWeaver;
+import com.rc.retroweaver.Weaver;
+import com.rc.retroweaver.event.VerifierListener;
+import com.rc.retroweaver.event.WeaveListener;
+
+/**
+ * A simple graphical user interface for Retroweaver.
+ */
+public class RetroWeaverGui extends JPanel implements WeaveListener,
+		VerifierListener {
+
+	public static void main(String[] args) {
+		String defaultPath = "";
+
+		if (args.length > 0) {
+			if (args[0].equals("-console")) {
+				String a[] = new String[args.length - 1];
+				System.arraycopy(args, 1, a, 0, args.length - 1);
+				Weaver.main(a);
+				return;
+			}
+			defaultPath = args[0];
+		}
+
+		String version = Weaver.getVersion();
+		showInJFrame("RetroWeaver " + version, new RetroWeaverGui(defaultPath));
+	}
+
+	private static void showInJFrame(String title, Component contents) {
+		JFrame frame = new JFrame(title);
+		frame.getContentPane().add(contents);
+		frame.setSize(400, 300);
+		centerOnScreen(frame);
+		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+		frame.setVisible(true);
+	}
+
+	private static void centerOnScreen(JFrame frame) {
+		Dimension frameSize = frame.getSize();
+		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+		int x = (screenSize.width - frameSize.width) / 2;
+		int y = (screenSize.height - frameSize.height) / 2;
+		frame.setLocation(x, y);
+	}
+
+	public RetroWeaverGui(String defaultPath) {
+		super(new BorderLayout());
+		refClassPath = new JTextField();
+		add(createParameterSection(), BorderLayout.NORTH);
+		add(createMessageArea(), BorderLayout.CENTER);
+		add(createSouthSection(), BorderLayout.SOUTH);
+		pathField.setText(defaultPath);
+	}
+
+	public void weavingStarted(String msg) {
+		messages.append("[RetroWeaver] " + msg + "\n");
+		messageScrollPane.getVerticalScrollBar().setValue(
+				messageScrollPane.getVerticalScrollBar().getMaximum());
+	}
+
+	public void weavingPath(String sourcePath) {
+		String pathAsString = path.getAbsolutePath();
+		if (sourcePath.startsWith(pathAsString)) {
+			sourcePath = sourcePath.substring(pathAsString.length());
+		}
+		messages.append("[RetroWeaver] Weaving " + sourcePath + "\n");
+		messageScrollPane.getVerticalScrollBar().setValue(
+				messageScrollPane.getVerticalScrollBar().getMaximum());
+	}
+
+	public void weavingCompleted(String msg) {
+		messages.append("[RetroWeaver] " + msg + "\n");
+		messageScrollPane.getVerticalScrollBar().setValue(
+				messageScrollPane.getVerticalScrollBar().getMaximum());	
+	}
+
+	public void verifyPathStarted(String msg) {
+		displayVerifierMessage(msg);
+	}
+
+	public void verifyClassStarted(String msg) {
+		displayVerifierMessage(msg);
+	}
+
+	public void acceptWarning(String msg) {
+		displayVerifierMessage(msg);
+	}
+
+	public void displaySummary(int warningCount) {
+		displayVerifierMessage("Verification complete, " + warningCount
+				+ " warning(s).");
+	}
+
+	private void displayVerifierMessage(String msg) {
+		messages.append("[RefVerifier] " + msg + "\n");
+		messageScrollPane.getVerticalScrollBar().setValue(
+				messageScrollPane.getVerticalScrollBar().getMaximum());
+	}
+
+	private Component createParameterSection() {
+		JPanel ret = new JPanel(new GridBagLayout());
+		addAt(ret, 0, 0, new JLabel("Source:"));
+		addAt(ret, 1, 0, GridBagConstraints.HORIZONTAL, 2, 0.0,
+				createPathField());
+		addAt(ret, 3, 0, createBrowse());
+		addAt(ret, 0, 1, new JLabel("Target:"));
+		addAt(ret, 1, 1, createTargetChooser());
+		addAt(ret, 2, 1, GridBagConstraints.HORIZONTAL, 1, 1.0, new JPanel());
+		addAt(ret, 0, 2, new JLabel("Ref Verify Classpath:"));
+		addAt(ret, 1, 2, GridBagConstraints.HORIZONTAL, 2, 0.0, refClassPath);
+		addAt(ret, 3, 2, GridBagConstraints.HORIZONTAL, 1, 1.0, new JPanel());
+		return ret;
+	}
+
+	private Component createSouthSection() {
+		JPanel ret = new JPanel(new BorderLayout());
+		ret.add(createActionButtons(), BorderLayout.CENTER);
+		ret.add(createStatus(), BorderLayout.SOUTH);
+		ret.setBorder(BorderFactory.createEmptyBorder(INSET_SIZE, INSET_SIZE,
+				INSET_SIZE, INSET_SIZE));
+		return ret;
+	}
+
+	private Component createActionButtons() {
+		JPanel ret = new JPanel(new FlowLayout(FlowLayout.RIGHT));
+		ret.add(createTransform());
+		ret.add(createExit());
+		return ret;
+	}
+
+	private Component createPathField() {
+		pathField = new JTextField();
+		pathField.getDocument().addDocumentListener(new DocumentListener() {
+			public void insertUpdate(DocumentEvent e) {
+				doPathChanged();
+			}
+
+			public void removeUpdate(DocumentEvent e) {
+				doPathChanged();
+			}
+
+			public void changedUpdate(DocumentEvent e) {
+				// do nothing
+			}
+		});
+		return pathField;
+	}
+
+	private Component createBrowse() {
+		browse = new JButton("Browse...");
+		browse.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent e) {
+				doBrowse();
+			}
+		});
+		return browse;
+	}
+
+	private Component createTargetChooser() {
+		targetCombo = new JComboBox(new String[] { "1.4", "1.3", "1.2" });
+		targetCombo.setSelectedIndex(0);
+		targetCombo.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent e) {
+				status.setText(READY);
+			}
+		});
+		return targetCombo;
+	}
+
+	private Component createTransform() {
+		transform = new JButton("Transform");
+		transform.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent e) {
+				doTransform();
+			}
+		});
+		return transform;
+	}
+
+	private Component createExit() {
+		exit = new JButton("Exit");
+		exit.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent e) {
+				doExit();
+			}
+		});
+		return exit;
+	}
+
+	private Component createStatus() {
+		status = new JLabel(READY);
+		return status;
+	}
+
+	private Component createMessageArea() {
+		JPanel ret = new JPanel(new BorderLayout());
+		ret.setBorder(BorderFactory.createTitledBorder("Messages"));
+		messages = new JTextArea();
+		messageScrollPane = new JScrollPane(messages);
+		ret.add(messageScrollPane, BorderLayout.CENTER);
+		return ret;
+	}
+
+	private void addAt(Container container, int x, int y, Component component) {
+		addAt(container, x, y, 0, 1, 0.0, component);
+	}
+
+	private void addAt(Container container, int x, int y, int fill,
+			int gridwidth, double weightx, Component component) {
+		GridBagConstraints constraints = new GridBagConstraints();
+		constraints.gridx = x;
+		constraints.gridy = y;
+		constraints.fill = fill;
+		constraints.insets = INSETS;
+		constraints.gridwidth = gridwidth;
+		constraints.weightx = weightx;
+		container.add(component, constraints);
+	}
+
+	private void doTransform() {
+
+		if (runWeaverThread != null && runWeaverThread.isAlive()) {
+			JOptionPane
+					.showMessageDialog(this,
+							"RetroWeaver is already running, wait until it has finished ");
+			return;
+		}
+
+		path = new File(pathField.getText());
+
+		if (!path.exists()) {
+			status.setText("Error: Path \"" + path + "\" does not exist");
+			return;
+		}
+
+		version = VERSION_NUMBERS[targetCombo.getSelectedIndex()];
+		runWeaverThread = createWeaverThread();
+		runWeaverThread.start();
+	}
+
+	private void doBrowse() {
+		JFileChooser fileChooser = new JFileChooser();
+		fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+
+		if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
+			return;
+		}
+
+		pathField.setText(fileChooser.getSelectedFile().getAbsolutePath());
+		status.setText(READY);
+	}
+
+	private void doExit() {
+		JFrame frame = (JFrame) getTopLevelAncestor();
+		frame.dispose();
+	}
+
+	private void doPathChanged() {
+		status.setText(READY);
+	}
+
+	private JButton transform;
+
+	private JButton browse;
+
+	private JTextField pathField;
+
+	private JTextField refClassPath;
+
+	private JComboBox targetCombo;
+
+	private JLabel status;
+
+	private JButton exit;
+
+	private JTextArea messages;
+
+	private int version;
+
+	private File path;
+
+	private JScrollPane messageScrollPane;
+
+	private static final String READY = "Ready";
+
+	private static final int INSET_SIZE = 3;
+
+	private static final Insets INSETS = new Insets(INSET_SIZE, INSET_SIZE,
+			INSET_SIZE, INSET_SIZE);
+
+	private static final int[] VERSION_NUMBERS = new int[] {
+			Weaver.VERSION_1_4, Weaver.VERSION_1_3, Weaver.VERSION_1_2 };
+
+	private Thread runWeaverThread;
+
+	private Thread createWeaverThread() {
+		return new Thread(new Runnable() {
+			public void run() {
+				Cursor oldCursor = getTopLevelAncestor().getCursor();
+				getTopLevelAncestor().setCursor(
+						Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+
+				try {
+					status.setText("Running");
+					RetroWeaver weaver = new RetroWeaver(version);
+					messages.setText("");
+					weaver.setListener(RetroWeaverGui.this);
+
+					String refCp = refClassPath.getText();
+
+					if (refCp.length() != 0) {
+						java.util.List<String> classpath = new ArrayList<String>();
+						StringTokenizer st = new StringTokenizer(refCp,
+								File.pathSeparator);
+						while (st.hasMoreTokens()) {
+							classpath.add(st.nextToken());
+						}
+						RefVerifier verifier = new RefVerifier(version, new EmptyVisitor(), classpath,
+								RetroWeaverGui.this);
+						weaver.setVerifier(verifier);
+					}
+
+					weaver.weave(path);
+
+					status.setText("Done");
+				} catch (Exception ex) {
+					status.setText("Error: " + ex.getMessage());
+				} finally {
+					getTopLevelAncestor().setCursor(oldCursor);
+				}
+			}
+		});
+	}
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/AnnotationConstantsCollector.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/AnnotationConstantsCollector.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/AnnotationConstantsCollector.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/AnnotationConstantsCollector.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,150 @@
+/***
+ * ASM: a very small and fast Java bytecode manipulation framework
+ * Copyright (c) 2000-2005 INRIA, France Telecom
+ * 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. Neither the name of the copyright holders nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS 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 COPYRIGHT OWNER OR 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.
+ */
+package com.rc.retroweaver.optimizer;
+
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.Type;
+
+/**
+ * An {@link AnnotationVisitor} that collects the {@link Constant}s of the
+ * annotations it visits.
+ * 
+ * @author Eric Bruneton
+ */
+public class AnnotationConstantsCollector implements AnnotationVisitor {
+
+    private AnnotationVisitor av;
+
+    private ConstantPool cp;
+
+    public AnnotationConstantsCollector(
+        final AnnotationVisitor av,
+        final ConstantPool cp)
+    {
+        this.av = av;
+        this.cp = cp;
+    }
+
+    public void visit(final String name, final Object value) {
+        if (name != null) {
+            cp.newUTF8(name);
+        }
+        if (value instanceof Byte) {
+            cp.newInteger(((Byte) value).byteValue());
+        } else if (value instanceof Boolean) {
+            cp.newInteger(((Boolean) value).booleanValue() ? 1 : 0);
+        } else if (value instanceof Character) {
+            cp.newInteger(((Character) value).charValue());
+        } else if (value instanceof Short) {
+            cp.newInteger(((Short) value).shortValue());
+        } else if (value instanceof Type) {
+            cp.newUTF8(((Type) value).getDescriptor());
+        } else if (value instanceof byte[]) {
+            byte[] v = (byte[]) value;
+            for (int i = 0; i < v.length; i++) {
+                cp.newInteger(v[i]);
+            }
+        } else if (value instanceof boolean[]) {
+            boolean[] v = (boolean[]) value;
+            for (int i = 0; i < v.length; i++) {
+                cp.newInteger(v[i] ? 1 : 0);
+            }
+        } else if (value instanceof short[]) {
+            short[] v = (short[]) value;
+            for (int i = 0; i < v.length; i++) {
+                cp.newInteger(v[i]);
+            }
+        } else if (value instanceof char[]) {
+            char[] v = (char[]) value;
+            for (int i = 0; i < v.length; i++) {
+                cp.newInteger(v[i]);
+            }
+        } else if (value instanceof int[]) {
+            int[] v = (int[]) value;
+            for (int i = 0; i < v.length; i++) {
+                cp.newInteger(v[i]);
+            }
+        } else if (value instanceof long[]) {
+            long[] v = (long[]) value;
+            for (int i = 0; i < v.length; i++) {
+                cp.newLong(v[i]);
+            }
+        } else if (value instanceof float[]) {
+            float[] v = (float[]) value;
+            for (int i = 0; i < v.length; i++) {
+                cp.newFloat(v[i]);
+            }
+        } else if (value instanceof double[]) {
+            double[] v = (double[]) value;
+            for (int i = 0; i < v.length; i++) {
+                cp.newDouble(v[i]);
+            }
+        } else {
+            cp.newConst(value);
+        }
+        av.visit(name, value);
+    }
+
+    public void visitEnum(
+        final String name,
+        final String desc,
+        final String value)
+    {
+        if (name != null) {
+            cp.newUTF8(name);
+        }
+        cp.newUTF8(desc);
+        cp.newUTF8(value);
+        av.visitEnum(name, desc, value);
+    }
+
+    public AnnotationVisitor visitAnnotation(
+        final String name,
+        final String desc)
+    {
+        if (name != null) {
+            cp.newUTF8(name);
+        }
+        cp.newUTF8(desc);
+        return new AnnotationConstantsCollector(av.visitAnnotation(name, desc),
+                cp);
+    }
+
+    public AnnotationVisitor visitArray(final String name) {
+        if (name != null) {
+            cp.newUTF8(name);
+        }
+        return new AnnotationConstantsCollector(av.visitArray(name), cp);
+    }
+
+    public void visitEnd() {
+        av.visitEnd();
+    }
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/ClassConstantsCollector.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/ClassConstantsCollector.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/ClassConstantsCollector.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/ClassConstantsCollector.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,212 @@
+/***
+ * ASM: a very small and fast Java bytecode manipulation framework
+ * Copyright (c) 2000-2005 INRIA, France Telecom
+ * 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. Neither the name of the copyright holders nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS 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 COPYRIGHT OWNER OR 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.
+ */
+package com.rc.retroweaver.optimizer;
+
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.Attribute;
+import org.objectweb.asm.ClassAdapter;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+
+/**
+ * A {@link ClassVisitor} that collects the {@link Constant}s of the classes it
+ * visits.
+ * 
+ * @author Eric Bruneton
+ */
+public class ClassConstantsCollector extends ClassAdapter {
+
+    private ConstantPool cp;
+
+    public ClassConstantsCollector(final ClassVisitor cv, final ConstantPool cp)
+    {
+        super(cv);
+        this.cp = cp;
+    }
+
+    public void visit(
+        final int version,
+        final int access,
+        final String name,
+        final String signature,
+        final String superName,
+        final String[] interfaces)
+    {
+        if ((access & Opcodes.ACC_DEPRECATED) != 0) {
+            cp.newUTF8("Deprecated");
+        }
+        if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
+            cp.newUTF8("Synthetic");
+        }
+        cp.newClass(name);
+        if (signature != null) {
+            cp.newUTF8("Signature");
+            cp.newUTF8(signature);
+        }
+        if (superName != null) {
+            cp.newClass(superName);
+        }
+        if (interfaces != null) {
+            for (int i = 0; i < interfaces.length; ++i) {
+                cp.newClass(interfaces[i]);
+            }
+        }
+        cv.visit(version, access, name, signature, superName, interfaces);
+    }
+
+    public void visitSource(final String source, final String debug) {
+        if (source != null) {
+            cp.newUTF8("SourceFile");
+            cp.newUTF8(source);
+        }
+        if (debug != null) {
+            cp.newUTF8("SourceDebugExtension");
+        }
+        cv.visitSource(source, debug);
+    }
+
+    public void visitOuterClass(
+        final String owner,
+        final String name,
+        final String desc)
+    {
+        cp.newUTF8("EnclosingMethod");
+        cp.newClass(owner);
+        if (name != null && desc != null) {
+            cp.newNameType(name, desc);
+        }
+        cv.visitOuterClass(owner, name, desc);
+    }
+
+    public AnnotationVisitor visitAnnotation(
+        final String desc,
+        final boolean visible)
+    {
+        cp.newUTF8(desc);
+        if (visible) {
+            cp.newUTF8("RuntimeVisibleAnnotations");
+        } else {
+            cp.newUTF8("RuntimeInvisibleAnnotations");
+        }
+        return new AnnotationConstantsCollector(cv.visitAnnotation(desc,
+                visible), cp);
+    }
+
+    public void visitAttribute(final Attribute attr) {
+        // can do nothing
+        cv.visitAttribute(attr);
+    }
+
+    public void visitInnerClass(
+        final String name,
+        final String outerName,
+        final String innerName,
+        final int access)
+    {
+        cp.newUTF8("InnerClasses");
+        if (name != null) {
+            cp.newClass(name);
+        }
+        if (outerName != null) {
+            cp.newClass(outerName);
+        }
+        if (innerName != null) {
+            cp.newClass(innerName);
+        }
+        cv.visitInnerClass(name, outerName, innerName, access);
+    }
+
+    public FieldVisitor visitField(
+        final int access,
+        final String name,
+        final String desc,
+        final String signature,
+        final Object value)
+    {
+        if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
+            cp.newUTF8("Synthetic");
+        }
+        if ((access & Opcodes.ACC_DEPRECATED) != 0) {
+            cp.newUTF8("Deprecated");
+        }
+        cp.newUTF8(name);
+        cp.newUTF8(desc);
+        if (signature != null) {
+            cp.newUTF8("Signature");
+            cp.newUTF8(signature);
+        }
+        if (value != null) {
+            cp.newConst(value);
+        }
+        return new FieldConstantsCollector(cv.visitField(access,
+                name,
+                desc,
+                signature,
+                value), cp);
+    }
+
+    public MethodVisitor visitMethod(
+        final int access,
+        final String name,
+        final String desc,
+        final String signature,
+        final String[] exceptions)
+    {
+        if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
+            cp.newUTF8("Synthetic");
+        }
+        if ((access & Opcodes.ACC_DEPRECATED) != 0) {
+            cp.newUTF8("Deprecated");
+        }
+        cp.newUTF8(name);
+        cp.newUTF8(desc);
+        if (signature != null) {
+            cp.newUTF8("Signature");
+            cp.newUTF8(signature);
+        }
+        if (exceptions != null) {
+            cp.newUTF8("Exceptions");
+            for (int i = 0; i < exceptions.length; ++i) {
+                cp.newClass(exceptions[i]);
+            }
+        }
+        return new MethodConstantsCollector(cv.visitMethod(access,
+                name,
+                desc,
+                signature,
+                exceptions), cp);
+    }
+
+    public void visitEnd() {
+        cv.visitEnd();
+    }
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/Constant.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/Constant.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/Constant.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/Constant.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,267 @@
+/***
+ * ASM: a very small and fast Java bytecode manipulation framework
+ * Copyright (c) 2000-2005 INRIA, France Telecom
+ * 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. Neither the name of the copyright holders nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS 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 COPYRIGHT OWNER OR 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.
+ */
+package com.rc.retroweaver.optimizer;
+
+import org.objectweb.asm.ClassWriter;
+
+/**
+ * A constant pool item.
+ * 
+ * @author Eric Bruneton
+ */
+public
+class Constant {
+
+    /**
+     * Type of this constant pool item. A single class is used to represent all
+     * constant pool item types, in order to minimize the bytecode size of this
+     * package. The value of this field is I, J, F, D, S, s, C, T, G, M, or N
+     * (for Constant Integer, Long, Float, Double, STR, UTF8, Class, NameType,
+     * Fieldref, Methodref, or InterfaceMethodref constant pool items
+     * respectively).
+     */
+    char type;
+
+    /**
+     * Value of this item, for an integer item.
+     */
+    int intVal;
+
+    /**
+     * Value of this item, for a long item.
+     */
+    long longVal;
+
+    /**
+     * Value of this item, for a float item.
+     */
+    float floatVal;
+
+    /**
+     * Value of this item, for a double item.
+     */
+    double doubleVal;
+
+    /**
+     * First part of the value of this item, for items that do not hold a
+     * primitive value.
+     */
+    String strVal1;
+
+    /**
+     * Second part of the value of this item, for items that do not hold a
+     * primitive value.
+     */
+    String strVal2;
+
+    /**
+     * Third part of the value of this item, for items that do not hold a
+     * primitive value.
+     */
+    String strVal3;
+
+    /**
+     * The hash code value of this constant pool item.
+     */
+    int hashCode;
+
+    public Constant() {
+    }
+
+    public Constant(final Constant i) {
+        type = i.type;
+        intVal = i.intVal;
+        longVal = i.longVal;
+        floatVal = i.floatVal;
+        doubleVal = i.doubleVal;
+        strVal1 = i.strVal1;
+        strVal2 = i.strVal2;
+        strVal3 = i.strVal3;
+        hashCode = i.hashCode;
+    }
+
+    /**
+     * Sets this item to an integer item.
+     * 
+     * @param intVal the value of this item.
+     */
+    void set(final int intVal) {
+        this.type = 'I';
+        this.intVal = intVal;
+        this.hashCode = 0x7FFFFFFF & (type + intVal);
+    }
+
+    /**
+     * Sets this item to a long item.
+     * 
+     * @param longVal the value of this item.
+     */
+    void set(final long longVal) {
+        this.type = 'J';
+        this.longVal = longVal;
+        this.hashCode = 0x7FFFFFFF & (type + (int) longVal);
+    }
+
+    /**
+     * Sets this item to a float item.
+     * 
+     * @param floatVal the value of this item.
+     */
+    void set(final float floatVal) {
+        this.type = 'F';
+        this.floatVal = floatVal;
+        this.hashCode = 0x7FFFFFFF & (type + (int) floatVal);
+    }
+
+    /**
+     * Sets this item to a double item.
+     * 
+     * @param doubleVal the value of this item.
+     */
+    void set(final double doubleVal) {
+        this.type = 'D';
+        this.doubleVal = doubleVal;
+        this.hashCode = 0x7FFFFFFF & (type + (int) doubleVal);
+    }
+
+    /**
+     * Sets this item to an item that do not hold a primitive value.
+     * 
+     * @param type the type of this item.
+     * @param strVal1 first part of the value of this item.
+     * @param strVal2 second part of the value of this item.
+     * @param strVal3 third part of the value of this item.
+     */
+    void set(
+        final char type,
+        final String strVal1,
+        final String strVal2,
+        final String strVal3)
+    {
+        this.type = type;
+        this.strVal1 = strVal1;
+        this.strVal2 = strVal2;
+        this.strVal3 = strVal3;
+        switch (type) {
+            case 's':
+            case 'S':
+            case 'C':
+                hashCode = 0x7FFFFFFF & (type + strVal1.hashCode());
+                return;
+            case 'T':
+                hashCode = 0x7FFFFFFF & (type + strVal1.hashCode()
+                        * strVal2.hashCode());
+                return;
+            // case 'G':
+            // case 'M':
+            // case 'N':
+            default:
+                hashCode = 0x7FFFFFFF & (type + strVal1.hashCode()
+                        * strVal2.hashCode() * strVal3.hashCode());
+        }
+    }
+
+    public
+    void write(final ClassWriter cw) {
+        switch (type) {
+            case 'I':
+                cw.newConst(new Integer(intVal));
+                break;
+            case 'J':
+                cw.newConst(new Long(longVal));
+                break;
+            case 'F':
+                cw.newConst(new Float(floatVal));
+                break;
+            case 'D':
+                cw.newConst(new Double(doubleVal));
+                break;
+            case 'S':
+                cw.newConst(strVal1);
+                break;
+            case 's':
+                cw.newUTF8(strVal1);
+                break;
+            case 'C':
+                cw.newClass(strVal1);
+                break;
+            case 'T':
+                cw.newNameType(strVal1, strVal2);
+                break;
+            case 'G':
+                cw.newField(strVal1, strVal2, strVal3);
+                break;
+            case 'M':
+                cw.newMethod(strVal1, strVal2, strVal3, false);
+                break;
+            case 'N':
+                cw.newMethod(strVal1, strVal2, strVal3, true);
+                break;
+        }
+    }
+
+    public boolean equals(final Object o) {
+        if (!(o instanceof Constant)) {
+            return false;
+        }
+        Constant c = (Constant) o;
+        if (c.type == type) {
+            switch (type) {
+                case 'I':
+                    return c.intVal == intVal;
+                case 'J':
+                    return c.longVal == longVal;
+                case 'F':
+                    return c.floatVal == floatVal;
+                case 'D':
+                    return c.doubleVal == doubleVal;
+                case 's':
+                case 'S':
+                case 'C':
+                    return c.strVal1.equals(strVal1);
+                case 'T':
+                    return c.strVal1.equals(strVal1)
+                            && c.strVal2.equals(strVal2);
+                // case 'G':
+                // case 'M':
+                // case 'N':
+                default:
+                    return c.strVal1.equals(strVal1)
+                            && c.strVal2.equals(strVal2)
+                            && c.strVal3.equals(strVal3);
+            }
+        }
+        return false;
+    }
+
+    public int hashCode() {
+        return hashCode;
+    }
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/ConstantComparator.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/ConstantComparator.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/ConstantComparator.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/ConstantComparator.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,98 @@
+/***
+ * ASM: a very small and fast Java bytecode manipulation framework
+ * Copyright (c) 2000-2005 INRIA, France Telecom
+ * 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. Neither the name of the copyright holders nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS 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 COPYRIGHT OWNER OR 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.
+ */
+package com.rc.retroweaver.optimizer;
+
+import java.util.Comparator;
+
+    public class ConstantComparator implements Comparator<Constant> {
+
+        public int compare(final Constant c1, final Constant c2) {
+            int d = getSort(c1) - getSort(c2);
+            if (d == 0) {
+                switch (c1.type) {
+                    case 'I':
+                        return new Integer(c1.intVal).compareTo(new Integer(c2.intVal));
+                    case 'J':
+                        return new Long(c1.longVal).compareTo(new Long(c2.longVal));
+                    case 'F':
+                        return new Float(c1.floatVal).compareTo(new Float(c2.floatVal));
+                    case 'D':
+                        return new Double(c1.doubleVal).compareTo(new Double(c2.doubleVal));
+                    case 's':
+                    case 'S':
+                    case 'C':
+                        return c1.strVal1.compareTo(c2.strVal1);
+                    case 'T':
+                        d = c1.strVal1.compareTo(c2.strVal1);
+                        if (d == 0) {
+                            d = c1.strVal2.compareTo(c2.strVal2);
+                        }
+                        break;
+                    default:
+                        d = c1.strVal1.compareTo(c2.strVal1);
+                        if (d == 0) {
+                            d = c1.strVal2.compareTo(c2.strVal2);
+                            if (d == 0) {
+                                d = c1.strVal3.compareTo(c2.strVal3);
+                            }
+                        }
+                }
+            }
+            return d;
+        }
+
+        private int getSort(Constant c) {
+            switch (c.type) {
+                case 'I':
+                    return 0;
+                case 'J':
+                    return 1;
+                case 'F':
+                    return 2;
+                case 'D':
+                    return 3;
+                case 's':
+                    return 4;
+                case 'S':
+                    return 5;
+                case 'C':
+                    return 6;
+                case 'T':
+                    return 7;
+                case 'G':
+                    return 8;
+                case 'M':
+                    return 9;
+                default:
+                    return 10;
+            }
+        }
+    }
+

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/ConstantPool.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/ConstantPool.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/ConstantPool.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/ConstantPool.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,194 @@
+/***
+ * ASM: a very small and fast Java bytecode manipulation framework
+ * Copyright (c) 2000-2005 INRIA, France Telecom
+ * 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. Neither the name of the copyright holders nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS 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 COPYRIGHT OWNER OR 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.
+ */
+package com.rc.retroweaver.optimizer;
+
+import java.util.HashMap;
+
+import org.objectweb.asm.Type;
+
+/**
+ * A constant pool.
+ * 
+ * @author Eric Bruneton
+ */
+public class ConstantPool extends HashMap<Constant, Constant> {
+
+    private Constant key1 = new Constant();
+
+    private Constant key2 = new Constant();
+
+    private Constant key3 = new Constant();
+
+    public Constant newInteger(final int value) {
+        key1.set(value);
+        Constant result = get(key1);
+        if (result == null) {
+            result = new Constant(key1);
+            put(result);
+        }
+        return result;
+    }
+
+    public Constant newFloat(final float value) {
+        key1.set(value);
+        Constant result = get(key1);
+        if (result == null) {
+            result = new Constant(key1);
+            put(result);
+        }
+        return result;
+    }
+
+    public Constant newLong(final long value) {
+        key1.set(value);
+        Constant result = get(key1);
+        if (result == null) {
+            result = new Constant(key1);
+            put(result);
+        }
+        return result;
+    }
+
+    public Constant newDouble(final double value) {
+        key1.set(value);
+        Constant result = get(key1);
+        if (result == null) {
+            result = new Constant(key1);
+            put(result);
+        }
+        return result;
+    }
+
+    public Constant newUTF8(final String value) {
+        key1.set('s', value, null, null);
+        Constant result = get(key1);
+        if (result == null) {
+            result = new Constant(key1);
+            put(result);
+        }
+        return result;
+    }
+
+    private Constant newString(final String value) {
+        key2.set('S', value, null, null);
+        Constant result = get(key2);
+        if (result == null) {
+            newUTF8(value);
+            result = new Constant(key2);
+            put(result);
+        }
+        return result;
+    }
+
+    public Constant newClass(final String value) {
+        key2.set('C', value, null, null);
+        Constant result = get(key2);
+        if (result == null) {
+            newUTF8(value);
+            result = new Constant(key2);
+            put(result);
+        }
+        return result;
+    }
+
+    public Constant newConst(final Object cst) {
+        if (cst instanceof Integer) {
+            int val = ((Integer) cst).intValue();
+            return newInteger(val);
+        } else if (cst instanceof Float) {
+            float val = ((Float) cst).floatValue();
+            return newFloat(val);
+        } else if (cst instanceof Long) {
+            long val = ((Long) cst).longValue();
+            return newLong(val);
+        } else if (cst instanceof Double) {
+            double val = ((Double) cst).doubleValue();
+            return newDouble(val);
+        } else if (cst instanceof String) {
+            return newString((String) cst);
+        } else if (cst instanceof Type) {
+            Type t = (Type) cst;
+            return newClass(t.getSort() == Type.OBJECT
+                    ? t.getInternalName()
+                    : t.getDescriptor());
+        } else {
+            throw new IllegalArgumentException("value " + cst);
+        }
+    }
+
+    public Constant newField(
+        final String owner,
+        final String name,
+        final String desc)
+    {
+        key3.set('G', owner, name, desc);
+        Constant result = get(key3);
+        if (result == null) {
+            newClass(owner);
+            newNameType(name, desc);
+            result = new Constant(key3);
+            put(result);
+        }
+        return result;
+    }
+
+    public Constant newMethod(
+        final String owner,
+        final String name,
+        final String desc,
+        final boolean itf)
+    {
+        key3.set(itf ? 'N' : 'M', owner, name, desc);
+        Constant result = get(key3);
+        if (result == null) {
+            newClass(owner);
+            newNameType(name, desc);
+            result = new Constant(key3);
+            put(result);
+        }
+        return result;
+    }
+
+    public Constant newNameType(final String name, final String desc) {
+        key2.set('T', name, desc, null);
+        Constant result = get(key2);
+        if (result == null) {
+            newUTF8(name);
+            newUTF8(desc);
+            result = new Constant(key2);
+            put(result);
+        }
+        return result;
+    }
+
+    private void put(final Constant cst) {
+        put(cst, cst);
+    }
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/FieldConstantsCollector.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/FieldConstantsCollector.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/FieldConstantsCollector.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/FieldConstantsCollector.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,76 @@
+/***
+ * ASM: a very small and fast Java bytecode manipulation framework
+ * Copyright (c) 2000-2005 INRIA, France Telecom
+ * 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. Neither the name of the copyright holders nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS 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 COPYRIGHT OWNER OR 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.
+ */
+package com.rc.retroweaver.optimizer;
+
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.Attribute;
+import org.objectweb.asm.FieldVisitor;
+
+/**
+ * A {@link FieldVisitor} that collects the {@link Constant}s of the fields it
+ * visits.
+ * 
+ * @author Eric Bruneton
+ */
+public class FieldConstantsCollector implements FieldVisitor {
+
+    private FieldVisitor fv;
+
+    private ConstantPool cp;
+
+    public FieldConstantsCollector(final FieldVisitor fv, final ConstantPool cp)
+    {
+        this.fv = fv;
+        this.cp = cp;
+    }
+
+    public AnnotationVisitor visitAnnotation(
+        final String desc,
+        final boolean visible)
+    {
+        cp.newUTF8(desc);
+        if (visible) {
+            cp.newUTF8("RuntimeVisibleAnnotations");
+        } else {
+            cp.newUTF8("RuntimeInvisibleAnnotations");
+        }
+        return new AnnotationConstantsCollector(fv.visitAnnotation(desc,
+                visible), cp);
+    }
+
+    public void visitAttribute(final Attribute attr) {
+        // can do nothing
+        fv.visitAttribute(attr);
+    }
+
+    public void visitEnd() {
+        fv.visitEnd();
+    }
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/MethodConstantsCollector.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/MethodConstantsCollector.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/MethodConstantsCollector.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/optimizer/MethodConstantsCollector.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,168 @@
+/***
+ * ASM: a very small and fast Java bytecode manipulation framework
+ * Copyright (c) 2000-2005 INRIA, France Telecom
+ * 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. Neither the name of the copyright holders nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS 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 COPYRIGHT OWNER OR 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.
+ */
+package com.rc.retroweaver.optimizer;
+
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.Label;
+import org.objectweb.asm.MethodAdapter;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+
+/**
+ * An {@link MethodVisitor} that collects the {@link Constant}s of the methods
+ * it visits.
+ * 
+ * @author Eric Bruneton
+ */
+public class MethodConstantsCollector extends MethodAdapter {
+
+    private ConstantPool cp;
+
+    public MethodConstantsCollector(
+        final MethodVisitor mv,
+        final ConstantPool cp)
+    {
+        super(mv);
+        this.cp = cp;
+    }
+
+    public AnnotationVisitor visitAnnotationDefault() {
+        cp.newUTF8("AnnotationDefault");
+        return new AnnotationConstantsCollector(mv.visitAnnotationDefault(), cp);
+    }
+
+    public AnnotationVisitor visitAnnotation(
+        final String desc,
+        final boolean visible)
+    {
+        cp.newUTF8(desc);
+        if (visible) {
+            cp.newUTF8("RuntimeVisibleAnnotations");
+        } else {
+            cp.newUTF8("RuntimeInvisibleAnnotations");
+        }
+        return new AnnotationConstantsCollector(mv.visitAnnotation(desc,
+                visible), cp);
+    }
+
+    public AnnotationVisitor visitParameterAnnotation(
+        final int parameter,
+        final String desc,
+        final boolean visible)
+    {
+        cp.newUTF8(desc);
+        if (visible) {
+            cp.newUTF8("RuntimeVisibleParameterAnnotations");
+        } else {
+            cp.newUTF8("RuntimeInvisibleParameterAnnotations");
+        }
+        return new AnnotationConstantsCollector(mv.visitParameterAnnotation(parameter,
+                desc,
+                visible),
+                cp);
+    }
+
+    public void visitTypeInsn(final int opcode, final String desc) {
+        cp.newClass(desc);
+        mv.visitTypeInsn(opcode, desc);
+    }
+
+    public void visitFieldInsn(
+        final int opcode,
+        final String owner,
+        final String name,
+        final String desc)
+    {
+        cp.newField(owner, name, desc);
+        mv.visitFieldInsn(opcode, owner, name, desc);
+    }
+
+    public void visitMethodInsn(
+        final int opcode,
+        final String owner,
+        final String name,
+        final String desc)
+    {
+        boolean itf = opcode == Opcodes.INVOKEINTERFACE;
+        cp.newMethod(owner, name, desc, itf);
+        mv.visitMethodInsn(opcode, owner, name, desc);
+    }
+
+    public void visitLdcInsn(final Object cst) {
+        cp.newConst(cst);
+        mv.visitLdcInsn(cst);
+    }
+
+    public void visitMultiANewArrayInsn(final String desc, final int dims) {
+        cp.newClass(desc);
+        mv.visitMultiANewArrayInsn(desc, dims);
+    }
+
+    public void visitTryCatchBlock(
+        final Label start,
+        final Label end,
+        final Label handler,
+        final String type)
+    {
+        if (type != null) {
+            cp.newClass(type);
+        }
+        mv.visitTryCatchBlock(start, end, handler, type);
+    }
+
+    public void visitLocalVariable(
+        final String name,
+        final String desc,
+        final String signature,
+        final Label start,
+        final Label end,
+        final int index)
+    {
+        if (signature != null) {
+            cp.newUTF8("LocalVariableTypeTable");
+            cp.newUTF8(name);
+            cp.newUTF8(signature);
+        }
+        cp.newUTF8("LocalVariableTable");
+        cp.newUTF8(name);
+        cp.newUTF8(desc);
+        mv.visitLocalVariable(name, desc, signature, start, end, index);
+    }
+
+    public void visitLineNumber(final int line, final Label start) {
+        cp.newUTF8("LineNumberTable");
+        mv.visitLineNumber(line, start);
+    }
+
+    public void visitMaxs(final int maxStack, final int maxLocals) {
+        cp.newUTF8("Code");
+        mv.visitMaxs(maxStack, maxLocals);
+    }
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/Autobox.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/Autobox.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/Autobox.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/Autobox.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,70 @@
+package com.rc.retroweaver.runtime;
+
+/**
+ * A replacement for the new boxing functions which were added for autoboxing in
+ * 1.5.
+ */
+public final class Autobox {
+
+	private static Byte[] byteVals = new Byte[256];
+
+	private static Character[] charVals = new Character[256];
+
+	private static Short[] shortVals = new Short[256];
+
+	private static Integer[] intVals = new Integer[256];
+
+	static {
+		for (int i = 0; i < 256; ++i) {
+			byte val = (byte) (i - 128);
+			byteVals[i] = new Byte(val);
+			charVals[i] = new Character((char) val);
+			shortVals[i] = new Short(val);
+			intVals[i] = new Integer(val);
+		}
+	}
+
+	public static Boolean valueOf(boolean b) {
+		return b ? Boolean.TRUE : Boolean.FALSE;
+	}
+
+	public static Byte valueOf(byte val) {
+		return byteVals[val + 128];
+	}
+
+	public static Character valueOf(char val) {
+		if (val >= -128 && val <= 127) {
+			return charVals[val + 128];
+		} else {
+			return new Character(val);
+		}
+	}
+
+	public static Short valueOf(short val) {
+		if (val >= -128 && val <= 127) {
+			return shortVals[val + 128];
+		} else {
+			return new Short(val);
+		}
+	}
+
+	public static Integer valueOf(int val) {
+		if (val >= -128 && val <= 127) {
+			return intVals[val + 128];
+		} else {
+			return new Integer(val);
+		}
+	}
+
+	public static Long valueOf(long l) {
+		return new Long(l);
+	}
+
+	public static Float valueOf(float f) {
+		return new Float(f);
+	}
+
+	public static Double valueOf(double d) {
+		return new Double(d);
+	}
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/ClassMethods.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/ClassMethods.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/ClassMethods.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/ClassMethods.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,72 @@
+package com.rc.retroweaver.runtime;
+
+/**
+ * Replacements for methods added to java.lang.Class in Java 1.5.
+ */
+public final class ClassMethods {
+
+	/**
+	 * Replacement for Class.asSubclass(Class).
+	 * 
+	 * @param c a Class
+	 * @param superclass another Class which must be a superclass of <i>c</i>
+	 * @return <i>c</i>
+	 * @throws java.lang.ClassCastException if <i>c</i> is
+	 */
+	public static Class asSubclass(Class<?> c, Class<?> superclass) {
+		if (!superclass.isAssignableFrom(c)) {
+			throw new ClassCastException(superclass.getName());
+		}
+		return c;
+	}
+
+	/**
+	 * Replacement for Class.cast(Object). Throws a ClassCastException if <i>obj</i>
+	 * is not an instance of class <var>c</var>, or a subtype of <var>c</var>.
+	 * 
+	 * @param c Class we want to cast <var>obj</var> to
+	 * @param object object we want to cast
+	 * @return The object, or <code>null</code> if the object is
+	 * <code>null</code>.
+	 * @throws java.lang.ClassCastException if <var>obj</var> is not
+	 * <code>null</code> or an instance of <var>c</var>
+	 */
+	public static Object cast(Class c, Object object) {
+		if (object == null || c.isInstance(object)) {
+			return object;
+		} else {
+			throw new ClassCastException(c.getName());
+		}
+	}
+
+	/**
+	 * Replacement for Class.isEnum().
+	 * 
+	 * @param class_ class we want to test.
+	 * @return true if the class was declared as an Enum.
+	 */
+	public static <T> boolean isEnum(Class<T> class_) {
+		Class c = class_.getSuperclass();
+
+		if (c == null) {
+			return false;
+		}
+
+		return Enum_.class.isAssignableFrom(c);
+	}
+
+	/**
+	 * Replacement for Class.getEnumConstants().
+	 * 
+	 * @param class_ class we want to get Enum constants for.
+	 * @return The elements of this enum class or null if this does not represent an enum type.
+	 */
+	public static <T> T[] getEnumConstants(Class<T> class_) {
+		if (!isEnum(class_)) {
+			return null;
+		}
+
+		return Enum_.getEnumValues(class_).clone();
+	}
+
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/Enum_.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/Enum_.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/Enum_.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/Enum_.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,156 @@
+package com.rc.retroweaver.runtime;
+
+import java.io.InvalidObjectException;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A version of the 1.5 java.lang.Enum class for the 1.4 VM.
+ */
+public class Enum_<E extends Enum_<E>> implements Comparable<E>, Serializable {
+
+	private final transient int ordinal;
+
+	private final String name;
+
+	private static final Map<Class, Object[]> enumValues = new HashMap<Class, Object[]>();
+
+	protected Enum_(String name, int ordinal) {
+		this.name = name;
+		this.ordinal = ordinal;
+	}
+
+	protected static final void setEnumValues(Object[] values, Class c) {
+		synchronized(enumValues) {
+			enumValues.put(c, values);
+		}
+	}
+
+	protected static final <T> T[] getEnumValues(Class<T> class_) {
+		synchronized(enumValues) {
+			T[] values = (T[]) enumValues.get(class_);
+			if (values != null)
+				return values;
+		}
+
+		if (!class_.isEnum())
+			return null;
+
+		// force initialization of class_ as
+		// class loader may not have called static initializers yet
+		try {
+			Class.forName(class_.getName(), true, class_.getClassLoader());
+		} catch (ClassNotFoundException e) {
+			// can not happen: class_ has already been resolved.
+		}
+	
+		synchronized(enumValues) {
+			return (T[]) enumValues.get(class_);
+		}
+	}
+
+	/**
+	 * Implement serialization so we can get the singleton behavior we're
+	 * looking for in enums.
+	 */
+	protected Object readResolve() throws ObjectStreamException {
+		/*
+		 * The implementation is based on "Java Object Serialization Specification",
+		 * revision 1.5.0:
+		 * 
+		 * only the name is saved, serialVersionUID is 0L for all enum types
+		 * InvalidObjectException is raised if valueOf() raises IllegalArgumentException.
+		 * 
+		 */
+
+		Class<E> c = getDeclaringClass();
+		/*
+		 * Note: getClass() would not work for enum inner classes
+		 * such as CMYK.Cyan in the test suite.
+		 */
+		try {
+			return valueOf(c, name);
+		} catch (IllegalArgumentException iae) {
+			InvalidObjectException ioe = new InvalidObjectException(name + " is not a valid enum for " + c.getName());
+			try {
+				ioe.initCause(iae);
+			} catch (NoSuchMethodError nsm) {
+				// cause should be set according to the spec but it's only available in 1.4
+			}
+				
+			throw ioe;
+		}
+	}
+
+	public static <T extends Enum_<T>> T valueOf(Class<T> enumType, String name) {
+
+		if (enumType == null) {
+			throw new NullPointerException("enumType is null");
+		}
+
+		if (name == null) {
+			throw new NullPointerException("name is null");
+		}
+
+		T[] enums = getEnumValues(enumType);
+
+		if (enums != null) {
+			for (T enum_ : enums) {
+				if (enum_.name.equals(name)) {
+					return enum_;
+				}
+			}
+		}
+
+		throw new IllegalArgumentException("No enum const " + enumType + "."
+				+ name);
+	}
+
+	public final boolean equals(Object other) {
+		return other == this;
+	}
+
+	public final int hashCode() {
+		return System.identityHashCode(this);
+	}
+
+	public String toString() {
+		return name;
+	}
+
+	public final int compareTo(E e) {
+		Class c1 = getDeclaringClass();
+		Class c2 = e.getDeclaringClass();
+
+		if (c1 == c2) {
+			return ordinal - e.ordinal;
+		}
+
+		throw new ClassCastException();
+	}
+
+	protected final Object clone() throws CloneNotSupportedException {
+		throw new CloneNotSupportedException();
+	}
+
+	public final String name() {
+		return name;
+	}
+
+	public final int ordinal() {
+		return ordinal;
+	}
+
+	public final Class<E> getDeclaringClass() {
+		Class clazz = getClass();
+		Class superClass = clazz.getSuperclass();
+		if (superClass != Enum_.class) {
+			return superClass;
+		} else {
+			return clazz;
+		}
+	}
+
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/IterableMethods.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/IterableMethods.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/IterableMethods.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/IterableMethods.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,53 @@
+package com.rc.retroweaver.runtime;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * Replacements for methods added to java.lang.Iterable in Java 1.5, used
+ * for targets of the "foreach" statement.
+ */
+public final class IterableMethods {
+
+	private IterableMethods() {
+	}
+
+	/**
+	 * Returns an iterator for <code>iterable</code>.
+	 * 
+	 * @param iterable  the object to get the Iterator from
+	 * @return an Iterator.
+	 * @throws UnsupportedOperationException if an iterator method can not be found.
+	 * @throws NullPointerException if <code>iterable</code> is null.
+	 */
+	public static Iterator iterator(Object iterable) {
+		if (iterable == null) {
+			throw new NullPointerException();
+		}
+
+		if (iterable instanceof Collection) {
+			// core jdk classes implementing Iterable: they are not weaved but,
+			// at least in 1.5, they all implement Collection and as its iterator
+			// method exits in pre 1.5 jdks, a valid Iterator can be returned.
+			return ((Collection) iterable).iterator();
+		}
+
+		if (iterable instanceof Iterable_) {
+			// weaved classes inheriting from Iterable
+			return ((Iterable_) iterable).iterator();
+		}
+
+		// for future jdk Iterable classes not inheriting from Collection
+		// use reflection to try to get the iterator if it was present pre 1.5
+		try {
+			Method m = iterable.getClass().getMethod("iterator", (Class[]) null);
+			if (m != null)
+				return (Iterator) m.invoke(iterable, (Object[]) null);
+		} catch (Exception ignored) {
+		}
+
+		throw new UnsupportedOperationException("iterator call on " + iterable.getClass());
+	}
+
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/Iterable_.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/Iterable_.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/Iterable_.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/runtime/Iterable_.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,10 @@
+package com.rc.retroweaver.runtime;
+
+import java.util.Iterator;
+
+/**
+ * A version of the 1.5 java.lang.Iterable class for the 1.4 VM.
+ */
+public interface Iterable_<E> {
+	Iterator<E> iterator();
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/AbstractTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/AbstractTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/AbstractTest.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/AbstractTest.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,23 @@
+package com.rc.retroweaver.tests;
+
+import junit.framework.TestCase;
+
+public abstract class AbstractTest extends TestCase {
+
+	public void success() {
+	}
+
+	public void success(String msg) {
+	}
+
+	public void assertArraySameItems(String msg, Object[] a1, Object[] a2) {
+		if (a1 == null)
+			assertNull(msg, a2);
+		else if (a2 == null || a1.length != a2.length)
+			fail(msg);
+		else {
+			for (int i = 0; i < a1.length; i++)
+				assertSame(msg, a1[i], a2[i]);
+		}
+	}
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/AppendableTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/AppendableTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/AppendableTest.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/AppendableTest.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,30 @@
+package com.rc.retroweaver.tests;
+
+public class AppendableTest extends AbstractTest {
+
+	public void testAppendable() {
+		try {
+			// Should generate a warning - implementing interface from 1.5
+			class Ap implements Appendable {
+				public Appendable append(char c) {
+					return null;
+				}
+
+				public Appendable append(CharSequence csq) {
+					return null;
+				}
+
+				public Appendable append(CharSequence csq, int start, int end) {
+					return null;
+				}
+			}
+
+			new Ap();
+
+			fail("testAppendable should raise a NoClassDefFoundError");
+		} catch (NoClassDefFoundError e) {
+			success("testAppendable");
+		}
+	}
+
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/AutoboxTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/AutoboxTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/AutoboxTest.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/AutoboxTest.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,100 @@
+package com.rc.retroweaver.tests;
+
+/**
+ * Ensures that Retroweaver performs autoboxing conversions
+ */
+
+public class AutoboxTest extends AbstractTest {
+
+	public void testByte() {
+		Byte b;
+		b = -3;
+		assertEquals("ByteSmall", b.byteValue(), (byte) -3);
+		b = 3;
+		assertEquals("ByteSmall", b.byteValue(), (byte) 3);
+	}
+
+	public void testBoolean() {
+		Boolean bool;
+		bool = true;
+		assertTrue("BooleanTrue", bool.booleanValue());
+		bool = false;
+		assertFalse("BooleanFalse", bool.booleanValue());
+	}
+
+	public void testCharacter() {
+		Character c;
+		c = 'a';
+		assertEquals("CharacterSmall", c.charValue(), 'a');
+		c = '\u1000';
+		assertEquals("CharacterLarge", c.charValue(), '\u1000');
+	}
+
+	public void testShort() {
+		Short s;
+		s = -3;
+		assertEquals("ShortSmall", s.shortValue(), (short) -3);
+		s = 3;
+		assertEquals("ShortSmall", s.shortValue(), (short) 3);
+		s = 3000;
+		assertEquals("ShortLarge", s.shortValue(), (short) 3000);
+	}
+
+	public void testInteger() {
+		Integer i;
+		i = -3;
+		assertEquals("IntegerSmall", i.intValue(), -3);
+		i = 3;
+		assertEquals("IntegerSmall", i.intValue(), 3);
+		i = 3000;
+		assertEquals("IntegerLarge", i.intValue(), 3000);
+	}
+
+	public void testLong() {
+		Long l;
+		l = -3L;
+		assertEquals("Long", l.longValue(), -3L);
+		l = 3L;
+		assertEquals("Long", l.longValue(),  3L);
+	}
+
+	public void testFloat() {
+		Float f;
+		f = -3.2f;
+		assertEquals("Float", f.floatValue(), -3.2f);
+		f = 3.2f;
+		assertEquals("Float", f.floatValue(), 3.2f);
+		f = Float.NaN;
+		assertTrue("Float NaN", f.isNaN());
+	}
+
+	public void testDouble() {
+		Double d;
+		d = -3.2d;
+		assertEquals("Double", d.doubleValue(), -3.2d);
+		d = 3.2d;
+		assertEquals("Double", d.doubleValue(), 3.2d);
+		d = Double.NaN;
+		assertTrue("Double NaN", d.isNaN());
+	}
+
+	public void testIdentity() {
+		// tests cached values from lookup tables:
+		// check that same object is returned
+		Boolean b1, b2;
+		b1 = false; b2 = false; assertSame("Boolean", b1, b2);
+		b1 = true; b2 = true; assertSame("Boolean", b1, b2);
+		
+		Byte byte1, byte2;
+		byte1 = 1; byte2 = 1; assertSame("Byte", byte1, byte2);
+		
+		Character c1, c2;
+		c1 = 'c'; c2 = 'c'; assertSame("Character", c1, c2);
+		
+		Short s1, s2;
+		s1 = 1; s2 = 1; assertSame("Short", s1, s2);
+		
+		Integer i1, i2;
+		i1 = 1; i2 = 1; assertSame("Integer", i1, i2);
+	}
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/BigDecimalTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/BigDecimalTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/BigDecimalTest.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/BigDecimalTest.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,23 @@
+package com.rc.retroweaver.tests;
+
+import java.math.BigDecimal;
+
+public class BigDecimalTest extends AbstractTest {
+
+	public void testInt() {
+		int i = Integer.MAX_VALUE;
+		
+		BigDecimal bd = new BigDecimal(i);
+		
+		assertEquals("testInt", bd.toString(), Integer.toString(i));
+	}
+
+	public void testLong() {
+		long l = Long.MAX_VALUE;
+		
+		BigDecimal bd = new BigDecimal(l);
+		
+		assertEquals("testLong", bd.toString(), Long.toString(l));
+	}
+	
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/ClassLiteralTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/ClassLiteralTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/ClassLiteralTest.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/ClassLiteralTest.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,70 @@
+package com.rc.retroweaver.tests;
+
+/**
+ * Ensures that Retroweaver translates LDC/LDC_W instructions for class literals
+ * correctly.
+ */
+
+public class ClassLiteralTest extends AbstractTest {
+
+	public void testClassLiteral() {
+		String name = ClassLiteralTest.class.getName();
+		assertEquals("testClassLiteral1", name,
+				"com.rc.retroweaver.tests.ClassLiteralTest");
+
+		name = String.class.getName();
+		assertEquals("testClassLiteral2", name, "java.lang.String");
+	}
+
+	public void testArrays() {
+		String name = ClassLiteralTest[].class.getName();
+		assertEquals("ClassLiteralTestArray", name,
+				"[Lcom.rc.retroweaver.tests.ClassLiteralTest;");
+		name = ClassLiteralTest[][].class.getName();
+		assertEquals("ClassLiteralTestArray2", name,
+				"[[Lcom.rc.retroweaver.tests.ClassLiteralTest;");
+
+		name = int[].class.getName();
+		assertEquals("intArray", name, "[I");
+	}
+
+	public void testInterface() {
+		Class clazz1 = String.class;
+		Class clazz2 = Integer.class;
+
+		assertEquals("testInterface class 1", clazz1, ClassLiteralTest1.clazz1);
+		assertEquals("testInterface class 2", clazz2, ClassLiteralTest1.clazz2);
+
+		assertEquals("testInterface interface 1", clazz1, ClassLiteralTest2.clazz1);
+		assertEquals("testInterface interface 2", clazz2, ClassLiteralTest2.clazz2);
+	}
+
+	public void testRetroweaverRuntime() {
+		assertTrue("testRetroweaverRuntime Enum", Enum.class.isAssignableFrom(LetterEnum.class));
+
+		assertEquals("testRetroweaverRuntime StringBuilder", StringBuilder.class, new StringBuilder().getClass());
+	}
+
+	public void testMissingClass() {
+		try {
+			Class clazz = MissingClass.class;
+			fail("Class should not be defined: " + clazz.getName());
+		} catch (NoClassDefFoundError e) {
+			success("testMissingClass");
+		}
+	}
+}
+
+class MissingClass {
+	// make sure class is not part of the weaved classes
+}
+
+class ClassLiteralTest1 {
+	static Class clazz1 = String.class;
+	static Class clazz2 = Integer.class;
+}
+
+interface ClassLiteralTest2 {
+	Class clazz1 = String.class;
+	Class clazz2 = Integer.class;
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/ClassMethodsTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/ClassMethodsTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/ClassMethodsTest.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/ClassMethodsTest.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,76 @@
+package com.rc.retroweaver.tests;
+
+/**
+ * Test that calls to 1.5-only Class methods work correctly. Only a subset of
+ * these are actually handled!
+ */
+
+public class ClassMethodsTest extends AbstractTest {
+
+	public void testCast() {
+		Object obj = mystery();
+		assertEquals("testCast", B.class.cast(obj).f(), "B");
+	}
+
+	public void testInvalidCast() {
+		Object obj2 = mystery2();
+		try {
+			B.class.cast(obj2).f();
+			fail("testInvalidCast should raise a ClassCastException");
+		} catch (ClassCastException e) {
+			success("testInvalidCast");
+		}
+	}
+
+	public void testAsSubclass() throws Exception {
+		Class<? extends A> bAsA = getBAsA();
+		Class<? extends B> b = bAsA.asSubclass(B.class);
+
+		B bInstance = b.newInstance();
+		assertEquals("testAsSubclass", bInstance.f(), "B");
+
+	}
+
+	public void testInvalidAsSubclass() {
+		Class<? extends A> cAsA = getCAsA();
+		try {
+			cAsA.asSubclass(B.class);
+			fail("testInvalidAsSubclass should raise a ClassCastException");
+		} catch (ClassCastException e) {
+			success("testInvalidAsSubclass");
+		}
+	}
+
+	static abstract class A {
+		public abstract String f();
+	}
+
+	static class B extends A {
+		public String f() {
+			return "B";
+		}
+	}
+
+	static class C extends A {
+		public String f() {
+			return "C";
+		}
+	}
+
+	public Object mystery() {
+		return new B();
+	}
+
+	public Object mystery2() {
+		return new C();
+	}
+
+	public Class<? extends A> getBAsA() {
+		return B.class;
+	}
+
+	public Class<? extends A> getCAsA() {
+		return C.class;
+	}
+
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/CollectionsTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/CollectionsTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/CollectionsTest.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/CollectionsTest.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,23 @@
+package com.rc.retroweaver.tests;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+public class CollectionsTest extends AbstractTest {
+
+	public void testEmptyList() {
+		List<Object> l = Collections.emptyList();
+		// replaced with Collections.EMPTY_LIST
+
+		assertEquals("testEmptyList", l.size(), 0);
+	}
+
+	public void testEmptySet() {
+		Set<Object> s = Collections.emptySet();
+		// replaced with Collections.EMPTY_SET
+
+		assertEquals("testEmptySet", s.size(), 0);
+	}
+
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/ConcurrentTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/ConcurrentTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/ConcurrentTest.java (added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/ConcurrentTest.java Thu Jul  6 15:08:30 2006
@@ -0,0 +1,28 @@
+package com.rc.retroweaver.tests;
+
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class ConcurrentTest extends AbstractTest {
+
+	public void testConcurrent() {
+		// Should not generate a warning
+		ConcurrentHashMap map = new ConcurrentHashMap();
+
+		assertNotNull("testConcurrent", map);
+	}
+
+	public void testConcurrentClassLiteral() {
+		ConcurrentHashMap map = new ConcurrentHashMap();
+		assertEquals("testConcurrentClassLiteral ConcurrentHashMap", ConcurrentHashMap.class, map.getClass());
+	}
+
+	public void testException() {
+		try {
+			throw new CancellationException();
+		} catch (CancellationException e) {
+			assertNotNull("testException", e);
+		}
+	}
+
+}



Mime
View raw message