You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pc...@apache.org on 2006/06/28 21:46:19 UTC

svn commit: r417860 [11/12] - in /incubator/openjpa/trunk: ./ openjpa-lib/ openjpa-lib/main/ openjpa-lib/src/ openjpa-lib/src/main/ openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ openjpa-lib/src/test/ openjpa-lib/src/test/java/ openjpa-lib/src/...

Added: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/visitor/PrettyPrintVisitor.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/visitor/PrettyPrintVisitor.java?rev=417860&view=auto
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/visitor/PrettyPrintVisitor.java (added)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/visitor/PrettyPrintVisitor.java Wed Jun 28 12:46:13 2006
@@ -0,0 +1,459 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package serp.bytecode.visitor;
+
+import serp.bytecode.*;
+
+import serp.bytecode.lowlevel.*;
+
+import java.io.*;
+
+
+/**
+ *  <p>Visitor type that outputs a detailed, formatted document of the
+ *  visited entity; similar to the <i>javap -c</i> command but more
+ *  detailed.</p>
+ *
+ *  @author Abe White
+ */
+public class PrettyPrintVisitor extends BCVisitor {
+    private PrintWriter _out = null;
+    private String _prefix = "";
+    private int _entryCount = 0;
+
+    /**
+     *  Constructor; all pritning will go to stdout.
+     */
+    public PrettyPrintVisitor() {
+        _out = new PrintWriter(System.out);
+    }
+
+    /**
+     *  Constructor.
+     *
+     *  @param out                the stream to print to
+     */
+    public PrettyPrintVisitor(PrintWriter out) {
+        _out = out;
+    }
+
+    /**
+     *  Invoke with the class or file names to pretty print; the
+     *  functionality is similar to the <i>javap -c</i> command, but more
+     *  detailed.
+     */
+    public static void main(String[] args)
+        throws ClassNotFoundException, IOException {
+        if (args.length == 0) {
+            System.err.println("Usage: java " +
+                PrettyPrintVisitor.class.getName() +
+                " <class name | .class file>+");
+            System.exit(1);
+        }
+
+        PrettyPrintVisitor ppv = new PrettyPrintVisitor();
+        Project project = new Project();
+        BCClass type;
+
+        for (int i = 0; i < args.length; i++) {
+            if (args[i].endsWith(".class")) {
+                type = project.loadClass(new File(args[i]));
+            } else {
+                type = project.loadClass(Class.forName(args[i], false,
+                            PrettyPrintVisitor.class.getClassLoader()));
+            }
+
+            ppv.visit(type);
+        }
+    }
+
+    public void visit(VisitAcceptor entity) {
+        super.visit(entity);
+        _out.flush();
+    }
+
+    public void enterProject(Project obj) {
+        openBlock("Project");
+
+        println("name=" + obj.getName());
+    }
+
+    public void exitProject(Project obj) {
+        closeBlock();
+    }
+
+    public void enterBCClass(BCClass obj) {
+        openBlock("Class");
+
+        println("magic=" + obj.getMagic());
+        println("minor=" + obj.getMinorVersion());
+        println("major=" + obj.getMajorVersion());
+        println("access=" + obj.getAccessFlags());
+        println("name=" + obj.getIndex() + " <" + obj.getName() + ">");
+        println("super=" + obj.getSuperclassIndex() + " <" +
+            obj.getSuperclassName() + ">");
+
+        int[] indexes = obj.getDeclaredInterfaceIndexes();
+        String[] names = obj.getDeclaredInterfaceNames();
+
+        for (int i = 0; i < indexes.length; i++)
+            println("interface=" + indexes[i] + " <" + names[i] + ">");
+    }
+
+    public void exitBCClass(BCClass obj) {
+        closeBlock();
+    }
+
+    public void enterBCField(BCField obj) {
+        openBlock("Field");
+        println("access=" + obj.getAccessFlags());
+        println("name=" + obj.getNameIndex() + " <" + obj.getName() + ">");
+        println("type=" + obj.getDescriptorIndex() + " <" + obj.getTypeName() +
+            ">");
+    }
+
+    public void exitBCField(BCField obj) {
+        closeBlock();
+    }
+
+    public void enterBCMethod(BCMethod obj) {
+        openBlock("Method");
+        println("access=" + obj.getAccessFlags());
+        println("name=" + obj.getNameIndex() + " <" + obj.getName() + ">");
+        println("descriptor=" + obj.getDescriptorIndex());
+        println("return=" + obj.getReturnName());
+
+        String[] params = obj.getParamNames();
+
+        for (int i = 0; i < params.length; i++)
+            println("param=" + params[i]);
+    }
+
+    public void exitBCMethod(BCMethod obj) {
+        closeBlock();
+    }
+
+    public void enterAttribute(Attribute obj) {
+        openBlock(obj.getName());
+    }
+
+    public void exitAttribute(Attribute obj) {
+        closeBlock();
+    }
+
+    public void enterConstantValue(ConstantValue obj) {
+        println("value=" + obj.getValueIndex() + " <" + obj.getTypeName() +
+            "=" + obj.getValue() + ">");
+    }
+
+    public void enterExceptions(Exceptions obj) {
+        int[] indexes = obj.getExceptionIndexes();
+        String[] names = obj.getExceptionNames();
+
+        for (int i = 0; i < indexes.length; i++)
+            println("exception=" + indexes[i] + " <" + names[i] + ">");
+    }
+
+    public void enterSourceFile(SourceFile obj) {
+        println("source=" + obj.getFileIndex() + " <" + obj.getFileName() +
+            ">");
+    }
+
+    public void enterCode(Code obj) {
+        println("maxStack=" + obj.getMaxStack());
+        println("maxLocals=" + obj.getMaxLocals());
+        println("");
+    }
+
+    public void enterExceptionHandler(ExceptionHandler obj) {
+        openBlock("ExceptionHandler");
+        println("startPc=" + obj.getTryStartPc());
+        println("endPc=" + obj.getTryEndPc());
+        println("handlerPc=" + obj.getHandlerStartPc());
+        println("catch=" + obj.getCatchIndex() + " <" + obj.getCatchName() +
+            ">");
+    }
+
+    public void exitExceptionHandler(ExceptionHandler obj) {
+        closeBlock();
+    }
+
+    public void enterInnerClass(InnerClass obj) {
+        openBlock("InnerClass");
+        println("access=" + obj.getAccessFlags());
+        println("name=" + obj.getNameIndex() + " <" + obj.getName() + ">");
+        println("type=" + obj.getTypeIndex() + "<" + obj.getTypeName() + ">");
+        println("declarer=" + obj.getDeclarerIndex() + "<" +
+            obj.getDeclarerName() + ">");
+    }
+
+    public void exitInnerClass(InnerClass obj) {
+        closeBlock();
+    }
+
+    public void enterLineNumber(LineNumber obj) {
+        openBlock("LineNumber");
+        println("startPc=" + obj.getStartPc());
+        println("line=" + obj.getLine());
+    }
+
+    public void exitLineNumber(LineNumber obj) {
+        closeBlock();
+    }
+
+    public void enterLocalVariable(LocalVariable obj) {
+        openBlock("LocalVariable");
+        println("startPc=" + obj.getStartPc());
+        println("length=" + obj.getLength());
+        println("local=" + obj.getLocal());
+        println("name=" + obj.getNameIndex() + " <" + obj.getName() + ">");
+        println("type=" + obj.getTypeIndex() + " <" + obj.getTypeName() + ">");
+    }
+
+    public void exitLocalVariable(LocalVariable obj) {
+        closeBlock();
+    }
+
+    public void enterLocalVariableType(LocalVariableType obj) {
+        openBlock("LocalVariableType");
+        println("startPc=" + obj.getStartPc());
+        println("length=" + obj.getLength());
+        println("local=" + obj.getLocal());
+        println("name=" + obj.getNameIndex() + " <" + obj.getName() + ">");
+        println("signature=" + obj.getTypeIndex() + " <" + obj.getTypeName() +
+            ">");
+    }
+
+    public void exitLocalVariableType(LocalVariableType obj) {
+        closeBlock();
+    }
+
+    public void enterInstruction(Instruction obj) {
+        _out.print(_prefix + obj.getByteIndex() + " " + obj.getName() + " ");
+    }
+
+    public void exitInstruction(Instruction obj) {
+        _out.println();
+    }
+
+    public void enterClassInstruction(ClassInstruction obj) {
+        _out.print(obj.getTypeIndex() + " <" + obj.getTypeName() + ">");
+    }
+
+    public void enterConstantInstruction(ConstantInstruction obj) {
+        _out.print("<" + obj.getValue() + ">");
+    }
+
+    public void enterGetFieldInstruction(GetFieldInstruction obj) {
+        _out.print(obj.getFieldIndex() + " <" + obj.getFieldTypeName() + " " +
+            obj.getFieldDeclarerName() + "." + obj.getFieldName() + ">");
+    }
+
+    public void enterIIncInstruction(IIncInstruction obj) {
+        _out.print(obj.getLocal() + " ");
+
+        if (obj.getIncrement() < 0) {
+            _out.print("-");
+        }
+
+        _out.print(obj.getIncrement());
+    }
+
+    public void enterJumpInstruction(JumpInstruction obj) {
+        _out.print(obj.getOffset());
+    }
+
+    public void enterIfInstruction(IfInstruction obj) {
+        _out.print(obj.getOffset());
+    }
+
+    public void enterLoadInstruction(LoadInstruction obj) {
+        _out.print("<" + obj.getLocal() + ">");
+    }
+
+    public void enterLookupSwitchInstruction(LookupSwitchInstruction obj) {
+        _out.println();
+        _prefix += "  ";
+
+        int[] offsets = obj.getOffsets();
+        int[] matches = obj.getMatches();
+
+        for (int i = 0; i < offsets.length; i++)
+            println("case " + matches[i] + "=" + offsets[i]);
+
+        _out.print(_prefix + "default=" + obj.getDefaultOffset());
+
+        _prefix = _prefix.substring(2);
+    }
+
+    public void enterMethodInstruction(MethodInstruction obj) {
+        _out.print(obj.getMethodIndex() + " <" + obj.getMethodReturnName() +
+            " " + obj.getMethodDeclarerName() + "." + obj.getMethodName() +
+            "(");
+
+        String[] params = obj.getMethodParamNames();
+        int dotIndex;
+
+        for (int i = 0; i < params.length; i++) {
+            dotIndex = params[i].lastIndexOf('.');
+
+            if (dotIndex != -1) {
+                params[i] = params[i].substring(dotIndex + 1);
+            }
+
+            _out.print(params[i]);
+
+            if (i != (params.length - 1)) {
+                _out.print(", ");
+            }
+        }
+
+        _out.print(")>");
+    }
+
+    public void enterMultiANewArrayInstruction(MultiANewArrayInstruction obj) {
+        _out.print(obj.getTypeIndex() + " " + obj.getDimensions() + " <" +
+            obj.getTypeName());
+
+        String post = "";
+
+        for (int i = 0; i < obj.getDimensions(); i++)
+            post += "[]";
+
+        _out.print(post + ">");
+    }
+
+    public void enterNewArrayInstruction(NewArrayInstruction obj) {
+        _out.print(obj.getTypeCode() + " <" + obj.getTypeName() + "[]>");
+    }
+
+    public void enterPutFieldInstruction(PutFieldInstruction obj) {
+        _out.print(obj.getFieldIndex() + " <" + obj.getFieldTypeName() + " " +
+            obj.getFieldDeclarerName() + "." + obj.getFieldName() + ">");
+    }
+
+    public void enterRetInstruction(RetInstruction obj) {
+        _out.print(obj.getLocal());
+    }
+
+    public void enterStoreInstruction(StoreInstruction obj) {
+        _out.print("<" + obj.getLocal() + ">");
+    }
+
+    public void enterTableSwitchInstruction(TableSwitchInstruction obj) {
+        _out.println();
+        _prefix += "  ";
+
+        println("low=" + obj.getLow());
+        println("high=" + obj.getHigh());
+
+        int[] offsets = obj.getOffsets();
+
+        for (int i = 0; i < offsets.length; i++)
+            println("case=" + offsets[i]);
+
+        _out.print(_prefix + "default=" + obj.getDefaultOffset());
+
+        _prefix = _prefix.substring(2);
+    }
+
+    public void enterWideInstruction(WideInstruction obj) {
+        int ins = obj.getInstruction();
+        _out.print(ins + " <" + Constants.OPCODE_NAMES[ins] + ">");
+    }
+
+    public void enterConstantPool(ConstantPool obj) {
+        _entryCount = 0;
+        openBlock("ConstantPool");
+    }
+
+    public void exitConstantPool(ConstantPool obj) {
+        closeBlock();
+    }
+
+    public void enterEntry(Entry obj) {
+        String name = obj.getClass().getName();
+        openBlock(++_entryCount + ": " +
+            name.substring(name.lastIndexOf('.') + 1));
+    }
+
+    public void exitEntry(Entry obj) {
+        closeBlock();
+    }
+
+    public void enterClassEntry(ClassEntry obj) {
+        println("name=" + obj.getNameIndex());
+    }
+
+    public void enterDoubleEntry(DoubleEntry obj) {
+        println("value=" + obj.getValue());
+    }
+
+    public void enterFieldEntry(FieldEntry obj) {
+        println("class=" + obj.getClassIndex());
+        println("nameAndType=" + obj.getNameAndTypeIndex());
+    }
+
+    public void enterFloatEntry(FloatEntry obj) {
+        println("value=" + obj.getValue());
+    }
+
+    public void enterIntEntry(IntEntry obj) {
+        println("value=" + obj.getValue());
+    }
+
+    public void enterInterfaceMethodEntry(InterfaceMethodEntry obj) {
+        println("class=" + obj.getClassIndex());
+        println("nameAndType=" + obj.getNameAndTypeIndex());
+    }
+
+    public void enterLongEntry(LongEntry obj) {
+        println("value=" + obj.getValue());
+    }
+
+    public void enterMethodEntry(MethodEntry obj) {
+        println("class=" + obj.getClassIndex());
+        println("nameAndType=" + obj.getNameAndTypeIndex());
+    }
+
+    public void enterNameAndTypeEntry(NameAndTypeEntry obj) {
+        println("name=" + obj.getNameIndex());
+        println("descriptor=" + obj.getDescriptorIndex());
+    }
+
+    public void enterStringEntry(StringEntry obj) {
+        println("index=" + obj.getStringIndex());
+    }
+
+    public void enterUTF8Entry(UTF8Entry obj) {
+        println("value=" + obj.getValue());
+    }
+
+    private void println(String ln) {
+        _out.print(_prefix);
+        _out.println(ln);
+    }
+
+    private void openBlock(String name) {
+        println(name + " {");
+        _prefix += "  ";
+    }
+
+    private void closeBlock() {
+        _prefix = _prefix.substring(2);
+        println("}");
+    }
+}

Propchange: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/visitor/PrettyPrintVisitor.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/visitor/VisitAcceptor.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/visitor/VisitAcceptor.java?rev=417860&view=auto
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/visitor/VisitAcceptor.java (added)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/visitor/VisitAcceptor.java Wed Jun 28 12:46:13 2006
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package serp.bytecode.visitor;
+
+
+/**
+ *  <p>Interface denoting an entity that can accept a {@link BCVisitor} and
+ *  provide        its internal state to it.  All entities in the bytecode framework
+ *  implement this interface.</p>
+ *
+ *  @author Abe White
+ */
+public interface VisitAcceptor {
+    /**
+     *  Accept a visit from a {@link BCVisitor}, calling the appropriate methods
+     *  to notify the visitor that it has entered this entity, and
+     *  to provide it with the proper callbacks for each sub-entity owned
+     *  by this one.
+     */
+    public void acceptVisit(BCVisitor visitor);
+}

Propchange: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/visitor/VisitAcceptor.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/visitor/package.html
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/visitor/package.html?rev=417860&view=auto
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/visitor/package.html (added)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/visitor/package.html Wed Jun 28 12:46:13 2006
@@ -0,0 +1,10 @@
+<html>
+<body>
+	<p><strong>Bytecode Visitor</strong></p>
+	<p>
+		This package implements the visitor pattern on bytecode entities 
+		and provides a useful concrete visitor that pretty-prints a detailed
+		document describing any bytecode entity.
+	</p>
+</body>
+</html>

Propchange: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/visitor/package.html
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/serp/src/main/java/serp/util/Numbers.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/util/Numbers.java?rev=417860&view=auto
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/util/Numbers.java (added)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/util/Numbers.java Wed Jun 28 12:46:13 2006
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package serp.util;
+
+
+/**
+ *  <p>Number utilities.</p>
+ *
+ *  @author Abe White
+ */
+public class Numbers {
+    private static final Integer INT_NEGONE = new Integer(-1);
+    private static final Long LONG_NEGONE = new Long(-1);
+    private static final Integer[] INTEGERS = new Integer[50];
+    private static final Long[] LONGS = new Long[50];
+
+    static {
+        for (int i = 0; i < INTEGERS.length; i++)
+            INTEGERS[i] = new Integer(i);
+
+        for (int i = 0; i < LONGS.length; i++)
+            LONGS[i] = new Long(i);
+    }
+
+    /**
+     *  Return the wrapper for the given number, taking advantage of cached
+     *  common values.
+     */
+    public static Integer valueOf(int n) {
+        if (n == -1) {
+            return INT_NEGONE;
+        }
+
+        if ((n >= 0) && (n < INTEGERS.length)) {
+            return INTEGERS[n];
+        }
+
+        return new Integer(n);
+    }
+
+    /**
+     *  Return the wrapper for the given number, taking advantage of cached
+     *  common values.
+     */
+    public static Long valueOf(long n) {
+        if (n == -1) {
+            return LONG_NEGONE;
+        }
+
+        if ((n >= 0) && (n < LONGS.length)) {
+            return LONGS[(int) n];
+        }
+
+        return new Long(n);
+    }
+}

Propchange: incubator/openjpa/trunk/serp/src/main/java/serp/util/Numbers.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/serp/src/main/java/serp/util/Strings.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/util/Strings.java?rev=417860&view=auto
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/util/Strings.java (added)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/util/Strings.java Wed Jun 28 12:46:13 2006
@@ -0,0 +1,417 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package serp.util;
+
+import java.math.*;
+
+import java.util.*;
+
+
+/**
+ *  <p>String utiltity methods.</p>
+ *
+ *  @author Abe White
+ */
+public class Strings {
+    private static final Object[][] _codes = new Object[][] {
+            { byte.class, "byte", "B" },
+            { char.class, "char", "C" },
+            { double.class, "double", "D" },
+            { float.class, "float", "F" },
+            { int.class, "int", "I" },
+            { long.class, "long", "J" },
+            { short.class, "short", "S" },
+            { boolean.class, "boolean", "Z" },
+            { void.class, "void", "V" }
+        };
+
+    /**
+     *  Replace all instances of <code>from</code> in <code>str</code>
+     *  with <code>to</code>.
+     *
+     *  @param str          the candidate string to replace
+     *  @param from         the token to replace
+     *  @param to           the new token
+     *  @return the string with all the replacements made
+     */
+    public static String replace(String str, String from, String to) {
+        String[] split = split(str, from, Integer.MAX_VALUE);
+
+        return join(split, to);
+    }
+
+    /**
+     *  Splits the given string on the given token.  Follows the semantics
+     *  of the Java 1.4 {@link String#split(String,int)} method, but does
+     *  not treat the given token as a regular expression.
+     */
+    public static String[] split(String str, String token, int max) {
+        if ((str == null) || (str.length() == 0)) {
+            return new String[0];
+        }
+
+        if ((token == null) || (token.length() == 0)) {
+            throw new IllegalArgumentException("token: [" + token + "]");
+        }
+
+        // split on token 
+        LinkedList ret = new LinkedList();
+        int start = 0;
+
+        for (int split = 0; split != -1;) {
+            split = str.indexOf(token, start);
+
+            if ((split == -1) && (start >= str.length())) {
+                ret.add("");
+            } else if (split == -1) {
+                ret.add(str.substring(start));
+            } else {
+                ret.add(str.substring(start, split));
+                start = split + token.length();
+            }
+        }
+
+        // now take max into account; this isn't the most efficient way
+        // of doing things since we split the maximum number of times
+        // regardless of the given parameters, but it makes things easy
+        if (max == 0) {
+            // discard any trailing empty splits
+            while (ret.getLast().equals(""))
+                ret.removeLast();
+        } else if ((max > 0) && (ret.size() > max)) {
+            // move all splits over max into the last split
+            StringBuffer buf = new StringBuffer(ret.removeLast().toString());
+
+            while (ret.size() >= max) {
+                buf.insert(0, token);
+                buf.insert(0, ret.removeLast());
+            }
+
+            ret.add(buf.toString());
+        }
+
+        return (String[]) ret.toArray(new String[ret.size()]);
+    }
+
+    /**
+     *  Joins the given strings, placing the given token between them.
+     */
+    public static String join(Object[] strings, String token) {
+        if (strings == null) {
+            return null;
+        }
+
+        StringBuffer buf = new StringBuffer(20 * strings.length);
+
+        for (int i = 0; i < strings.length; i++) {
+            if (i > 0) {
+                buf.append(token);
+            }
+
+            if (strings[i] != null) {
+                buf.append(strings[i]);
+            }
+        }
+
+        return buf.toString();
+    }
+
+    /**
+     *  Return the class for the given string, correctly handling
+     *  primitive types.  If the given class loader is null, the context
+     *  loader of the current thread will be used.
+     *
+     *  @throws RuntimeException on load error
+     */
+    public static Class toClass(String str, ClassLoader loader) {
+        return toClass(str, false, loader);
+    }
+
+    /**
+     *  Return the class for the given string, correctly handling
+     *  primitive types.  If the given class loader is null, the context
+     *  loader of the current thread will be used.
+     *
+     *  @throws RuntimeException on load error
+     */
+    public static Class toClass(String str, boolean resolve, ClassLoader loader) {
+        if (str == null) {
+            throw new NullPointerException("str == null");
+        }
+
+        // array handling
+        int dims = 0;
+
+        while (str.endsWith("[]")) {
+            dims++;
+            str = str.substring(0, str.length() - 2);
+        }
+
+        // check against primitive types
+        boolean primitive = false;
+
+        if (str.indexOf('.') == -1) {
+            for (int i = 0; !primitive && (i < _codes.length); i++) {
+                if (_codes[i][1].equals(str)) {
+                    if (dims == 0) {
+                        return (Class) _codes[i][0];
+                    }
+
+                    str = (String) _codes[i][2];
+                    primitive = true;
+                }
+            }
+        }
+
+        if (dims > 0) {
+            int size = str.length() + dims;
+
+            if (!primitive) {
+                size += 2;
+            }
+
+            StringBuffer buf = new StringBuffer(size);
+
+            for (int i = 0; i < dims; i++)
+                buf.append('[');
+
+            if (!primitive) {
+                buf.append('L');
+            }
+
+            buf.append(str);
+
+            if (!primitive) {
+                buf.append(';');
+            }
+
+            str = buf.toString();
+        }
+
+        if (loader == null) {
+            loader = Thread.currentThread().getContextClassLoader();
+        }
+
+        try {
+            return Class.forName(str, resolve, loader);
+        } catch (Throwable t) {
+            throw new IllegalArgumentException(t.toString());
+        }
+    }
+
+    /**
+     *  Return only the class name, without package.
+     */
+    public static String getClassName(Class cls) {
+        return (cls == null) ? null : getClassName(cls.getName());
+    }
+
+    /**
+     *  Return only the class name.
+     */
+    public static String getClassName(String fullName) {
+        if (fullName == null) {
+            return null;
+        }
+
+        // special case for arrays
+        int dims = 0;
+
+        for (int i = 0; i < fullName.length(); i++) {
+            if (fullName.charAt(i) != '[') {
+                dims = i;
+
+                break;
+            }
+        }
+
+        if (dims > 0) {
+            fullName = fullName.substring(dims);
+        }
+
+        // check for primitives
+        for (int i = 0; i < _codes.length; i++) {
+            if (_codes[i][2].equals(fullName)) {
+                fullName = (String) _codes[i][1];
+
+                break;
+            }
+        }
+
+        fullName = fullName.substring(fullName.lastIndexOf('.') + 1);
+
+        for (int i = 0; i < dims; i++)
+            fullName = fullName + "[]";
+
+        return fullName;
+    }
+
+    /**
+     *  Return only the package, or empty string if none.
+     */
+    public static String getPackageName(Class cls) {
+        return (cls == null) ? null : getPackageName(cls.getName());
+    }
+
+    /**
+     *  Return only the package, or empty string if none.
+     */
+    public static String getPackageName(String fullName) {
+        if (fullName == null) {
+            return null;
+        }
+
+        int dotIdx = fullName.lastIndexOf('.');
+
+        return (dotIdx == -1) ? "" : fullName.substring(0, dotIdx);
+    }
+
+    /**
+     *  Return <code>val</code> as the type specified by
+     *  <code>type</code>. If <code>type</code> is a primitive, the
+     *  primitive wrapper type is created and returned, and
+     *  <code>null</code>s are converted to the Java default for the
+     *  primitive type.
+     *
+     *  @param val                The string value to parse
+     *  @param type        The type to parse. This must be a primitive or a
+     *                                  primitive wrapper, or one of {@link BigDecimal},
+     *                                  {@link BigInteger}, {@link String}, {@link Date}.
+     *  @throws IllegalArgumentException if <code>type</code> is not a
+     *                                  supported type, or if <code>val</code> cannot be
+     *                                  converted into an instance of type <code>type</code>.
+     */
+    public static Object parse(String val, Class type) {
+        if (!canParse(type)) {
+            throw new IllegalArgumentException("invalid type: " +
+                type.getName());
+        }
+
+        // deal with null value
+        if (val == null) {
+            if (!type.isPrimitive()) {
+                return null;
+            }
+
+            if (type == boolean.class) {
+                return Boolean.FALSE;
+            }
+
+            if (type == byte.class) {
+                return new Byte((byte) 0);
+            }
+
+            if (type == char.class) {
+                return new Character((char) 0);
+            }
+
+            if (type == double.class) {
+                return new Double(0);
+            }
+
+            if (type == float.class) {
+                return new Float(0);
+            }
+
+            if (type == int.class) {
+                return Numbers.valueOf(0);
+            }
+
+            if (type == long.class) {
+                return Numbers.valueOf(0L);
+            }
+
+            if (type == short.class) {
+                return new Short((short) 0);
+            }
+
+            throw new IllegalStateException("invalid type: " + type);
+        }
+
+        // deal with non-null value
+        if ((type == boolean.class) || (type == Boolean.class)) {
+            return Boolean.valueOf(val);
+        }
+
+        if ((type == byte.class) || (type == Byte.class)) {
+            return Byte.valueOf(val);
+        }
+
+        if ((type == char.class) || (type == Character.class)) {
+            if (val.length() == 0) {
+                return new Character((char) 0);
+            }
+
+            if (val.length() == 1) {
+                return new Character(val.charAt(0));
+            }
+
+            throw new IllegalArgumentException("'" + val + "' is longer than " +
+                "one character.");
+        }
+
+        if ((type == double.class) || (type == Double.class)) {
+            return Double.valueOf(val);
+        }
+
+        if ((type == float.class) || (type == Float.class)) {
+            return Float.valueOf(val);
+        }
+
+        if ((type == int.class) || (type == Integer.class)) {
+            return Integer.valueOf(val);
+        }
+
+        if ((type == long.class) || (type == Long.class)) {
+            return Long.valueOf(val);
+        }
+
+        if ((type == short.class) || (type == Short.class)) {
+            return Short.valueOf(val);
+        }
+
+        if (type == String.class) {
+            return val;
+        }
+
+        if (type == Date.class) {
+            return new Date(val);
+        }
+
+        if (type == BigInteger.class) {
+            return new BigInteger(val);
+        }
+
+        if (type == BigDecimal.class) {
+            return new BigDecimal(val);
+        }
+
+        throw new IllegalArgumentException("Invalid type: " + type);
+    }
+
+    /**
+     *  Whether the given type is parsable via {@link #parse}.
+     */
+    public static boolean canParse(Class type) {
+        return type.isPrimitive() || (type == Boolean.class) ||
+        (type == Byte.class) || (type == Character.class) ||
+        (type == Short.class) || (type == Integer.class) ||
+        (type == Long.class) || (type == Float.class) ||
+        (type == Double.class) || (type == String.class) ||
+        (type == Date.class) || (type == BigInteger.class) ||
+        (type == BigDecimal.class);
+    }
+}

Propchange: incubator/openjpa/trunk/serp/src/main/java/serp/util/Strings.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/serp/src/main/java/serp/util/package.html
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/util/package.html?rev=417860&view=auto
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/util/package.html (added)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/util/package.html Wed Jun 28 12:46:13 2006
@@ -0,0 +1,8 @@
+<html>
+<body>
+	<p><strong>Utilties</strong></p>
+	<p>
+		Utilities used by bytecode libraries.
+	</p>
+</body>
+</html>

Propchange: incubator/openjpa/trunk/serp/src/main/java/serp/util/package.html
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/AbstractStateTest.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/AbstractStateTest.java?rev=417860&view=auto
==============================================================================
--- incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/AbstractStateTest.java (added)
+++ incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/AbstractStateTest.java Wed Jun 28 12:46:13 2006
@@ -0,0 +1,207 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package serp.bytecode;
+
+import junit.framework.*;
+
+import junit.textui.*;
+
+
+/**
+ *  <p>Base class for testing the handling of the {@link PrimitiveState} and
+ *  {@link ArrayState}.  Subclasses should set the {@link #_bc} member in
+ *  their {@link TestCase#setUp} method.</p>
+ *
+ *  @author Abe White
+ */
+public abstract class AbstractStateTest extends TestCase {
+    protected Project _project = new Project();
+    protected BCClass _bc = null;
+
+    public AbstractStateTest(String test) {
+        super(test);
+    }
+
+    /**
+     *  Test the name and type operations.
+     */
+    public abstract void testType();
+
+    /**
+     *  Test operations on the superclass.
+     */
+    public abstract void testSuperclass();
+
+    /**
+     *  Test operations on the component type.
+     */
+    public abstract void testComponent();
+
+    /**
+     *  Test the basics -- magic number, etc.
+     */
+    public void testBasics() {
+        assertEquals(Constants.VALID_MAGIC, _bc.getMagic());
+
+        try {
+            _bc.setMagic(1);
+            fail("Allowed set magic");
+        } catch (UnsupportedOperationException uoe) {
+        }
+
+        assertEquals(Constants.MAJOR_VERSION, _bc.getMajorVersion());
+
+        try {
+            _bc.setMajorVersion(1);
+            fail("Allowed set major version");
+        } catch (UnsupportedOperationException uoe) {
+        }
+
+        assertEquals(Constants.MINOR_VERSION, _bc.getMinorVersion());
+
+        try {
+            _bc.setMinorVersion(1);
+            fail("Allowed set minor version");
+        } catch (UnsupportedOperationException uoe) {
+        }
+
+        assertEquals(Constants.ACCESS_PUBLIC | Constants.ACCESS_FINAL,
+            _bc.getAccessFlags());
+
+        try {
+            _bc.setAccessFlags(1);
+            fail("Allowed set access flags");
+        } catch (UnsupportedOperationException uoe) {
+        }
+
+        try {
+            _bc.getPool();
+            fail("Allowed access constant pool");
+        } catch (UnsupportedOperationException uoe) {
+        }
+    }
+
+    /**
+     *  Test operations on interfaces.
+     */
+    public void testInterfaces() {
+        assertEquals(0, _bc.getDeclaredInterfaceNames().length);
+        assertEquals(0, _bc.getInterfaceNames().length);
+
+        try {
+            _bc.declareInterface("foo");
+            fail("Allowed declare interface");
+        } catch (UnsupportedOperationException uoe) {
+        }
+
+        _bc.clearDeclaredInterfaces();
+        assertTrue(!_bc.removeDeclaredInterface((String) null));
+        assertTrue(!_bc.removeDeclaredInterface("foo"));
+
+        assertTrue(_bc.isInstanceOf(_bc.getName()));
+        assertTrue(!_bc.isInstanceOf("foo"));
+    }
+
+    /**
+     *  Test operations on fields.
+     */
+    public void testFields() {
+        assertEquals(0, _bc.getDeclaredFields().length);
+        assertEquals(0, _bc.getFields().length);
+
+        try {
+            _bc.declareField("foo", int.class);
+            fail("Allowed declare field");
+        } catch (UnsupportedOperationException uoe) {
+        }
+
+        _bc.clearDeclaredFields();
+        assertTrue(!_bc.removeDeclaredField((String) null));
+        assertTrue(!_bc.removeDeclaredField("foo"));
+    }
+
+    /**
+     *  Test operations on methods.
+     */
+    public void testMethods() {
+        assertEquals(0, _bc.getDeclaredMethods().length);
+
+        try {
+            _bc.declareMethod("foo", int.class, null);
+            fail("Allowed declare method");
+        } catch (UnsupportedOperationException uoe) {
+        }
+
+        _bc.clearDeclaredMethods();
+        assertTrue(!_bc.removeDeclaredMethod((String) null));
+        assertTrue(!_bc.removeDeclaredMethod("foo"));
+
+        try {
+            _bc.addDefaultConstructor();
+            fail("Allowed add default constructor");
+        } catch (UnsupportedOperationException uoe) {
+        }
+    }
+
+    /**
+     *  Test operations on attributes.
+     */
+    public void testAttributes() {
+        assertNull(_bc.getSourceFile(false));
+
+        try {
+            _bc.getSourceFile(true);
+            fail("Allowed add source file");
+        } catch (UnsupportedOperationException uoe) {
+        }
+
+        assertNull(_bc.getInnerClasses(false));
+
+        try {
+            _bc.getInnerClasses(true);
+            fail("Allowed add inner classes");
+        } catch (UnsupportedOperationException uoe) {
+        }
+
+        assertTrue(!_bc.isDeprecated());
+
+        try {
+            _bc.setDeprecated(true);
+            fail("Allowed set deprecated");
+        } catch (UnsupportedOperationException uoe) {
+        }
+
+        assertEquals(0, _bc.getAttributes().length);
+        _bc.clearAttributes();
+        assertTrue(!_bc.removeAttribute(Constants.ATTR_SYNTHETIC));
+
+        try {
+            _bc.addAttribute(Constants.ATTR_SYNTHETIC);
+            fail("Allowed add attribute");
+        } catch (UnsupportedOperationException uoe) {
+        }
+    }
+
+    /**
+     *  Tests that these types cannot be written.
+     */
+    public void testWrite() {
+        try {
+            _bc.toByteArray();
+        } catch (UnsupportedOperationException uoe) {
+        }
+    }
+}

Propchange: incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/AbstractStateTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestArray.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestArray.java?rev=417860&view=auto
==============================================================================
--- incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestArray.java (added)
+++ incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestArray.java Wed Jun 28 12:46:13 2006
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package serp.bytecode;
+
+import junit.framework.*;
+
+import junit.textui.*;
+
+
+/**
+ *  <p>Tests the handling of array {@link BCClass}es.</p>
+ *
+ *  @author Abe White
+ */
+public class TestArray extends AbstractStateTest {
+    private BCClass _bc2 = null;
+
+    public TestArray(String test) {
+        super(test);
+    }
+
+    public void setUp() {
+        _bc = _project.loadClass(String[].class);
+        _bc2 = _project.loadClass(int[][].class);
+    }
+
+    public void testType() {
+        assertEquals(String[].class.getName(), _bc.getName());
+        assertEquals("java.lang", _bc.getPackageName());
+        assertEquals("String[]", _bc.getClassName());
+        assertEquals(String[].class, _bc.getType());
+
+        try {
+            _bc.setName("Foo[]");
+            fail("Allowed set name");
+        } catch (UnsupportedOperationException uoe) {
+        }
+
+        assertTrue(!_bc.isPrimitive());
+        assertTrue(_bc.isArray());
+
+        assertEquals(int[][].class.getName(), _bc2.getName());
+        assertNull(_bc2.getPackageName());
+        assertEquals("int[][]", _bc2.getClassName());
+        assertEquals(int[][].class, _bc2.getType());
+    }
+
+    public void testSuperclass() {
+        assertEquals(Object.class.getName(), _bc.getSuperclassName());
+
+        try {
+            _bc.setSuperclass("Foo");
+            fail("Allowed set superclass");
+        } catch (UnsupportedOperationException uoe) {
+        }
+    }
+
+    public void testComponent() {
+        assertEquals(String.class.getName(), _bc.getComponentName());
+        assertEquals(String.class, _bc.getComponentType());
+        assertEquals(String.class, _bc.getComponentBC().getType());
+        assertEquals(int[].class.getName(), _bc2.getComponentName());
+        assertEquals(int[].class, _bc2.getComponentType());
+        assertEquals(int[].class, _bc2.getComponentBC().getType());
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestArray.class);
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(suite());
+    }
+}

Propchange: incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestArray.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestArrayLoadInstruction.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestArrayLoadInstruction.java?rev=417860&view=auto
==============================================================================
--- incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestArrayLoadInstruction.java (added)
+++ incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestArrayLoadInstruction.java Wed Jun 28 12:46:13 2006
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package serp.bytecode;
+
+import junit.framework.*;
+
+import junit.textui.*;
+
+
+/**
+ *  <p>Tests the {@link ArrayLoadInstruction} type.</p>
+ *
+ *  @author Abe White
+ */
+public class TestArrayLoadInstruction extends TestCase {
+    private Code _code = new Code();
+
+    public TestArrayLoadInstruction(String test) {
+        super(test);
+    }
+
+    /**
+     *  Test that the instruction initializes correctly when generated.
+     */
+    public void testIniitalize() {
+        assertEquals(Constants.NOP, _code.xaload().getOpcode());
+        assertEquals(Constants.IALOAD, _code.iaload().getOpcode());
+        assertEquals(Constants.LALOAD, _code.laload().getOpcode());
+        assertEquals(Constants.FALOAD, _code.faload().getOpcode());
+        assertEquals(Constants.DALOAD, _code.daload().getOpcode());
+        assertEquals(Constants.AALOAD, _code.aaload().getOpcode());
+        assertEquals(Constants.BALOAD, _code.baload().getOpcode());
+        assertEquals(Constants.CALOAD, _code.caload().getOpcode());
+        assertEquals(Constants.SALOAD, _code.saload().getOpcode());
+    }
+
+    /**
+     *  Test the the instruction returns its type correctly.
+     */
+    public void testGetType() {
+        assertNull(_code.xaload().getType());
+        assertEquals(int.class, _code.iaload().getType());
+        assertEquals(long.class, _code.laload().getType());
+        assertEquals(float.class, _code.faload().getType());
+        assertEquals(double.class, _code.daload().getType());
+        assertEquals(Object.class, _code.aaload().getType());
+        assertEquals(byte.class, _code.baload().getType());
+        assertEquals(char.class, _code.caload().getType());
+        assertEquals(short.class, _code.saload().getType());
+    }
+
+    /**
+     *  Test that the opcode morphs correctly with type changes.
+     */
+    public void testOpcodeMorph() {
+        ArrayLoadInstruction ins = _code.xaload();
+        assertEquals(Constants.NOP, ins.getOpcode());
+        assertEquals(Constants.NOP, ins.setType((String) null).getOpcode());
+        assertEquals(Constants.NOP, ins.setType((BCClass) null).getOpcode());
+        assertEquals(Constants.NOP, ins.setType((Class) null).getOpcode());
+
+        assertEquals(Constants.IALOAD, ins.setType(int.class).getOpcode());
+        assertEquals(Constants.NOP, ins.setType((String) null).getOpcode());
+        assertEquals(Constants.LALOAD, ins.setType(long.class).getOpcode());
+        assertEquals(Constants.FALOAD, ins.setType(float.class).getOpcode());
+        assertEquals(Constants.DALOAD, ins.setType(double.class).getOpcode());
+        assertEquals(Constants.AALOAD, ins.setType(Object.class).getOpcode());
+        assertEquals(Constants.BALOAD, ins.setType(byte.class).getOpcode());
+        assertEquals(Constants.CALOAD, ins.setType(char.class).getOpcode());
+        assertEquals(Constants.SALOAD, ins.setType(short.class).getOpcode());
+        assertEquals(Constants.IALOAD, ins.setType(void.class).getOpcode());
+        assertEquals(Constants.AALOAD, ins.setType(String.class).getOpcode());
+        assertEquals(Constants.IALOAD, ins.setType(boolean.class).getOpcode());
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestArrayLoadInstruction.class);
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(suite());
+    }
+}

Propchange: incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestArrayLoadInstruction.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestArrayStoreInstruction.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestArrayStoreInstruction.java?rev=417860&view=auto
==============================================================================
--- incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestArrayStoreInstruction.java (added)
+++ incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestArrayStoreInstruction.java Wed Jun 28 12:46:13 2006
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package serp.bytecode;
+
+import junit.framework.*;
+
+import junit.textui.*;
+
+
+/**
+ *  <p>Tests the {@link ArrayStoreInstruction} type.</p>
+ *
+ *  @author Abe White
+ */
+public class TestArrayStoreInstruction extends TestCase {
+    private Code _code = new Code();
+
+    public TestArrayStoreInstruction(String test) {
+        super(test);
+    }
+
+    /**
+     *  Test that the instruction initializes correctly when generated.
+     */
+    public void testIniitalize() {
+        assertEquals(Constants.NOP, _code.xastore().getOpcode());
+        assertEquals(Constants.IASTORE, _code.iastore().getOpcode());
+        assertEquals(Constants.LASTORE, _code.lastore().getOpcode());
+        assertEquals(Constants.FASTORE, _code.fastore().getOpcode());
+        assertEquals(Constants.DASTORE, _code.dastore().getOpcode());
+        assertEquals(Constants.AASTORE, _code.aastore().getOpcode());
+        assertEquals(Constants.BASTORE, _code.bastore().getOpcode());
+        assertEquals(Constants.CASTORE, _code.castore().getOpcode());
+        assertEquals(Constants.SASTORE, _code.sastore().getOpcode());
+    }
+
+    /**
+     *  Test the the instruction returns its type correctly.
+     */
+    public void testGetType() {
+        assertNull(_code.xastore().getType());
+        assertEquals(int.class, _code.iastore().getType());
+        assertEquals(long.class, _code.lastore().getType());
+        assertEquals(float.class, _code.fastore().getType());
+        assertEquals(double.class, _code.dastore().getType());
+        assertEquals(Object.class, _code.aastore().getType());
+        assertEquals(byte.class, _code.bastore().getType());
+        assertEquals(char.class, _code.castore().getType());
+        assertEquals(short.class, _code.sastore().getType());
+    }
+
+    /**
+     *  Test that the opcode morphs correctly with type changes.
+     */
+    public void testOpcodeMorph() {
+        ArrayStoreInstruction ins = _code.xastore();
+        assertEquals(Constants.NOP, ins.getOpcode());
+        assertEquals(Constants.NOP, ins.setType((String) null).getOpcode());
+        assertEquals(Constants.NOP, ins.setType((BCClass) null).getOpcode());
+        assertEquals(Constants.NOP, ins.setType((Class) null).getOpcode());
+
+        assertEquals(Constants.IASTORE, ins.setType(int.class).getOpcode());
+        assertEquals(Constants.NOP, ins.setType((String) null).getOpcode());
+        assertEquals(Constants.LASTORE, ins.setType(long.class).getOpcode());
+        assertEquals(Constants.FASTORE, ins.setType(float.class).getOpcode());
+        assertEquals(Constants.DASTORE, ins.setType(double.class).getOpcode());
+        assertEquals(Constants.AASTORE, ins.setType(Object.class).getOpcode());
+        assertEquals(Constants.BASTORE, ins.setType(byte.class).getOpcode());
+        assertEquals(Constants.CASTORE, ins.setType(char.class).getOpcode());
+        assertEquals(Constants.SASTORE, ins.setType(short.class).getOpcode());
+        assertEquals(Constants.IASTORE, ins.setType(void.class).getOpcode());
+        assertEquals(Constants.AASTORE, ins.setType(String.class).getOpcode());
+        assertEquals(Constants.IASTORE, ins.setType(boolean.class).getOpcode());
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestArrayStoreInstruction.class);
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(suite());
+    }
+}

Propchange: incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestArrayStoreInstruction.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestAttributes.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestAttributes.java?rev=417860&view=auto
==============================================================================
--- incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestAttributes.java (added)
+++ incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestAttributes.java Wed Jun 28 12:46:13 2006
@@ -0,0 +1,155 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package serp.bytecode;
+
+import junit.framework.*;
+
+import junit.textui.*;
+
+
+/**
+ *  <p>Tests the {@link Attributes} type.</p>
+ *
+ *  @author Abe White
+ */
+public class TestAttributes extends TestCase {
+    private Project _project = new Project();
+    private Attributes _attrs = _project.loadClass("serp.Attrs");
+    private Attributes _attrs2 = _project.loadClass("serp.Attrs2");
+
+    public TestAttributes(String test) {
+        super(test);
+    }
+
+    /**
+     *  Test getting attributes.
+     */
+    public void testGetAttributes() {
+        assertEquals(0, _attrs.getAttributes().length);
+        assertNull(_attrs.getAttribute(Constants.ATTR_SYNTHETIC));
+
+        Attribute attr1 = _attrs.addAttribute(Constants.ATTR_DEPRECATED);
+        Attribute attr2 = _attrs.addAttribute(Constants.ATTR_SYNTHETIC);
+
+        assertEquals(2, _attrs.getAttributes().length);
+        assertNull(_attrs.getAttribute(Constants.ATTR_CODE));
+        assertTrue(attr1 == _attrs.getAttribute(Constants.ATTR_DEPRECATED));
+        assertTrue(attr2 == _attrs.getAttribute(Constants.ATTR_SYNTHETIC));
+        assertEquals(0, _attrs.getAttributes(Constants.ATTR_CODE).length);
+        assertEquals(1, _attrs.getAttributes(Constants.ATTR_DEPRECATED).length);
+        assertEquals(1, _attrs.getAttributes(Constants.ATTR_SYNTHETIC).length);
+        assertTrue(attr1 == _attrs.getAttributes(Constants.ATTR_DEPRECATED)[0]);
+        assertTrue(attr2 == _attrs.getAttributes(Constants.ATTR_SYNTHETIC)[0]);
+
+        Attribute attr3 = _attrs.addAttribute(Constants.ATTR_DEPRECATED);
+        assertEquals(3, _attrs.getAttributes().length);
+        assertEquals(2, _attrs.getAttributes(Constants.ATTR_DEPRECATED).length);
+    }
+
+    /**
+     *  Test setting attributes.
+     */
+    public void testSetAttributes() {
+        Attribute attr1 = _attrs.addAttribute(Constants.ATTR_DEPRECATED);
+        Attribute attr2 = _attrs.addAttribute(Constants.ATTR_SYNTHETIC);
+
+        _attrs2.setAttributes(_attrs.getAttributes());
+        assertEquals(2, _attrs2.getAttributes().length);
+        assertEquals(Constants.ATTR_DEPRECATED,
+            _attrs2.getAttribute(Constants.ATTR_DEPRECATED).getName());
+        assertEquals(Constants.ATTR_SYNTHETIC,
+            _attrs2.getAttribute(Constants.ATTR_SYNTHETIC).getName());
+        assertTrue(attr1 != _attrs2.getAttribute(Constants.ATTR_DEPRECATED));
+        assertTrue(attr2 != _attrs2.getAttribute(Constants.ATTR_SYNTHETIC));
+
+        Attribute attr3 = _attrs.addAttribute(Constants.ATTR_SOURCE);
+        _attrs2.setAttributes(new Attribute[] { attr3 });
+        assertEquals(1, _attrs2.getAttributes().length);
+        assertEquals(Constants.ATTR_SOURCE, _attrs2.getAttributes()[0].getName());
+    }
+
+    /**
+     *  Test adding attributs.
+     */
+    public void testAddAttributes() {
+        SourceFile attr1 = (SourceFile) _attrs.addAttribute(Constants.ATTR_SOURCE);
+        assertEquals(attr1.getName(), Constants.ATTR_SOURCE);
+        assertTrue(attr1 != _attrs.addAttribute(Constants.ATTR_SOURCE));
+        assertEquals(2, _attrs.getAttributes(Constants.ATTR_SOURCE).length);
+        attr1.setFile("foo");
+
+        SourceFile attr2 = (SourceFile) _attrs2.addAttribute(attr1);
+        assertTrue(attr1 != attr2);
+        assertEquals("foo", attr2.getFileName());
+    }
+
+    /**
+     *  Test clearing attributes.
+     */
+    public void testClear() {
+        _attrs.clearAttributes();
+
+        Attribute attr1 = _attrs.addAttribute(Constants.ATTR_SYNTHETIC);
+        Attribute attr2 = _attrs.addAttribute(Constants.ATTR_DEPRECATED);
+
+        assertTrue(attr1.isValid());
+        assertTrue(attr2.isValid());
+
+        assertEquals(2, _attrs.getAttributes().length);
+        _attrs.clearAttributes();
+        assertEquals(0, _attrs.getAttributes().length);
+
+        // cleared classes should be invalid
+        assertTrue(!attr1.isValid());
+        assertTrue(!attr2.isValid());
+    }
+
+    /**
+     *  Test removing a class.
+     */
+    public void testRemoveAttribute() {
+        assertTrue(!_attrs.removeAttribute((String) null));
+        assertTrue(!_attrs.removeAttribute((Attribute) null));
+        assertTrue(!_attrs.removeAttribute(Constants.ATTR_SYNTHETIC));
+        assertTrue(!_attrs.removeAttribute(_attrs2.addAttribute(
+                    Constants.ATTR_SYNTHETIC)));
+
+        Attribute attr1 = _attrs.addAttribute(Constants.ATTR_SYNTHETIC);
+        Attribute attr2 = _attrs.addAttribute(Constants.ATTR_DEPRECATED);
+
+        assertTrue(attr1.isValid());
+        assertTrue(attr2.isValid());
+        assertEquals(2, _attrs.getAttributes().length);
+
+        assertTrue(_attrs.removeAttribute(attr1.getName()));
+        assertEquals(1, _attrs.getAttributes().length);
+
+        assertTrue(!_attrs.removeAttribute(_attrs2.addAttribute(attr2.getName())));
+        assertTrue(_attrs.removeAttribute(attr2));
+        assertEquals(0, _attrs.getAttributes().length);
+
+        assertTrue(!attr1.isValid());
+        assertTrue(!attr2.isValid());
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestAttributes.class);
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(suite());
+    }
+}

Propchange: incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestAttributes.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestBCClass.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestBCClass.java?rev=417860&view=auto
==============================================================================
--- incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestBCClass.java (added)
+++ incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestBCClass.java Wed Jun 28 12:46:13 2006
@@ -0,0 +1,269 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package serp.bytecode;
+
+import junit.framework.*;
+
+import junit.textui.*;
+
+import java.io.*;
+
+
+/**
+ *  <p>Tests the {@link BCClass} type.</p>
+ *
+ *  UNFINISHED
+ *
+ *  @author Abe White
+ */
+public class TestBCClass extends TestCase {
+    private Project _project = new Project();
+    private BCClass _bc = _project.loadClass(Integer.class);
+
+    public TestBCClass(String test) {
+        super(test);
+    }
+
+    /**
+     *  Test accessing the class project.
+     */
+    public void testProject() {
+        assertTrue(_project == _bc.getProject());
+        assertTrue(_bc.isValid());
+        assertTrue(_project.removeClass(_bc));
+        assertTrue(!_bc.isValid());
+    }
+
+    /**
+     *  Test read/write.
+     */
+    public void testReadWrite() throws IOException {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        InputStream in = Integer.class.getResourceAsStream("Integer.class");
+        int ch;
+
+        while ((ch = in.read()) != -1)
+            out.write(ch);
+
+        byte[] origBytes = out.toByteArray();
+        byte[] bytes = _bc.toByteArray();
+        assertEquals(origBytes.length, bytes.length);
+
+        for (int i = 0; i < origBytes.length; i++)
+            assertEquals(origBytes[i], bytes[i]);
+
+        // also test copying one class to another
+        BCClass bc2 = new Project().loadClass(_bc);
+        bytes = bc2.toByteArray();
+        assertEquals(origBytes.length, bytes.length);
+
+        for (int i = 0; i < origBytes.length; i++)
+            assertEquals(origBytes[i], bytes[i]);
+    }
+
+    /**
+     *  Test basics -- magic number, major version, minor version.
+     */
+    public void testBasics() {
+        assertEquals(Constants.VALID_MAGIC, _bc.getMagic());
+        _bc.setMagic(1);
+        assertEquals(1, _bc.getMagic());
+
+        assertTrue(Constants.MAJOR_VERSION <= _bc.getMajorVersion());
+        _bc.setMajorVersion(1);
+        assertEquals(1, _bc.getMajorVersion());
+
+        _bc.setMinorVersion(1);
+        assertEquals(1, _bc.getMinorVersion());
+
+        assertTrue(!_bc.isPrimitive());
+        assertTrue(!_bc.isArray());
+        assertNull(_bc.getComponentName());
+        assertNull(_bc.getComponentType());
+        assertNull(_bc.getComponentBC());
+    }
+
+    /**
+     *  Test access flags.
+     */
+    public void testAccessFlags() {
+        assertEquals(Constants.ACCESS_PUBLIC | Constants.ACCESS_SUPER |
+            Constants.ACCESS_FINAL, _bc.getAccessFlags());
+        assertTrue(_bc.isPublic());
+        assertTrue(!_bc.isPackage());
+        assertTrue(_bc.isFinal());
+        assertTrue(!_bc.isInterface());
+        assertTrue(!_bc.isAbstract());
+
+        _bc.setAccessFlags(Constants.ACCESS_ABSTRACT |
+            Constants.ACCESS_INTERFACE);
+        assertTrue(!_bc.isPublic());
+        assertTrue(_bc.isPackage());
+        assertTrue(!_bc.isFinal());
+        assertTrue(_bc.isInterface());
+        assertTrue(_bc.isAbstract());
+
+        _bc.setAccessFlags(Constants.ACCESS_PUBLIC | Constants.ACCESS_SUPER |
+            Constants.ACCESS_FINAL);
+
+        _bc.makePackage();
+        assertTrue(!_bc.isPublic());
+        assertTrue(_bc.isPackage());
+        _bc.makePublic();
+        assertTrue(_bc.isPublic());
+        assertTrue(!_bc.isPackage());
+
+        _bc.setFinal(false);
+        assertTrue(!_bc.isFinal());
+        _bc.setFinal(true);
+        assertTrue(_bc.isFinal());
+
+        _bc.setAbstract(true);
+        assertTrue(_bc.isAbstract());
+        _bc.setAbstract(false);
+        assertTrue(!_bc.isAbstract());
+
+        _bc.setInterface(true);
+        assertTrue(_bc.isInterface());
+        assertTrue(_bc.isAbstract());
+        _bc.setInterface(false);
+        assertTrue(!_bc.isInterface());
+    }
+
+    /**
+      *  Test class type operations.
+     */
+    public void testType() {
+        assertEquals(Integer.class.getName(), _bc.getName());
+        assertEquals("java.lang", _bc.getPackageName());
+        assertEquals("Integer", _bc.getClassName());
+        assertEquals(Integer.class, _bc.getType());
+
+        _bc.setName("serp.Foo");
+        assertEquals("serp.Foo", _bc.getName());
+    }
+
+    /**
+      *  Test superclass operations.
+     */
+    public void testSuperclass() {
+        assertEquals(Number.class.getName(), _bc.getSuperclassName());
+        assertEquals(Number.class, _bc.getSuperclassType());
+        assertEquals(Number.class.getName(), _bc.getSuperclassBC().getName());
+        assertEquals(null,
+            _bc.getSuperclassBC().getSuperclassBC().getSuperclassBC());
+
+        _bc.setSuperclass(String.class);
+        assertEquals(String.class.getName(), _bc.getSuperclassName());
+
+        _bc.setSuperclass((BCClass) null);
+        _bc.setSuperclass((Class) null);
+        _bc.setSuperclass((String) null);
+        assertNull(_bc.getSuperclassName());
+        assertNull(_bc.getSuperclassType());
+        assertNull(_bc.getSuperclassBC());
+
+        assertEquals(0, _bc.getSuperclassIndex());
+    }
+
+    /**
+     *  Test operations on interfaces.
+     */
+    public void testInterfaces() {
+        Object[] interfaces = _bc.getInterfaceNames();
+        assertEquals(2, interfaces.length);
+        assertEquals(Comparable.class.getName(), interfaces[0]);
+        assertEquals(Serializable.class.getName(), interfaces[1]);
+
+        interfaces = _bc.getInterfaceTypes();
+        assertEquals(2, interfaces.length);
+        assertEquals(Comparable.class, interfaces[0]);
+        assertEquals(Serializable.class, interfaces[1]);
+
+        interfaces = _bc.getInterfaceBCs();
+        assertEquals(2, interfaces.length);
+        assertEquals(Comparable.class, ((BCClass) interfaces[0]).getType());
+        assertEquals(Serializable.class, ((BCClass) interfaces[1]).getType());
+
+        interfaces = _bc.getDeclaredInterfaceNames();
+        assertEquals(1, interfaces.length);
+        assertEquals(Comparable.class.getName(), interfaces[0]);
+
+        interfaces = _bc.getDeclaredInterfaceTypes();
+        assertEquals(1, interfaces.length);
+        assertEquals(Comparable.class, interfaces[0]);
+
+        interfaces = _bc.getDeclaredInterfaceBCs();
+        assertEquals(1, interfaces.length);
+        assertEquals(Comparable.class, ((BCClass) interfaces[0]).getType());
+
+        assertTrue(_bc.isInstanceOf(Comparable.class.getName()));
+        assertTrue(_bc.isInstanceOf(Comparable.class));
+        assertTrue(_bc.isInstanceOf(_project.loadClass(Comparable.class)));
+        assertTrue(_bc.isInstanceOf(Serializable.class));
+        assertTrue(!_bc.isInstanceOf(Cloneable.class.getName()));
+        assertTrue(!_bc.isInstanceOf(Cloneable.class));
+        assertTrue(!_bc.isInstanceOf(_project.loadClass(Cloneable.class)));
+
+        _bc.clearDeclaredInterfaces();
+        interfaces = _bc.getInterfaceNames();
+        assertEquals(1, interfaces.length);
+        assertEquals(Serializable.class.getName(), interfaces[0]);
+
+        interfaces = _bc.getDeclaredInterfaceNames();
+        assertEquals(0, interfaces.length);
+
+        _bc.declareInterface(Comparable.class.getName());
+        assertTrue(_bc.isInstanceOf(Comparable.class.getName()));
+        interfaces = _bc.getDeclaredInterfaceNames();
+        assertEquals(1, interfaces.length);
+        assertEquals(Comparable.class.getName(), interfaces[0]);
+
+        assertTrue(!_bc.removeDeclaredInterface(Serializable.class));
+        assertTrue(_bc.removeDeclaredInterface(Comparable.class.getName()));
+        interfaces = _bc.getDeclaredInterfaceNames();
+        assertEquals(0, interfaces.length);
+
+        _bc.declareInterface(Comparable.class);
+        assertTrue(_bc.isInstanceOf(Comparable.class));
+        interfaces = _bc.getDeclaredInterfaceTypes();
+        assertEquals(1, interfaces.length);
+        assertEquals(Comparable.class, interfaces[0]);
+
+        assertTrue(_bc.removeDeclaredInterface(Comparable.class));
+        interfaces = _bc.getDeclaredInterfaceNames();
+        assertEquals(0, interfaces.length);
+
+        _bc.declareInterface(_project.loadClass(Comparable.class));
+        assertTrue(_bc.isInstanceOf(_project.loadClass(Comparable.class)));
+        interfaces = _bc.getDeclaredInterfaceBCs();
+        assertEquals(1, interfaces.length);
+        assertEquals(Comparable.class, ((BCClass) interfaces[0]).getType());
+
+        assertTrue(_bc.removeDeclaredInterface(_project.loadClass(
+                    Comparable.class)));
+        interfaces = _bc.getDeclaredInterfaceNames();
+        assertEquals(0, interfaces.length);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestBCClass.class);
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(suite());
+    }
+}

Propchange: incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestBCClass.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestCode.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestCode.java?rev=417860&view=auto
==============================================================================
--- incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestCode.java (added)
+++ incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestCode.java Wed Jun 28 12:46:13 2006
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package serp.bytecode;
+
+import junit.framework.*;
+
+import junit.textui.*;
+
+
+/**
+ *  <p>Tests the {@link Code} class.</p>
+ *
+ *  @author Eric Lindauer
+ */
+public class TestCode extends TestCase {
+    public TestCode(String test) {
+        super(test);
+    }
+
+    /**
+     *  Test that removing Instructions from a Code block
+     *  removes the correct Instructions.
+     */
+    public void testRemove() {
+        Code code = new Code();
+        JumpInstruction go2 = code.go2();
+        Instruction first = code.nop();
+        Instruction second = code.nop();
+        Instruction third = code.nop();
+        Instruction fourth = code.nop();
+        go2.setTarget(second);
+
+        // remove 'second' after a next() call
+        code.beforeFirst();
+        code.next();
+        code.next();
+        code.next();
+        code.remove();
+        assertEquals(third, code.next());
+        assertEquals(third, go2.getTarget());
+        code.beforeFirst();
+        assertEquals(go2, code.next());
+        assertEquals(first, code.next());
+        assertEquals(third, code.next());
+        assertEquals(fourth, code.next());
+
+        // remove 'third' after a previous() call
+        code.beforeFirst();
+        code.next();
+        code.next();
+        code.next();
+        code.next();
+        code.previous();
+        code.previous();
+        code.remove();
+        assertEquals(fourth, go2.getTarget());
+        assertEquals(fourth, code.next());
+
+        assertTrue(!code.hasNext());
+        assertEquals(fourth, code.previous());
+        code.remove();
+        code.afterLast();
+        assertEquals(code.previous(), go2.getTarget());
+        assertEquals(first, code.previous());
+    }
+
+    /**
+     *  Test that instruction indexes work correctly.
+     */
+    public void testIndexes() {
+        Code code = new Code();
+        assertEquals(0, code.nextIndex());
+        assertEquals(-1, code.previousIndex());
+
+        Instruction first = code.nop();
+        assertEquals(1, code.nextIndex());
+        assertEquals(0, code.previousIndex());
+
+        Instruction second = code.nop();
+        assertEquals(2, code.nextIndex());
+        assertEquals(1, code.previousIndex());
+        code.previous();
+        assertEquals(1, code.nextIndex());
+        assertEquals(0, code.previousIndex());
+        code.next();
+        assertEquals(2, code.nextIndex());
+        assertEquals(1, code.previousIndex());
+
+        Instruction third = code.nop();
+        assertEquals(3, code.nextIndex());
+        assertEquals(2, code.previousIndex());
+
+        code.afterLast();
+        assertEquals(3, code.nextIndex());
+        assertEquals(2, code.previousIndex());
+
+        code.beforeFirst();
+        assertEquals(0, code.nextIndex());
+        assertEquals(-1, code.previousIndex());
+
+        code.before(first);
+        assertEquals(0, code.nextIndex());
+        assertEquals(-1, code.previousIndex());
+        code.before(second);
+        assertEquals(1, code.nextIndex());
+        assertEquals(0, code.previousIndex());
+        code.before(third);
+        assertEquals(2, code.nextIndex());
+        assertEquals(1, code.previousIndex());
+
+        code.after(first);
+        assertEquals(1, code.nextIndex());
+        assertEquals(0, code.previousIndex());
+        code.after(second);
+        assertEquals(2, code.nextIndex());
+        assertEquals(1, code.previousIndex());
+        code.after(third);
+        assertEquals(3, code.nextIndex());
+        assertEquals(2, code.previousIndex());
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestCode.class);
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(suite());
+    }
+}

Propchange: incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestCode.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestConstantInstruction.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestConstantInstruction.java?rev=417860&view=auto
==============================================================================
--- incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestConstantInstruction.java (added)
+++ incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestConstantInstruction.java Wed Jun 28 12:46:13 2006
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package serp.bytecode;
+
+import junit.framework.*;
+
+import junit.textui.*;
+
+
+/**
+ *  <p>Tests the {@link ConstantInstruction} type.</p>
+ *
+ *  @author Abe White
+ */
+public class TestConstantInstruction extends TestCase {
+    private ConstantInstruction _const = new Code().constant();
+
+    public TestConstantInstruction(String test) {
+        super(test);
+    }
+
+    /**
+     *  Test that the type instruction returns its type correctly.
+     */
+    public void testGetType() {
+        assertNull(_const.getType());
+        assertEquals(int.class, _const.setValue(0).getType());
+        assertEquals(int.class, _const.setValue(2 << 3).getType());
+        assertEquals(int.class, _const.setValue(2 << 7).getType());
+        assertEquals(int.class, _const.setValue(2 << 15).getType());
+        assertEquals(long.class, _const.setValue(0L).getType());
+        assertEquals(long.class, _const.setValue(1000L).getType());
+        assertEquals(float.class, _const.setValue(0F).getType());
+        assertEquals(float.class, _const.setValue(1000F).getType());
+        assertEquals(double.class, _const.setValue(0D).getType());
+        assertEquals(double.class, _const.setValue(1000D).getType());
+        assertEquals(Object.class, _const.setValue((Object) null).getType());
+        assertEquals(String.class, _const.setValue("foo").getType());
+        assertEquals(int.class, _const.setValue(true).getType());
+        assertEquals(int.class, _const.setValue((short) 0).getType());
+        assertEquals(int.class, _const.setValue('a').getType());
+        assertEquals(Class.class, _const.setValue(String.class).getType());
+    }
+
+    /**
+     *  Test that the value is stored correctly.
+     */
+    public void testGetValue() {
+        assertNull(_const.getValue());
+        assertEquals(0, _const.setValue(0).getIntValue());
+        assertEquals(-1, _const.setValue(-1).getIntValue());
+        assertEquals(2 << 3, _const.setValue(2 << 3).getIntValue());
+        assertEquals(2 << 7, _const.setValue(2 << 7).getIntValue());
+        assertEquals(2 << 15, _const.setValue(2 << 15).getIntValue());
+        assertEquals(0L, _const.setValue(0L).getLongValue());
+        assertEquals(1000L, _const.setValue(1000L).getLongValue());
+        assertEquals(0F, _const.setValue(0F).getFloatValue(), .001);
+        assertEquals(1000F, _const.setValue(1000F).getFloatValue(), .001);
+        assertEquals(0D, _const.setValue(0D).getDoubleValue(), .001);
+        assertEquals(1000D, _const.setValue(1000D).getDoubleValue(), .001);
+        assertNull(_const.setValue((Object) null).getValue());
+        assertEquals("foo", _const.setValue("foo").getStringValue());
+        assertEquals(1, _const.setValue(true).getIntValue());
+        assertEquals(0, _const.setValue((short) 0).getIntValue());
+        assertEquals((int) 'a', _const.setValue('a').getIntValue());
+        assertEquals(String.class.getName(),
+            _const.setValue(String.class).getClassNameValue());
+    }
+
+    /**
+     *  Test the the opcode is morphed correctly when the value is set.
+     */
+    public void testOpcodeMorph() {
+        assertEquals(Constants.NOP, _const.getOpcode());
+        assertEquals(Constants.ICONSTM1, _const.setValue(-1).getOpcode());
+        assertEquals(Constants.ICONST0, _const.setValue(0).getOpcode());
+        assertEquals(Constants.ICONST1, _const.setValue(1).getOpcode());
+        assertEquals(Constants.ICONST2, _const.setValue(2).getOpcode());
+        assertEquals(Constants.ICONST3, _const.setValue(3).getOpcode());
+        assertEquals(Constants.ICONST4, _const.setValue(4).getOpcode());
+        assertEquals(Constants.ICONST5, _const.setValue(5).getOpcode());
+        assertEquals(Constants.BIPUSH, _const.setValue(2 << 3).getOpcode());
+        assertEquals(Constants.SIPUSH, _const.setValue(2 << 7).getOpcode());
+        assertEquals(Constants.LDC, _const.setValue(2 << 15).getOpcode());
+        assertEquals(Constants.LCONST0, _const.setValue(0L).getOpcode());
+        assertEquals(Constants.LCONST1, _const.setValue(1L).getOpcode());
+        assertEquals(Constants.LDC2W, _const.setValue(1000L).getOpcode());
+        assertEquals(Constants.FCONST2, _const.setValue(2F).getOpcode());
+        assertEquals(Constants.FCONST1, _const.setValue(1F).getOpcode());
+        assertEquals(Constants.FCONST0, _const.setValue(0F).getOpcode());
+        assertEquals(Constants.LDC, _const.setValue(1000F).getOpcode());
+        assertEquals(Constants.DCONST0, _const.setValue(0D).getOpcode());
+        assertEquals(Constants.DCONST1, _const.setValue(1D).getOpcode());
+        assertEquals(Constants.LDC2W, _const.setValue(2D).getOpcode());
+        assertEquals(Constants.LDC2W, _const.setValue(1000D).getOpcode());
+        assertEquals(Constants.LDC, _const.setValue("foo").getOpcode());
+        assertEquals(Constants.ICONST1, _const.setValue(true).getOpcode());
+        assertEquals(Constants.BIPUSH, _const.setValue('a').getOpcode());
+        assertEquals(Constants.ICONST0, _const.setValue((short) 0).getOpcode());
+        assertEquals(Constants.ACONSTNULL,
+            _const.setValue((Object) null).getOpcode());
+        assertEquals(Constants.LDCW, _const.setValue(String.class).getOpcode());
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestConstantInstruction.class);
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(suite());
+    }
+}

Propchange: incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestConstantInstruction.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestConvertInstruction.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestConvertInstruction.java?rev=417860&view=auto
==============================================================================
--- incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestConvertInstruction.java (added)
+++ incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestConvertInstruction.java Wed Jun 28 12:46:13 2006
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package serp.bytecode;
+
+import junit.framework.*;
+
+import junit.textui.*;
+
+
+/**
+ *  <p>Tests the {@link ConvertInstruction} type.</p>
+ *
+ *  @author Abe White
+ */
+public class TestConvertInstruction extends TestCase {
+    private Code _code = new Code();
+
+    public TestConvertInstruction(String test) {
+        super(test);
+    }
+
+    /**
+     *  Test that the opcode is morphed correctly when the types are set.
+     */
+    public void testOpcodeMorph() {
+        ConvertInstruction ins = _code.convert();
+        assertEquals(Constants.NOP, ins.getOpcode());
+
+        ins.setFromType(int.class);
+        assertEquals(Constants.NOP, ins.getOpcode());
+        assertEquals(int.class, ins.getFromType());
+        assertNull(ins.getType());
+
+        ins.setType(int.class);
+        assertEquals(Constants.NOP, ins.getOpcode());
+        assertEquals(int.class, ins.getFromType());
+        assertEquals(int.class, ins.getType());
+
+        ins.setType(long.class);
+        assertEquals(Constants.I2L, ins.getOpcode());
+        assertEquals(int.class, ins.getFromType());
+        assertEquals(long.class, ins.getType());
+
+        ins.setType(float.class);
+        assertEquals(Constants.I2F, ins.getOpcode());
+        assertEquals(int.class, ins.getFromType());
+        assertEquals(float.class, ins.getType());
+
+        ins.setType(double.class);
+        assertEquals(Constants.I2D, ins.getOpcode());
+        assertEquals(int.class, ins.getFromType());
+        assertEquals(double.class, ins.getType());
+
+        ins.setFromType(long.class);
+        assertEquals(Constants.L2D, ins.getOpcode());
+        assertEquals(long.class, ins.getFromType());
+        assertEquals(double.class, ins.getType());
+
+        ins.setType(long.class);
+        assertEquals(Constants.NOP, ins.getOpcode());
+        assertEquals(long.class, ins.getFromType());
+        assertEquals(long.class, ins.getType());
+
+        ins.setType(int.class);
+        assertEquals(Constants.L2I, ins.getOpcode());
+        assertEquals(long.class, ins.getFromType());
+        assertEquals(int.class, ins.getType());
+
+        ins.setType(String.class);
+        assertEquals(Constants.L2I, ins.getOpcode());
+
+        ins.setType((Class) null);
+        assertEquals(Constants.NOP, ins.getOpcode());
+
+        ins.setType(float.class);
+        assertEquals(Constants.L2F, ins.getOpcode());
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestConvertInstruction.class);
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(suite());
+    }
+}

Propchange: incubator/openjpa/trunk/serp/src/test/java/serp/bytecode/TestConvertInstruction.java
------------------------------------------------------------------------------
    svn:executable = *