diff options
author | Kenny Ballou <kballou@devnulllabs.io> | 2018-11-19 22:59:50 -0700 |
---|---|---|
committer | Kenny Ballou <kballou@devnulllabs.io> | 2018-11-19 22:59:50 -0700 |
commit | ea3e1b949dcbdc09518f17eee0bcf21d41d76896 (patch) | |
tree | 7ec7a7fb4df67815a9b7bb0e4d95d67c4050e2a2 /src/test | |
download | openjava-ea3e1b949dcbdc09518f17eee0bcf21d41d76896.tar.gz openjava-ea3e1b949dcbdc09518f17eee0bcf21d41d76896.tar.xz |
OJ (aka OpenJava) modernization/mirroring
Signed-off-by: Kenny Ballou <kballou@devnulllabs.io>
Diffstat (limited to 'src/test')
76 files changed, 2218 insertions, 0 deletions
diff --git a/src/test/java/antonio/Test.oj b/src/test/java/antonio/Test.oj new file mode 100644 index 0000000..b9c9c26 --- /dev/null +++ b/src/test/java/antonio/Test.oj @@ -0,0 +1,36 @@ +package antonio; + +import java.util.*; + +public class Test +{ + public int bbb() { + return 1; + } + + class InnerVector extends Vector { + public int ff = 3; + public int aaa() { + return bbb(); + } + + public int ccc() { + return 0; + } + } + + public void ddd() { + InnerVector v = new InnerVector() { + public int ccc() { + int j = ff; + return aaa(); + } + }; + System.err.println("Result:" + v.ccc()); + } + + + public static void main(String[] args) { + (new Test()).ddd(); + } +} diff --git a/src/test/java/bryn/ArraySupport.oj b/src/test/java/bryn/ArraySupport.oj new file mode 100644 index 0000000..156ee50 --- /dev/null +++ b/src/test/java/bryn/ArraySupport.oj @@ -0,0 +1,62 @@ +package bryn; + +import io.devnulllabs.openjava.mop.*; +import io.devnulllabs.openjava.ptree.*; +import io.devnulllabs.openjava.syntax.*; +import io.devnulllabs.openjava.ptree.util.VariableBinder; + +public class ArraySupport instantiates Metaclass extends OJClass { + /* overrides for translation */ + public void translateDefinition() throws MOPException { + OJMethod[] methods = getDeclaredMethods(); + for (int i = 0; i < methods.length; ++i) { + ArrayAccessReplace.run(methods[i]); + } + } + + convenient public static boolean needed(OJClass type) { + return (type == java.util.ArrayList.class); + } + +} + +class ArrayAccessReplace extends VariableBinder { + public static void run(OJMethod method) throws MOPException { + ArrayAccessReplace replacer = + new ArrayAccessReplace(method.getEnvironment()); + try { + method.getBody().accept(replacer); + } catch (ParseTreeException e) { + throw new MOPException(e); + } + } + + public ArrayAccessReplace(Environment env) { + super(new ClosedEnvironment(env)); + } + + public Expression evaluateUp(ArrayAccess org_expr) + throws ParseTreeException { + /* "list" of "list[0]" */ + Expression refexpr = org_expr.getReferenceExpr(); + + /* this is only for java.util.ArrayList instances */ + try { + OJClass reftype = refexpr.getType(getEnvironment()); + if (!ArraySupport.needed(reftype)) + return org_expr; + } catch (Exception ex) { + throw new ParseTreeException(ex); + } + + /* Creates arguments for method call */ + ExpressionList args = new ExpressionList(org_expr.getIndexExpr()); + + /* returns "list.get(0)" from "list[0]" */ + MethodCall result = new MethodCall(refexpr, "get", args); + + System.err.println(org_expr + " -> " + result); + return result; + } + +} diff --git a/src/test/java/bryn/ArrayTest.oj b/src/test/java/bryn/ArrayTest.oj new file mode 100644 index 0000000..eceba8b --- /dev/null +++ b/src/test/java/bryn/ArrayTest.oj @@ -0,0 +1,13 @@ +package bryn; + +import java.util.*; + +public class ArrayTest instantiates ArraySupport { + public static void main(String[] args) { + int[] il = new int[32]; + ArrayList list = new ArrayList(); + list.add("Hello"); + list.add("World"); + System.out.println(list[0] + " " + list[1] + " " + il[0]); + } +} diff --git a/src/test/java/cristophe/SigPrintClass.oj b/src/test/java/cristophe/SigPrintClass.oj new file mode 100644 index 0000000..462f43b --- /dev/null +++ b/src/test/java/cristophe/SigPrintClass.oj @@ -0,0 +1,22 @@ +import cristophe; + +import io.devnulllabs.openjava.mop.*; +import io.devnulllabs.openjava.ptree.*; + +/** + * The class <code>SigPrintClass</code> prints out the signature of + * public methods in the class metaobject. + */ +public class SigPrintClass instantiates Metaclass extends OJClass { + public ClassDeclaration translateDefinition( + Environment env, + ClassDeclaration decl) { + OJMethod[] m = getMethods(); + + for (int i = 0; i < m.length; ++i) { + System.out.println(m[i].signature()); + } + + return decl; + } +} diff --git a/src/test/java/cristophe/Test.oj b/src/test/java/cristophe/Test.oj new file mode 100644 index 0000000..accd283 --- /dev/null +++ b/src/test/java/cristophe/Test.oj @@ -0,0 +1,24 @@ +package cristophe; + +public class Test instantiates SigPrintClass +{ + public void f() { + } + + public String g(String s, int i) { + return null; + } + +} + + +class Test2 instantiates SigPrintClass +{ + public void f() { + } + + public String g(String s, int i) { + return null; + } + +} diff --git a/src/test/java/cristophe2/MethodRemovingClass.oj b/src/test/java/cristophe2/MethodRemovingClass.oj new file mode 100644 index 0000000..2041dec --- /dev/null +++ b/src/test/java/cristophe2/MethodRemovingClass.oj @@ -0,0 +1,20 @@ +package cristophe2; + +import io.devnulllabs.openjava.mop.*; +import io.devnulllabs.openjava.ptree.*; + +public class MethodRemovingClass instantiates Metaclass extends OJClass { + public ClassDeclaration translateDefinition( + Environment env, + ClassDeclaration decl) + throws MOPException { + OJMethod[] m = getDeclaredMethods(); + + if (m.length >= 1) { + System.out.println("Removing " + m[0].signature()); + removeMethod(m[0]); + } + + return decl; + } +} diff --git a/src/test/java/cristophe2/Test.oj b/src/test/java/cristophe2/Test.oj new file mode 100644 index 0000000..80ea445 --- /dev/null +++ b/src/test/java/cristophe2/Test.oj @@ -0,0 +1,21 @@ +pacakge cristophe2; + +public class Test instantiates MethodRemovingClass { + public void f() { + } + + public String g(String s, int i) { + return null; + } + +} + +class Test2 instantiates MethodRemovingClass { + public String g(String s, int i) { + return null; + } + + public void f() { + } + +} diff --git a/src/test/java/dardia/InterImpl.oj b/src/test/java/dardia/InterImpl.oj new file mode 100644 index 0000000..1a36255 --- /dev/null +++ b/src/test/java/dardia/InterImpl.oj @@ -0,0 +1,117 @@ +package dardia; + +import java.lang.reflect.Modifier; + +import io.devnulllabs.openjava.mop.CannotAlterException; +import io.devnulllabs.openjava.mop.Environment; +import io.devnulllabs.openjava.mop.FileEnvironment; +import io.devnulllabs.openjava.mop.MOPException; +import io.devnulllabs.openjava.mop.Metaclass; +import io.devnulllabs.openjava.mop.MetaInfo; +import io.devnulllabs.openjava.mop.OJClass; +import io.devnulllabs.openjava.mop.OJConstructor; +import io.devnulllabs.openjava.mop.OJField; +import io.devnulllabs.openjava.mop.OJMethod; +import io.devnulllabs.openjava.mop.OJModifier; +import io.devnulllabs.openjava.mop.OJSystem; +import io.devnulllabs.openjava.ptree.ClassDeclaration; +import io.devnulllabs.openjava.ptree.MemberDeclarationList; +import io.devnulllabs.openjava.ptree.ModifierList; +import io.devnulllabs.openjava.ptree.ParseTreeException; +import io.devnulllabs.openjava.ptree.TypeName; + +public class InterImpl instantiates Metaclass extends openjava.mop.OJClass { + + public void translateDefinition() throws MOPException { + EditableClass newClass = + new EditableClass(makeCopy(getName() + "Impl")); + OJSystem.addNewClass(newClass); + + beInterface(); + removeFieldsAndConstructors(); + turnMethodsEmpty(); + + newClass.addInterface(this); + } + + private void beInterface() throws MOPException { + ClassDeclaration orgDecl = getSourceCode(); + ModifierList modifs = new ModifierList(Modifier.PUBLIC); + String name = orgDecl.getName(); + TypeName[] bases = new TypeName[0]; + TypeName[] faces = new TypeName[0]; + MemberDeclarationList classBody = orgDecl.getBody(); + ClassDeclaration newDecl = + new ClassDeclaration(modifs, name, bases, faces, classBody, false); + try { + orgDecl.replace(newDecl); + } catch (ParseTreeException e) { + throw new MOPException(e.toString()); + } + } + + private void removeFieldsAndConstructors() throws MOPException { + OJField[] f = getDeclaredFields(); + for (int i = 0; i < f.length; ++i) { + removeField(f[i]); + } + OJConstructor[] cons = getDeclaredConstructors(); + for (int i = 0; i < cons.length; ++i) { + removeConstructor(cons[i]); + } + } + + private void turnMethodsEmpty() throws MOPException { + OJMethod[] m = getDeclaredMethods(); + for (int i = 0; i < m.length; ++i) { + OJModifier modif = m[i].getModifiers(); + if (!modif.isPublic() || modif.isStatic()) { + removeMethod(m[i]); + } + m[i].setModifiers(OJModifier.forModifier(OJModifier.PUBLIC)); + m[i].setBody(null); + } + } + +} + +class EditableClass extends OJClass { + + public EditableClass(OJClass original) + throws CannotAlterException { + super( + new FileEnvironment( + OJSystem.env, + original.getPackage(), + original.getSimpleName()), + original.getDeclaringClass(), + original.getSourceCode()); + } + + public OJClass addClass(OJClass clazz) + throws CannotAlterException { + return super.addClass(clazz); + } + + public OJConstructor addConstructor( + OJConstructor constr) + throws CannotAlterException { + return super.addConstructor(constr); + } + + public OJField addField(OJField field) + throws CannotAlterException { + return super.addField(field); + } + + public void addInterface(OJClass clazz) + throws CannotAlterException { + super.addInterface(clazz); + } + + public OJMethod addMethod(OJMethod method) + throws CannotAlterException { + return super.addMethod(method); + } + +} diff --git a/src/test/java/dardia/MIJava.oj b/src/test/java/dardia/MIJava.oj new file mode 100644 index 0000000..574b11c --- /dev/null +++ b/src/test/java/dardia/MIJava.oj @@ -0,0 +1,109 @@ +import io.devnulllabs.openjava.mop.*; +import io.devnulllabs.openjava.ptree.*; +import io.devnulllabs.openjava.syntax.*; + +import java.util.*; + +public class MIJava instantiates Metaclass extends OJClass { + + // The below logic performs conflict resolution by not overwriting any methods already existing. + // This means that if in the TA multiextends Staff, Student example both Staff and Student have a field or + // a method with the same name, the field/method that is copied into TA's body is the one from the base + // class that occurs earlier in the argument list to multiextends. + public void translateDefinition() throws MOPException { + transformMultiextendingClass(); + } + + public void transformMultiextendingClass() throws MOPException { + ObjectList extendedClasses = (ObjectList)getSuffix("multiextends"); + + Collection existingSignatures = new Vector(); + OJMethod[] currentMethods = getDeclaredMethods(); + for (int i = 0; i < currentMethods.length; i++) { + existingSignatures.add((currentMethods[i].signature()).toString()); + } + + Collection existingFields = new Vector(); + OJField[] currentFields = getDeclaredFields(); + for (int i = 0; i < currentFields.length; i++) { + existingFields.add((currentFields[i].signature()).toString()); + } + + if (extendedClasses != null) { + for (int i = 0; i < extendedClasses.size(); i++) { + try { + OJClass currentExtendedClass = OJClass.forName((extendedClasses.get(i)).toString()); + + // open each class that we multiextended and copy its methods into a local variable + OJMethod[] currentExtendedClassMethods = currentExtendedClass.getDeclaredMethods(); + + // copy all of the methods for the current extended class into the output if they don't already exist + for (int j = 0; j < currentExtendedClassMethods.length; j++) { + if (!existingSignatures.contains((currentExtendedClassMethods[j].signature()).toString())) { + // if we don't currently have this method, add it + //addMethod(currentExtendedClassMethods[j]); + + // Because the above addMethod() causes odd CannotAlterExceptions to be thrown, I do + // the below to describe what is happening in the multiextending class and where its + // methods come from. + + StatementList statementsToInsert = new StatementList(); + Statement cameFromStatement = makeStatement("System.out.println(\"this body would come from " + (extendedClasses.get(i)).toString() + "\\n\");"); + statementsToInsert.add(cameFromStatement); + + + OJMethod methodToInsert = new OJMethod((OJClass)this, + currentExtendedClassMethods[j].getModifiers(), + currentExtendedClassMethods[j].getReturnType(), + currentExtendedClassMethods[j].getName(), + currentExtendedClassMethods[j].getParameterTypes(), + currentExtendedClassMethods[j].getExceptionTypes(), + statementsToInsert); + + addMethod(methodToInsert); + + // make note that we added a mehtod with some signature so we don't put multiple methods + // with the same signature into the class. this would be invalid Java code and unlogical. + existingSignatures.add((methodToInsert.signature()).toString()); + } // else, a method with the same signature already exists, skip it + } + + + // open each class and copy its fields into local variable + OJField[] currentExtendedClassFields = currentExtendedClass.getDeclaredFields(); + + // copy all of the fields for the current extended class into the output if they don't already exist + for (int j = 0; j < currentExtendedClassFields.length; j++) { + if (!existingFields.contains((currentExtendedClassFields[j].signature()).toString())) { + // if we don't currently have this field, add it + addField(currentExtendedClassFields[j]); + existingFields.add((currentExtendedClassFields[j].signature()).toString()); + } + } + + } catch (OJClassNotFoundException e) { + System.err.println(e); + System.exit(-1); + } + } + } + } + + // new class modifier: "multiextends". + public static boolean isRegisteredKeyword(String str) { + if (str.equals("multiextends")) { + return(true); + } + + return OJClass.isRegisteredKeyword(str); + } + + // overridden to let OpenJava know how multiextends arguments are separated. + public static SyntaxRule getDeclSuffixRule(String str) { + if (str.equals("multiextends")) { + return new DefaultListRule(new TypeNameRule(), TokenID.COMMA ); + } + + return null; + } +} diff --git a/src/test/java/dardia/MultiextendingClass.oj b/src/test/java/dardia/MultiextendingClass.oj new file mode 100644 index 0000000..51bdccf --- /dev/null +++ b/src/test/java/dardia/MultiextendingClass.oj @@ -0,0 +1,129 @@ +package dardia; + +import io.devnulllabs.openjava.mop.CannotAlterException; +import io.devnulllabs.openjava.mop.Environment; +import io.devnulllabs.openjava.mop.MOPException; +import io.devnulllabs.openjava.mop.Metaclass; +import io.devnulllabs.openjava.mop.MetaInfo; +import io.devnulllabs.openjava.mop.OJClass; +import io.devnulllabs.openjava.mop.OJConstructor; +import io.devnulllabs.openjava.mop.OJField; +import io.devnulllabs.openjava.mop.OJMethod; +import io.devnulllabs.openjava.mop.OJModifier; +import io.devnulllabs.openjava.mop.OJSystem; +import io.devnulllabs.openjava.ptree.ClassDeclaration; +import io.devnulllabs.openjava.ptree.ObjectList; +import io.devnulllabs.openjava.syntax.DefaultListRule; +import io.devnulllabs.openjava.syntax.SyntaxRule; +import io.devnulllabs.openjava.syntax.TokenID; +import io.devnulllabs.openjava.syntax.TypeNameRule; + +public class InterImpl instantiates Metaclass extends OJClass { + + public void translateDefinition() throws io.devnulllabs.openjava.mop.MOPException { + ObjectList extendedClasses = + (openjava.ptree.ObjectList) getSuffix("multiextends"); + if (extendedClasses == null) + return; + + EditableClass newClass = + new EditableClass(makeCopy(getName() + "Impl")); + for (int i = 0; i < extendedClasses.size(); ++i) { + OJClass extendedInterface = + OJClass.forName(extendedClasses.get(i).toString()); + addImplementation(newClass, extendedInterface); + } + + beInterface(); + for (int i = 0; i < extendedClasses.size(); ++i) { + OJClass extendedInterface = + OJClass.forName(extendedClasses.get(i).toString()); + addInterface(extendedInterface); + } + + newClass.addInterface(this); + OJSystem.addNewClass(newClass); + } + + public void addImplementation( + EditableClass newClass, + OJClass extendedInterface) + throws MOPException { + newClass.addInterface(extendedInterface); + OJClass extendedImpl = + OJClass.forName(extendedInterface.getName() + "Impl"); + OJMethod[] methodImpls = extendedImpl.getDeclaredMethods(); + for (int i = 0; i < methodImpls.length; ++i) { + newClass.addMethod(methodImpls[i]); + } + } + + public void beInterface() throws MOPException { + getModifiers().add(OJModifier.INTERFACE); + OJMethod[] methods = getDeclaredMethods(); + for (int i = 0; i < methods.length; ++i) { + methods[i].getModifiers().setAbstract(); + methods[i].setBody(null); + } + } + + public InterImpl( + Environment oj_param0, + OJClass oj_param1, + ClassDeclaration oj_param2) { + super(oj_param0, oj_param1, oj_param2); + } + + public InterImpl(Class oj_param0, MetaInfo oj_param1) { + super(oj_param0, oj_param1); + } + + // new class modifier: "multiextends". + public static boolean isRegisteredKeyword(String str) { + if (str.equals("multiextends")) { + return (true); + } + return OJClass.isRegisteredKeyword(str); + } + + // overridden to let OpenJava know how multiextends arguments are + // separated. + public static SyntaxRule getDeclSuffixRule(String str) { + if (str.equals("multiextends")) { + return new DefaultListRule(new TypeNameRule(), TokenID.COMMA); + } + return OJClass.getDeclSuffixRule(str); + } +} + +class EditableClass extends io.devnulllabs.openjava.mop.OJClass { + public EditableClass(OJClass original) throws CannotAlterException { + super( + original.getEnvironment(), + original.getDeclaringClass(), + original.getSourceCode()); + } + + public OJClass addClass(openjava.mop.OJClass clazz) + throws CannotAlterException { + return super.addClass(clazz); + } + + public OJConstructor addConstructor(OJConstructor constr) + throws CannotAlterException { + return super.addConstructor(constr); + } + + public OJField addField(OJField field) throws CannotAlterException { + return super.addField(field); + } + + public void addInterface(OJClass clazz) throws CannotAlterException { + super.addInterface(clazz); + } + + public OJMethod addMethod(OJMethod method) throws CannotAlterException { + return super.addMethod(method); + } + +} diff --git a/src/test/java/dardia/Person.oj b/src/test/java/dardia/Person.oj new file mode 100644 index 0000000..0f43577 --- /dev/null +++ b/src/test/java/dardia/Person.oj @@ -0,0 +1,17 @@ +/* + * Person.java + * + * Created on 2003/11/02 + * $Id$ + */ +package dardia; + +/** + * The type Person. + * @author Michiaki Tatsubori + * @version 1.0 2003/11/02 + */ +public class Person instantiates InterImpl { + public String getName() { + } +} diff --git a/src/test/java/dardia/Student.oj b/src/test/java/dardia/Student.oj new file mode 100644 index 0000000..2a4e07d --- /dev/null +++ b/src/test/java/dardia/Student.oj @@ -0,0 +1,19 @@ +package dardia; + +public class Student instantiates InterImpl { + public Double GPA; + + public Double getGPA() { + System.out.println("Student's getGPA() invoked!"); + return GPA; + } + + public void setGPA(Double _GPA) { + System.out.println("Student's setGPA() invoked!"); + GPA = _GPA; + } + + public String toString() { + return "Student's toString (GPA=" + GPA.toString() + ")"; + } +}
\ No newline at end of file diff --git a/src/test/java/dardia/TA.oj b/src/test/java/dardia/TA.oj new file mode 100644 index 0000000..ce0ccb2 --- /dev/null +++ b/src/test/java/dardia/TA.oj @@ -0,0 +1,16 @@ +/******************************************************** +| Art Dardia <dardia@rpi.edu> [10-27-2003] +| +| CSCI-4430 Programming Languages +| Carlos Varela +| Mon.,Thurs. @ 12-1:50pm +| +| filename: TA.oj +| descrip.: +********************************************************/ + +// no imports + +public class TA instantiates MIJava multiextends Student, Staff { + +}
\ No newline at end of file diff --git a/src/test/java/demobug/Bug1.java b/src/test/java/demobug/Bug1.java new file mode 100644 index 0000000..dca6c4a --- /dev/null +++ b/src/test/java/demobug/Bug1.java @@ -0,0 +1,8 @@ +package demobug; + +public class Bug1 { + int a; + public static final class Bug2 { + static int bug = 12; + }; +}; diff --git a/src/test/java/demobug/DemoBug1.java b/src/test/java/demobug/DemoBug1.java new file mode 100644 index 0000000..f0b10f2 --- /dev/null +++ b/src/test/java/demobug/DemoBug1.java @@ -0,0 +1,58 @@ +package demobug; + +import io.devnulllabs.openjava.mop.Environment; +import io.devnulllabs.openjava.mop.MOPException; +import io.devnulllabs.openjava.mop.MetaInfo; +import io.devnulllabs.openjava.mop.OJClass; +import io.devnulllabs.openjava.mop.OJMethod; +import io.devnulllabs.openjava.mop.OJModifier; +import io.devnulllabs.openjava.mop.OJSystem; +import io.devnulllabs.openjava.ptree.ClassDeclaration; +import io.devnulllabs.openjava.ptree.StatementList; + +public class DemoBug1 extends OJClass { + + public void translateDefinition() throws MOPException { + + // Must load some classes + String[] toFind = new String[] { "Bug1", "Bug1$Bug2", "Bug1.Bug2" }; + for (int i = 0; i < toFind.length; ++i) { + try { + forName("examples.test." + toFind[i]); + } catch (io.devnulllabs.openjava.mop.OJClassNotFoundException ex) { + System.err.println(toFind[i] + " not found !"); + } + } + String body = + "{\n" + + "\t int i=Bug1.Bug2.bug;" + + "\t Integer I=new Integer(i);\n" + + "\t System.out.println(\"Here's the famous value : \"+I);\n" + + "}\n"; + + OJMethod buggy = + new OJMethod( + this, + OJModifier.forModifier(OJModifier.PUBLIC), + OJSystem.VOID, + "Buggy", + new OJClass[] { + }, null, null); + StatementList StBody = + new StatementList(makeStatement(buggy.getEnvironment(), body)); + buggy.setBody(StBody); + addMethod(buggy); + + } + + public DemoBug1( + Environment outer_env, + OJClass declarer, + ClassDeclaration ptree) { + super(outer_env, declarer, ptree); + } + + public DemoBug1(Class javaclass, MetaInfo minfo) { + super(javaclass, minfo); + } +}; diff --git a/src/test/java/demobug/DemoBug1Test.oj b/src/test/java/demobug/DemoBug1Test.oj new file mode 100644 index 0000000..992e48f --- /dev/null +++ b/src/test/java/demobug/DemoBug1Test.oj @@ -0,0 +1,5 @@ +package demobug; + +public class DemoBug1Test instantiates DemoBug1 { + int a; +}; diff --git a/src/test/java/demobug/DemoBug2.java b/src/test/java/demobug/DemoBug2.java new file mode 100644 index 0000000..aa5058e --- /dev/null +++ b/src/test/java/demobug/DemoBug2.java @@ -0,0 +1,47 @@ +package demobug; + +import io.devnulllabs.openjava.mop.Environment; +import io.devnulllabs.openjava.mop.MOPException; +import io.devnulllabs.openjava.mop.MetaInfo; +import io.devnulllabs.openjava.mop.OJClass; +import io.devnulllabs.openjava.mop.OJMethod; +import io.devnulllabs.openjava.mop.OJModifier; +import io.devnulllabs.openjava.mop.OJSystem; +import io.devnulllabs.openjava.ptree.ClassDeclaration; +import io.devnulllabs.openjava.ptree.StatementList; + +public class DemoBug2 extends OJClass { + + public void translateDefinition() throws MOPException { + + String body = + "{\n" + + "\t String Michi=\"My name is Tatsubori ... Michi Tatsubori\";\n" + + "\t System.out.println(\"Here's the famous sentence from 009 : \"+Michi);\n" + + "}\n"; + + OJMethod buggy = + new OJMethod( + this, + OJModifier.forModifier(OJModifier.PUBLIC), + OJSystem.VOID, + "Buggy", + new OJClass[] { + }, null, null); + StatementList StBody = + new StatementList(makeStatement(buggy.getEnvironment(), body)); + buggy.setBody(StBody); + addMethod(buggy); + } + + public DemoBug2( + Environment outer_env, + OJClass declarer, + ClassDeclaration ptree) { + super(outer_env, declarer, ptree); + } + + public DemoBug2(Class javaclass, MetaInfo minfo) { + super(javaclass, minfo); + } +} diff --git a/src/test/java/demobug/DemoBug2Test.oj b/src/test/java/demobug/DemoBug2Test.oj new file mode 100644 index 0000000..fe6de4c --- /dev/null +++ b/src/test/java/demobug/DemoBug2Test.oj @@ -0,0 +1,5 @@ +package demobug; + +public class DemoBug2Test instantiates DemoBug2 { + int a; +} diff --git a/src/test/java/demobug/InnerTest.oj b/src/test/java/demobug/InnerTest.oj new file mode 100644 index 0000000..e3f5ed3 --- /dev/null +++ b/src/test/java/demobug/InnerTest.oj @@ -0,0 +1,29 @@ +/* + * InterTest.java + * + * May 4, 1999 by Michiaki Tatsubori + */ +package demobug; + +import java.lang.System; + +public class InnerTest { + public JJCalls jj; + + public static void main(String[] argv) { + /* + System.out.println( JJCalls.gen ); + JJCalls dummy = new JJCalls(); + JJCalls[] test = new JJCalls[53]; + */ + JJCalls hoge = InnerTest.JJCalls.next; + + //InnerTest u = new InnerTest(); + //hoge = u.JJCalls.next; + } + + static final class JJCalls { + static int gen = 0; + static JJCalls next; + } +} diff --git a/src/test/java/demobug/InnerTest2.oj b/src/test/java/demobug/InnerTest2.oj new file mode 100644 index 0000000..2fb2916 --- /dev/null +++ b/src/test/java/demobug/InnerTest2.oj @@ -0,0 +1,16 @@ +/* + * InterTest.java + * + * May 4, 1999 by Michiaki Tatsubori + */ +package demobug; + +public class InnerTest2 { + public static void main(String[] argv) { + Runnable r = new Runnable() { + public void run() { + } + }; + String s = new String(""); + } +} diff --git a/src/test/java/demobug/MetaTest.oj b/src/test/java/demobug/MetaTest.oj new file mode 100644 index 0000000..acbefdb --- /dev/null +++ b/src/test/java/demobug/MetaTest.oj @@ -0,0 +1,78 @@ +/* + * MetaTest.java + * + * comments here. + * + * @author Michiaki Tatsubori + * @version %VERSION% %DATE% + * @see java.lang.Object + * + * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED. + */ +package demobug; + +import java.lang.Object; +import io.devnulllabs.openjava.mop.*; +import io.devnulllabs.openjava.ptree.ClassDeclaration; +import io.devnulllabs.openjava.syntax.*; + +/** + * The class <code>MetaTest</code> + * <p> + * For example + * <pre> + * </pre> + * <p> + * + * @author Michiaki Tatsubori + * @version 1.0 + * @since %SOFTWARE% 1.0 + * @see java.lang.Object + */ +public class MetaTest extends OJClass { + public MetaTest( + Environment outer_env, + OJClass declarer, + ClassDeclaration ptree) { + super(outer_env, declarer, ptree); + } + + public ClassDeclaration translateDefinition( + Environment env, + ClassDeclaration decl) { + OJMethod[] m = getAllMethods(); + for (int i = 0; i < m.length; ++i) { + System.out.println(m[i].toString()); + } + return decl; + } + + public static boolean isRegisteredKeyword(String keyword) { + if (keyword.equals("likes")) + return true; + if (keyword.equals("hates")) + return true; + if (keyword.equals("loves")) + return true; + if (keyword.equals("forwards")) + return true; + return false; + } + + public static SyntaxRule getDeclSuffixRule(String keyword) { + return new NameListRule(); + } + + public static SyntaxRule getTypeSuffixRule(String keyword) { + return new NameListRule(); + } + + public static boolean isRegisteredModifier(String keyword) { + if (keyword.equals("remote")) + return true; + if (keyword.equals("crazy")) + return true; + return false; + } + +} diff --git a/src/test/java/demobug/Mix.oj b/src/test/java/demobug/Mix.oj new file mode 100644 index 0000000..54a92a3 --- /dev/null +++ b/src/test/java/demobug/Mix.oj @@ -0,0 +1,47 @@ +package demobug; + +import java.awt.*; +import examples.capsule.Point; +import examples.capsule.Test; +import examples.multimethod.MultimethodClass; + +public class Mix instantiates MultimethodClass extends Point { + + Point test; + + private Mix() { + super("Mix's", 0, 0); + this.test = new Point("Mix's", 0, 0); + } + + public String toString() { + System.out.println(test.name.toString()); + System.out.println("(" + test.x + "," + test.y + ")"); + return super.toString(); + } + + public multiform String bar(Panel a, Button b) { + return "panel"; + } + + public multiform String bar(Button a, Button b) { + return "button"; + } + + public multiform String bar(Canvas a, Panel b) { + return "canvas"; + } + + public static void main(String[] argv) { + Point p = new Mix(); + } + + public multiform void bar(Panel a, Window b) { + System.out.println("panel"); + String s = ((String) Test.NAME).toString(); + String sa = Test.NAME + "_ALPHA"; + String ss = (Test.NAME).toString(); + return; + } + +} diff --git a/src/test/java/demobug/Normal.oj b/src/test/java/demobug/Normal.oj new file mode 100644 index 0000000..cece63a --- /dev/null +++ b/src/test/java/demobug/Normal.oj @@ -0,0 +1,96 @@ +/* + * Normal.java + * + * comments here. + * + * @author Michiaki Tatsubori + * @version %VERSION% %DATE% + * @see java.lang.Object + * + * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED. + */ +package demobug; + +import java.awt.Panel; +import java.util.*; +import java.io.PrintStream; + +/** + * The class <code>Normal</code> + * <p> + * For example + * <pre> + * </pre> + * <p> + * + * @author Michiaki Tatsubori + * @version 1.0 + * @since %SOFTWARE% 1.0 + * @see java.lang.Object + */ +public class Normal extends Panel { + private int iii = 0; + + private Normal n = null; + + private String str; + + protected Normal(String str) { + super(); + this.str = str; + n = null; + } + + /** + * @param + * @return + * @exception + * @see java.lang.Object + */ + public static void main(String[] argv) { + PrintStream out = System.out; + PrintStream error = java.lang.System.err; + out.println("Hello" + " " + "World"); + Normal n = new Normal(null); + java.lang.System.err.println("done"); + + for (int index = 0; index < argv.length; ++index) { + System.out.println(index); + } + } + + public void hoge() { + Local l = new Local(); + System.out.println(l.foo); + System.out.println(l.bar.str); + } + + public int foo() { + int[] ia = { 0, 0x0, 0x82094000 }; + return JJCalls.gen; + } + + public String toString() { + if (n == null) + return str; + return str + n; + } + + static final class JJCalls { + static int gen = 0; + JJCalls next; + } +} + +class Local { + Local() { + } + String foo = null; + Local2 bar = new Local2(); +} + +class Local2 { + Local2() { + } + String str = "" + "TEST"; +} diff --git a/src/test/java/demobug/Simple.oj b/src/test/java/demobug/Simple.oj new file mode 100644 index 0000000..199ae48 --- /dev/null +++ b/src/test/java/demobug/Simple.oj @@ -0,0 +1,90 @@ +/* + * Simple.java + * + * comments here. + * + * @author Michiaki Tatsubori + * @version %VERSION% %DATE% + * @see java.lang.Object + * + * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED. + */ +package demobug; + +import java.awt.Panel; +import java.util.*; +import java.io.PrintStream; + +/** + * The class <code>Simple</code> + * <p> + * For example + * <pre> + * </pre> + * <p> + * + * @author Michiaki Tatsubori + * @version 1.0 + * @since %SOFTWARE% 1.0 + * @see java.lang.Object + */ +public class Simple instantiates MetaTest likes Apple, Macintosh hates Windows + extends Panel { + private int iii = 0; + ; + ; + + private Simple n = null; + + private String str = "string"; + + public Simple() { + super(); + } + + /** + * @param + * @return + * @exception + * @see java.lang.Object + */ + public static void main(String[] argv) { + PrintStream out = System.out; + PrintStream error = java.lang.System.err; + out.println("Hello" + " " + "World"); + Simple n = new Simple(); + java.lang.System.err.println("done"); + } + + public void hoge() { + SLocal l = new SLocal(); + System.out.println(l.foo); + System.out.println(l.bar.str); + } + + public Simple(String str) { + this.str = str; + n = null; + } + + public int foo() { + return iii; + } + + public String toString() { + if (n == null) + return str; + return str + n; + }; + ; + +} + +class SLocal { + String foo = null; + SLocal2 bar = new SLocal2(); +} + +class SLocal2 { + String str = "" + "TEST"; +} diff --git a/src/test/java/desell/MIJava.oj b/src/test/java/desell/MIJava.oj new file mode 100644 index 0000000..81498d2 --- /dev/null +++ b/src/test/java/desell/MIJava.oj @@ -0,0 +1,7 @@ +package desell; + +import io.devnulllabs.openjava.mop.*; +import io.devnulllabs.openjava.ptree.*; +import io.devnulllabs.openjava.syntax.*; +public class MIJava instantiates Metaclass extends OJClass { +} diff --git a/src/test/java/desell/TrivialSuperClass.oj b/src/test/java/desell/TrivialSuperClass.oj new file mode 100644 index 0000000..d408101 --- /dev/null +++ b/src/test/java/desell/TrivialSuperClass.oj @@ -0,0 +1,7 @@ +package desell; + +public class TrivialSuperClass instantiates MIJava { + public void hello_world() { + System.out.println("Hello, World!"); + } +}
\ No newline at end of file diff --git a/src/test/java/fabio/Hello.oj b/src/test/java/fabio/Hello.oj new file mode 100644 index 0000000..518faf4 --- /dev/null +++ b/src/test/java/fabio/Hello.oj @@ -0,0 +1,12 @@ +package fabio; + +public class Hello instantiates VerboseClass +{ + public static void main(String[] argv) { + hello(); + } + + static void hello() { + System.out.println("Hello, world."); + } +} diff --git a/src/test/java/fabio/HelloWithError.oj b/src/test/java/fabio/HelloWithError.oj new file mode 100644 index 0000000..350be40 --- /dev/null +++ b/src/test/java/fabio/HelloWithError.oj @@ -0,0 +1,12 @@ +package fabio; + +public class Hello instantiates VerboseClazz /* typo */ +{ + public static void main(String[] argv) { + hello(); + } + + static void hello() { + System.out.println("Hello, world."); + } +} diff --git a/src/test/java/fabio/VerboseClass.oj b/src/test/java/fabio/VerboseClass.oj new file mode 100644 index 0000000..a361896 --- /dev/null +++ b/src/test/java/fabio/VerboseClass.oj @@ -0,0 +1,21 @@ +package fabio; + +import io.devnulllabs.openjava.mop.*; +import io.devnulllabs.openjava.ptree.*; +import io.devnulllabs.openjava.syntax.*; + +public class VerboseClass instantiates Metaclass extends OJClass { + /* overrides for translation */ + //public void translateDefinition() throws MOPException { + public void translatioDefinition() throws MOPException { + OJMethod[] methods = getDeclaredMethods(); + for (int i = 0; i < methods.length; ++i) { + Statement printer = + makeStatement( + "System.out.println( \"" + + methods[i].toString() + + " is called.\" );"); + methods[i].getBody().insertElementAt(printer, 0); + } + } +} diff --git a/src/test/java/inner/BIND b/src/test/java/inner/BIND new file mode 100644 index 0000000..07180c5 --- /dev/null +++ b/src/test/java/inner/BIND @@ -0,0 +1,3 @@ +inner.VerboseClass inner.ImageMap.Timer +inner.VerboseClass inner.ImageMap$Tool +inner.VerboseClass inner.ImageMap diff --git a/src/test/java/inner/ImageMap.oj b/src/test/java/inner/ImageMap.oj new file mode 100644 index 0000000..50334c2 --- /dev/null +++ b/src/test/java/inner/ImageMap.oj @@ -0,0 +1,80 @@ +package inner; + +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import javax.swing.*; +import javax.swing.event.*; +//import java.util.*; + +public class ImageMap extends JPanel { + + Timer polyTimer; + Tool tool; + + public ImageMap(Image image, String imagePath) { + tool = new Tool(this); + addMouseListener(tool); + addMouseMotionListener(tool); + polyTimer = new Timer(this); + polyTimer.start(); + repaint(); + } + + public void paint(Graphics g) { + } + + class Tool extends MouseAdapter implements MouseMotionListener { + ImageMap map; + + Color color = Color.blue; + + public Tool(ImageMap map) { + this.map = map; + } + + public void showPolyPopup() { + } + + public void mousePressed(MouseEvent e) { + } + + public void mouseDragged(MouseEvent e) { + } + + public void mouseMoved(MouseEvent e) { + repaint(); + } + } + + class Timer extends Thread { + ImageMap map; + boolean active = false; + String command; + int x,y,node; + MouseEvent e; + + public Timer(ImageMap map) { + this.map = map; + } + + public void run() { + while (true) { + try { + sleep(900); + if (this.command=="poly") { + map.tool.showPolyPopup(); + } + } + catch (InterruptedException e) { } + suspend(); + } + } + } + +} + + + + + diff --git a/src/test/java/inner/VerboseClass.oj b/src/test/java/inner/VerboseClass.oj new file mode 100644 index 0000000..3cfe7a8 --- /dev/null +++ b/src/test/java/inner/VerboseClass.oj @@ -0,0 +1,49 @@ +/* + * VerboseClass.java + * + * @author Michiaki Tatsubori + * @version %VERSION% %DATE% + * @see java.lang.Object + * + * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED. + */ +package inner; + +import io.devnulllabs.openjava.mop.*; +import io.devnulllabs.openjava.ptree.*; +import io.devnulllabs.openjava.syntax.*; + +public class VerboseClass instantiates Metaclass extends OJClass { + + public VerboseClass( + Environment env, + openjava.mop.OJClass declaring, + ClassDeclaration cd) { + super(env, declaring, cd); + System.out.println( + "A class metaobject for " + + cd.getName() + + " created from source code."); + } + + public VerboseClass(Class javaclazz, MetaInfo minfo) { + super(javaclazz, minfo); + System.out.println( + "A class metaobject for " + + javaclazz.getName() + + " created from byte code."); + } + + /* overrides for translation */ + public void translateDefinition() throws MOPException { + OJMethod[] methods = getDeclaredMethods(); + for (int i = 0; i < methods.length; ++i) { + Statement printer = + makeStatement( + "java.lang.System.out.println( \"" + + methods[i].toString() + + " was called\" );"); + methods[i].getBody().insertElementAt(printer, 0); + } + } +} diff --git a/src/test/java/jarrett/NonPub.oj b/src/test/java/jarrett/NonPub.oj new file mode 100644 index 0000000..b8b80ba --- /dev/null +++ b/src/test/java/jarrett/NonPub.oj @@ -0,0 +1,19 @@ +/* + * This code was generated by ojc. + */ +package jarrett; + + +class NonPub1 +{ +} + + +class NonPub2 +{ +} + + +class NonPub3 +{ +} diff --git a/src/test/java/lionel/Hello.oj b/src/test/java/lionel/Hello.oj new file mode 100644 index 0000000..48fa88a --- /dev/null +++ b/src/test/java/lionel/Hello.oj @@ -0,0 +1,11 @@ +package lionel; + +public class Hello { + public static void main(String[] argv) { + hello(); + } + + static void hello() { + System.out.println("Hello, world."); + } +} diff --git a/src/test/java/lionel/Hello2.oj b/src/test/java/lionel/Hello2.oj new file mode 100644 index 0000000..7c2718d --- /dev/null +++ b/src/test/java/lionel/Hello2.oj @@ -0,0 +1,11 @@ +package lionel; + +public class Hello2 { + public static void main(String[] argv) { + hello(); + } + + static void hello() { + System.out.println("Hello, world."); + } +} diff --git a/src/test/java/lionel/Hello3.oj b/src/test/java/lionel/Hello3.oj new file mode 100644 index 0000000..c5fd6ce --- /dev/null +++ b/src/test/java/lionel/Hello3.oj @@ -0,0 +1,11 @@ +package lionel; + +public class Hello3 { + public static void main(String[] argv) { + hello(); + } + + static void hello() { + System.out.println("Hello, world."); + } +} diff --git a/src/test/java/lionel/metabind b/src/test/java/lionel/metabind new file mode 100644 index 0000000..621ff16 --- /dev/null +++ b/src/test/java/lionel/metabind @@ -0,0 +1,2 @@ +examples.verbose.VerboseClass lionel.Hello +examples.verbose.VerboseClass lionel.Hello3 diff --git a/src/test/java/lionel2/NonPubTest.oj b/src/test/java/lionel2/NonPubTest.oj new file mode 100644 index 0000000..727bd3b --- /dev/null +++ b/src/test/java/lionel2/NonPubTest.oj @@ -0,0 +1,36 @@ +package lionel2; + +public class NonPubTest instantiates Printer +{ + NonPubTest(String s) {} + + public String toString() { + NonPubTest t = new NonPubTest("at NonPubTest"); + A a = new A("at NonPubTest"); + B b = new B("at NonPubTest"); + return super.toString(); + } +} + + +class A instantiates Printer +{ + A(String s) {} + + public void foo() { + NonPubTest t = new NonPubTest("at A"); + A a = new A("at A"); + B b = new B("at A"); + } +} + +class B instantiates Printer +{ + B(String s) {} + + public void bar() { + NonPubTest t = new NonPubTest("at B"); + A a = new A("at B"); + B b = new B("at B"); + } +} diff --git a/src/test/java/lionel2/Printer.oj b/src/test/java/lionel2/Printer.oj new file mode 100644 index 0000000..b196798 --- /dev/null +++ b/src/test/java/lionel2/Printer.oj @@ -0,0 +1,18 @@ +package lionel2; + +import io.devnulllabs.openjava.mop.*; +import io.devnulllabs.openjava.ptree.*; + +public class Printer instantiates Metaclass extends OJClass { + public void translateDefinition() throws MOPException { + System.out.println("translateDefinition() of " + getName()); + } + + public Expression expandAllocation( + Environment env, + AllocationExpression expr) { + System.out.println( + "expandAllocation() of " + getName() + " for " + expr.toString()); + return expr; + } +} diff --git a/src/test/java/lionel2/SimpleConst.oj b/src/test/java/lionel2/SimpleConst.oj new file mode 100644 index 0000000..7641a6e --- /dev/null +++ b/src/test/java/lionel2/SimpleConst.oj @@ -0,0 +1,6 @@ +package lionel2; + +public class SimpleConst { + public SimpleConst() { + } +} diff --git a/src/test/java/luciano/AutoConstructorClass.oj b/src/test/java/luciano/AutoConstructorClass.oj new file mode 100644 index 0000000..65f04ad --- /dev/null +++ b/src/test/java/luciano/AutoConstructorClass.oj @@ -0,0 +1,71 @@ +import luciano; + +import io.devnulllabs.openjava.mop.*; +import io.devnulllabs.openjava.ptree.*; +import io.devnulllabs.openjava.syntax.*; +import io.devnulllabs.openjava.ptree.util.VariableBinder; + +/** + * This metaclass appends a constructor of a String parameter. + * It makes no sense but shows an example of adding a special + * statement of calling super constructor. + */ +public class AutoConstructorClass instantiates Metaclass extends OJClass { + public convenient void translateDefinition() throws MOPException { + System.out.println("translateDefinition() of " + getName()); + if (doesClassHaveStringCons()) + return; + if (!doesSuperHaveDefaultCons()) + return; + + OJConstructor con = + new OJConstructor( + this, + OJModifier.forModifier(OJModifier.PUBLIC), + new OJClass[] { String.class }, + new OJClass[0], + null, + null /* temporally */ + ); + + ExpressionList conargs = con.getParameterVariables(); + Expression conarg = conargs.get(0); + + /* "super()" */ + ConstructorInvocation ci = + new ConstructorInvocation(new ExpressionList(), null); + + /* other part of constructors' body */ + StatementList body = + makeStatementList( + con.getEnvironment(), + "/* test */" + "java.lang.System.out.println(" + conarg + ");"); + + con.setTransference(ci); + con.setBody(body); + + addConstructor(con); + } + + private convenient boolean doesClassHaveStringCons() { + try { + this.getConstructor(new OJClass[] { String.class }, this); + return true; + } catch (NoSuchMemberException ex) { + return false; + } + } + + private boolean doesSuperHaveDefaultCons() { + OJClass baseclazz = this.getSuperclass(); + if (baseclazz == null) + return false; + try { + baseclazz.getConstructor(new OJClass[0], this); + return true; + } catch (NoSuchMemberException ex) { + return false; + } + } + +} diff --git a/src/test/java/luciano/Test.oj b/src/test/java/luciano/Test.oj new file mode 100644 index 0000000..3f624e0 --- /dev/null +++ b/src/test/java/luciano/Test.oj @@ -0,0 +1,4 @@ +import luciano; + +public class Test instantiates AutoConstructorClass { +} diff --git a/src/test/java/maurizio/Test.oj b/src/test/java/maurizio/Test.oj new file mode 100644 index 0000000..829cd18 --- /dev/null +++ b/src/test/java/maurizio/Test.oj @@ -0,0 +1,7 @@ +import maurizio; + +public class Test instantiates TestClass { + public String toString() { + return super.toString(); + } +} diff --git a/src/test/java/maurizio/TestClass.oj b/src/test/java/maurizio/TestClass.oj new file mode 100644 index 0000000..60c8ffa --- /dev/null +++ b/src/test/java/maurizio/TestClass.oj @@ -0,0 +1,15 @@ +import maurizio; + +import io.devnulllabs.openjava.mop.*; +import io.devnulllabs.openjava.ptree.*; +import io.devnulllabs.openjava.syntax.*; +import io.devnulllabs.openjava.ptree.util.VariableBinder; + +public class TestClass instantiates Metaclass extends OJClass { + public TypeName expandTypeName(Environment env, TypeName type) { + System.out.println("I'm into expandTypeName"); + TypeName result = new TypeName("java.lang.String", 0); + return super.expandTypeName(env, result); + } + +} diff --git a/src/test/java/maurizio/TestUser.oj b/src/test/java/maurizio/TestUser.oj new file mode 100644 index 0000000..9ad64af --- /dev/null +++ b/src/test/java/maurizio/TestUser.oj @@ -0,0 +1,11 @@ +import maurizio; + +public class TestUser { + public static void main(String[] args) { + Test t = new Test(); + Object o = t; + Test t2 = (Test) o; + System.out.println(Test.class); + System.out.println(t); + } +} diff --git a/src/test/java/maurizio2/Test.oj b/src/test/java/maurizio2/Test.oj new file mode 100644 index 0000000..9c9c071 --- /dev/null +++ b/src/test/java/maurizio2/Test.oj @@ -0,0 +1,12 @@ +import maurizio2; + +public class Test instantiates TestClass { + public void foo(short a1, int a2) { + } + + public void foo(int[] a1, short[] a2) { + } + + public void foo(short[] a1, int[] a2) { + } +} diff --git a/src/test/java/maurizio2/TestClass.oj b/src/test/java/maurizio2/TestClass.oj new file mode 100644 index 0000000..e15ce86 --- /dev/null +++ b/src/test/java/maurizio2/TestClass.oj @@ -0,0 +1,23 @@ +import maurizio2; + +import io.devnulllabs.openjava.mop.*; +import io.devnulllabs.openjava.ptree.*; +import io.devnulllabs.openjava.syntax.*; +import io.devnulllabs.openjava.ptree.util.VariableBinder; + +public class TestClass instantiates Metaclass extends OJClass { + public Expression expandMethodCall(Environment env, MethodCall expr) { + System.out.println("Argument Types of : " + expr.toString()); + ExpressionList args = expr.getArguments(); + OJClass[] argtypes = new OJClass[args.size()]; + try { + for (int i = 0; i < argtypes.length; ++i) { + argtypes[i] = args.get(i).getType(env); + System.out.println("\t" + argtypes[i]); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + return super.expandMethodCall(env, expr); + } +} diff --git a/src/test/java/maurizio2/TestUser.oj b/src/test/java/maurizio2/TestUser.oj new file mode 100644 index 0000000..830569a --- /dev/null +++ b/src/test/java/maurizio2/TestUser.oj @@ -0,0 +1,14 @@ +import maurizio2; + +public class TestUser { + static short s = 0; + static short as[] = null; + static int o = 0; + static int os[] = null; + + public static void main(String[] args) { + Test t = new Test(); + t.foo(s, o); + t.foo(as, os); + } +} diff --git a/src/test/java/mazza/Test.oj b/src/test/java/mazza/Test.oj new file mode 100644 index 0000000..520e129 --- /dev/null +++ b/src/test/java/mazza/Test.oj @@ -0,0 +1,6 @@ +import mazza; + +public class Test instantiates TestClass { + public void foo() { + } +} diff --git a/src/test/java/mazza/TestClass.oj b/src/test/java/mazza/TestClass.oj new file mode 100644 index 0000000..2f4b23a --- /dev/null +++ b/src/test/java/mazza/TestClass.oj @@ -0,0 +1,19 @@ +import mazza; + +import io.devnulllabs.openjava.mop.*; +import io.devnulllabs.openjava.ptree.*; + +public class TestClass instantiates Metaclass extends OJClass { + public void translateDefinition() throws MOPException { + OJClass dummy = OJClass.forClass(String.class); + OJSystem.env.record("NonExisting", dummy); + + FieldDeclaration fd = + new FieldDeclaration( + new ModifierList(ModifierList.PUBLIC), + new TypeName("NonExisting"), + new VariableDeclarator("sender", null)); + OJField field = new OJField(getEnvironment(), this, fd); + addField(field); + } +} diff --git a/src/test/java/metatest/Meta2.java b/src/test/java/metatest/Meta2.java new file mode 100644 index 0000000..e584e61 --- /dev/null +++ b/src/test/java/metatest/Meta2.java @@ -0,0 +1,38 @@ +/* + * Meta2.java + * Michiaki Tatsubori + * + */ +package metatest; + + +/** + * This code is + */ +public class Meta2 +{ + + static String[] userModifiers + = {}; + static String[] userKeywords + = { "from", "to" }; + + public static boolean isRegisteredModifier( String name ) + { + if(name == null || userModifiers == null) return false; + for( int i = 0; i < userModifiers.length; i++ ){ + if(name.equals( userModifiers[i] )) return true; + } + return false; + } + + public static boolean isRegisteredKeyword( String name ) + { + if(name == null || userKeywords == null) return false; + for( int i = 0; i < userKeywords.length; i++ ){ + if(name.equals( userKeywords[i] )) return true; + } + return false; + } + +} diff --git a/src/test/java/metatest/TestMetaclass.java b/src/test/java/metatest/TestMetaclass.java new file mode 100644 index 0000000..8ef3d54 --- /dev/null +++ b/src/test/java/metatest/TestMetaclass.java @@ -0,0 +1,37 @@ +/* + * TestMetaclass.java + * Michiaki Tatsubori + * + */ +package metatest; + +/** + * This code is + */ +public class TestMetaclass { + + static String[] userModifiers = + { "changable", "persistant", "distributed", "nop" }; + static String[] userKeywords = { "on", "of", "with" }; + + public static boolean isRegisteredModifier(String name) { + if (name == null || userModifiers == null) + return false; + for (int i = 0; i < userModifiers.length; i++) { + if (name.equals(userModifiers[i])) + return true; + } + return false; + } + + public static boolean isRegisteredKeyword(String name) { + if (name == null || userKeywords == null) + return false; + for (int i = 0; i < userKeywords.length; i++) { + if (name.equals(userKeywords[i])) + return true; + } + return false; + } + +} diff --git a/src/test/java/nopub/Pub.oj b/src/test/java/nopub/Pub.oj new file mode 100644 index 0000000..43b20ed --- /dev/null +++ b/src/test/java/nopub/Pub.oj @@ -0,0 +1,7 @@ +import nopub; + +public class Pub { +} + +class B { +} diff --git a/src/test/java/nopub/Test.oj b/src/test/java/nopub/Test.oj new file mode 100644 index 0000000..3c54e46 --- /dev/null +++ b/src/test/java/nopub/Test.oj @@ -0,0 +1,7 @@ +import nopub; + +class Test { +} + +class A { +} diff --git a/src/test/java/openjava/mop/OJSystemTest.java b/src/test/java/openjava/mop/OJSystemTest.java new file mode 100644 index 0000000..3cdf610 --- /dev/null +++ b/src/test/java/openjava/mop/OJSystemTest.java @@ -0,0 +1,60 @@ +/* + * OJSystemTest.java + * + * Created on 2003/11/02 $Id: OJSystemTest.java,v 1.2 2003/11/14 13:52:02 tatsubori Exp $ + */ +package io.devnulllabs.openjava.mop; + +import java.io.File; + +import junit.framework.TestCase; +import io.devnulllabs.openjava.mop.edit.OJEditableClass; +import io.devnulllabs.openjava.ptree.ClassDeclaration; +import io.devnulllabs.openjava.ptree.StatementList; + +/** + * The type OJSystemTest. + * + * @author Michiaki Tatsubori + * @version 1.0 2003/11/02 + */ +public class OJSystemTest extends TestCase { + + public static void main(String[] args) { + junit.textui.TestRunner.run(OJSystemTest.class); + } + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + OJSystem.initConstants(); + } + + class TestFileEnvironment extends FileEnvironment { + public TestFileEnvironment(Environment env) { + super(env); + } + public String getPackage() { + return "test"; + } + public File getFile() { + return new File("test", "A.oj"); + } + public String currentClassName() { + return "A"; + } + } + + public void testAddNewClasses() throws MOPException { + FileEnvironment fenv = new TestFileEnvironment(OJSystem.env); + StatementList stmts = + OJClass.makeStatementList(OJSystem.env, "class A { }"); + ClassDeclaration cdecl = (ClassDeclaration) stmts.get(0); + + OJEditableClass newClass = + new OJEditableClass(new OJClass(OJSystem.env, null, cdecl)); + OJSystem.addNewClass(newClass); + } + +} diff --git a/src/test/java/openjava/ptree/ClassDeclarationTest.java b/src/test/java/openjava/ptree/ClassDeclarationTest.java new file mode 100644 index 0000000..b0a8b1d --- /dev/null +++ b/src/test/java/openjava/ptree/ClassDeclarationTest.java @@ -0,0 +1,27 @@ +/* + * ClassDeclarationTest.java + * Created on 2005/04/04 by Michiaki Tatsubori + * @version $Id$ + */ +package io.devnulllabs.openjava.ptree; + +import junit.framework.TestCase; + +/** + * ClassDeclarationTest + * @author mich + */ +public class ClassDeclarationTest extends TestCase { + + public void testBeInterface() { + ModifierList modifs = new ModifierList(ModifierList.PUBLIC); + MemberDeclarationList members = new MemberDeclarationList(); + ClassDeclaration cd = new ClassDeclaration(modifs, "Dummy", null, null, members); + assertFalse(cd.isInterface()); + System.out.println(cd.toString()); + cd.beInterface(true); + assertTrue(cd.isInterface()); + System.out.println(cd.toString()); + } + +} diff --git a/src/test/java/openjava/ptree/ModifierListTest.java b/src/test/java/openjava/ptree/ModifierListTest.java new file mode 100644 index 0000000..77458db --- /dev/null +++ b/src/test/java/openjava/ptree/ModifierListTest.java @@ -0,0 +1,30 @@ +/* + * ModifierListTest.java + * Created on 2005/04/04 by Michiaki Tatsubori + * @version $Id$ + */ +package io.devnulllabs.openjava.ptree; + +import junit.framework.TestCase; + +/** + * ModifierListTest + * @author mich + */ +public class ModifierListTest extends TestCase { + + /* + * Class under test for void ModifierList() + */ + public void testModifierList() { + ModifierList modifs = new ModifierList(); + assertEquals(0, modifs.size()); + modifs.add(ModifierList.PUBLIC); + assertEquals("public", modifs.toString()); + // standard modifiers do not affect the size of the list + assertEquals(0, modifs.size()); + assertTrue(modifs.contains(ModifierList.PUBLIC)); + assertTrue(modifs.contains("public")); + } + +} diff --git a/src/test/java/packfld/Test.java b/src/test/java/packfld/Test.java new file mode 100644 index 0000000..8613686 --- /dev/null +++ b/src/test/java/packfld/Test.java @@ -0,0 +1,14 @@ +package packfld; + +/* + * This code was generated by ojc. + */ +public class Test { + static final int HSIZE = 50000; +} + +class A { + public static void main(java.lang.String[] args) { + System.err.println(Test.HSIZE); + } +} diff --git a/src/test/java/pp/C.java b/src/test/java/pp/C.java new file mode 100644 index 0000000..b0c7416 --- /dev/null +++ b/src/test/java/pp/C.java @@ -0,0 +1,44 @@ +package pp; + +import io.devnulllabs.openjava.mop.Environment; +import io.devnulllabs.openjava.mop.MOPException; +import io.devnulllabs.openjava.mop.MetaInfo; +import io.devnulllabs.openjava.mop.OJClass; +import io.devnulllabs.openjava.mop.OJMethod; +import io.devnulllabs.openjava.ptree.ClassDeclaration; +import io.devnulllabs.openjava.ptree.MethodDeclaration; +import io.devnulllabs.openjava.ptree.ModifierList; +import io.devnulllabs.openjava.ptree.Parameter; +import io.devnulllabs.openjava.ptree.ParameterList; +import io.devnulllabs.openjava.ptree.StatementList; +import io.devnulllabs.openjava.ptree.TypeName; + +public class C extends OJClass { + + public void translateDefinition() throws MOPException { + ModifierList ml; + TypeName tn; + ParameterList pl; + StatementList sl; + Environment env; + MethodDeclaration md; + + ml = new ModifierList(); + tn = new TypeName("boolean"); + pl = new ParameterList(new Parameter(new TypeName("int"), "ind")); + + env = getEnvironment(); + sl = makeStatementList(env, "System.out.println(ind); return true;"); + + md = new MethodDeclaration(ml, tn, "myMeth", pl, null, sl); + addMethod(new OJMethod(getEnvironment(), getDeclaringClass(), md)); + } + + public C(Environment p0, OJClass p1, ClassDeclaration p2) { + super(p0, p1, p2); + } + + public C(Class p0, MetaInfo p1) { + super(p0, p1); + } +} diff --git a/src/test/java/pp/CTest.oj b/src/test/java/pp/CTest.oj new file mode 100644 index 0000000..4cb1289 --- /dev/null +++ b/src/test/java/pp/CTest.oj @@ -0,0 +1,6 @@ +package pp; + +public class CTest instantiates C +{ + void f( int i, int j ) {} +} diff --git a/src/test/java/pp/SyncTest.oj b/src/test/java/pp/SyncTest.oj new file mode 100644 index 0000000..e1fba1d --- /dev/null +++ b/src/test/java/pp/SyncTest.oj @@ -0,0 +1,8 @@ +package pp; + +public class SyncTest +{ + void f() { + synchronized (this) {} + } +} diff --git a/src/test/java/schulz/A.oj b/src/test/java/schulz/A.oj new file mode 100644 index 0000000..16e7d3a --- /dev/null +++ b/src/test/java/schulz/A.oj @@ -0,0 +1,9 @@ +import schulz; + +public class A instantiates Sample { + + public A() { + super(); + } + +} diff --git a/src/test/java/schulz/Sample.oj b/src/test/java/schulz/Sample.oj new file mode 100644 index 0000000..780851a --- /dev/null +++ b/src/test/java/schulz/Sample.oj @@ -0,0 +1,18 @@ +import schulz; + +import io.devnulllabs.openjava.mop.*; + +public class Sample instantiates Metaclass extends OJClass { + + public void translateDefinition() throws MOPException { + + OJConstructor[] tabCons = getConstructors(); + + if (tabCons.length > 0) { + tabCons[0].addExceptionType( + OJClass.forName("java.lang.ArithmeticException")); + tabCons[0].addExceptionType( + OJClass.forName("java.lang.ArrayStoreException")); + } + } +} diff --git a/src/test/java/smyth/BankAccount.oj b/src/test/java/smyth/BankAccount.oj new file mode 100644 index 0000000..d2402af --- /dev/null +++ b/src/test/java/smyth/BankAccount.oj @@ -0,0 +1,25 @@ +import smyth; + +public distributed class BankAccount instantiates MDistributed { + private int balance = 100; + + public BankAccount() { + super(); + } + + public int getBalance() { + return balance; + } + + public void deposit(int d) { + System.out.println(d); + balance += d; + System.out.println(d + " has been deposited in your account."); + } + + public void withdraw(int w) { + System.out.println(w); + balance -= w; + System.out.println(w + " has been withdrawn from your account."); + } +} diff --git a/src/test/java/smyth/MDistributed.oj b/src/test/java/smyth/MDistributed.oj new file mode 100644 index 0000000..c9d50be --- /dev/null +++ b/src/test/java/smyth/MDistributed.oj @@ -0,0 +1,111 @@ +package smyth; + +import io.devnulllabs.openjava.mop.*; +import io.devnulllabs.openjava.ptree.*; +import io.devnulllabs.openjava.syntax.*; + +import java.util.*; + +public class MDistributed instantiates Metaclass extends OJClass { + /** + * Class Declarations + */ + public static final String DISTRIBUTED = "distributed"; + public static final String SUFFIX = "Inner"; + + private OJClass inner = null; + + /** + * Overide the isRegistered method for DISTRIUBTED + */ + public static boolean isRegisteredModifier(String keyword) { + if (keyword.equals(DISTRIBUTED)) + return true; + return false; + } + + /** + * Main method - translateDefinition + */ + public void translateDefinition() throws MOPException { + if (getModifiers().has(DISTRIBUTED)) { + System.out.println("makeInnerClass()"); + makeInnerClass(); + System.out.println("changeOutterFields()"); + changeOutterFields(); + System.out.println("changeOutterConstructors()"); + changeOutterConstructors(); + } else { + System.out.println( + "You must attach the class modifier 'distributed' = for translation to take place."); + } + } + + /** + * This method makes an innerclass from the outter class. + * + * The outter class then acts as a wrapper for this inner class. + * + */ + public void makeInnerClass() throws openjava.mop.CannotAlterException { + /* Declarations */ + ClassDeclaration clsdecl; + MemberDeclarationList memlist; + + /* Make the ClassDeclaration from the OJClass */ + clsdecl = (ClassDeclaration) getSourceCode().makeRecursiveCopy(); + + /* Change the name of ClassDeclaration */ + clsdecl.setName(clsdecl.getName() + SUFFIX); + + /* Change the name of the Constructors to match new name */ + memlist = clsdecl.getBody(); + + for (int i = 0; i < memlist.size(); i++) { + if (memlist.get(i) instanceof ConstructorDeclaration) { + ((ConstructorDeclaration) memlist.get(i)).setName( + clsdecl.getName()); + } + } + + /* Add the inner class */ + /*original (getSourceCode().getBody()).add(clsdecl);*/ + inner = new OJClass(getEnvironment(), this, clsdecl); + OJSystem.env.record(inner.getName(), inner); + inner = addClass(inner); + } + + /** + * This method is to remove the fields from the outter (wrapper) class. + * + * It is also to add a field of the type of the (new) innner class. + */ + public void changeOutterFields() throws MOPException { + /* Remove the fields from the outter (wrapper) class */ + OJField[] ojfld = getDeclaredFields(); + for (int i = 0; i < ojfld.length; ++i) { + removeField(ojfld[i]); + } + + /* Add the new field of type of the new inner class */ + /* At the moment this is just given the variable name 'inner' */ + OJModifier modif = OJModifier.forModifier(OJModifier.PRIVATE); + addField(new OJField(this, modif, inner, "inner")); + } + + /* Change the constructors */ + public void changeOutterConstructors() throws MOPException { + OJConstructor[] ojconstr = getConstructors(); + for (int i = 0; i < ojconstr.length; ++i) { + StatementList body = + makeStatementList( + "inner=new " + + inner.getName() + + "(" + + ojconstr[i].getParameterVariables() + + ");"); + ojconstr[i].setBody(body); + } + } + +} diff --git a/src/test/java/smyth/Test.oj b/src/test/java/smyth/Test.oj new file mode 100644 index 0000000..c1451ce --- /dev/null +++ b/src/test/java/smyth/Test.oj @@ -0,0 +1,15 @@ +package smyth; + +public distributed class Test instantiates MDistributed { + private int balance = 100; + + public Test() { + super(); + } + + public int f() { + return 0; + } + public void g() { + } +} diff --git a/src/test/java/thorsten/MetaTest.oj b/src/test/java/thorsten/MetaTest.oj new file mode 100644 index 0000000..ca6ec45 --- /dev/null +++ b/src/test/java/thorsten/MetaTest.oj @@ -0,0 +1,21 @@ +package thorsten; + +import io.devnulllabs.openjava.mop.*; +import io.devnulllabs.openjava.ptree.*; +import io.devnulllabs.openjava.syntax.*; + +public class MetaTest instantiates Metaclass extends OJClass { + + public static final String KEY_ADAPTS = "adapts"; + + /* overrides for translation */ + public void translateDefinition() throws MOPException { + //StatementList metStmts = makeStatementList( + // "String str = \"test\";" + //); + Statement metStmt = makeStatement("System.out.println( \"test\" );"); + //Statement metStmt = makeStatement( + // "String str = \"test\";" + //); + } +} diff --git a/src/test/java/thorsten/Test.oj b/src/test/java/thorsten/Test.oj new file mode 100644 index 0000000..b1bc24b --- /dev/null +++ b/src/test/java/thorsten/Test.oj @@ -0,0 +1,6 @@ +package thorsten; + +public class Test instantiates MetaTest { + public static void main(String[] args) { + } +} diff --git a/src/test/java/walter/Test.oj b/src/test/java/walter/Test.oj new file mode 100644 index 0000000..f238bda --- /dev/null +++ b/src/test/java/walter/Test.oj @@ -0,0 +1,15 @@ +package walter; + +public class Test instantiates multiTrig { + + public multi_trig void dummyMethod() { + System.out.println("dummyMethod was called"); + } + + public static void main(String[] argv) { + int i = 0; + Test dC = new Test(); + for (; i <= 100; i++) + dC.dummyMethod(); + } +} diff --git a/src/test/java/walter/dummyClass.oj b/src/test/java/walter/dummyClass.oj new file mode 100644 index 0000000..97333e1 --- /dev/null +++ b/src/test/java/walter/dummyClass.oj @@ -0,0 +1,18 @@ +package walter; + +public class dummyClass instantiates multiTrig { + + public dummyClass() { + } + + public multi_trig void dummyMethod(int i) { + System.out.println("dummyMethod was called " + i + " times!"); + } + + public static void main(String[] argv) { + int i = 0; + dummyClass dC = new dummyClass(); + for (; i <= 100; i++) + dC.dummyMethod(i); + } +} diff --git a/src/test/java/walter/multiTrig.oj b/src/test/java/walter/multiTrig.oj new file mode 100644 index 0000000..18c194a --- /dev/null +++ b/src/test/java/walter/multiTrig.oj @@ -0,0 +1,65 @@ +package walter; + +import io.devnulllabs.openjava.ptree.*; +import io.devnulllabs.openjava.ptree.ModifierList; +import io.devnulllabs.openjava.mop.*; + +public class multiTrig instantiates Metaclass extends OJClass { + + private static final String MULTI_TRIG = "multi_trig"; + private final int triggerValue = 10; + + public static boolean isRegisteredModifier(String keyword) { + if (keyword.equals(MULTI_TRIG)) + return true; + return OJClass.isRegisteredModifier(keyword); + } + + public void translateDefinition() throws MOPException { + OJMethod[] methods = getDeclaredMethods(); + for (int i = 0; i < methods.length; ++i) { + if (!methods[i].getModifiers().has(MULTI_TRIG)) + continue; + String name = methods[i].getName(); // is a multi-trigged method + ModifierList ml = new ModifierList(ModifierList.PRIVATE); + TypeName tn = new TypeName("int"); + /* inserts a field for counting the method calls + private int <method name>Counter = 0 */ + String counterName = name + "Counter"; + VariableInitializer vi = Literal.makeLiteral(0); + FieldDeclaration fd = new FieldDeclaration(ml, tn, counterName, vi); + OJField field = new OJField(getEnvironment(), this, fd); + addField(field); + + /* inserts a field keeping the trigger value + private int <method name>Trigger = 10 */ + String triggerName = name + "Trigger"; + vi = Literal.makeLiteral(triggerValue); + fd = new FieldDeclaration(ml, tn, triggerName, vi); + field = new OJField(getEnvironment(), this, fd); + addField(field); + + /* inserts a precondition on the execution of the method body + if (<method name>Counter == <method name>Trigger) { + and a post action + <method body> + <method name>Counter = 0; + } <method name>Counter++; */ + StatementList newBody = + makeStatementList( + methods[i].getEnvironment(), + "if (" + + counterName + + " == " + + triggerName + + ") {" + + methods[i].getBody().toString() + + counterName + + "=0;}; " + + counterName + + "++;"); + methods[i].setBody(newBody); + } + } + +} diff --git a/src/test/java/walter2/ArraysTest.oj b/src/test/java/walter2/ArraysTest.oj new file mode 100644 index 0000000..4c76f7e --- /dev/null +++ b/src/test/java/walter2/ArraysTest.oj @@ -0,0 +1,11 @@ +package walter2; + +import java.util.*; + +public class ArraysTest { + + public static void main(String[] args) { + Arrays.sort(args, new MyComp()); + } + +} diff --git a/src/test/java/walter2/MyComp.oj b/src/test/java/walter2/MyComp.oj new file mode 100644 index 0000000..5afc869 --- /dev/null +++ b/src/test/java/walter2/MyComp.oj @@ -0,0 +1,9 @@ +package walter2; + +import java.util.*; + +public class MyComp implements Comparator { + public int compare(Object o1, Object o2) { + return ((String) o2).length() - ((String) o1).length(); + } +} diff --git a/src/test/java/walter2/StaticTest.oj b/src/test/java/walter2/StaticTest.oj new file mode 100644 index 0000000..cbc23a0 --- /dev/null +++ b/src/test/java/walter2/StaticTest.oj @@ -0,0 +1,11 @@ +package walter2; + +import java.util.*; + +public class StaticTest { + + public void main(String[] args) { + StaticUtil.foo(args, new MyComp()); + } + +} diff --git a/src/test/java/walter2/StaticUtil.oj b/src/test/java/walter2/StaticUtil.oj new file mode 100644 index 0000000..affc0bc --- /dev/null +++ b/src/test/java/walter2/StaticUtil.oj @@ -0,0 +1,9 @@ +package walter2; + +import java.util.*; + +public class StaticUtil { + public static boolean foo(String[] args, Comparator c) { + return true; + } +} diff --git a/src/test/java/walter2/Test.oj b/src/test/java/walter2/Test.oj new file mode 100644 index 0000000..660585c --- /dev/null +++ b/src/test/java/walter2/Test.oj @@ -0,0 +1,26 @@ +package walter2; + +import sun.applet.*; +import java.applet.*; +import java.lang.*; +import java.net.*; +import java.util.*; + +public class Test { + + public static void main(String argv[]) throws Exception { + System.out.println(Object[].class.isAssignableFrom(String[].class)); + System.out.println(Float.class.isAssignableFrom(Integer.class)); + System.out.println(float.class.isAssignableFrom(int.class)); + System.out.println(int.class.isAssignableFrom(float.class)); + System.out.println(float.class.isAssignableFrom(double.class)); + System.out.println(double.class.isAssignableFrom(float.class)); + System.out.println(int.class.isAssignableFrom(long.class)); + System.out.println(long.class.isAssignableFrom(int.class)); + + foo(1); + } + + public static void foo(double i) { + } +} |