summaryrefslogtreecommitdiff
path: root/tutorial
diff options
context:
space:
mode:
authorKenny Ballou <kballou@devnulllabs.io>2018-11-19 22:59:50 -0700
committerKenny Ballou <kballou@devnulllabs.io>2018-11-19 22:59:50 -0700
commitea3e1b949dcbdc09518f17eee0bcf21d41d76896 (patch)
tree7ec7a7fb4df67815a9b7bb0e4d95d67c4050e2a2 /tutorial
downloadopenjava-ea3e1b949dcbdc09518f17eee0bcf21d41d76896.tar.gz
openjava-ea3e1b949dcbdc09518f17eee0bcf21d41d76896.tar.xz
OJ (aka OpenJava) modernization/mirroring
Signed-off-by: Kenny Ballou <kballou@devnulllabs.io>
Diffstat (limited to 'tutorial')
-rw-r--r--tutorial/Adapter.html258
-rw-r--r--tutorial/AutoImpl.html150
-rw-r--r--tutorial/FreeArgs.html171
-rw-r--r--tutorial/Introduction.html96
-rw-r--r--tutorial/NewMethod.html209
-rw-r--r--tutorial/Override.html181
-rw-r--r--tutorial/Overview.html208
-rw-r--r--tutorial/Synchronize.html131
-rw-r--r--tutorial/Syntax.html171
-rw-r--r--tutorial/VerboseClass.html212
-rw-r--r--tutorial/examples/adapter/AdapterClass.java155
-rw-r--r--tutorial/examples/adapter/AdapterClass.oj152
-rw-r--r--tutorial/examples/adapter/Stack.java29
-rw-r--r--tutorial/examples/adapter/Stack.oj15
-rw-r--r--tutorial/examples/adapter/VectorStack.java68
-rw-r--r--tutorial/examples/adapter/VectorStack.oj24
-rw-r--r--tutorial/examples/autoimp/AutoImplementerClass.java78
-rw-r--r--tutorial/examples/autoimp/AutoImplementerClass.oj64
-rw-r--r--tutorial/examples/autoimp/InnerTest.java29
-rw-r--r--tutorial/examples/autoimp/InnerTest.oj15
-rw-r--r--tutorial/examples/autoimp/Test.java55
-rw-r--r--tutorial/examples/autoimp/Test.oj8
-rw-r--r--tutorial/examples/bca/AutoAdaptationClass.java53
-rw-r--r--tutorial/examples/bca/AutoAdaptationClass.oj48
-rw-r--r--tutorial/examples/bca/Printable.java7
-rw-r--r--tutorial/examples/bca/RTReflClass.java51
-rw-r--r--tutorial/examples/bca/Test.java24
-rw-r--r--tutorial/examples/bca/Test.oj13
-rw-r--r--tutorial/examples/bca/Test2.java18
-rw-r--r--tutorial/examples/bca/Test2.oj12
-rw-r--r--tutorial/examples/bca/Writable.java10
-rw-r--r--tutorial/examples/capsule/CapsuleClass.oj130
-rw-r--r--tutorial/examples/capsule/Point.oj22
-rw-r--r--tutorial/examples/capsule/PointUser.oj17
-rw-r--r--tutorial/examples/capsule/Test.oj47
-rw-r--r--tutorial/examples/capsule/TestUser.oj38
-rw-r--r--tutorial/examples/capsule/TestUser2.oj8
-rw-r--r--tutorial/examples/copy/CopiedClass.java43
-rw-r--r--tutorial/examples/copy/CopiedClass.oj37
-rw-r--r--tutorial/examples/copy/Test.java62
-rw-r--r--tutorial/examples/copy/Test.oj52
-rw-r--r--tutorial/examples/copy/TestShadow.java58
-rw-r--r--tutorial/examples/decorator/0UNDERCONSTRUCTION0
-rw-r--r--tutorial/examples/decorator/AdapterClass.oj152
-rw-r--r--tutorial/examples/decorator/ReturnSpecifier.java67
-rw-r--r--tutorial/examples/decorator/ReturnSpecifier.oj39
-rw-r--r--tutorial/examples/decorator/Test.java21
-rw-r--r--tutorial/examples/decorator/Test.oj21
-rw-r--r--tutorial/examples/facemake/FaceProvidedClass.java76
-rw-r--r--tutorial/examples/facemake/FaceProvidedClass.oj57
-rw-r--r--tutorial/examples/facemake/Test.java62
-rw-r--r--tutorial/examples/facemake/Test.oj52
-rw-r--r--tutorial/examples/facemake/TestFace.java516
-rw-r--r--tutorial/examples/freeargs/Collection.java61
-rw-r--r--tutorial/examples/freeargs/Collection.oj52
-rw-r--r--tutorial/examples/freeargs/FreeArgsClass.java117
-rw-r--r--tutorial/examples/freeargs/FreeArgsClass.oj95
-rw-r--r--tutorial/examples/freeargs/Test.java32
-rw-r--r--tutorial/examples/freeargs/Test.oj28
-rw-r--r--tutorial/examples/mixin/0UNDERCONSTRUCTION0
-rw-r--r--tutorial/examples/mixin/MixinedClass.java124
-rw-r--r--tutorial/examples/mixin/MixinedClass.oj115
-rw-r--r--tutorial/examples/mixin/Textbox.java23
-rw-r--r--tutorial/examples/mixin/Textbox.oj17
-rw-r--r--tutorial/examples/mixin/TextboxWithUndo.java22
-rw-r--r--tutorial/examples/mixin/TextboxWithUndo.oj8
-rw-r--r--tutorial/examples/mixin/Undo.java8
-rw-r--r--tutorial/examples/mixin/Undo.oj19
-rw-r--r--tutorial/examples/multimeta/CombinedClass.oj397
-rw-r--r--tutorial/examples/multimeta/MyPerson.oj15
-rw-r--r--tutorial/examples/multimeta/MyPerson2.oj15
-rw-r--r--tutorial/examples/multimeta/MyPerson3.oj14
-rw-r--r--tutorial/examples/multimethod/MultimethodClass.java169
-rw-r--r--tutorial/examples/multimethod/NoAddaptableMethodException.java24
-rw-r--r--tutorial/examples/multimethod/ParameterSetTree.java215
-rw-r--r--tutorial/examples/multimethod/Test.oj52
-rw-r--r--tutorial/examples/multimethod/Test2.oj20
-rw-r--r--tutorial/examples/operator/OperatorOverridable.oj7
-rw-r--r--tutorial/examples/operator/OperatorOverridableClass.oj97
-rw-r--r--tutorial/examples/orcheck/OverrideCheckerClass.java82
-rw-r--r--tutorial/examples/orcheck/OverridingClass.oj62
-rw-r--r--tutorial/examples/orcheck/Test.java15
-rw-r--r--tutorial/examples/orcheck/Test.oj9
-rw-r--r--tutorial/examples/orcheck/TestWithError.oj10
-rw-r--r--tutorial/examples/order/OrderKeeperClass.java65
-rw-r--r--tutorial/examples/order/OrderKeeperClass.oj46
-rw-r--r--tutorial/examples/order/Test.java21
-rw-r--r--tutorial/examples/order/Test.oj12
-rw-r--r--tutorial/examples/order2/Printer.java46
-rw-r--r--tutorial/examples/order2/Printer.oj33
-rw-r--r--tutorial/examples/order2/Test.java34
-rw-r--r--tutorial/examples/order2/Test.oj11
-rw-r--r--tutorial/examples/print/MyClass.java30
-rw-r--r--tutorial/examples/print/MyClass.oj21
-rw-r--r--tutorial/examples/print/Printer.java64
-rw-r--r--tutorial/examples/print/Test.java119
-rw-r--r--tutorial/examples/print/Test.oj107
-rw-r--r--tutorial/examples/print/TestPrinter.java99
-rw-r--r--tutorial/examples/rtrefl/Point.java107
-rw-r--r--tutorial/examples/rtrefl/Point.oj35
-rw-r--r--tutorial/examples/rtrefl/PointUser.java25
-rw-r--r--tutorial/examples/rtrefl/PointUser.oj19
-rw-r--r--tutorial/examples/rtrefl/RTMetaLevel.java6
-rw-r--r--tutorial/examples/rtrefl/RTMetaObject.java81
-rw-r--r--tutorial/examples/rtrefl/RTReflClass.java229
-rw-r--r--tutorial/examples/rtrefl/RTReflClass.oj247
-rw-r--r--tutorial/examples/rtrefl/VerboseRTMetaObject.java38
-rw-r--r--tutorial/examples/serialize/BIND5
-rw-r--r--tutorial/examples/serialize/Color.oj44
-rw-r--r--tutorial/examples/serialize/Colored3DPoint.oj19
-rw-r--r--tutorial/examples/serialize/ColoredPoint.oj28
-rw-r--r--tutorial/examples/serialize/Marshalable.java9
-rw-r--r--tutorial/examples/serialize/OIOTest.java56
-rw-r--r--tutorial/examples/serialize/ObjectIn.java34
-rw-r--r--tutorial/examples/serialize/ObjectOut.java36
-rw-r--r--tutorial/examples/serialize/Point.oj29
-rw-r--r--tutorial/examples/serialize/SerializableClass.oj121
-rw-r--r--tutorial/examples/syntax/ErrorTest.java97
-rw-r--r--tutorial/examples/syntax/ErrorTest.oj96
-rw-r--r--tutorial/examples/syntax/RichSyntaxClass.java129
-rw-r--r--tutorial/examples/syntax/RichSyntaxClass.oj102
-rw-r--r--tutorial/examples/syntax/Test.java97
-rw-r--r--tutorial/examples/syntax/Test.oj96
-rw-r--r--tutorial/examples/verbose/Hello.java22
-rw-r--r--tutorial/examples/verbose/Hello.oj13
-rw-r--r--tutorial/examples/verbose/Test.java98
-rw-r--r--tutorial/examples/verbose/Test.oj73
-rw-r--r--tutorial/examples/verbose/VerboseClass.java45
-rw-r--r--tutorial/examples/verbose/VerboseClass.oj30
-rw-r--r--tutorial/examples/verbose2/Test.java98
-rw-r--r--tutorial/examples/verbose2/Test.oj73
-rw-r--r--tutorial/examples/verbose2/VerboseClass.java50
-rw-r--r--tutorial/images/comflow.gifbin0 -> 2697 bytes
-rw-r--r--tutorial/index.html83
134 files changed, 9294 insertions, 0 deletions
diff --git a/tutorial/Adapter.html b/tutorial/Adapter.html
new file mode 100644
index 0000000..ae333a2
--- /dev/null
+++ b/tutorial/Adapter.html
@@ -0,0 +1,258 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<h2>6. <font color="blue">Callee-side Translation</font></h2>
+
+
+<p>In this section, an example of simple translation at <i>callee-side</i>
+is described.
+
+
+<h3>6.1. What the base-level program should look like</h3>
+
+<br><blockquote><pre><font color=darkblue>
+import java.util.*;
+public class <font color=black>VectorStack</font> <b>instantiates <font color=black>AdapterClass</font></b>
+ <b>adapts <font color=black>Vector</font> in v to <font color=black>Stack</font></b>
+{
+ <font color=black>Vector</font> v;
+ public <font color=black>VectorStack</font>( <font color=black>Vector</font> v ) {
+ this.v = v;
+ }
+ public <font color=black>void</font> push( <font color=black>Object</font> o ) {
+ v.addElement( o );
+ }
+ public <font color=black>Object</font> pop() {
+ <font color=black>Object</font> result = peek();
+ v.removeElementAt( v.size() - 1 );
+ return result;
+ }
+ public <font color=black>Object</font> peek() {
+ return v.elementAt( v.size() - 1 );
+ }
+}
+</font></pre></blockquote>
+
+<br><blockquote><pre><font color=darkblue>
+public interface <font color=black>Stack</font>
+{
+ public <font color=black>int</font> size();
+ public <font color=black>boolean</font> isEmpty();
+ public <font color=black>Enumeration</font> elements();
+ public <font color=black>Object[]</font> toArray();
+ public <font color=black>int</font> hashCode();
+ public <font color=black>void</font> push( <font color=black>Object</font> o );
+ public <font color=black>Object</font> pop();
+ public <font color=black>Object</font> peek();
+}
+</font></pre></blockquote>
+
+
+<h3>6.2. What the base-level program should be translated</h3>
+
+<p>Like following:
+<br><blockquote><pre><font color=darkblue>
+import java.util.*;
+public class <font color=black>VectorStack</font> implements <font color=black>Stack</font>
+{
+ <font color=black>Vector</font> v;
+ public <font color=black>VectorStack</font>( <font color=black>Vector</font> v ) {
+ this.v = v;
+ }
+ public <font color=black>void</font> push( <font color=black>Object</font> o ) {
+ v.addElement( o );
+ }
+ public <font color=black>Object</font> pop() {
+ <font color=black>Object</font> result = peek();
+ v.removeElementAt( v.size() - 1 );
+ return result;
+ }
+ public <font color=black>Object</font> peek() {
+ return v.elementAt( v.size() - 1 );
+ }
+ <b>public <font color=black>Object[]</font> toArray() {</b>
+ <b>return v.toArray();</b>
+ <b>}</b>
+ <b>public <font color=black>int</font> size() {</b>
+ <b>return v.size();</b>
+ <b>}</b>
+ <b>public <font color=black>Enumeration</font> elements() {</b>
+ <b>return v.elements();</b>
+ <b>}</b>
+ <b>public <font color=black>boolean</font> isEmpty() {</b>
+ <b>return v.isEmpty();</b>
+ <b>}</b>
+ <b>public <font color=black>int</font> hashCode() {</b>
+ <b>return v.hashCode();</b>
+ <b>}</b>
+}
+</font></pre></blockquote>
+
+
+<h3>6.3. Write a meta-level program</h3>
+
+<br><blockquote><pre><font color=darkblue>
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.syntax.*;
+
+/**
+ * The metaclass <code>AdapterClass</code> supports classes
+ * implementing an adapter role of the Adapter pattern.
+ * The target's methods with same signatures as the adaptee's are
+ * automatically implemented into the adapter class.
+ */
+public class AdapterClass instantiates Metaclass extends OJClass
+{
+
+ public static final String KEY_ADAPTS = "adapts";
+
+ /* overrides for translation */
+ public void translateDefinition() throws MOPException {
+ OJClass target = getTarget(), adaptee = getAdaptee();
+ if (target == null || adaptee == null) return;
+
+ /* implicit forwarding to the same signature's */
+ OJMethod[] adapteds = adaptee.getMethods( this );
+ for (int i = 0; i < adapteds.length; ++i) {
+ /* picks up the method with same signature */
+ OJMethod m;
+ try {
+ m = getTarget().getMethod( adapteds[i].getName(),
+ adapteds[i].getParameterTypes(),
+ this );
+ } catch ( NoSuchMemberException e ) { /* not match */ continue; }
+
+ /* generate a forwarding method with forwarded's name */
+ addMethod( makeForwardingMethod( m.getName(), m ) );
+ }
+
+ addInterface( getTarget() );
+ }
+
+ /**
+ * Generates a forwarding method with specified name.
+ *
+ * @param name generating method's name.
+ * @param forwarded method to which the generated method forwards.
+ * @return a generated forwarding method.
+ */
+ private OJMethod makeForwardingMethod( String name, OJMethod forwarded )
+ throws MOPException
+ {
+ /* generates a new method without body */
+ OJMethod result = new OJMethod(
+ this,
+ forwarded.getModifiers().remove( OJModifier.ABSTRACT ),
+ forwarded.getReturnType(),
+ name,
+ forwarded.getParameterTypes(),
+ forwarded.getExceptionTypes(),
+ null
+ );
+
+ /* generates a method call and return statement */
+ ExpressionList params = result.getParameterVariables();
+ Expression expr = new MethodCall( getContainer(), name, params );
+ StatementList body = new StatementList();
+ if (forwarded.getReturnType() == OJSystem.VOID) {
+ body.add( new ExpressionStatement( expr ) );
+ body.add( new ReturnStatement() );
+ } else {
+ body.add( new ReturnStatement( expr ) );
+ }
+
+ result.setBody( body );
+ return result;
+ }
+
+ /* extended information */
+
+ private OJClass getAdaptee() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_ADAPTS );
+ return OJClass.forName( suffix.get( 0 ).toString() );
+ }
+
+ private Variable getContainer() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_ADAPTS );
+ return new Variable( suffix.get( 1 ).toString() );
+ }
+
+ private OJClass getTarget() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_ADAPTS );
+ return OJClass.forName( suffix.get( 2 ).toString() );
+ }
+
+ /* override to extend syntax */
+ public static boolean isRegisteredKeyword( String keyword ) {
+ return keyword.equals( KEY_ADAPTS );
+ }
+
+ /* override to extend syntax */
+ public static SyntaxRule getDeclSuffixRule( String keyword ) {
+ if (keyword.equals( KEY_ADAPTS )) {
+ return new CompositeRule(
+ new TypeNameRule(),
+ new PrepPhraseRule( "in", new NameRule() ),
+ new PrepPhraseRule( "to", new TypeNameRule() ) );
+ }
+ return null;
+ }
+
+}
+
+</font></pre></blockquote>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/AutoImpl.html b/tutorial/AutoImpl.html
new file mode 100644
index 0000000..9fd017f
--- /dev/null
+++ b/tutorial/AutoImpl.html
@@ -0,0 +1,150 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<h2>5. <font color="blue">Automatic Methods Implementation</font></h2>
+
+
+<p>In this section, an example of simple translation at <i>callee-side</i>
+is described.
+
+<p>The callee-side of a class is whole the declration source code of the
+class. Metaprogram in the metaclass for that class (base class)
+introspects that class definition in <code>this</code> class object
+through the inheriting <code>OJClass</code> interface.
+
+<p>Imagine an utility metaclass which automatically implements
+empty methods in its base classes according to their interfaces.
+
+<h3>5.1. What the base-level program should look like</h3>
+
+<p>A base class <code>QuickTest</code> has to implement an interface
+<code>java.awt.event.WindowListener</code>, which has several methods
+to have to be implemented, but we want to make most of these methods
+to have empty body, i.e. do nothing.
+
+<br><blockquote><pre><font color=darkblue>
+import java.awt.event.*;
+public class <font color=black>QuickTest</font> <b>instantiates <font color=black>AutoImplementerClass</font></b>
+ implements <font color=black>WindowListener</font>
+{
+ public <font color=black>void</font> windowClosed( <font color=black>WindowEvent</font> e ) { <font color=black>System</font>.exit( 0 ); }
+}
+</font></pre></blockquote>
+
+
+<h3>5.2. What the base-level program should be translated</h3>
+
+<p>Like following:
+
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>QuickTest</font> instantiates <font color=black>AutoImplementerClass</font>
+ implements <font color=black>WindowListener</font>
+{
+ public <font color=black>void</font> windowClosed( <font color=black>WindowEvent</font> e ) { <font color=black>System</font>.exit( 0 ); }
+ <b>public <font color=black>void</font> windowIconified( <font color=black>WindowEvent</font> e ) { return; }</b>
+ <b>public <font color=black>void</font> windowDeactivated( <font color=black>WindowEvent</font> e ) { return; }</b>
+ ....
+}
+</font></pre></blockquote>
+
+
+<h3>5.3. Write a meta-level program</h3>
+
+<p>So.
+
+<br><blockquote><pre><font color=darkblue>
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.syntax.*;
+
+public class AutoImplementerClass instantiates Metaclass extends OJClass
+{
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getInheritedMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (! methods[i].getModifiers().isAbstract()
+ || methods[i].getReturnType() != OJSystem.VOID
+ || hasDeclaredMethod( methods[i] )) continue;
+ addMethod( makeEmptyMethod( methods[i] ) );
+ }
+ }
+ ....
+}
+</font></pre></blockquote>
+
+<br><blockquote><pre><font color=darkblue>
+ private boolean hasDeclaredMethod( OJMethod m ) {
+ try {
+ getDeclaredMethod( m.getName(), m.getParameterTypes() );
+ return true;
+ } catch ( NoSuchMemberException e ) {
+ return false;
+ }
+ }
+</font></pre></blockquote>
+
+<br><blockquote><pre><font color=darkblue>
+ private OJMethod makeEmptyMethod( OJMethod m ) throws MOPException {
+ /* generates a new method without body */
+ return new OJMethod( this,
+ m.getModifiers().remove( OJModifier.ABSTRACT ),
+ m.getReturnType(), m.getName(), m.getParameterTypes(),
+ m.getExceptionTypes(),
+ new StatementList( new ReturnStatement() )
+ );
+ }
+</font></pre></blockquote>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/FreeArgs.html b/tutorial/FreeArgs.html
new file mode 100644
index 0000000..43c9cb9
--- /dev/null
+++ b/tutorial/FreeArgs.html
@@ -0,0 +1,171 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<h2>6. <font color="blue">Callee-side Translation</font></h2>
+
+
+<p>In this section, an example of simple translation at <i>caller-side</i>
+is described.
+
+<h3>6.1. What the base-level program should look like</h3>
+
+<p>Most of example programs given in the text are ready to be executed by
+the OpenJava system and are similar in form to:
+
+
+<br><blockquote><pre><font color=darkblue>
+import java.util.*;
+public class <font color=black>StringCollection</font> <b>instantiates <font color=black>FreeArgsClass</font></b>
+{
+ <font color=black>Vector</font> contents = new <font color=black>Vector</font>();
+ public <b>generous</b> <font color=black>void</font> addAll( <font color=black>String[]</font> args ) {
+ for (<font color=black>int</font> i = 0; i < args.length; ++i) contents.addElement( args[i] );
+ }
+}
+</font></pre></blockquote>
+
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>Test</font>
+{
+ void test() {
+ <font color=black>StringCollection</font> strs = new <font color=black>StringCollection</font>();
+ strs.addAll( <b>"one", "two", "three"</b> );
+ }
+}
+</font></pre></blockquote>
+
+
+<h3>6.2. What the base-level program should be translated</h3>
+
+<p>Like following:
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>Test</font>
+{
+ void test() {
+ <font color=black>StringCollection</font> strs = new <font color=black>StringCollection</font>();
+ strs.addAll( <b>new <font color=black>String</font>[]{ "one", "two", "three" }</b> );
+ }
+}
+</font></pre></blockquote>
+
+
+<h3>6.3. Write a meta-level program</h3>
+
+<br><blockquote><pre><font color=darkblue>
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+public class FreeArgsClass instantiates Metaclass extends OJClass
+{
+ private static final String GENEROUS = "generous";
+ /** Translates definition */
+
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (! methods[i].getModifiers().has( GENEROUS )) continue;
+ System.err.println( methods[i] );
+ OJClass[] paramtypes = methods[i].getParameterTypes();
+ if (paramtypes.length != 1 || ! paramtypes[0].isArray()) {
+ System.err.println( "illegal parameter, ignored." );
+ continue;
+ }
+ putMetaInfo( methods[i].getName(), paramtypes[0].getName() );
+ }
+ }
+
+ public OJMethod resolveException( NoSuchMemberException e,
+ String name, OJClass[] params )
+ throws NoSuchMemberException
+ {
+ try {
+ String argtypename = getMetaInfo( name );
+ if (argtypename != null) {
+ OJClass paramtype = OJClass.forName( argtypename );
+ return getMethod( name, new OJClass[]{ paramtype }, this );
+ }
+ } catch ( OJClassNotFoundException e2 ) {
+ System.err.println( e2 );
+ }
+ return super.resolveException( e, name, params );
+ }
+
+ /** Translates allocation parts */
+ public Expression expandMethodCall( Environment env, MethodCall expr ) {
+ String argtypename = getMetaInfo( expr.getName() );
+ if (argtypename == null) return expr;
+ OJClass comptype;
+ try {
+ comptype = OJClass.forName( argtypename ).getComponentType();
+ } catch ( OJClassNotFoundException e ) {
+ System.err.println( e );
+ return expr;
+ }
+ ExpressionList dim = new ExpressionList( null );
+ ArrayInitializer ainit = new ArrayInitializer( expr.getArguments() );
+ ArrayAllocationExpression carrier
+ = new ArrayAllocationExpression( comptype, dim, ainit );
+ expr.setArguments( new ExpressionList( carrier ) );
+ return expr;
+ }
+
+ public static boolean isRegisteredModifier( String keyword ) {
+ if (keyword.equals( GENEROUS )) return true;
+ return false;
+ }
+</font></pre></blockquote>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/Introduction.html b/tutorial/Introduction.html
new file mode 100644
index 0000000..fdec2c2
--- /dev/null
+++ b/tutorial/Introduction.html
@@ -0,0 +1,96 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<h2>1. <font color="blue">Introduction</font></h2>
+
+
+<p>OpenJava is an extensible language based on Java. The extended
+features of OpenJava are specified by a meta-level program given at
+compile time. For distinction, programs written in OpenJava are called
+base-level programs. If no meta-level program is given, OpenJava is
+identical to regular Java.
+
+<p>The meta-level program extends OpenJava through the interface
+called the OpenJava MOP (Metaobject Protocol). The OpenJava compiler
+consists of three stages: preprocessor, source-to-source translator
+from OpenJava to Java, and the back-end Java compiler. The OpenJava
+MOP is an interface to control the translator at the second stage. It
+allows to specify how an extended feature of OpenJava is translated
+into regular Java code.
+
+<p>An extended feature of OpenJava is supplied as an add-on software
+for the compiler. The add-on software consists of not only the
+meta-level program but runtime support code. The runtime support code
+provides classes used by the base-level program translated into
+Java. The base-level program in OpenJava is first translated into Java
+by the meta-level program and is dynamically linked with the runtime
+support code. This flow is illustrated by Figure 1.
+
+<center>
+<img src="images/comflow.gif"><br>
+Figure 1 : Data Flow of OpenJava Compiler
+</center>
+
+<p>The meta-level program is written in Java, accurately in OpenJava
+because OpenJava is a self-reflective language. It defines new
+metaobjects to control source-to-source translation. The metaobjects
+are the meta-level representation of the base-level program and they
+perform the translation. Details of the metaobjects are specified by
+the OpenJava MOP. In the following, we go through a few examples so
+that we illustrate how the OpenJava MOP is used to implement language
+extensions.
+<p>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/NewMethod.html b/tutorial/NewMethod.html
new file mode 100644
index 0000000..efa7192
--- /dev/null
+++ b/tutorial/NewMethod.html
@@ -0,0 +1,209 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<h2><!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+4. <font color="blue">Generating New Methods</font>
+</h2>
+<p>
+
+A MOP version of "hello world" is verbose objects, which print a message
+for every method call.
+We choose them as our first example.
+<p>
+The MOP programming in OpenJava is done through three steps :
+(1) decide what the base-level program should look like,
+(2) figure out what it should be translated into and what runtime support
+code is needed,
+and (3) write a meta-level program to perform the translation and also
+write the runtime support code.
+We implement the verbose objects through these steps.
+<p>
+
+
+<h3>2.1. What the base-level program should look like</h3>
+<p>
+
+Most of example programs given in the text are ready to be executed by
+the OpenJava system and are similar in form to:
+
+<br><blockquote><pre>
+public class <b>Hello</b> instantiates <b>VerboseClass</b> {
+ public static void main( String[] args ) {
+ hello();
+ }
+ static void hello() {
+ System.out.println( "<i>Hello, world.</i>" );
+ }
+}
+</pre></blockquote>
+
+This is an ordinary source code except for the first line.
+The annotation in the first line :
+
+<br><blockquote><pre>
+instantiates <b>VerboseClass</b>
+</pre></blockquote>
+
+is a special annotation for OpenJava, and means that the semantics of
+the class <b>Hello</b>, called metaobject, is specified to be extended
+by the class <b>VerboseClass</b>, called metaclass. In practice, the
+source code of the class <b>Hello</b> is translated by the object of
+the metaclass <b>VerboseClass</b>.
+
+<p>
+
+
+<h3>2.2. What the base-level program should be translated</h3>
+<p>
+
+In this example, consider the metaclass <b>VerboseClass</b> to extend
+the metaobjects to show messages for every call for its methods. In
+practice, the statement in order to put the message into system
+standard output is to be inserted at the first line of each methods'
+body in the class <b>Hello</b> via the metaclass <b>VerboseClass</b>. Then
+the first source code of class <b>Hello</b> should be translated into:
+
+<br><blockquote><pre>
+public class Hello {
+ public static void main( String[] args ) {
+ System.out.println( "<i>main is called.</i>" );
+ hello();
+ }
+ static void hello() {
+ System.out.println( "<i>hello is called.</i>" );
+ System.out.println( "<i>Hello, world.</i>" );
+ }
+}
+</pre></blockquote>
+
+<p>
+
+
+<h3>2.3. Write a meta-level program</h3>
+<p>
+
+Now, we write a meta-level program. What we should do is to translate
+only method member in the class <b>Hello</b> in the way shown above.
+We can easily do that if we use the MOP.
+<p>
+
+In OpenJava, classes are objects as in Smalltalk. We call them class
+metaobjects when we refer to their meta-level representation. A
+unique feature of OpenJava is that a class metaobject translates the
+source code defining the class at compile time. For example, the
+class metaobject for <b>Hello</b> translates a method declaration
+<b>hello()</b>.
+<p>
+
+By default, class metaobjects are identity functions; they do not change
+the program. So, to implement our translation, we define a new metaclass
+- a new class for class metaobjects - and use it to make the class
+metaobject for <b>Hello</b>.
+<p>
+
+Such a metaclass <b>VerboseClass</b> has been compiled and is similar
+to in form to:
+
+<br><blockquote><pre><font color=darkblue>
+import openjava.mop.*;
+import openjava.ptree.*;
+public class <font color=black>VerboseClass</font> instantiates <font
+color=black>Metaclass</font> extends <font color=black>OJClass</font>
+{
+ public <font color=black>void</font> translatioDefinition() throws <font color=black>MOPException</font> {
+ <font color=black>OJMethod</font>[] methods = getDeclaredMethods();
+ for (<font color=black>int</font> i = 0; i < methods.length; ++i) {
+ <font color=black>Statement</font> printer = makeStatement(
+ "<font color=gray><i>System.out.println( \"</i></font>" + methods[i].getName() +
+ "<font color=gray><i> is called.\" );</i></font>"
+ );
+ methods[i].getBody().insertElementAt( printer, 0 );
+ }
+ }
+}
+</font></pre></blockquote>
+
+The metaclass <b>VerboseClass</b> is just a regular Java class. It
+inherits from <b>openjava.mop.OJClass</b> and overrides one member
+function. <b>translateMethodDeclaration</b> takes an object of the
+class <b>MethodDeclaration</b> and returns the translated one. Both
+the given expression and the translated one are represented in the
+form of parse tree.
+<p>
+
+
+<h3>2.4. Compile, debug, and run</h3>
+<p>
+
+On a Sun workstation, the first class, stored in the file
+<tt>Hello.oj</tt>, can be translated into Java source code file named
+<tt>Hello.java</tt> and the generated source code can be compiled into
+byte code file named <tt>Hello.class</tt> by giving the commands :
+
+<br><blockquote><pre>
+% ojc VerboseClass.oj
+% ojc Hello.oj
+</pre></blockquote>
+<p>
+
+Execution of its bytecode on JVM (Java Virtual Machine) produces the
+output :
+
+<br><blockquote><pre>
+main is called.
+hello is called.
+Hello, world.
+</pre></blockquote>
+<p>
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/Override.html b/tutorial/Override.html
new file mode 100644
index 0000000..32dbbb0
--- /dev/null
+++ b/tutorial/Override.html
@@ -0,0 +1,181 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<h2><!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+4. <font color="blue">Custom Modifiers</font>
+</h2>
+
+<p>OpenJava allows meta-programmer to extend the syntax of language in
+limited way. The easiest part of the syntax extension is adding
+new modifiers for class declaration or member declarations.
+
+<p>In this section, suppose an example of syntax extension for method
+declarations which explicitly describes the modified method should
+override the methed in superclasses. With this extension, base-level
+programmers can detect errors at compile-time. Otherwise,
+the regular Java compiler doesn't complain about it because it's
+proper method declaration defining a new method in the class.
+
+
+<h3>2.1. What the base-level program should look like</h3>
+
+<p>In defining a new class which must override some methods in
+superclasses, programmers would add the modifier <tt>overriding</tt>
+to each method overriding the corresponding method in superclasses.
+Here, we define a new class <b>MyObject</b> which surely overrides
+the method <tt>toString()</tt> in the superclass <b>java.lang.Object</b>:
+
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>MyObject</font> instantiates <font color=black>OverrideCheckerClass</font> {
+ public <b>overriding</b> <font color=black>String</font> toString() {
+ return "<i>MyString</i>";
+ }
+}
+</font></pre></blockquote>
+
+<p>OpenJava compiler doesn't show any error message for this source code
+as it overrides the supermethod properly. But the system should
+show some error messages if the source code is as follows:
+
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>MyObjectWithError</font> instantiates <font color=black>OverrideCheckerClass</font> {
+ public <b>overriding</b> <font color=black>String</font> toStr<b>u</b>ng() {
+ return "<i>MyString</i>";
+ }
+}
+</font></pre></blockquote>
+
+because there is no <tt>toStrung()</tt> method in the superclasses
+of the class <b>MyObjectWithError</b>.
+
+
+<h3>2.2. What the base-level program should be translated</h3>
+
+<p>In this example, only the error checking is performed thus no translation
+of source code are performed by the metaclass. Thus the system
+should produce the source code in the regular Java like following for
+the class <b>MyObject</b>:
+
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>MyObject</font> {
+ public <font color=black>String</font> toString() {
+ return "<i>MyString</i>";
+ }
+}
+</font></pre></blockquote>
+
+<p>Only the difference from the original is the absense of the
+extended modifier <tt>overriding</tt>.
+
+
+<h3>2.3. Write a meta-level program</h3>
+
+<p>Extended modifiers are automatically removed by the
+system in generating source code. Thus we do not have to care about
+it here.
+
+We should define such a metaclass <b>OverrideCheckerClass</b>
+to override two methods. The first method:
+
+<br><blockquote><pre><font color=darkblue>
+public static boolean isRegisteredModifier(String)
+</font></pre></blockquote>
+is for the purpose of allowing the custom modifier <tt>overriding</tt>.
+
+<p>And the second method is:
+
+<br><blockquote><pre><font color=darkblue>
+public void translateDefinition()
+</font></pre></blockquote>
+
+Though there are no translation, we must show alert in case of missing
+overriding.
+
+<p>The source code following is a such implementation.
+
+<br><blockquote><pre><font color=darkblue>
+import openjava.mop.*;
+import openjava.ptree.*;
+public class <font color=black>OverrideCheckerClass</font> instantiates <font color=black>Metaclass</font> extends <font color=black>OJClass</font>
+{
+ private static final <font color=black>String</font> OVERRIDING = "overriding";
+
+ public static <font color=black>boolean</font> isRegisteredModifier( <font color=black>String</font> keyword ) {
+ if (keyword.equals( OVERRIDING )) return true;
+ return <font color=black>OJClass</font>.isRegisteredModifier( keyword );
+ }
+
+ public <font color=black>void</font> translateDefinition() throws <font color=black>MOPException</font> {
+ <font color=black>OJMethod</font>[] methods = getDeclaredMethods();
+ for (<font color=black>int</font> i = 0; i < methods.length; ++i) {
+ if (! methods[i].getModifiers().has( OVERRIDING )) continue;
+ <font color=black>String</font> name = methods[i].getName();
+ <font color=black>OJClass</font>[] ptypes = methods[i].getParameterTypes();
+ try {
+ getSuperclass().getMethod( name, ptypes, this );
+ } catch (<font color=black>NoSuchMemberException</font> e) {
+ <font color=black>System</font>.err.println( "<i>warning: </i> " + methods[i] + "<i> doesn't </i>" +
+ "<i>override any method in the superclasses.</i>" );
+ }
+ }
+ }
+
+}
+</font></pre></blockquote>
+
+<p>In order to add a new modifier, we override the method
+<tt>isRegisteredModifier()</tt> and make it return true for the
+<b>String</b> object <tt>"overriding"</tt>.
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/Overview.html b/tutorial/Overview.html
new file mode 100644
index 0000000..2ebb0b6
--- /dev/null
+++ b/tutorial/Overview.html
@@ -0,0 +1,208 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<h2><!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+3. <font color="blue">API and Framework at a Glance</font>
+</h2>
+<p>
+
+<h3>3.1. Overriding for Translation</h3>
+
+<p>As already describe before, we define a translation on a class by
+defining a new subclass of the metaclass <b>openjava.mop.OJClass</b>.
+The new metaclass overrides some methods in <b>OJClass</b> to change
+how to translate sourcecode related to the base class.
+
+<p>The main part of translation may be the translation on class
+definition. We call this kind of translation <i>callee-side
+translation</i>. For the convenience of explanation, suppose a base
+class <b>MyObject</b> extended by a metaclass <b>MyClass</b>, like
+following:
+
+<br><blockquote><pre><font color=darkblue>
+public class MyObject instantiates MyClass
+{
+ public String str;
+ public int f() { return 1; }
+}
+</font></pre></blockquote>
+
+<p>To modify the source code at the callee-side of classes, we should
+override the following method:
+
+<br><blockquote><pre>
+public void translateDefinition()
+ throws MOPException
+</pre></blockquote>
+
+in the metaclass<b>MyClass</b>, which is a subclass of the
+metaclass<b>OJClass</b>.
+
+<p>Furthermore, the part possible to translate is where the class is
+used. There are several part related to the use of class.
+i.e. object allocations, method calls, field accesses, .. We call
+this kind of translation <i>caller-side translation</i>. Similarly to
+callee-side translation, we should override appropriate methods in
+<b>OJClass</b>.
+
+<p>The following methods are for translation of object allocation parts.
+
+<br><blockquote><pre>
+public Expression expandAllocation(Evnironment,AllocationExpression)
+ throws MOPException
+</pre></blockquote>
+
+is applied to explessions like: <code><font color=darkblue>new
+MyObject()</font></code>, and
+
+<br><blockquote><pre>
+public Expression expandArrayAllocation(Evnironment,ArrayAllocationExpression)
+ throws MOPException
+</pre></blockquote>
+is applied for explessions like: <code><font color=darkblue>new
+MyObject[10]</font></code> or <code><font color=darkblue>new
+MyObject[]{ null, null }</font></code>
+
+<p>Here, suppose a variable <code><font color=darkblue>obj</font>
+</code> is declared somewhere as follows:
+
+<br><blockquote><pre><font color=darkblue>
+MyObject obj;
+</font></pre></blockquote>
+
+<p>The following methods are for translation of member access on either
+class or object.
+
+<br><blockquote><pre>
+public Expression expandFieldRead(Evnironment,FieldAccess)
+ throws MOPException
+</pre></blockquote>
+
+is applied to explessions like: <code><font
+color=darkblue>obj.str</font></code>,
+
+<br><blockquote><pre>
+public Expression expandMethodCall(Evnironment,MethodCall)
+ throws MOPException
+</pre></blockquote>
+
+is applied to explessions like: <code><font
+color=darkblue>obj.f()</font></code>, and
+
+<br><blockquote><pre>
+public Expression expandFieldWrite(Evnironment,AssignmentExpression)
+ throws MOPException
+</pre></blockquote>
+is applied to explessions like: <code><font color=darkblue>obj.str =
+"Hello"</font></code>
+
+
+<p>The following methods are for translation of where the name of the
+class appears.
+
+<br><blockquote><pre>
+public Expression expandTypeName(Evnironment,TypeName)
+ throws MOPException
+</pre></blockquote>
+
+<p>
+<br><blockquote><pre>
+public Expression expandArrayAccess(Evnironment,ArrayAccess)
+ throws MOPException
+public Expression expandAssignmentExpression(Evnironment,AssignmentExpression)
+ throws MOPException
+public Expression expandExpression(Evnironment,Expression)
+ throws MOPException
+public Statement expandVariableDeclaration(Evnironment,VariableDeclaration)
+ throws MOPException
+</pre></blockquote>
+<p>
+
+<h3>3.2. Getting Information of Class Metaobjects</h3>
+
+<p>In the overriding methods, we can get information about the class by
+using the methods defined in <b>OJClass</b> such as follows:
+<ul>
+<li><pre>public String getName()</pre>
+<li><pre>public OJClass getSuperclass()</pre>
+<li><pre>public OJClass[] getInterfaces()</pre>
+<li><pre>public OJField[] getDeclaredFields()</pre>
+<li><pre>public OJField[] getFields(OJClass situation)</pre>
+<li><pre>public OJMethod[] getDeclaredMethods()</pre>
+<li><pre>public OJMethod[] getMethods(OJClass situation)</pre>
+<li><pre>public OJConstructor[] getDeclaredConstructors()</pre>
+<li><pre>public OJConstructor[] getConstructors(OJClass situation)</pre>
+<li><pre>public OJField getField(String name)</pre>
+<li><pre>public OJMethod getMethod(String name,OJClass[] parameterTypes)</pre>
+<li><pre>public OJConstructor getConstructor(OJClass[] parameterTypes)</pre>
+</ul>
+
+<h3>3.3. Modifying a Class Metaobject</h3>
+
+<p>In the overriding <tt>translateDefinition()</tt> method, we can modify
+the class definition by using the methods defined in <b>OJClass</b>
+such as follows:
+
+<ul>
+<li><pre>protected OJField addField(OJField field)</pre>
+<li><pre>protected OJField removeField(OJField field)</pre>
+<li><pre>protected OJMethod addMethod(OJMethod method)</pre>
+<li><pre>protected OJMethod removeMethod(OJMethod method)</pre>
+<li><pre>protected OJConstructor addConstructor(OJConstructor constr)</pre>
+<li><pre>protected OJConstructor removeConstructor(OJConstructor constr)</pre>
+</ul>
+
+<p>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/Synchronize.html b/tutorial/Synchronize.html
new file mode 100644
index 0000000..6385a6b
--- /dev/null
+++ b/tutorial/Synchronize.html
@@ -0,0 +1,131 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<h2><!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+7. <font color="blue">Synchronization of Translation</font>
+</h2>
+<p>
+
+As the default behavior of OpenJava compiler, there is no assurance of
+callee-side translation ordering. In the case that we make it sure to
+translate a class <b>SubMyObject</b> after a class <b>MyObject</b>, we
+can use the method <code>waitTranslation()</code> in
+<b>java.lang.OJClass</b>.
+
+<br><blockquote><pre>
+public void waitTranslation(OJClass)
+ throws MOPException
+</pre></blockquote>
+
+At the invocation of this method, the translation on the current
+class declaration stops and it return to continue after the
+translation on the class given as the argument finished.
+
+<h3>7.1. Simple Examples</h3>
+<p>
+
+Furthermore, the part where that class is used comes. There are
+several part related to the use of class. i.e. object allocations,
+method calls, field accesses, .. We call this kind of translation
+<i>caller-side translation</i>.
+<p>
+
+For the convenience of explanation, suppose a base class
+<b>MyObject</b> extended by a metaclass <b>MyClass</b>, like
+following:
+
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>SubMyObject</font> instantiates <font color=black>SyncClass</font> extends <font color=black>MyObject</font>
+{}
+class <font color=black>MyObject</font> instantiates <font color=black>AnotherClass</font>
+{}
+class <font color=black>SubSubMyObject</font> instantiates <font color=black>SyncClass</font> extends <font color=black>SubMyObject</font>
+{}
+</font></pre></blockquote>
+
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>SyncClass</font> instantiates <font color=black>Metaclass</font> extends <font color=black>OJClass</font>
+{
+ void translateDefinition() throws <font color=black>MOPException</font> {
+ <font color=black>OJClass</font> baseclazz = getSuperclass();
+ <font color=black>System</font>.out.println( getName() + "<i> is waiting for </i>" + base.getName() );
+ waitTranslation( baseclazz );
+ <font color=black>System</font>.out.println( getName() + "<i> finished</i>" );
+ }
+}
+</font></pre></blockquote>
+
+We can see the following messages in running OpenJava compiler.
+<br><blockquote><pre><font color=darkred>
+MyObject is waiting for java.lang.Object
+MyObject finished
+SubSubMyObject is waiting for SubMyObject
+SubMyObject is waiting for MyObject
+SubMyObject finished
+SubSubMyObject finished
+</font></pre></blockquote>
+<p>
+
+<h3>7.2. Deadlocks</h3>
+<p>
+
+In the case of the system detects some deadlocks,
+<code>waitTranslation()</code> throws an exception
+<code>MOPException</code>. If already the translation of
+a class <b>A</b> were waiting for the translation of a class <b>B</b>,
+the invocation of <code>waitTranslation()</code> on the translation
+of the class <b>B</b> would not block but throw an exception.
+<p>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/Syntax.html b/tutorial/Syntax.html
new file mode 100644
index 0000000..ca1fb2f
--- /dev/null
+++ b/tutorial/Syntax.html
@@ -0,0 +1,171 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<h2>6. <font color="blue">Callee-side Translation</font></h2>
+
+
+<p>In this section, an example of simple translation at <i>callee-side</i>
+is described.
+
+
+<h3>6.1. What the base-level program should look like</h3>
+
+<p>Most of example programs given in the text are ready to be executed by
+the OpenJava system and are similar in form to:
+
+<br><blockquote><pre><font color=darkblue>
+import java.util.*;
+public class StringCollection instantiates FreeArgsClass
+{
+ Vector contents = new Vector();
+ public generous void addAll( String[] args ) {
+ for (int i = 0; i < args.length; ++i) contents.addElement( args[i] );
+ }
+}
+</font></pre></blockquote>
+
+<br><blockquote><pre><font color=darkblue>
+public class Test
+{
+ void test() {
+ StringCollection strs = new StringCollection();
+ strs.addAll( "one", "two", "three" );
+ }
+}
+</font></pre></blockquote>
+
+
+<h3>6.2. What the base-level program should be translated</h3>
+
+<p>Like following:
+<br><blockquote><pre><font color=darkblue>
+public class Test
+{
+ void test() {
+ StringCollection strs = new StringCollection();
+ strs.addAll( new String[]{ "one", "two", "three" } );
+ }
+}
+</font></pre></blockquote>
+
+
+<h3>6.3. Write a meta-level program</h3>
+
+<br><blockquote><pre><font color=darkblue>
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+public class FreeArgsClass instantiates Metaclass extends OJClass
+{
+ private static final String GENEROUS = "generous";
+ /** Translates definition */
+
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (! methods[i].getModifiers().has( GENEROUS )) continue;
+ System.err.println( methods[i] );
+ OJClass[] paramtypes = methods[i].getParameterTypes();
+ if (paramtypes.length != 1 || ! paramtypes[0].isArray()) {
+ System.err.println( "illegal parameter, ignored." );
+ continue;
+ }
+ putMetaInfo( methods[i].getName(), paramtypes[0].getName() );
+ }
+ }
+
+ public OJMethod resolveException( NoSuchMemberException e,
+ String name, OJClass[] params )
+ throws NoSuchMemberException
+ {
+ try {
+ String argtypename = getMetaInfo( name );
+ if (argtypename != null) {
+ OJClass paramtype = OJClass.forName( argtypename );
+ return getMethod( name, new OJClass[]{ paramtype }, this );
+ }
+ } catch ( OJClassNotFoundException e2 ) {
+ System.err.println( e2 );
+ }
+ return super.resolveException( e, name, params );
+ }
+
+ /** Translates allocation parts */
+ public Expression expandMethodCall( Environment env, MethodCall expr ) {
+ String argtypename = getMetaInfo( expr.getName() );
+ if (argtypename == null) return expr;
+ OJClass comptype;
+ try {
+ comptype = OJClass.forName( argtypename ).getComponentType();
+ } catch ( OJClassNotFoundException e ) {
+ System.err.println( e );
+ return expr;
+ }
+ ExpressionList dim = new ExpressionList( null );
+ ArrayInitializer ainit = new ArrayInitializer( expr.getArguments() );
+ ArrayAllocationExpression carrier
+ = new ArrayAllocationExpression( comptype, dim, ainit );
+ expr.setArguments( new ExpressionList( carrier ) );
+ return expr;
+ }
+
+ public static boolean isRegisteredModifier( String keyword ) {
+ if (keyword.equals( GENEROUS )) return true;
+ return false;
+ }
+</font></pre></blockquote>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/VerboseClass.html b/tutorial/VerboseClass.html
new file mode 100644
index 0000000..43e0637
--- /dev/null
+++ b/tutorial/VerboseClass.html
@@ -0,0 +1,212 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<h2>2. <font color="blue">Hello World</font></h2>
+
+
+<p>A MOP version of "hello world" is verbose objects, which print a message
+for every method call.
+We choose them as our first example.
+
+<p>The MOP programming in OpenJava is done through three steps :
+<ul>
+<li>(1) decide what the base-level program should look like,
+<li>(2) figure out what it should be translated into and what runtime support
+code is needed,
+</ul>
+and
+<ul>
+<li>(3) write a meta-level program to perform the translation and also
+write the runtime support code.
+</ul>
+We implement the verbose objects through these steps.
+
+
+<h3>2.1. What the base-level program should look like</h3>
+
+<p>Most of example programs given in the text are ready to be executed by
+the OpenJava system and are similar in form to:
+
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>Hello</font> <b>instantiates <font color=black>VerboseClass</font></b> {
+ public static <font color=black>void</font> main( <font color=black>String</font>[] args ) {
+ hello();
+ }
+ static <font color=black>void</font> hello() {
+ <font color=black>System</font>.out.println( "<font color=gray><i>Hello, world.</i></font>" );
+ }
+}
+</font></pre></blockquote>
+
+<p>This is an ordinary source code except for the first line.
+The annotation in the first line :
+
+<br><blockquote><pre><font color=darkblue>
+instantiates <font color=black>VerboseClass</font>
+</font></pre></blockquote>
+
+is a special annotation for OpenJava, and means that the semantics of
+the class <b>Hello</b>, called metaobject, is specified to be extended
+by the class <b>VerboseClass</b>, called metaclass. In practice, the
+source code of the class <b>Hello</b> is translated by the object of
+the metaclass <b>VerboseClass</b>.
+
+
+<h3>2.2. What the base-level program should be translated</h3>
+
+<p>In this example, consider the metaclass <b>VerboseClass</b> to extend
+the metaobjects to show messages for every call for its methods. In
+practice, the statement in order to put the message into system
+standard output is to be inserted at the first line of each methods'
+body in the class <b>Hello</b> via the metaclass <b>VerboseClass</b>. Then
+the first source code of class <b>Hello</b> should be translated into:
+
+<br><blockquote><pre><font color=darkblue>
+public class <font color=black>Hello</font> {
+ public static <font color=black>void</font> main( <font color=black>String</font>[] args ) {
+ <b><font color=black>System</font>.out.println( "<i>main is called.</i>" );</b>
+ hello();
+ }
+ static <font color=black>void</font> hello() {
+ <b><font color=black>System</font>.out.println( "<i>hello is called.</i>" );</b>
+ <font color=black>System</font>.out.println( "<i>Hello, world.</i>" );
+ }
+}
+</font></pre></blockquote>
+
+
+
+<h3>2.3. Write a meta-level program</h3>
+
+<p>Now, we write a meta-level program. What we should do is to
+translate only method member in the class <b>Hello</b> in the way
+shown above. We can easily do that if we use the MOP.
+
+<p>In OpenJava, classes are objects as in Smalltalk. We call them class
+metaobjects when we refer to their meta-level representation. A
+unique feature of OpenJava is that a class metaobject translates the
+source code defining the class at compile time. For example, the
+class metaobject for <b>Hello</b> translates a method declaration
+<b>hello()</b>.
+
+<p>By default, class metaobjects are identity functions; they do not
+change the program. So, to implement our translation, we define a new
+metaclass - a new class for class metaobjects - and use it to make the
+class metaobject for <b>Hello</b>. Such a metaclass
+<b>VerboseClass</b> has been compiled and is similar to in form to:
+
+<br><blockquote><pre><font color=darkblue>
+import openjava.mop.*;
+import openjava.ptree.*;
+public class <font color=black>VerboseClass</font> instantiates <font
+color=black>Metaclass</font> extends <font color=black>OJClass</font>
+{
+ public <font color=black>void</font> translateDefinition() throws <font color=black>MOPException</font> {
+ <font color=black>OJMethod</font>[] methods = getDeclaredMethods();
+ for (<font color=black>int</font> i = 0; i < methods.length; ++i) {
+ <font color=black>Statement</font> printer = makeStatement(
+ "<font color=gray><i>System.out.println( \"</i></font>" + methods[i] +
+ "<font color=gray><i> is called.\" );</i></font>"
+ );
+ methods[i].getBody().insertElementAt( printer, 0 );
+ }
+ }
+}
+</font></pre></blockquote>
+
+<p>Here, the metaclass <b>VerboseClass</b> is a base-level class of
+OpenJava from the view point of meta programming and in fact it
+declares its metaclass as <b>openjava.mop.Metaclass</b> though could
+be written in the regular Java. It inherits from
+<b>openjava.mop.OJClass</b> and overrides one member function.
+
+<p>In order to translate the definition part (callee-side) of the base
+class <b>Hello</b>, we should override the method
+<tt>translateMethodDeclaration()</tt>, which is to be invoked by the
+system automatically. In the method
+<tt>translateMethodDeclaration()</tt>, we can obtain all the method
+objects which are declared in the base-level class by invoking the
+method <tt>getDeclaredMethods()</tt> on the class object
+<tt>this</tt>.
+
+The method <tt>makeStatement()</tt> is the partial parser which
+produces a <b>openjava.ptree.Statement</b> object from a
+<b>java.lang.String</b> object. Here we produces a statement which
+print that the method is called, then inserts it at the body for each
+method.
+
+
+<h3>2.4. Compile, debug, and run</h3>
+
+<p>On a Sun workstation, the first class, stored in the file
+<tt>Hello.oj</tt>, can be translated into Java source code file named
+<tt>Hello.java</tt> and the generated source code can be compiled into
+byte code file named <tt>Hello.class</tt> by giving the commands:
+
+<br><blockquote><pre>
+% ojc VerboseClass.oj
+% ojc Hello.oj
+</pre></blockquote>
+
+<p>Execution of its bytecode on JVM (Java Virtual Machine) produces
+the output :
+
+<br><blockquote><pre><font color=darkred>
+void Hello.main(String[]) is called.
+void Hello.hello() is called.
+Hello, world.
+</font></pre></blockquote>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>
diff --git a/tutorial/examples/adapter/AdapterClass.java b/tutorial/examples/adapter/AdapterClass.java
new file mode 100644
index 0000000..0b2e60c
--- /dev/null
+++ b/tutorial/examples/adapter/AdapterClass.java
@@ -0,0 +1,155 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * AdapterClass.oj
+ *
+ * An OpenJava example to support programming with the Adapter pattern.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.adapter;
+
+
+import java.lang.Object;
+import io.devnulllabs.openjava.mop.*;
+import io.devnulllabs.openjava.ptree.*;
+import io.devnulllabs.openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>AdapterClass</code> supports classes
+ * implementing an adapter role of the Adapter pattern.
+ * The target's methods with same signatures as the adaptee's are
+ * automatically implemented into the adapter class.
+ * <p>
+ * For example, the class <code>VectorStack</code>:
+ * <pre>
+ * public class VectorStack instantiates AdapterClass
+ * adapts Vector in v to Stack
+ * {
+ * Vector v;
+ * public VectorStack( Vector v ) {
+ * this.v = v;
+ * }
+ * public void push( Object o ) {
+ * v.addElement( o );
+ * }
+ * public Object pop() {
+ * return v.removeElementAt( v.size() - 1 );
+ * }
+ * }
+ * </pre>
+ * would be automatically implemented with the forwarding methods
+ * size(), isEmpty(), hashCode(), etc, which are found in both
+ * the class Vector(adaptee) and the class Stack(target).
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: AdapterClass.java,v 1.2 2003/02/19 02:55:02 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class AdapterClass extends io.devnulllabs.openjava.mop.OJClass
+{
+
+ public static final java.lang.String KEY_ADAPTS = "adapts";
+
+ /* overrides for translation */
+ public void translateDefinition()
+ throws io.devnulllabs.openjava.mop.MOPException
+ {
+ io.devnulllabs.openjava.mop.OJClass target = getTarget();
+ io.devnulllabs.openjava.mop.OJClass adaptee = getAdaptee();
+ if (target == null || adaptee == null) {
+ return;
+ }
+ io.devnulllabs.openjava.mop.OJMethod[] adapteds = adaptee.getMethods( this );
+ for (int i = 0; i < adapteds.length; ++i) {
+ io.devnulllabs.openjava.mop.OJMethod m;
+ try {
+ m = getTarget().getMethod( adapteds[i].getName(), adapteds[i].getParameterTypes(), this );
+ } catch ( io.devnulllabs.openjava.mop.NoSuchMemberException e ) {
+ continue;
+ }
+ addMethod( makeForwardingMethod( m.getName(), m ) );
+ }
+ addInterface( getTarget() );
+ }
+
+ /**
+ * Generates a forwarding method with specified name.
+ *
+ * @param name generating method's name.
+ * @param forwarded method to which the generated method forwards.
+ * @return a generated forwarding method.
+ */
+ private io.devnulllabs.openjava.mop.OJMethod makeForwardingMethod( java.lang.String name, io.devnulllabs.openjava.mop.OJMethod forwarded )
+ throws io.devnulllabs.openjava.mop.MOPException
+ {
+ io.devnulllabs.openjava.mop.OJMethod result = new io.devnulllabs.openjava.mop.OJMethod( this, forwarded.getModifiers().remove( OJModifier.ABSTRACT ), forwarded.getReturnType(), name, forwarded.getParameterTypes(), forwarded.getExceptionTypes(), null );
+ io.devnulllabs.openjava.ptree.ExpressionList params = result.getParameterVariables();
+ io.devnulllabs.openjava.ptree.Expression expr = new io.devnulllabs.openjava.ptree.MethodCall( getContainer(), name, params );
+ io.devnulllabs.openjava.ptree.StatementList body = new io.devnulllabs.openjava.ptree.StatementList();
+ if (forwarded.getReturnType() == OJSystem.VOID) {
+ body.add( new io.devnulllabs.openjava.ptree.ExpressionStatement( expr ) );
+ body.add( new io.devnulllabs.openjava.ptree.ReturnStatement() );
+ } else {
+ body.add( new io.devnulllabs.openjava.ptree.ReturnStatement( expr ) );
+ }
+ result.setBody( body );
+ return result;
+ }
+
+ /* extended information */
+ private io.devnulllabs.openjava.mop.OJClass getAdaptee()
+ throws io.devnulllabs.openjava.mop.MOPException
+ {
+ io.devnulllabs.openjava.ptree.ObjectList suffix = (io.devnulllabs.openjava.ptree.ObjectList) getSuffix( KEY_ADAPTS );
+ return OJClass.forName( suffix.get( 0 ).toString() );
+ }
+
+ private io.devnulllabs.openjava.ptree.Variable getContainer()
+ throws io.devnulllabs.openjava.mop.MOPException
+ {
+ io.devnulllabs.openjava.ptree.ObjectList suffix = (io.devnulllabs.openjava.ptree.ObjectList) getSuffix( KEY_ADAPTS );
+ return new io.devnulllabs.openjava.ptree.Variable( suffix.get( 1 ).toString() );
+ }
+
+ private io.devnulllabs.openjava.mop.OJClass getTarget()
+ throws io.devnulllabs.openjava.mop.MOPException
+ {
+ io.devnulllabs.openjava.ptree.ObjectList suffix = (io.devnulllabs.openjava.ptree.ObjectList) getSuffix( KEY_ADAPTS );
+ return OJClass.forName( suffix.get( 2 ).toString() );
+ }
+
+ /* override to extend syntax */
+ public static boolean isRegisteredKeyword( java.lang.String keyword )
+ {
+ return keyword.equals( KEY_ADAPTS );
+ }
+
+ /* override to extend syntax */
+ public static io.devnulllabs.openjava.syntax.SyntaxRule getDeclSuffixRule( java.lang.String keyword )
+ {
+ if (keyword.equals( KEY_ADAPTS )) {
+ return new io.devnulllabs.openjava.syntax.CompositeRule( new io.devnulllabs.openjava.syntax.TypeNameRule(), new io.devnulllabs.openjava.syntax.PrepPhraseRule( "in", new io.devnulllabs.openjava.syntax.NameRule() ), new io.devnulllabs.openjava.syntax.PrepPhraseRule( "to", new io.devnulllabs.openjava.syntax.TypeNameRule() ) );
+ }
+ return null;
+ }
+
+ public AdapterClass( io.devnulllabs.openjava.mop.Environment oj_param0, io.devnulllabs.openjava.mop.OJClass oj_param1, io.devnulllabs.openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public AdapterClass( java.lang.Class oj_param0, io.devnulllabs.openjava3.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/adapter/AdapterClass.oj b/tutorial/examples/adapter/AdapterClass.oj
new file mode 100644
index 0000000..c0f9763
--- /dev/null
+++ b/tutorial/examples/adapter/AdapterClass.oj
@@ -0,0 +1,152 @@
+/*
+ * AdapterClass.oj
+ *
+ * An OpenJava example to support programming with the Adapter pattern.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.adapter;
+
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>AdapterClass</code> supports classes
+ * implementing an adapter role of the Adapter pattern.
+ * The target's methods with same signatures as the adaptee's are
+ * automatically implemented into the adapter class.
+ * <p>
+ * For example, the class <code>VectorStack</code>:
+ * <pre>
+ * public class VectorStack instantiates AdapterClass
+ * adapts Vector in v to Stack
+ * {
+ * Vector v;
+ * public VectorStack( Vector v ) {
+ * this.v = v;
+ * }
+ * public void push( Object o ) {
+ * v.addElement( o );
+ * }
+ * public Object pop() {
+ * return v.removeElementAt( v.size() - 1 );
+ * }
+ * }
+ * </pre>
+ * would be automatically implemented with the forwarding methods
+ * size(), isEmpty(), hashCode(), etc, which are found in both
+ * the class Vector(adaptee) and the class Stack(target).
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since %SOFTWARE% 1.0
+ * @see java.lang.Object
+ */
+public class AdapterClass instantiates Metaclass extends OJClass
+{
+
+ public static final String KEY_ADAPTS = "adapts";
+
+ /* overrides for translation */
+ public void translateDefinition() throws MOPException {
+ OJClass target = getTarget(), adaptee = getAdaptee();
+ if (target == null || adaptee == null) return;
+
+ /* implicit forwarding to the same signature's */
+ OJMethod[] adapteds = adaptee.getMethods( this );
+ for (int i = 0; i < adapteds.length; ++i) {
+ /* picks up the method with same signature */
+ OJMethod m;
+ try {
+ m = getTarget().getMethod( adapteds[i].getName(),
+ adapteds[i].getParameterTypes(),
+ this );
+ } catch ( NoSuchMemberException e ) { /* not match */ continue; }
+
+ /* generate a forwarding method with forwarded's name */
+ addMethod( makeForwardingMethod( m.getName(), m ) );
+ }
+
+ addInterface( getTarget() );
+ }
+
+ /**
+ * Generates a forwarding method with specified name.
+ *
+ * @param name generating method's name.
+ * @param forwarded method to which the generated method forwards.
+ * @return a generated forwarding method.
+ */
+ private OJMethod makeForwardingMethod( String name, OJMethod forwarded )
+ throws MOPException
+ {
+ /* generates a new method without body */
+ OJMethod result = new OJMethod(
+ this,
+ forwarded.getModifiers().remove( OJModifier.ABSTRACT ),
+ forwarded.getReturnType(),
+ name,
+ forwarded.getParameterTypes(),
+ forwarded.getExceptionTypes(),
+ null
+ );
+
+ /* generates a method call and return statement */
+ ExpressionList params = result.getParameterVariables();
+ Expression expr = new MethodCall( getContainer(), name, params );
+ StatementList body = new StatementList();
+ if (forwarded.getReturnType() == OJSystem.VOID) {
+ body.add( new ExpressionStatement( expr ) );
+ body.add( new ReturnStatement() );
+ } else {
+ body.add( new ReturnStatement( expr ) );
+ }
+
+ result.setBody( body );
+ return result;
+ }
+
+ /* extended information */
+
+ private OJClass getAdaptee() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_ADAPTS );
+ return OJClass.forName( suffix.get( 0 ).toString() );
+ }
+
+ private Variable getContainer() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_ADAPTS );
+ return new Variable( suffix.get( 1 ).toString() );
+ }
+
+ private OJClass getTarget() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_ADAPTS );
+ return OJClass.forName( suffix.get( 2 ).toString() );
+ }
+
+ /* override to extend syntax */
+ public static boolean isRegisteredKeyword( String keyword ) {
+ return keyword.equals( KEY_ADAPTS );
+ }
+
+ /* override to extend syntax */
+ public static SyntaxRule getDeclSuffixRule( String keyword ) {
+ if (keyword.equals( KEY_ADAPTS )) {
+ return new CompositeRule(
+ new TypeNameRule(),
+ new PrepPhraseRule( "in", new NameRule() ),
+ new PrepPhraseRule( "to", new TypeNameRule() ) );
+ }
+ return null;
+ }
+
+}
+
diff --git a/tutorial/examples/adapter/Stack.java b/tutorial/examples/adapter/Stack.java
new file mode 100644
index 0000000..37f4035
--- /dev/null
+++ b/tutorial/examples/adapter/Stack.java
@@ -0,0 +1,29 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.adapter;
+
+
+import java.util.Enumeration;
+
+
+public interface Stack
+{
+
+ public int size();
+
+ public boolean isEmpty();
+
+ public java.util.Enumeration elements();
+
+ public java.lang.Object[] toArray();
+
+ public int hashCode();
+
+ public void push( java.lang.Object o );
+
+ public java.lang.Object pop();
+
+ public java.lang.Object peek();
+
+}
diff --git a/tutorial/examples/adapter/Stack.oj b/tutorial/examples/adapter/Stack.oj
new file mode 100644
index 0000000..2ef6f27
--- /dev/null
+++ b/tutorial/examples/adapter/Stack.oj
@@ -0,0 +1,15 @@
+package examples.adapter;
+
+import java.util.Enumeration;
+
+public interface Stack
+{
+ public int size();
+ public boolean isEmpty();
+ public Enumeration elements();
+ public Object[] toArray();
+ public int hashCode();
+ public void push( Object o );
+ public Object pop();
+ public Object peek();
+}
diff --git a/tutorial/examples/adapter/VectorStack.java b/tutorial/examples/adapter/VectorStack.java
new file mode 100644
index 0000000..9f14a60
--- /dev/null
+++ b/tutorial/examples/adapter/VectorStack.java
@@ -0,0 +1,68 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.adapter;
+
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+
+public class VectorStack implements examples.adapter.Stack
+{
+
+ java.util.Vector v;
+
+ public VectorStack( java.util.Vector v )
+ {
+ this.v = v;
+ }
+
+ public void push( java.lang.Object o )
+ {
+ v.addElement( o );
+ }
+
+ public java.lang.Object pop()
+ {
+ java.lang.Object result = peek();
+ v.removeElementAt( v.size() - 1 );
+ return result;
+ }
+
+ public java.lang.Object peek()
+ {
+ return v.elementAt( v.size() - 1 );
+ }
+
+
+ public java.lang.Object[] toArray()
+ {
+ return v.toArray();
+ }
+
+
+ public int size()
+ {
+ return v.size();
+ }
+
+
+ public java.util.Enumeration elements()
+ {
+ return v.elements();
+ }
+
+
+ public boolean isEmpty()
+ {
+ return v.isEmpty();
+ }
+
+
+ public int hashCode()
+ {
+ return v.hashCode();
+ }
+
+}
diff --git a/tutorial/examples/adapter/VectorStack.oj b/tutorial/examples/adapter/VectorStack.oj
new file mode 100644
index 0000000..7306e98
--- /dev/null
+++ b/tutorial/examples/adapter/VectorStack.oj
@@ -0,0 +1,24 @@
+package examples.adapter;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+public class VectorStack instantiates AdapterClass
+ adapts Vector in v to examples.adapter.Stack
+{
+ Vector v;
+ public VectorStack( Vector v ) {
+ this.v = v;
+ }
+ public void push( Object o ) {
+ v.addElement( o );
+ }
+ public Object pop() {
+ Object result = peek();
+ v.removeElementAt( v.size() - 1 );
+ return result;
+ }
+ public Object peek() {
+ return v.elementAt( v.size() - 1 );
+ }
+}
diff --git a/tutorial/examples/autoimp/AutoImplementerClass.java b/tutorial/examples/autoimp/AutoImplementerClass.java
new file mode 100644
index 0000000..11f5040
--- /dev/null
+++ b/tutorial/examples/autoimp/AutoImplementerClass.java
@@ -0,0 +1,78 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * AutoImplementerClass.oj
+ *
+ * Apr 29, 1999, by Michiaki Tatsubori
+ * Feb 2, 1999, by Michiaki Tatsubori
+ */
+package examples.autoimp;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>AutoImprementerClass</code> provides classes
+ * with a facility automatically implementing null methods for
+ * not implemented methods.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @see openjava.mop.OJClass#translateDefinition()
+ * @see openjava.mop.OJClass#isRegisteredModifier()
+ */
+public class AutoImplementerClass extends OJClass
+{
+
+ public void translateDefinition()
+ throws MOPException
+ {
+ OJMethod[] methods = getInheritedMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (!methods[i].getModifiers().isAbstract() || hasDeclaredMethod( methods[i] )) {
+ continue;
+ }
+ addMethod( makeNullMethod( methods[i] ) );
+ }
+ }
+
+ private boolean hasDeclaredMethod( OJMethod m )
+ {
+ try {
+ getDeclaredMethod( m.getName(), m.getParameterTypes() );
+ return true;
+ } catch ( NoSuchMemberException e ) {
+ return false;
+ }
+ }
+
+ private OJMethod makeNullMethod( OJMethod m )
+ throws MOPException
+ {
+ OJMethod result = new OJMethod( this, m.getModifiers().remove( OJModifier.ABSTRACT ), m.getReturnType(), m.getName(), m.getParameterTypes(), m.getExceptionTypes(), null );
+ StatementList body = new StatementList();
+ if (m.getReturnType() == OJSystem.VOID) {
+ body.add( new ReturnStatement() );
+ } else {
+ body.add( new ReturnStatement( Literal.constantNull() ) );
+ }
+ result.setBody( body );
+ return result;
+ }
+
+ public AutoImplementerClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public AutoImplementerClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/autoimp/AutoImplementerClass.oj b/tutorial/examples/autoimp/AutoImplementerClass.oj
new file mode 100644
index 0000000..29ca2b2
--- /dev/null
+++ b/tutorial/examples/autoimp/AutoImplementerClass.oj
@@ -0,0 +1,64 @@
+/*
+ * AutoImplementerClass.oj
+ *
+ * Apr 29, 1999, by Michiaki Tatsubori
+ * Feb 2, 1999, by Michiaki Tatsubori
+ */
+package examples.autoimp;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>AutoImprementerClass</code> provides classes
+ * with a facility automatically implementing null methods for
+ * not implemented methods.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @see openjava.mop.OJClass#translateDefinition()
+ * @see openjava.mop.OJClass#isRegisteredModifier()
+ */
+public class AutoImplementerClass instantiates Metaclass extends OJClass
+{
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getInheritedMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (! methods[i].getModifiers().isAbstract()
+ || hasDeclaredMethod( methods[i] )) continue;
+ addMethod( makeNullMethod( methods[i] ) );
+ }
+ }
+
+ private boolean hasDeclaredMethod( OJMethod m ) {
+ try {
+ getDeclaredMethod( m.getName(), m.getParameterTypes() );
+ return true;
+ } catch ( NoSuchMemberException e ) {
+ return false;
+ }
+ }
+
+ private OJMethod makeNullMethod( OJMethod m ) throws MOPException {
+ /* generates a new method without body */
+ OJMethod result = new OJMethod( this,
+ m.getModifiers().remove( OJModifier.ABSTRACT ),
+ m.getReturnType(), m.getName(), m.getParameterTypes(),
+ m.getExceptionTypes(), null
+ );
+ /* generates a return statement */
+ StatementList body = new StatementList();
+ if (m.getReturnType() == OJSystem.VOID) {
+ body.add( new ReturnStatement() );
+ } else {
+ body.add( new ReturnStatement( Literal.constantNull() ) );
+ }
+ result.setBody( body );
+ return result;
+ }
+
+}
diff --git a/tutorial/examples/autoimp/InnerTest.java b/tutorial/examples/autoimp/InnerTest.java
new file mode 100644
index 0000000..f97f1d8
--- /dev/null
+++ b/tutorial/examples/autoimp/InnerTest.java
@@ -0,0 +1,29 @@
+/*
+ * This code was generated by ojc.
+ */
+/* quick implementation! */
+package examples.autoimp;
+
+
+import java.awt.event.*;
+
+
+public class InnerTest
+{
+
+ public static void main( String[] args )
+ {
+ WindowListener tmp = new MyWindowListener();
+ }
+
+ static class MyWindowListener implements WindowListener
+ {
+
+ public void windowClosed( WindowEvent e )
+ {
+ System.exit( 0 );
+ }
+
+ }
+
+}
diff --git a/tutorial/examples/autoimp/InnerTest.oj b/tutorial/examples/autoimp/InnerTest.oj
new file mode 100644
index 0000000..926ce48
--- /dev/null
+++ b/tutorial/examples/autoimp/InnerTest.oj
@@ -0,0 +1,15 @@
+/* quick implementation! */
+package examples.autoimp;
+import java.awt.event.*;
+public class InnerTest
+{
+ public static void main( String[] args ) {
+ WindowListener tmp = new MyWindowListener();
+ }
+
+ static class MyWindowListener instantiates AutoImplementerClass
+ implements WindowListener
+ {
+ public void windowClosed( WindowEvent e ) { System.exit( 0 ); }
+ }
+}
diff --git a/tutorial/examples/autoimp/Test.java b/tutorial/examples/autoimp/Test.java
new file mode 100644
index 0000000..6fa37b4
--- /dev/null
+++ b/tutorial/examples/autoimp/Test.java
@@ -0,0 +1,55 @@
+/*
+ * This code was generated by ojc.
+ */
+/* quick implementation! */
+package examples.autoimp;
+
+
+import java.awt.event.*;
+
+
+public class Test implements WindowListener
+{
+
+ public void windowClosed( WindowEvent e )
+ {
+ System.exit( 0 );
+ }
+
+
+ public void windowIconified( java.awt.event.WindowEvent oj_param0 )
+ {
+ return;
+ }
+
+
+ public void windowDeactivated( java.awt.event.WindowEvent oj_param0 )
+ {
+ return;
+ }
+
+
+ public void windowActivated( java.awt.event.WindowEvent oj_param0 )
+ {
+ return;
+ }
+
+
+ public void windowOpened( java.awt.event.WindowEvent oj_param0 )
+ {
+ return;
+ }
+
+
+ public void windowDeiconified( java.awt.event.WindowEvent oj_param0 )
+ {
+ return;
+ }
+
+
+ public void windowClosing( java.awt.event.WindowEvent oj_param0 )
+ {
+ return;
+ }
+
+}
diff --git a/tutorial/examples/autoimp/Test.oj b/tutorial/examples/autoimp/Test.oj
new file mode 100644
index 0000000..9f22972
--- /dev/null
+++ b/tutorial/examples/autoimp/Test.oj
@@ -0,0 +1,8 @@
+/* quick implementation! */
+package examples.autoimp;
+import java.awt.event.*;
+public class Test instantiates AutoImplementerClass
+ implements WindowListener
+{
+ public void windowClosed( WindowEvent e ) { System.exit( 0 ); }
+}
diff --git a/tutorial/examples/bca/AutoAdaptationClass.java b/tutorial/examples/bca/AutoAdaptationClass.java
new file mode 100644
index 0000000..5e088bc
--- /dev/null
+++ b/tutorial/examples/bca/AutoAdaptationClass.java
@@ -0,0 +1,53 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * AUtoAdaptationClass.oj
+ *
+ * Source Code Adaptation example.
+ * (Not real Binary Code Adaptation)
+ *
+ * Oct 29, 1999 by Michiaki Tatsubori
+ */
+package examples.bca;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The class <code>RTReflClass</code> patches the class
+ * implementing <code>Writable</code> to implement <code>Printable</code>.
+ */
+public class AutoAdaptationClass extends OJClass
+{
+
+ /** Overrides to translate definition */
+ public void translateDefinition()
+ throws MOPException
+ {
+ if (!openjava.mop.OJClass.forClass( Writable.class ).isAssignableFrom( this )) {
+ return;
+ }
+ OJClass newface = openjava.mop.OJClass.forClass( Printable.class );
+ addInterface( newface );
+ OJMethod facemtd = newface.getMethod( "print", new OJClass[0] );
+ OJMethod impmtd = new OJMethod( this, facemtd.getModifiers().remove( OJModifier.ABSTRACT ), facemtd.getReturnType(), facemtd.getName(), facemtd.getParameterTypes(), facemtd.getExceptionTypes(), null );
+ addMethod( impmtd );
+ StatementList body = makeStatementList( "this.write(java.lang.System.out);" );
+ impmtd.setBody( body );
+ }
+
+ public AutoAdaptationClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public AutoAdaptationClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/bca/AutoAdaptationClass.oj b/tutorial/examples/bca/AutoAdaptationClass.oj
new file mode 100644
index 0000000..9819bc2
--- /dev/null
+++ b/tutorial/examples/bca/AutoAdaptationClass.oj
@@ -0,0 +1,48 @@
+/*
+ * AUtoAdaptationClass.oj
+ *
+ * Source Code Adaptation example.
+ * (Not real Binary Code Adaptation)
+ *
+ * Oct 29, 1999 by Michiaki Tatsubori
+ */
+package examples.bca;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The class <code>RTReflClass</code> patches the class
+ * implementing <code>Writable</code> to implement <code>Printable</code>.
+ */
+public class AutoAdaptationClass instantiates Metaclass extends OJClass
+{
+ /** Overrides to translate definition */
+ public convenient void translateDefinition() throws MOPException {
+ /* only the case this class implements Writable */
+ if (! Writable.class.isAssignableFrom( this )) return;
+
+ OJClass newface = Printable.class;
+
+ addInterface( newface );
+
+ OJMethod facemtd = newface.getMethod( "print", new OJClass[0] );
+
+ OJMethod impmtd = new OJMethod( this,
+ facemtd.getModifiers().remove( OJModifier.ABSTRACT ),
+ facemtd.getReturnType(),
+ facemtd.getName(), facemtd.getParameterTypes(),
+ facemtd.getExceptionTypes(),
+ null
+ );
+ addMethod( impmtd );
+
+ StatementList body = makeStatementList(
+ "this.write(java.lang.System.out);"
+ );
+ impmtd.setBody( body );
+ }
+}
diff --git a/tutorial/examples/bca/Printable.java b/tutorial/examples/bca/Printable.java
new file mode 100644
index 0000000..296850e
--- /dev/null
+++ b/tutorial/examples/bca/Printable.java
@@ -0,0 +1,7 @@
+package examples.bca;
+
+
+public interface Printable
+{
+ public void print();
+}
diff --git a/tutorial/examples/bca/RTReflClass.java b/tutorial/examples/bca/RTReflClass.java
new file mode 100644
index 0000000..429b241
--- /dev/null
+++ b/tutorial/examples/bca/RTReflClass.java
@@ -0,0 +1,51 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * RTReflClass.oj
+ *
+ * Source Code Adaptation example.
+ *
+ * Oct 29, 1999 by Michiaki Tatsubori
+ */
+package examples.bca;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The class <code>RTReflClass</code> patches the class
+ * implementing <code>Writable</code> to implement <code>Printable</code>.
+ */
+public class RTReflClass extends OJClass
+{
+
+ /** Overrides to translate definition */
+ public void translateDefinition()
+ throws MOPException
+ {
+ if (!openjava.mop.OJClass.forClass( Writable.class ).isAssignableFrom( this )) {
+ return;
+ }
+ addInterface( openjava.mop.OJClass.forClass( Printable.class ) );
+ OJMethod facemtd = getMethod( "write", new OJClass[]{ openjava.mop.OJClass.forClass( java.io.PrintStream.class ) } );
+ OJMethod impmtd = new OJMethod( this, facemtd.getModifiers(), facemtd.getReturnType(), facemtd.getName(), facemtd.getParameterTypes(), facemtd.getExceptionTypes(), null );
+ addMethod( impmtd );
+ StatementList body = makeStatementList( "this.write(java.lang.System.out);" );
+ impmtd.setBody( body );
+ }
+
+ public RTReflClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public RTReflClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/bca/Test.java b/tutorial/examples/bca/Test.java
new file mode 100644
index 0000000..5de77d0
--- /dev/null
+++ b/tutorial/examples/bca/Test.java
@@ -0,0 +1,24 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.bca;
+
+
+import java.io.PrintStream;
+
+
+public class Test implements examples.bca.Writable, examples.bca.Printable
+{
+
+ public void write( PrintStream out )
+ {
+ out.println( "Hello" );
+ }
+
+
+ public void print()
+ {
+ this.write( java.lang.System.out );
+ }
+
+}
diff --git a/tutorial/examples/bca/Test.oj b/tutorial/examples/bca/Test.oj
new file mode 100644
index 0000000..2514028
--- /dev/null
+++ b/tutorial/examples/bca/Test.oj
@@ -0,0 +1,13 @@
+package examples.bca;
+
+
+import java.io.PrintStream;
+
+
+public class Test instantiates AutoAdaptationClass
+ implements Writable
+{
+ public void write(PrintStream out) {
+ out.println( "Hello" );
+ }
+}
diff --git a/tutorial/examples/bca/Test2.java b/tutorial/examples/bca/Test2.java
new file mode 100644
index 0000000..013c360
--- /dev/null
+++ b/tutorial/examples/bca/Test2.java
@@ -0,0 +1,18 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.bca;
+
+
+import java.io.PrintStream;
+
+
+public class Test2
+{
+
+ public void write( PrintStream out )
+ {
+ out.println( "Hello" );
+ }
+
+}
diff --git a/tutorial/examples/bca/Test2.oj b/tutorial/examples/bca/Test2.oj
new file mode 100644
index 0000000..ca72a4c
--- /dev/null
+++ b/tutorial/examples/bca/Test2.oj
@@ -0,0 +1,12 @@
+package examples.bca;
+
+
+import java.io.PrintStream;
+
+
+public class Test2 instantiates AutoAdaptationClass
+{
+ public void write(PrintStream out) {
+ out.println( "Hello" );
+ }
+}
diff --git a/tutorial/examples/bca/Writable.java b/tutorial/examples/bca/Writable.java
new file mode 100644
index 0000000..f8df297
--- /dev/null
+++ b/tutorial/examples/bca/Writable.java
@@ -0,0 +1,10 @@
+package examples.bca;
+
+
+import java.io.PrintStream;
+
+
+public interface Writable
+{
+ public void write(PrintStream out);
+}
diff --git a/tutorial/examples/capsule/CapsuleClass.oj b/tutorial/examples/capsule/CapsuleClass.oj
new file mode 100644
index 0000000..9d54fe3
--- /dev/null
+++ b/tutorial/examples/capsule/CapsuleClass.oj
@@ -0,0 +1,130 @@
+/*
+ * CapsuleClass.oj
+ *
+ * Apr 23, 1999 by Michiaki Tatsubori
+ */
+package examples.capsule;
+
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The class <code>CapsuleClass</code> is a metaclass which
+ * hides all the fields in the class and provides reader and writer
+ * methods corresponding to each field. Furthermore, accesses
+ * to fields of the class is to be replaced with these methods.
+ */
+public class CapsuleClass instantiates Metaclass extends OJClass
+{
+ /** Overrides to translate definition */
+ public void translateDefinition() throws MOPException {
+ /* Detect public fields in superclass */
+ OJField[] inherited_flds = getSuperclass().getFields();
+ if (inherited_flds.length > 0) {
+ System.err.println( "WARNING: Leak Possibilities" );
+ for (int i = 0; i < inherited_flds.length; ++i)
+ System.err.println( inherited_flds[i].toString() );
+ }
+
+ /* Get all declared fields and hide it */
+ OJField[] fields = getDeclaredFields();
+ for (int i = 0; i < fields.length; ++i) {
+ OJModifier modif = fields[i].getModifiers();
+ if (! modif.isPrivate()) hideField( fields[i] );
+ }
+ }
+
+ private void hideField( OJField field ) throws MOPException {
+ System.err.println( "Hiding a field : " + field.toString() );
+ generateReaderMethod( field );
+ generateWriterMethod( field );
+ field.setModifiers( field.getModifiers().setPrivate() );
+ }
+
+ private void generateReaderMethod( OJField field ) throws MOPException {
+ StatementList body = makeStatementList(
+ "return " + field.getName() + ";"
+ );
+ OJMethod reader = new OJMethod( this,
+ field.getModifiers(), field.getType(),
+ fieldReaderName( field.getName() ),
+ (OJClass[]) null, null, body
+ );
+ addMethod( reader );
+ }
+
+ private void generateWriterMethod( OJField field ) throws MOPException {
+ OJMethod writer = new OJMethod( this,
+ field.getModifiers(), field.getType(),
+ fieldWriterName( field.getName() ),
+ new OJClass[]{ field.getType() }, null, null
+ );
+ String param = writer.getParameters()[0];
+ StatementList body = makeStatementList( writer.getEnvironment(),
+ "return " + field.getName() + "=" + param + ";"
+ );
+ writer.setBody( body );
+ addMethod( writer );
+ }
+
+ private static final String fieldReaderName( String name ) {
+ return "read_" + name;
+ }
+
+ private static final String fieldWriterName( String name ) {
+ return "write_" + name;
+ }
+
+ /* overrides */
+
+ /** Allows references to private fields */
+ public OJField resolveException( NoSuchMemberException e, String name )
+ throws NoSuchMemberException
+ {
+ try {
+ return getDeclaredField( name );
+ } catch ( NoSuchMemberException e2 ) {}
+ return super.resolveException( e, name );
+ }
+
+ /** Overrides to expand fields to be read */
+ public Expression expandFieldRead(
+ Environment env,
+ FieldAccess expr )
+ {
+ Expression ref = expr.getReferenceExpr();
+ String name = fieldReaderName( expr.getName() );
+ Expression result;
+ if (ref != null) {
+ result = new MethodCall( ref, name, null );
+ } else {
+ result = new MethodCall( expr.getReferenceType(), name, null );
+ }
+ System.err.println( "Patch FR : " + expr + "\tto\t" + result );
+ return result;
+ }
+
+ /** Overrides to expand fields to be written */
+ public Expression expandFieldWrite(
+ Environment env,
+ AssignmentExpression expr )
+ {
+ FieldAccess fldac = (FieldAccess) expr.getLeft();
+ ExpressionList args = new ExpressionList( expr.getRight() );
+ Expression ref = fldac.getReferenceExpr();
+ String name = fieldWriterName( fldac.getName() );
+ Expression result;
+ if (ref != null) {
+ result = new MethodCall( ref, name, args );
+ } else {
+ result = new MethodCall( fldac.getReferenceType(), name, args );
+ }
+ System.err.println( "Patch FW : " + expr + "\tto\t" + result );
+ return result;
+ }
+
+}
diff --git a/tutorial/examples/capsule/Point.oj b/tutorial/examples/capsule/Point.oj
new file mode 100644
index 0000000..a74f566
--- /dev/null
+++ b/tutorial/examples/capsule/Point.oj
@@ -0,0 +1,22 @@
+/*
+ * Point.oj
+ */
+package examples.capsule;
+
+
+public class Point instantiates CapsuleClass
+{
+ public int x, y;
+ protected String name;
+
+ public Point( String name, int x, int y ) {
+ this.x = x;
+ this.y = y;
+ this.name = name;
+ }
+
+ public Point( int x, int y ) {
+ this( "DefaultName", x, y );
+ }
+
+}
diff --git a/tutorial/examples/capsule/PointUser.oj b/tutorial/examples/capsule/PointUser.oj
new file mode 100644
index 0000000..f81a335
--- /dev/null
+++ b/tutorial/examples/capsule/PointUser.oj
@@ -0,0 +1,17 @@
+/*
+ * PointUser.oj
+ */
+package examples.capsule;
+
+
+public class PointUser
+{
+
+ public static void main( String[] args ) {
+ Point p = new Point( 1, 2 );
+ p.name = "MyFavorite";
+ int x = p.x + 1;
+ p.y = x * 2 + p.y;
+ }
+
+}
diff --git a/tutorial/examples/capsule/Test.oj b/tutorial/examples/capsule/Test.oj
new file mode 100644
index 0000000..4b25816
--- /dev/null
+++ b/tutorial/examples/capsule/Test.oj
@@ -0,0 +1,47 @@
+package examples.capsule;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test instantiates CapsuleClass
+{
+ private int iii = 0;
+
+ protected Test n = null;
+
+ public String str = "string";
+
+ public static String NAME = "Test";
+
+ public Test() {
+ super();
+ }
+
+ public static void main( String[] argv ) {
+ PrintStream out = System.out;
+ PrintStream error = java.lang.System.err;
+ out.println( "Hello" + " " + "World" );
+ Test n = new Test();
+ java.lang.System.err.println( "done. " );
+ Test test = new Test();
+ test.foo();
+ }
+
+ public Test( String str ) {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo() {
+ return iii;
+ }
+
+ public String toString() {
+ if (n == null) return str;
+ return str + n;
+ }
+
+}
diff --git a/tutorial/examples/capsule/TestUser.oj b/tutorial/examples/capsule/TestUser.oj
new file mode 100644
index 0000000..1aa85b6
--- /dev/null
+++ b/tutorial/examples/capsule/TestUser.oj
@@ -0,0 +1,38 @@
+package examples.capsule;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class TestUser
+{
+ Test test;
+
+ public static void main( String[] argv ) {
+ TestUser user = new TestUser();
+ Test test = new Test();
+ System.out.println( test.str.toString() );
+ System.out.println( test.n.toString() );
+ test.foo();
+ }
+
+ private TestUser() {
+ this.test = new Test();
+ }
+
+ public void run() {
+ test.n = test;
+ java.lang.System.out.println( test.n = test );
+ System.out.println( (test.n = test).toString() );
+ }
+
+ public void print() {
+ System.out.println( test.n.str );
+ String s = ((String) Test.NAME).toString();
+ String sa = Test.NAME + "_ALPHA";
+ String ss = (Test.NAME).toString();
+ return;
+ }
+}
diff --git a/tutorial/examples/capsule/TestUser2.oj b/tutorial/examples/capsule/TestUser2.oj
new file mode 100644
index 0000000..931f279
--- /dev/null
+++ b/tutorial/examples/capsule/TestUser2.oj
@@ -0,0 +1,8 @@
+package examples.capsule;
+
+public class TestUser2
+{
+ public static void main( String[] argv ) {
+ Test.NAME.toString();
+ }
+}
diff --git a/tutorial/examples/copy/CopiedClass.java b/tutorial/examples/copy/CopiedClass.java
new file mode 100644
index 0000000..e709187
--- /dev/null
+++ b/tutorial/examples/copy/CopiedClass.java
@@ -0,0 +1,43 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * CopiedClass.oj
+ *
+ * @author Michiaki Tatsubori
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.copy;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+import openjava.ptree.util.TypeNameQualifier;
+
+
+public class CopiedClass extends OJClass
+{
+
+ /* overrides for translation */
+ public void translateDefinition()
+ throws MOPException
+ {
+ String newqname = getName() + "Shadow";
+ OJClass shadow = makeCopy( newqname );
+ OJSystem.addNewClass( shadow );
+ }
+
+ public CopiedClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public CopiedClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/copy/CopiedClass.oj b/tutorial/examples/copy/CopiedClass.oj
new file mode 100644
index 0000000..7799f59
--- /dev/null
+++ b/tutorial/examples/copy/CopiedClass.oj
@@ -0,0 +1,37 @@
+/*
+ * CopiedClass.oj
+ *
+ * @author Michiaki Tatsubori
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.copy;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+import openjava.ptree.util.TypeNameQualifier;
+
+
+public class CopiedClass instantiates Metaclass extends OJClass
+{
+ /* overrides for translation */
+ public convenient void translateDefinition() throws MOPException {
+ String newqname = getName() + "Shadow";
+ OJClass shadow = makeCopy( newqname );
+ /***
+ ClassDeclaration org = getSourceCode();
+ ClassDeclaration copy = (ClassDeclaration) org.makeRecursiveCopy();
+ String pack = Environment.toPackageName( newqname );
+ String sname = Environment.toSimpleName( newqname );
+ copy.setName( sname );
+ copy.accept( new TypeNameQualifier( getEnvironment(), sname ) );
+ FileEnvironment env = new FileEnvironment( OJSystem.env, pack, sname );
+ OJClass shadow = new OJClass( env, null, copy );
+ ***/
+ OJSystem.addNewClass( shadow );
+ }
+
+}
diff --git a/tutorial/examples/copy/Test.java b/tutorial/examples/copy/Test.java
new file mode 100644
index 0000000..2a37ecf
--- /dev/null
+++ b/tutorial/examples/copy/Test.java
@@ -0,0 +1,62 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.copy;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test extends Panel
+{
+
+ private int iii = 0;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ public Test()
+ {
+ 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" );
+ Test n = new Test();
+ java.lang.System.err.println( "done. " );
+ Test test = new Test();
+ test.foo();
+ }
+
+ public Test( String str )
+ {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo()
+ {
+ return iii;
+ }
+
+ public String toString()
+ {
+ if (n == null) {
+ return str;
+ }
+ return str + n;
+ }
+
+}
diff --git a/tutorial/examples/copy/Test.oj b/tutorial/examples/copy/Test.oj
new file mode 100644
index 0000000..f0db01d
--- /dev/null
+++ b/tutorial/examples/copy/Test.oj
@@ -0,0 +1,52 @@
+package examples.copy;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test instantiates CopiedClass
+ extends Panel
+{
+ private int iii = 0;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ public Test() {
+ 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" );
+ Test n = new Test();
+ java.lang.System.err.println( "done. " );
+ Test test = new Test();
+ test.foo();
+ }
+
+ public Test( String str ) {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo() {
+ return iii;
+ }
+
+ public String toString() {
+ if (n == null) return str;
+ return str + n;
+ }
+
+}
diff --git a/tutorial/examples/copy/TestShadow.java b/tutorial/examples/copy/TestShadow.java
new file mode 100644
index 0000000..dc07b66
--- /dev/null
+++ b/tutorial/examples/copy/TestShadow.java
@@ -0,0 +1,58 @@
+/*
+ * This code was generated by ojc.
+ */
+
+package examples.copy;
+
+
+public class TestShadow extends java.awt.Panel
+{
+
+ private int iii = 0;
+
+ private examples.copy.Test n = null;
+
+ private java.lang.String str = "string";
+
+ public TestShadow()
+ {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main( java.lang.String[] argv )
+ {
+ java.io.PrintStream out = java.lang.System.out;
+ java.io.PrintStream error = java.lang.System.err;
+ out.println( "Hello" + " " + "World" );
+ examples.copy.Test n = new examples.copy.Test();
+ java.lang.System.err.println( "done. " );
+ examples.copy.Test test = new examples.copy.Test();
+ test.foo();
+ }
+
+ public TestShadow( java.lang.String str )
+ {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo()
+ {
+ return iii;
+ }
+
+ public java.lang.String toString()
+ {
+ if (n == null) {
+ return str;
+ }
+ return str + n;
+ }
+
+}
diff --git a/tutorial/examples/decorator/0UNDERCONSTRUCTION b/tutorial/examples/decorator/0UNDERCONSTRUCTION
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tutorial/examples/decorator/0UNDERCONSTRUCTION
diff --git a/tutorial/examples/decorator/AdapterClass.oj b/tutorial/examples/decorator/AdapterClass.oj
new file mode 100644
index 0000000..c0f9763
--- /dev/null
+++ b/tutorial/examples/decorator/AdapterClass.oj
@@ -0,0 +1,152 @@
+/*
+ * AdapterClass.oj
+ *
+ * An OpenJava example to support programming with the Adapter pattern.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.adapter;
+
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>AdapterClass</code> supports classes
+ * implementing an adapter role of the Adapter pattern.
+ * The target's methods with same signatures as the adaptee's are
+ * automatically implemented into the adapter class.
+ * <p>
+ * For example, the class <code>VectorStack</code>:
+ * <pre>
+ * public class VectorStack instantiates AdapterClass
+ * adapts Vector in v to Stack
+ * {
+ * Vector v;
+ * public VectorStack( Vector v ) {
+ * this.v = v;
+ * }
+ * public void push( Object o ) {
+ * v.addElement( o );
+ * }
+ * public Object pop() {
+ * return v.removeElementAt( v.size() - 1 );
+ * }
+ * }
+ * </pre>
+ * would be automatically implemented with the forwarding methods
+ * size(), isEmpty(), hashCode(), etc, which are found in both
+ * the class Vector(adaptee) and the class Stack(target).
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since %SOFTWARE% 1.0
+ * @see java.lang.Object
+ */
+public class AdapterClass instantiates Metaclass extends OJClass
+{
+
+ public static final String KEY_ADAPTS = "adapts";
+
+ /* overrides for translation */
+ public void translateDefinition() throws MOPException {
+ OJClass target = getTarget(), adaptee = getAdaptee();
+ if (target == null || adaptee == null) return;
+
+ /* implicit forwarding to the same signature's */
+ OJMethod[] adapteds = adaptee.getMethods( this );
+ for (int i = 0; i < adapteds.length; ++i) {
+ /* picks up the method with same signature */
+ OJMethod m;
+ try {
+ m = getTarget().getMethod( adapteds[i].getName(),
+ adapteds[i].getParameterTypes(),
+ this );
+ } catch ( NoSuchMemberException e ) { /* not match */ continue; }
+
+ /* generate a forwarding method with forwarded's name */
+ addMethod( makeForwardingMethod( m.getName(), m ) );
+ }
+
+ addInterface( getTarget() );
+ }
+
+ /**
+ * Generates a forwarding method with specified name.
+ *
+ * @param name generating method's name.
+ * @param forwarded method to which the generated method forwards.
+ * @return a generated forwarding method.
+ */
+ private OJMethod makeForwardingMethod( String name, OJMethod forwarded )
+ throws MOPException
+ {
+ /* generates a new method without body */
+ OJMethod result = new OJMethod(
+ this,
+ forwarded.getModifiers().remove( OJModifier.ABSTRACT ),
+ forwarded.getReturnType(),
+ name,
+ forwarded.getParameterTypes(),
+ forwarded.getExceptionTypes(),
+ null
+ );
+
+ /* generates a method call and return statement */
+ ExpressionList params = result.getParameterVariables();
+ Expression expr = new MethodCall( getContainer(), name, params );
+ StatementList body = new StatementList();
+ if (forwarded.getReturnType() == OJSystem.VOID) {
+ body.add( new ExpressionStatement( expr ) );
+ body.add( new ReturnStatement() );
+ } else {
+ body.add( new ReturnStatement( expr ) );
+ }
+
+ result.setBody( body );
+ return result;
+ }
+
+ /* extended information */
+
+ private OJClass getAdaptee() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_ADAPTS );
+ return OJClass.forName( suffix.get( 0 ).toString() );
+ }
+
+ private Variable getContainer() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_ADAPTS );
+ return new Variable( suffix.get( 1 ).toString() );
+ }
+
+ private OJClass getTarget() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_ADAPTS );
+ return OJClass.forName( suffix.get( 2 ).toString() );
+ }
+
+ /* override to extend syntax */
+ public static boolean isRegisteredKeyword( String keyword ) {
+ return keyword.equals( KEY_ADAPTS );
+ }
+
+ /* override to extend syntax */
+ public static SyntaxRule getDeclSuffixRule( String keyword ) {
+ if (keyword.equals( KEY_ADAPTS )) {
+ return new CompositeRule(
+ new TypeNameRule(),
+ new PrepPhraseRule( "in", new NameRule() ),
+ new PrepPhraseRule( "to", new TypeNameRule() ) );
+ }
+ return null;
+ }
+
+}
+
diff --git a/tutorial/examples/decorator/ReturnSpecifier.java b/tutorial/examples/decorator/ReturnSpecifier.java
new file mode 100644
index 0000000..031958b
--- /dev/null
+++ b/tutorial/examples/decorator/ReturnSpecifier.java
@@ -0,0 +1,67 @@
+package examples.decorator;
+
+
+import java.io.Writer;
+import java.io.IOException;
+
+
+/*
+ * Here assumes there's no implementation in Writer
+ * like 'implements Writer'
+ */
+public class ReturnSpecifier
+ extends Writer
+{
+ private static final char[] mark = { ' ', '<' };
+
+ private Writer out;
+
+ public ReturnSpecifier(Writer out) {
+ this.out = out;
+ }
+
+ public void write(char cbuf[], int off, int len)
+ throws IOException
+ {
+ int done = off;
+ for (int i = done; i < off + len; ++i) {
+ if (cbuf[i] == Character.LINE_SEPARATOR
+ || cbuf[i] == '\n')
+ {
+ out.write(cbuf, done, i - done);
+ // print a mark for carriage return
+ out.write(mark, 0, mark.length);
+ // print a carriage return
+ out.write(cbuf, i, 1);
+ done = i + 1;
+ }
+ }
+ out.write(cbuf, done, off + len - done);
+ }
+
+ public void close() throws IOException {
+ out.close();
+ }
+
+ public void flush() throws IOException {
+ out.flush();
+ }
+
+/*****
+ public void write(char[] cbuf) throws IOException {
+ out.write(cbuf);
+ }
+
+ public void write(int c) throws IOException {
+ out.write(c);
+ }
+
+ public void write(String str) throws IOException {
+ out.write(str);
+ }
+
+ public void write(String str, int off, int len) throws IOException {
+ out.write(str, off, len);
+ }
+*****/
+}
diff --git a/tutorial/examples/decorator/ReturnSpecifier.oj b/tutorial/examples/decorator/ReturnSpecifier.oj
new file mode 100644
index 0000000..e1e4f73
--- /dev/null
+++ b/tutorial/examples/decorator/ReturnSpecifier.oj
@@ -0,0 +1,39 @@
+package exampls.decorator;
+
+
+import java.io.Writer;
+import java.io.IOException;
+
+
+public class ReturnSpecifier instantiates DecoratorClass
+ decorates Writer in out
+{
+ private static final char[] mark = { '\\', '<' };
+
+ private Writer out;
+
+ public ReturnSpecifier(Writer out) {
+ this.out = out;
+ }
+
+ public void write(char cbuf[], int off, int len)
+ throws IOException
+ {
+ int done = off;
+ for (int i = done; i < off + len; ++i) {
+ if (cbuf[i] == Character.LINE_SEPARATOR
+ || cbuf[i] == '\n')
+ {
+ out.write(cbuf, done, i - done);
+ // print a mark for carriage return
+ out.write(mark, 0, mark.length);
+ // print a carriage return
+ out.write(cbuf, i, 1);
+ done = i + 1;
+ }
+ }
+ out.write(cbuf, done, off + len - done);
+ }
+
+
+}
diff --git a/tutorial/examples/decorator/Test.java b/tutorial/examples/decorator/Test.java
new file mode 100644
index 0000000..9f7b450
--- /dev/null
+++ b/tutorial/examples/decorator/Test.java
@@ -0,0 +1,21 @@
+package examples.decorator;
+
+
+import java.io.Writer;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+
+
+public class Test
+{
+ public static void main(String[] args) {
+ Writer baseout
+ = new ReturnSpecifier(new OutputStreamWriter(System.out));
+ PrintWriter out = new PrintWriter(baseout);
+ out.println( "Hi there." );
+ out.println( "This is a test." );
+ out.println( "Thank you." );
+ out.flush();
+ }
+
+}
diff --git a/tutorial/examples/decorator/Test.oj b/tutorial/examples/decorator/Test.oj
new file mode 100644
index 0000000..3989a56
--- /dev/null
+++ b/tutorial/examples/decorator/Test.oj
@@ -0,0 +1,21 @@
+package examples.decorator;
+
+
+import java.io.Writer;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+
+
+public class Test
+{
+ public static void main(String[] args) {
+ Writer baseout
+ = new ReturnSpecifier(System.out) decorates OutputStreamWriter;
+ PrintWriter out = new PrintWriter(baseout);
+ out.println( "Hi there." );
+ out.println( "This is a test." );
+ out.println( "Thank you." );
+ out.flush();
+ }
+
+}
diff --git a/tutorial/examples/facemake/FaceProvidedClass.java b/tutorial/examples/facemake/FaceProvidedClass.java
new file mode 100644
index 0000000..e2d15df
--- /dev/null
+++ b/tutorial/examples/facemake/FaceProvidedClass.java
@@ -0,0 +1,76 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * FaceProvidedClass.oj
+ *
+ * @author Michiaki Tatsubori
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.facemake;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+public class FaceProvidedClass extends OJClass
+{
+
+ /* overrides for translation */
+ public void translateDefinition()
+ throws MOPException
+ {
+ OJMethod[] methods = getMethods();
+ String fname = getName() + "Face";
+ FaceProvidedClass face = createEmptyInterface( fname );
+ OJSystem.addNewClass( face );
+ for (int i = 0; i < methods.length; ++i) {
+ OJMethod fmtd = OJMethod.makePrototype( methods[i] );
+ OJModifier modif = fmtd.getModifiers();
+ if (modif.isStatic()) {
+ continue;
+ }
+ if (isMethodOfObject( methods[i] )) {
+ continue;
+ }
+ fmtd.setModifiers( OJModifier.PUBLIC );
+ face.addMethod( fmtd );
+ }
+ addInterface( face );
+ }
+
+ public static FaceProvidedClass createEmptyInterface( String qname )
+ {
+ String pack = Environment.toPackageName( qname );
+ String sname = Environment.toSimpleName( qname );
+ ClassDeclaration cd = new ClassDeclaration( new ModifierList( ModifierList.PUBLIC ), sname, new TypeName[0], new TypeName[0], new MemberDeclarationList(), false );
+ FileEnvironment env = new FileEnvironment( OJSystem.env, pack, sname );
+ return new FaceProvidedClass( env, null, cd );
+ }
+
+ public static boolean isMethodOfObject( OJMethod m )
+ {
+ try {
+ OJClass clazz = OJSystem.OBJECT;
+ clazz.getMethod( m.getName(), m.getParameterTypes(), clazz );
+ return true;
+ } catch ( NoSuchMemberException ex ) {
+ return false;
+ }
+ }
+
+ public FaceProvidedClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public FaceProvidedClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/facemake/FaceProvidedClass.oj b/tutorial/examples/facemake/FaceProvidedClass.oj
new file mode 100644
index 0000000..8d0857f
--- /dev/null
+++ b/tutorial/examples/facemake/FaceProvidedClass.oj
@@ -0,0 +1,57 @@
+/*
+ * FaceProvidedClass.oj
+ *
+ * @author Michiaki Tatsubori
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.facemake;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+public class FaceProvidedClass instantiates Metaclass extends OJClass
+{
+ /* overrides for translation */
+ public convenient void translateDefinition() throws MOPException {
+ OJMethod[] methods = getMethods();
+ String fname = getName() + "Face";
+ FaceProvidedClass face = createEmptyInterface(fname);
+ OJSystem.addNewClass(face);
+ for (int i = 0; i < methods.length; ++i) {
+ OJMethod fmtd = OJMethod.makePrototype(methods[i]);
+ OJModifier modif = fmtd.getModifiers();
+ if (modif.isStatic()) continue; /* non-static only */
+ if (isMethodOfObject(methods[i])) continue;
+ fmtd.setModifiers( OJModifier.PUBLIC );
+ face.addMethod(fmtd);
+ }
+ addInterface(face);
+ }
+
+ public static FaceProvidedClass createEmptyInterface(String qname) {
+ String pack = Environment.toPackageName(qname);
+ String sname = Environment.toSimpleName(qname);
+ ClassDeclaration cd
+ = new ClassDeclaration(new ModifierList(ModifierList.PUBLIC),
+ sname, new TypeName[0], new TypeName[0],
+ new MemberDeclarationList(), false );
+ FileEnvironment env = new FileEnvironment(OJSystem.env, pack, sname);
+ return new FaceProvidedClass(env, null, cd);
+ }
+
+ public static boolean isMethodOfObject(OJMethod m) {
+ try {
+ OJClass clazz = OJSystem.OBJECT;
+ clazz.getMethod(m.getName(), m.getParameterTypes(), clazz);
+ return true;
+ } catch (NoSuchMemberException ex) {
+ return false;
+ }
+ }
+
+}
diff --git a/tutorial/examples/facemake/Test.java b/tutorial/examples/facemake/Test.java
new file mode 100644
index 0000000..96f738d
--- /dev/null
+++ b/tutorial/examples/facemake/Test.java
@@ -0,0 +1,62 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.facemake;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test extends Panel implements examples.facemake.TestFace
+{
+
+ private int iii = 0;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ public Test()
+ {
+ 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" );
+ Test n = new Test();
+ java.lang.System.err.println( "done. " );
+ Test test = new Test();
+ test.foo();
+ }
+
+ public Test( String str )
+ {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo()
+ {
+ return iii;
+ }
+
+ public String toString()
+ {
+ if (n == null) {
+ return str;
+ }
+ return str + n;
+ }
+
+}
diff --git a/tutorial/examples/facemake/Test.oj b/tutorial/examples/facemake/Test.oj
new file mode 100644
index 0000000..03f7dbe
--- /dev/null
+++ b/tutorial/examples/facemake/Test.oj
@@ -0,0 +1,52 @@
+package examples.facemake;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test instantiates FaceProvidedClass
+ extends Panel
+{
+ private int iii = 0;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ public Test() {
+ 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" );
+ Test n = new Test();
+ java.lang.System.err.println( "done. " );
+ Test test = new Test();
+ test.foo();
+ }
+
+ public Test( String str ) {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo() {
+ return iii;
+ }
+
+ public String toString() {
+ if (n == null) return str;
+ return str + n;
+ }
+
+}
diff --git a/tutorial/examples/facemake/TestFace.java b/tutorial/examples/facemake/TestFace.java
new file mode 100644
index 0000000..878d91d
--- /dev/null
+++ b/tutorial/examples/facemake/TestFace.java
@@ -0,0 +1,516 @@
+/*
+ * This code was generated by ojc.
+ */
+
+package examples.facemake;
+
+
+
+public interface TestFace
+{
+
+
+ public void print( java.awt.Graphics oj_param0 );
+
+
+ public void layout();
+
+
+ public void setLocation( java.awt.Point oj_param0 );
+
+
+ public java.awt.Dimension getPreferredSize();
+
+
+ public java.awt.Dimension getSize( java.awt.Dimension oj_param0 );
+
+
+ public boolean isShowing();
+
+
+ public void repaint( long oj_param0 );
+
+
+ public java.awt.Point getLocationOnScreen();
+
+
+ public void update( java.awt.Graphics oj_param0 );
+
+
+ public java.awt.Dimension minimumSize();
+
+
+ public int getHeight();
+
+
+ public void reshape( int oj_param0, int oj_param1, int oj_param2, int oj_param3 );
+
+
+ public java.awt.Insets insets();
+
+
+ public boolean keyUp( java.awt.Event oj_param0, int oj_param1 );
+
+
+ public void show();
+
+
+ public boolean contains( java.awt.Point oj_param0 );
+
+
+ public boolean action( java.awt.Event oj_param0, java.lang.Object oj_param1 );
+
+
+ public boolean mouseDown( java.awt.Event oj_param0, int oj_param1, int oj_param2 );
+
+
+ public void addMouseMotionListener( java.awt.event.MouseMotionListener oj_param0 );
+
+
+ public boolean isEnabled();
+
+
+ public void setFont( java.awt.Font oj_param0 );
+
+
+ public boolean prepareImage( java.awt.Image oj_param0, int oj_param1, int oj_param2, java.awt.image.ImageObserver oj_param3 );
+
+
+ public boolean mouseEnter( java.awt.Event oj_param0, int oj_param1, int oj_param2 );
+
+
+ public void addFocusListener( java.awt.event.FocusListener oj_param0 );
+
+
+ public void setBounds( java.awt.Rectangle oj_param0 );
+
+
+ public boolean inside( int oj_param0, int oj_param1 );
+
+
+ public void setBounds( int oj_param0, int oj_param1, int oj_param2, int oj_param3 );
+
+
+ public float getAlignmentX();
+
+
+ public boolean contains( int oj_param0, int oj_param1 );
+
+
+ public java.awt.peer.ComponentPeer getPeer();
+
+
+ public java.awt.Component[] getComponents();
+
+
+ public java.awt.Component findComponentAt( int oj_param0, int oj_param1 );
+
+
+ public void setComponentOrientation( java.awt.ComponentOrientation oj_param0 );
+
+
+ public java.awt.Component getComponentAt( int oj_param0, int oj_param1 );
+
+
+ public java.awt.Component getComponent( int oj_param0 );
+
+
+ public void removeContainerListener( java.awt.event.ContainerListener oj_param0 );
+
+
+ public void remove( int oj_param0 );
+
+
+ public void remove( java.awt.MenuComponent oj_param0 );
+
+
+ public java.awt.Cursor getCursor();
+
+
+ public java.awt.Component getComponentAt( java.awt.Point oj_param0 );
+
+
+ public void move( int oj_param0, int oj_param1 );
+
+
+ public java.awt.Dimension preferredSize();
+
+
+ public java.awt.Image createImage( int oj_param0, int oj_param1 );
+
+
+ public void removeInputMethodListener( java.awt.event.InputMethodListener oj_param0 );
+
+
+ public int getComponentCount();
+
+
+ public void removeComponentListener( java.awt.event.ComponentListener oj_param0 );
+
+
+ public void setForeground( java.awt.Color oj_param0 );
+
+
+ public void addPropertyChangeListener( java.lang.String oj_param0, java.beans.PropertyChangeListener oj_param1 );
+
+
+ public int foo();
+
+
+ public void setLocale( java.util.Locale oj_param0 );
+
+
+ public java.awt.Point getLocation( java.awt.Point oj_param0 );
+
+
+ public void list( java.io.PrintStream oj_param0, int oj_param1 );
+
+
+ public int checkImage( java.awt.Image oj_param0, java.awt.image.ImageObserver oj_param1 );
+
+
+ public java.awt.Dimension size();
+
+
+ public boolean isVisible();
+
+
+ public java.awt.Dimension getMinimumSize();
+
+
+ public void doLayout();
+
+
+ public boolean gotFocus( java.awt.Event oj_param0, java.lang.Object oj_param1 );
+
+
+ public void addInputMethodListener( java.awt.event.InputMethodListener oj_param0 );
+
+
+ public int getY();
+
+
+ public java.awt.Component add( java.awt.Component oj_param0, int oj_param1 );
+
+
+ public boolean isOpaque();
+
+
+ public boolean isValid();
+
+
+ public void removeKeyListener( java.awt.event.KeyListener oj_param0 );
+
+
+ public boolean isDisplayable();
+
+
+ public void setName( java.lang.String oj_param0 );
+
+
+ public java.awt.Toolkit getToolkit();
+
+
+ public java.awt.ComponentOrientation getComponentOrientation();
+
+
+ public void setLocation( int oj_param0, int oj_param1 );
+
+
+ public void addNotify();
+
+
+ public java.awt.Dimension getMaximumSize();
+
+
+ public java.lang.String getName();
+
+
+ public void setSize( int oj_param0, int oj_param1 );
+
+
+ public void add( java.awt.PopupMenu oj_param0 );
+
+
+ public void list( java.io.PrintWriter oj_param0 );
+
+
+ public int countComponents();
+
+
+ public java.awt.Point getLocation();
+
+
+ public void resize( java.awt.Dimension oj_param0 );
+
+
+ public java.util.Locale getLocale();
+
+
+ public void removePropertyChangeListener( java.beans.PropertyChangeListener oj_param0 );
+
+
+ public void resize( int oj_param0, int oj_param1 );
+
+
+ public boolean mouseDrag( java.awt.Event oj_param0, int oj_param1, int oj_param2 );
+
+
+ public java.awt.Point location();
+
+
+ public java.awt.image.ColorModel getColorModel();
+
+
+ public void removeNotify();
+
+
+ public void repaint( long oj_param0, int oj_param1, int oj_param2, int oj_param3, int oj_param4 );
+
+
+ public void removePropertyChangeListener( java.lang.String oj_param0, java.beans.PropertyChangeListener oj_param1 );
+
+
+ public void removeMouseListener( java.awt.event.MouseListener oj_param0 );
+
+
+ public int checkImage( java.awt.Image oj_param0, int oj_param1, int oj_param2, java.awt.image.ImageObserver oj_param3 );
+
+
+ public void paintComponents( java.awt.Graphics oj_param0 );
+
+
+ public void list();
+
+
+ public void dispatchEvent( java.awt.AWTEvent oj_param0 );
+
+
+ public java.lang.Object getTreeLock();
+
+
+ public void printAll( java.awt.Graphics oj_param0 );
+
+
+ public void nextFocus();
+
+
+ public boolean mouseExit( java.awt.Event oj_param0, int oj_param1, int oj_param2 );
+
+
+ public void addComponentListener( java.awt.event.ComponentListener oj_param0 );
+
+
+ public void deliverEvent( java.awt.Event oj_param0 );
+
+
+ public void requestFocus();
+
+
+ public void disable();
+
+
+ public void setEnabled( boolean oj_param0 );
+
+
+ public void repaint();
+
+
+ public void setVisible( boolean oj_param0 );
+
+
+ public java.awt.FontMetrics getFontMetrics( java.awt.Font oj_param0 );
+
+
+ public java.awt.Color getBackground();
+
+
+ public java.awt.Rectangle getBounds();
+
+
+ public void invalidate();
+
+
+ public boolean hasFocus();
+
+
+ public void show( boolean oj_param0 );
+
+
+ public java.awt.Dimension getSize();
+
+
+ public java.awt.Font getFont();
+
+
+ public boolean mouseUp( java.awt.Event oj_param0, int oj_param1, int oj_param2 );
+
+
+ public boolean imageUpdate( java.awt.Image oj_param0, int oj_param1, int oj_param2, int oj_param3, int oj_param4, int oj_param5 );
+
+
+ public boolean prepareImage( java.awt.Image oj_param0, java.awt.image.ImageObserver oj_param1 );
+
+
+ public java.awt.Image createImage( java.awt.image.ImageProducer oj_param0 );
+
+
+ public void add( java.awt.Component oj_param0, java.lang.Object oj_param1, int oj_param2 );
+
+
+ public int getX();
+
+
+ public java.awt.Container getParent();
+
+
+ public java.awt.dnd.DropTarget getDropTarget();
+
+
+ public boolean lostFocus( java.awt.Event oj_param0, java.lang.Object oj_param1 );
+
+
+ public void enable( boolean oj_param0 );
+
+
+ public void addKeyListener( java.awt.event.KeyListener oj_param0 );
+
+
+ public void setSize( java.awt.Dimension oj_param0 );
+
+
+ public void paint( java.awt.Graphics oj_param0 );
+
+
+ public java.awt.Rectangle getBounds( java.awt.Rectangle oj_param0 );
+
+
+ public void removeFocusListener( java.awt.event.FocusListener oj_param0 );
+
+
+ public void removeAll();
+
+
+ public float getAlignmentY();
+
+
+ public boolean isFocusTraversable();
+
+
+ public void enable();
+
+
+ public java.awt.Rectangle bounds();
+
+
+ public java.awt.Component locate( int oj_param0, int oj_param1 );
+
+
+ public java.awt.im.InputContext getInputContext();
+
+
+ public boolean keyDown( java.awt.Event oj_param0, int oj_param1 );
+
+
+ public void addPropertyChangeListener( java.beans.PropertyChangeListener oj_param0 );
+
+
+ public java.awt.Component add( java.awt.Component oj_param0 );
+
+
+ public void printComponents( java.awt.Graphics oj_param0 );
+
+
+ public java.awt.LayoutManager getLayout();
+
+
+ public void paintAll( java.awt.Graphics oj_param0 );
+
+
+ public void addMouseListener( java.awt.event.MouseListener oj_param0 );
+
+
+ public java.awt.Component add( java.lang.String oj_param0, java.awt.Component oj_param1 );
+
+
+ public void add( java.awt.Component oj_param0, java.lang.Object oj_param1 );
+
+
+ public void addContainerListener( java.awt.event.ContainerListener oj_param0 );
+
+
+ public void hide();
+
+
+ public void list( java.io.PrintStream oj_param0 );
+
+
+ public void enableInputMethods( boolean oj_param0 );
+
+
+ public void transferFocus();
+
+
+ public java.awt.im.InputMethodRequests getInputMethodRequests();
+
+
+ public java.awt.Insets getInsets();
+
+
+ public void setCursor( java.awt.Cursor oj_param0 );
+
+
+ public boolean mouseMove( java.awt.Event oj_param0, int oj_param1, int oj_param2 );
+
+
+ public void setBackground( java.awt.Color oj_param0 );
+
+
+ public void setDropTarget( java.awt.dnd.DropTarget oj_param0 );
+
+
+ public boolean isLightweight();
+
+
+ public void repaint( int oj_param0, int oj_param1, int oj_param2, int oj_param3 );
+
+
+ public void remove( java.awt.Component oj_param0 );
+
+
+ public boolean isAncestorOf( java.awt.Component oj_param0 );
+
+
+ public boolean postEvent( java.awt.Event oj_param0 );
+
+
+ public boolean isDoubleBuffered();
+
+
+ public int getWidth();
+
+
+ public java.awt.Component findComponentAt( java.awt.Point oj_param0 );
+
+
+ public boolean handleEvent( java.awt.Event oj_param0 );
+
+
+ public java.awt.Graphics getGraphics();
+
+
+ public void validate();
+
+
+ public java.awt.Color getForeground();
+
+
+ public void list( java.io.PrintWriter oj_param0, int oj_param1 );
+
+
+ public void removeMouseMotionListener( java.awt.event.MouseMotionListener oj_param0 );
+
+
+ public void setLayout( java.awt.LayoutManager oj_param0 );
+
+}
diff --git a/tutorial/examples/freeargs/Collection.java b/tutorial/examples/freeargs/Collection.java
new file mode 100644
index 0000000..74fff0f
--- /dev/null
+++ b/tutorial/examples/freeargs/Collection.java
@@ -0,0 +1,61 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * Collection.oj
+ *
+ * Apr 13, 1999 Michiaki Tatsubori
+ */
+package examples.freeargs;
+
+
+import examples.freeargs.FreeArgsClass;
+import examples.print.*;
+
+
+/**
+ * The class <code>Collection</code> represents a collection of objects.
+ */
+public class Collection
+{
+
+ private java.lang.Object[] contents;
+
+ public Collection()
+ {
+ contents = new java.lang.Object[0];
+ }
+
+ public boolean isEmpty()
+ {
+ return contents.length == 0;
+ }
+
+ /** Accepts any number of arguments. */
+ public void set( java.lang.Object[] args )
+ {
+ contents = new java.lang.Object[args.length];
+ System.arraycopy( args, 0, contents, 0, args.length );
+ }
+
+ /** Accepts any number of arguments. */
+ public void add( java.lang.Object[] args )
+ {
+ java.lang.Object[] old = contents;
+ contents = new java.lang.Object[old.length + args.length];
+ System.arraycopy( old, 0, contents, 0, old.length );
+ System.arraycopy( args, 0, contents, old.length, args.length );
+ }
+
+ public int size()
+ {
+ return contents.length;
+ }
+
+ /** Obtains a specified object. */
+ public java.lang.Object get( int i )
+ {
+ return contents[i];
+ }
+
+}
diff --git a/tutorial/examples/freeargs/Collection.oj b/tutorial/examples/freeargs/Collection.oj
new file mode 100644
index 0000000..77e4c81
--- /dev/null
+++ b/tutorial/examples/freeargs/Collection.oj
@@ -0,0 +1,52 @@
+/*
+ * Collection.oj
+ *
+ * Apr 13, 1999 Michiaki Tatsubori
+ */
+package examples.freeargs;
+
+
+import examples.freeargs.FreeArgsClass;
+import examples.print.*;
+
+
+/**
+ * The class <code>Collection</code> represents a collection of objects.
+ */
+public class Collection instantiates FreeArgsClass
+{
+
+ private Object[] contents;
+
+ public Collection() {
+ contents = new Object[0];
+ }
+
+ public boolean isEmpty() {
+ return (contents.length == 0);
+ }
+
+ /** Accepts any number of arguments. */
+ public generous void set( Object[] args ) {
+ contents = new Object[args.length];
+ System.arraycopy( args, 0, contents, 0, args.length );
+ }
+
+ /** Accepts any number of arguments. */
+ public generous void add( Object[] args ) {
+ Object[] old = contents;
+ contents = new Object[old.length + args.length];
+ System.arraycopy( old, 0, contents, 0, old.length );
+ System.arraycopy( args, 0, contents, old.length, args.length );
+ }
+
+ public int size() {
+ return contents.length;
+ }
+
+ /** Obtains a specified object. */
+ public Object get( int i ) {
+ return contents[i];
+ }
+
+}
diff --git a/tutorial/examples/freeargs/FreeArgsClass.java b/tutorial/examples/freeargs/FreeArgsClass.java
new file mode 100644
index 0000000..2349869
--- /dev/null
+++ b/tutorial/examples/freeargs/FreeArgsClass.java
@@ -0,0 +1,117 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * FreeArgsClass.oj
+ *
+ * Apr 29, 1999, by Michiaki Tatsubori
+ * Feb 2, 1999, by Michiaki Tatsubori
+ */
+package examples.freeargs;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>FreeArgsClass</code> provides classes with
+ * a facility of methods to accept unknown number of arguments.
+ * <p>
+ * For example, for the class:
+ * <pre>
+ * class MyCollection instantiates FreeArgsClass {
+ * public generous add( Object[] arg ) { .. }
+ * }
+ * </pre>
+ * We can use the class above as follows:
+ * <pre>
+ * MyCollection collection = ..;
+ * collection.add( a, b, null, c, d );
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @see java.lang.OJClass
+ */
+public class FreeArgsClass extends openjava.mop.OJClass
+{
+
+ private static final java.lang.String GENEROUS = "generous";
+
+ /** Translates definition */
+ public void translateDefinition()
+ throws openjava.mop.MOPException
+ {
+ openjava.mop.OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (!methods[i].getModifiers().has( GENEROUS )) {
+ continue;
+ }
+ System.err.println( methods[i] );
+ openjava.mop.OJClass[] paramtypes = methods[i].getParameterTypes();
+ if (paramtypes.length != 1 || !paramtypes[0].isArray()) {
+ System.err.println( "illegal parameter, ignored." );
+ continue;
+ }
+ putMetaInfo( methods[i].getName(), paramtypes[0].getName() );
+ }
+ }
+
+ public openjava.mop.OJMethod resolveException( openjava.mop.NoSuchMemberException e, java.lang.String name, openjava.mop.OJClass[] params )
+ throws openjava.mop.NoSuchMemberException
+ {
+ try {
+ java.lang.String argtypename = getMetaInfo( name );
+ if (argtypename != null) {
+ openjava.mop.OJClass paramtype = OJClass.forName( argtypename );
+ return getMethod( name, new openjava.mop.OJClass[]{ paramtype }, this );
+ }
+ } catch ( openjava.mop.OJClassNotFoundException e2 ) {
+ System.err.println( e2 );
+ }
+ return super.resolveException( e, name, params );
+ }
+
+ /** Translates allocation parts */
+ public openjava.ptree.Expression expandMethodCall( openjava.mop.Environment env, openjava.ptree.MethodCall expr )
+ {
+ java.lang.String argtypename = getMetaInfo( expr.getName() );
+ if (argtypename == null) {
+ return expr;
+ }
+ openjava.mop.OJClass comptype;
+ try {
+ comptype = OJClass.forName( argtypename ).getComponentType();
+ } catch ( openjava.mop.OJClassNotFoundException e ) {
+ System.err.println( e );
+ return expr;
+ }
+ openjava.ptree.ExpressionList dim = new openjava.ptree.ExpressionList( null );
+ openjava.ptree.ArrayInitializer ainit = new openjava.ptree.ArrayInitializer( expr.getArguments() );
+ openjava.ptree.ArrayAllocationExpression carrier = new openjava.ptree.ArrayAllocationExpression( comptype, dim, ainit );
+ expr.setArguments( new openjava.ptree.ExpressionList( carrier ) );
+ return expr;
+ }
+
+ public static boolean isRegisteredModifier( java.lang.String keyword )
+ {
+ if (keyword.equals( GENEROUS )) {
+ return true;
+ }
+ return false;
+ }
+
+ public FreeArgsClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public FreeArgsClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/freeargs/FreeArgsClass.oj b/tutorial/examples/freeargs/FreeArgsClass.oj
new file mode 100644
index 0000000..aba5b41
--- /dev/null
+++ b/tutorial/examples/freeargs/FreeArgsClass.oj
@@ -0,0 +1,95 @@
+/*
+ * FreeArgsClass.oj
+ *
+ * Apr 29, 1999, by Michiaki Tatsubori
+ * Feb 2, 1999, by Michiaki Tatsubori
+ */
+package examples.freeargs;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>FreeArgsClass</code> provides classes with
+ * a facility of methods to accept unknown number of arguments.
+ * <p>
+ * For example, for the class:
+ * <pre>
+ * class MyCollection instantiates FreeArgsClass {
+ * public generous add( Object[] arg ) { .. }
+ * }
+ * </pre>
+ * We can use the class above as follows:
+ * <pre>
+ * MyCollection collection = ..;
+ * collection.add( a, b, null, c, d );
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @see java.lang.OJClass
+ */
+public class FreeArgsClass instantiates Metaclass extends OJClass
+{
+ private static final String GENEROUS = "generous";
+ /** Translates definition */
+
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (! methods[i].getModifiers().has( GENEROUS )) continue;
+ System.err.println( methods[i] );
+ OJClass[] paramtypes = methods[i].getParameterTypes();
+ if (paramtypes.length != 1 || ! paramtypes[0].isArray()) {
+ System.err.println( "illegal parameter, ignored." );
+ continue;
+ }
+ putMetaInfo( methods[i].getName(), paramtypes[0].getName() );
+ }
+ }
+
+ public OJMethod resolveException( NoSuchMemberException e,
+ String name, OJClass[] params )
+ throws NoSuchMemberException
+ {
+ try {
+ String argtypename = getMetaInfo( name );
+ if (argtypename != null) {
+ OJClass paramtype = OJClass.forName( argtypename );
+ return getMethod( name, new OJClass[]{ paramtype }, this );
+ }
+ } catch ( OJClassNotFoundException e2 ) {
+ System.err.println( e2 );
+ }
+ return super.resolveException( e, name, params );
+ }
+
+ /** Translates allocation parts */
+ public Expression expandMethodCall( Environment env, MethodCall expr ) {
+ String argtypename = getMetaInfo( expr.getName() );
+ if (argtypename == null) return expr;
+ OJClass comptype;
+ try {
+ comptype = OJClass.forName( argtypename ).getComponentType();
+ } catch ( OJClassNotFoundException e ) {
+ System.err.println( e );
+ return expr;
+ }
+ ExpressionList dim = new ExpressionList( null );
+ ArrayInitializer ainit = new ArrayInitializer( expr.getArguments() );
+ ArrayAllocationExpression carrier
+ = new ArrayAllocationExpression( comptype, dim, ainit );
+ expr.setArguments( new ExpressionList( carrier ) );
+ return expr;
+ }
+
+ public static boolean isRegisteredModifier( String keyword ) {
+ if (keyword.equals( GENEROUS )) return true;
+ return false;
+ }
+
+}
diff --git a/tutorial/examples/freeargs/Test.java b/tutorial/examples/freeargs/Test.java
new file mode 100644
index 0000000..7f2c928
--- /dev/null
+++ b/tutorial/examples/freeargs/Test.java
@@ -0,0 +1,32 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * Test.oj
+ *
+ * Apr 13, 1999 Michiaki Tatsubori
+ */
+package examples.freeargs;
+
+
+import java.lang.Object;
+
+
+/**
+ * Just a test.
+ */
+public class Test
+{
+
+ /**
+ * This is main method.
+ */
+ public static void main( java.lang.String[] args )
+ {
+ examples.freeargs.Collection c = new examples.freeargs.Collection();
+ c.set( new java.lang.Object[]{ new java.lang.Integer( args.length ), args[0], args[1] } );
+ c.add( new java.lang.Object[]{ new java.lang.Integer( args.length ), args[0], args[1] } );
+ System.out.println( c.size() );
+ }
+
+}
diff --git a/tutorial/examples/freeargs/Test.oj b/tutorial/examples/freeargs/Test.oj
new file mode 100644
index 0000000..86a6cc9
--- /dev/null
+++ b/tutorial/examples/freeargs/Test.oj
@@ -0,0 +1,28 @@
+/*
+ * Test.oj
+ *
+ * Apr 13, 1999 Michiaki Tatsubori
+ */
+package examples.freeargs;
+
+
+import java.lang.Object;
+
+
+/**
+ * Just a test.
+ */
+public class Test
+{
+
+ /**
+ * This is main method.
+ */
+ public static void main( String[] args ) {
+ Collection c = new Collection();
+ c.set( new Integer( args.length ), args[0], args[1] );
+ c.add( new Integer( args.length ), args[0], args[1] );
+ System.out.println( c.size() );
+ }
+
+}
diff --git a/tutorial/examples/mixin/0UNDERCONSTRUCTION b/tutorial/examples/mixin/0UNDERCONSTRUCTION
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tutorial/examples/mixin/0UNDERCONSTRUCTION
diff --git a/tutorial/examples/mixin/MixinedClass.java b/tutorial/examples/mixin/MixinedClass.java
new file mode 100644
index 0000000..c281fb9
--- /dev/null
+++ b/tutorial/examples/mixin/MixinedClass.java
@@ -0,0 +1,124 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * MixinedClass.oj
+ *
+ * An OpenJava example for incorporating mixin mechanism.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.mixin;
+
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>MixinedClass</code> supports classes
+ * using mixin.
+ * <p>
+ * For example, the class <code>MixinedClass</code>:
+ * <pre>
+ * public class TextboxWithUndo instantiates MixinedClass
+ * extends Textbox mixs Undo
+ * {
+ * }
+ * </pre>
+ * would be automatically implemented.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: MixinedClass.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class MixinedClass extends OJClass
+{
+
+ public static final String KEY_MIXES = "mixes";
+
+ /* overrides for translation */
+ public void translateDefinition()
+ throws MOPException
+ {
+ OJClass[] mixinClasses = getMixins();
+ for (int i = 0; i < mixinClasses.length; ++i) {
+ incorporateMixin( mixinClasses[i] );
+ }
+ }
+
+ public void incorporateMixin( OJClass mixinClazz )
+ throws MOPException
+ {
+ addInterface( mixinClazz );
+ OJMethod[] mixeds = mixinClazz.getMethods();
+ for (int i = 0; i < mixeds.length; ++i) {
+ addMethod( makeEmptyMethod( mixeds[i] ) );
+ }
+ }
+
+ /**
+ * Generates a empty method with specified name.
+ *
+ * @param name generating method's name.
+ * @param forwarded method to which the generated method forwards.
+ * @return a generated empty method.
+ */
+ private OJMethod makeEmptyMethod( OJMethod implementee )
+ throws MOPException
+ {
+ StatementList body = new StatementList();
+ if (implementee.getReturnType() == OJSystem.VOID) {
+ body.add( new ReturnStatement() );
+ } else {
+ body.add( new ReturnStatement( Literal.constantNull() ) );
+ }
+ return new OJMethod( this, implementee.getModifiers().remove( OJModifier.ABSTRACT ), implementee.getReturnType(), implementee.getName(), implementee.getParameterTypes(), implementee.getExceptionTypes(), body );
+ }
+
+ /* extended information */
+ private OJClass[] getMixins()
+ throws MOPException
+ {
+ ObjectList suffix = (ObjectList) getSuffix( KEY_MIXES );
+ OJClass[] result = new OJClass[suffix.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = OJClass.forName( suffix.get( i ).toString() );
+ }
+ return result;
+ }
+
+ /* override to extend syntax */
+ public static boolean isRegisteredKeyword( String keyword )
+ {
+ return keyword.equals( KEY_MIXES );
+ }
+
+ /* override to extend syntax */
+ public static SyntaxRule getDeclSuffixRule( String keyword )
+ {
+ if (keyword.equals( KEY_MIXES )) {
+ return new DefaultListRule( new TypeNameRule(), TokenID.COMMA );
+ }
+ return null;
+ }
+
+ public MixinedClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public MixinedClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/mixin/MixinedClass.oj b/tutorial/examples/mixin/MixinedClass.oj
new file mode 100644
index 0000000..8883948
--- /dev/null
+++ b/tutorial/examples/mixin/MixinedClass.oj
@@ -0,0 +1,115 @@
+/*
+ * MixinedClass.oj
+ *
+ * An OpenJava example for incorporating mixin mechanism.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.mixin;
+
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>MixinedClass</code> supports classes
+ * using mixin.
+ * <p>
+ * For example, the class <code>MixinedClass</code>:
+ * <pre>
+ * public class TextboxWithUndo instantiates MixinedClass
+ * extends Textbox mixs Undo
+ * {
+ * }
+ * </pre>
+ * would be automatically implemented.
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since %SOFTWARE% 1.0
+ * @see java.lang.Object
+ */
+public class MixinedClass instantiates Metaclass extends OJClass
+{
+
+ public static final String KEY_MIXES = "mixes";
+
+ /* overrides for translation */
+ public void translateDefinition() throws MOPException {
+ OJClass[] mixinClasses = getMixins();
+
+ for (int i = 0; i < mixinClasses.length; ++i) {
+ incorporateMixin(mixinClasses[i]);
+ }
+ }
+
+ public void incorporateMixin(OJClass mixinClazz) throws MOPException {
+ /* implicit forwarding to the same signature's */
+ addInterface(mixinClazz);
+ OJMethod[] mixeds = mixinClazz.getMethods();
+ for (int i = 0; i < mixeds.length; ++i) {
+ /* generate a forwarding method with forwarded's name */
+ addMethod(makeEmptyMethod(mixeds[i]));
+ }
+ }
+
+ /**
+ * Generates a empty method with specified name.
+ *
+ * @param name generating method's name.
+ * @param forwarded method to which the generated method forwards.
+ * @return a generated empty method.
+ */
+ private OJMethod makeEmptyMethod(OJMethod implementee)
+ throws MOPException
+ {
+ /* generates a return statement */
+ StatementList body = new StatementList();
+ if (implementee.getReturnType() == OJSystem.VOID) {
+ body.add(new ReturnStatement());
+ } else {
+ body.add(new ReturnStatement(Literal.constantNull()));
+ }
+
+ /* generates a new method without body */
+ return new OJMethod( this,
+ implementee.getModifiers().remove(OJModifier.ABSTRACT),
+ implementee.getReturnType(), implementee.getName(),
+ implementee.getParameterTypes(), implementee.getExceptionTypes(),
+ body );
+ }
+
+ /* extended information */
+
+ private OJClass[] getMixins() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix(KEY_MIXES);
+ OJClass[] result = new OJClass[suffix.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = OJClass.forName(suffix.get(i).toString());
+ }
+ return result;
+ }
+
+ /* override to extend syntax */
+ public static boolean isRegisteredKeyword( String keyword ) {
+ return keyword.equals( KEY_MIXES );
+ }
+
+ /* override to extend syntax */
+ public static SyntaxRule getDeclSuffixRule( String keyword ) {
+ if (keyword.equals( KEY_MIXES )) {
+ return new DefaultListRule(new TypeNameRule(), TokenID.COMMA);
+ }
+ return null;
+ }
+
+}
+
diff --git a/tutorial/examples/mixin/Textbox.java b/tutorial/examples/mixin/Textbox.java
new file mode 100644
index 0000000..5b0e06b
--- /dev/null
+++ b/tutorial/examples/mixin/Textbox.java
@@ -0,0 +1,23 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.mixin;
+
+
+public class Textbox extends java.awt.Component
+{
+
+ String text = null;
+
+ /* ..... */
+ public String getText()
+ {
+ return text;
+ }
+
+ public void setText( String s )
+ {
+ text = s;
+ }
+
+}
diff --git a/tutorial/examples/mixin/Textbox.oj b/tutorial/examples/mixin/Textbox.oj
new file mode 100644
index 0000000..a3313d0
--- /dev/null
+++ b/tutorial/examples/mixin/Textbox.oj
@@ -0,0 +1,17 @@
+package examples.mixin;
+
+
+public class Textbox extends java.awt.Component
+{
+ String text = null;
+
+ /* ..... */
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String s) {
+ text = s;
+ }
+}
diff --git a/tutorial/examples/mixin/TextboxWithUndo.java b/tutorial/examples/mixin/TextboxWithUndo.java
new file mode 100644
index 0000000..9772e62
--- /dev/null
+++ b/tutorial/examples/mixin/TextboxWithUndo.java
@@ -0,0 +1,22 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.mixin;
+
+
+public class TextboxWithUndo extends Textbox implements examples.mixin.Undo
+{
+
+
+ public void setText( java.lang.String oj_param0 )
+ {
+ return;
+ }
+
+
+ public void undo()
+ {
+ return;
+ }
+
+}
diff --git a/tutorial/examples/mixin/TextboxWithUndo.oj b/tutorial/examples/mixin/TextboxWithUndo.oj
new file mode 100644
index 0000000..cc04f88
--- /dev/null
+++ b/tutorial/examples/mixin/TextboxWithUndo.oj
@@ -0,0 +1,8 @@
+package examples.mixin;
+
+
+public class TextboxWithUndo instantiates MixinedClass
+ extends Textbox
+ mixes Undo
+{
+}
diff --git a/tutorial/examples/mixin/Undo.java b/tutorial/examples/mixin/Undo.java
new file mode 100644
index 0000000..a7f6bfb
--- /dev/null
+++ b/tutorial/examples/mixin/Undo.java
@@ -0,0 +1,8 @@
+package examples.mixin;
+
+
+public interface Undo
+{
+ public void setText(String s);
+ public void undo();
+}
diff --git a/tutorial/examples/mixin/Undo.oj b/tutorial/examples/mixin/Undo.oj
new file mode 100644
index 0000000..66ad9a9
--- /dev/null
+++ b/tutorial/examples/mixin/Undo.oj
@@ -0,0 +1,19 @@
+package examples.mixin;
+
+
+public class Undo
+{
+ inherited String getText();
+ inherited void setText(String s);
+
+ String lastText;
+
+ public void setText(String s) {
+ lastText = getText();
+ super.setText(s);
+ }
+
+ public void undo() {
+ super.setText(lastText);
+ }
+}
diff --git a/tutorial/examples/multimeta/CombinedClass.oj b/tutorial/examples/multimeta/CombinedClass.oj
new file mode 100644
index 0000000..703f871
--- /dev/null
+++ b/tutorial/examples/multimeta/CombinedClass.oj
@@ -0,0 +1,397 @@
+/*
+ * CombinedClass.oj
+ *
+ * Oct 24, 2000 by Michiaki Tatsubori
+ */
+package examples.multimeta;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+import java.util.*;
+import java.lang.reflect.*;
+
+
+/**
+ * The metaclass <code>CombinedClass</code> provides a class to be
+ * bound to more than one metaclass.
+ * <p>
+ * An usage are:
+ * <pre>
+ * class MyPerson instantiates CombinedClass
+ * extends Object implements Runnable
+ * obeys PersistableClass, TransactionableClass
+ * {
+ * ...
+ * }
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @see java.lang.OJClass
+ */
+public class CombinedClass instantiates Metaclass extends OJClass
+{
+ private static final String KEYWORD_OBEYS = "obeys";
+
+ /**
+ * Composing class metaobjects.
+ */
+ protected OJClass[] substances = null;
+
+ public CombinedClass(Class javaclazz, MetaInfo metainfo) {
+ super(javaclazz, metainfo);
+ initializeSubstantialMetaclasses(javaclazz, metainfo);
+ }
+
+ /**
+ * Initializes the substantial class metaobjects, which were specified
+ * by the "obeys" phrase in the class declaration.
+ */
+ private void initializeSubstantialMetaclasses(Class javaclazz,
+ MetaInfo metainfo) {
+ int cnum = 0;
+ while (metainfo.get(KEYWORD_OBEYS + cnum) != null) ++cnum;
+ substances = new OJClass[cnum];
+ for (int i = 0; i < substances.length; ++i) {
+ String cname = metainfo.get(KEYWORD_OBEYS + i);
+ /* Do not use OJClass.forClass() here. It would changes
+ * the bind of the metaclass to the class name.
+ * The substantial class metaobjects must be created directly.
+ */
+ try {
+ Class clazz = Class.forName(cname);
+ Constructor cons = clazz.getConstructor(new Class[] {
+ Class.class, MetaInfo.class });
+ substances[i] = (OJClass) cons.newInstance(new Object[] {
+ javaclazz, metainfo});
+ } catch (Exception ex) {
+ throw new Error(ex.toString());
+ }
+ }
+ }
+
+ public CombinedClass(Environment env, OJClass declaring,
+ ClassDeclaration cdecl) {
+ super(env, declaring, cdecl);
+ }
+
+ /**
+ * Translates the declaration part of base classes.
+ */
+ public void translateDefinition() throws MOPException {
+ initializeSubstantialMetaclasses();
+
+ System.out.println("The class " + getName() +
+ " obeys the specified substantial metaclass/es :");
+ for (int i = 0; i < substances.length; ++i) {
+ System.out.println(substances[i].getClass().getName());
+ substances[i].translateDefinition();
+ }
+ }
+
+ /**
+ * Initializes the substantial class metaobjects, which are specified
+ * by the "obeys" phrase.
+ */
+ private void initializeSubstantialMetaclasses() throws MOPException {
+ String[] metaclazz = getSubstantialMetaclasses();
+
+ for (int i = 0; i < metaclazz.length; ++i) {
+ putMetaInfo(KEYWORD_OBEYS + i, metaclazz[i]);
+ }
+
+ substances = new OJClass[metaclazz.length];
+ for (int i = 0; i < substances.length; ++i) {
+ String cname = metaclazz[i];
+ /* Do not use OJClass.forParseTree() here. It would changes
+ * the bind of the metaclass to the class name
+ * The substantial class metaobjects must be created directly.
+ */
+ try {
+ Class clazz = Class.forName(cname);
+ Constructor cons = clazz.getConstructor(new Class[] {
+ Environment.class, OJClass.class,
+ ClassDeclaration.class });
+ Environment env = getEnvironment();
+ OJClass declaring = getDeclaringClass();
+ ClassDeclaration cdecl = getSourceCode();
+ substances[i] = (OJClass) cons.newInstance(new Object[] {
+ env, declaring, cdecl});
+ } catch (Exception ex) {
+ throw new Error(ex.toString());
+ }
+ }
+ }
+
+ private String[] getSubstantialMetaclasses() throws MOPException {
+ ObjectList suffix = (ObjectList) getSuffix(KEYWORD_OBEYS);
+ String[] result = new String[suffix.size()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = suffix.get(i).toString();
+ }
+ return result;
+ }
+
+ private static Vector modifVec = new Vector();
+ private static Hashtable keyTable = new Hashtable();
+
+ /**
+ * Metaclasses of the parsing class declaration.
+ */
+ private static Class[] metaclasses = null;
+
+ /* Extends syntax for custom modifiers */
+ public static boolean isRegisteredModifier(String keyword) {
+ if (metaclasses == null) {
+ System.err.println("No consultant for modifiers!");
+ return false;
+ }
+
+ for (int i = 0; i < metaclasses.length; ++i) {
+ Class c = metaclasses[i];
+ System.err.println("Consulting " + c +
+ " for the syntax of modifiers");
+ try {
+ Method m = c.getMethod("isRegisteredModifier",
+ new Class[] {String.class});
+ Boolean result
+ = (Boolean) m.invoke(null, new Object[] {keyword});
+ if (result.booleanValue() == true) return true;
+ } catch (Exception ex) {
+ System.err.println(ex);
+ }
+ }
+
+ return false;
+ }
+
+ /* Extends syntax for custom suffix phrases */
+ public static boolean isRegisteredKeyword(String keyword) {
+ if (keyword.equals(KEYWORD_OBEYS)) return true;
+
+ if (metaclasses == null) {
+ System.err.println("No consultant for suffix phrases!");
+ return false;
+ }
+
+ for (int i = 0; i < metaclasses.length; ++i) {
+ Class c = metaclasses[i];
+ System.err.println("Consulting " + c +
+ " for the syntax of suffix phrases");
+ try {
+ Method m = c.getMethod("isRegisteredKeyword",
+ new Class[] {String.class});
+ Boolean result
+ = (Boolean) m.invoke(null, new Object[] {keyword});
+ if (result.booleanValue() == true) return true;
+ } catch (Exception ex) {
+ System.err.println(ex);
+ }
+ }
+
+ return false;
+ }
+
+ /* Extends syntax for custom suffix phrases */
+ public static SyntaxRule getDeclSuffixRule(String keyword) {
+ if (keyword.equals(KEYWORD_OBEYS)) {
+ /* The returned rule object is hacked to call back and register
+ * type names them.
+ */
+ System.err.println("Consultants dismissed");
+ metaclasses = null;
+ return new HackedTypeNameListRule(new TypeNameParsingListener() {
+ public void addTypeName(String tname) {
+ System.err.println("Found a consultant " + tname);
+
+ Class[] old = metaclasses;
+ if (old == null) {
+ metaclasses = new Class[1];
+ } else {
+ metaclasses = new Class[old.length + 1];
+ for (int i = 0; i < old.length; ++i) {
+ metaclasses[i] = old[i];
+ }
+ }
+ try {
+ Class mc = Class.forName(tname);
+ metaclasses[metaclasses.length - 1] = mc;
+ } catch (ClassNotFoundException ex) {
+ System.err.println(ex);
+ metaclasses = old;
+ }
+ }
+ });
+ }
+
+ if (metaclasses == null) {
+ System.err.println("No consultant for suffix phrases!");
+ return null;
+ }
+
+ for (int i = 0; i < metaclasses.length; ++i) {
+ Class c = metaclasses[i];
+ System.err.println("Consulting " + c +
+ " for the syntax of suffix phrases");
+ try {
+ Method m = c.getMethod("getDeclSuffixRule",
+ new Class[] {String.class});
+ SyntaxRule result
+ = (SyntaxRule) m.invoke(null, new Object[] {keyword});
+ if (result != null) return result;
+ } catch (Exception ex) {
+ System.err.println(ex);
+ }
+ }
+
+ return null;
+ }
+
+ /* -- Caller-side expansions -- */
+
+ public Expression expandFieldRead(Environment env, FieldAccess expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandFieldRead(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandFieldRead(env, expr);
+ }
+
+ public Expression expandFieldWrite(Environment env,
+ AssignmentExpression expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandFieldWrite(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandFieldWrite(env, expr);
+ }
+
+ public Expression expandMethodCall(Environment env,
+ MethodCall expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandMethodCall(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandMethodCall(env, expr);
+ }
+
+ public TypeName expandTypeName(Environment env, TypeName tname) {
+ TypeName result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandTypeName(env, tname);
+ if (result != tname) return result;
+ }
+ return super.expandTypeName(env, tname);
+ }
+
+ public Expression expandAllocation(Environment env,
+ AllocationExpression expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandAllocation(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandAllocation(env, expr);
+ }
+
+ public Expression expandArrayAllocation(Environment env,
+ ArrayAllocationExpression expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandArrayAllocation(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandArrayAllocation(env, expr);
+ }
+
+ public Expression expandArrayAccess(Environment env, ArrayAccess expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandArrayAccess(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandArrayAccess(env, expr);
+ }
+
+ public Expression expandAssignmentExpression(Environment env,
+ AssignmentExpression expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandAssignmentExpression(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandAssignmentExpression(env, expr);
+ }
+
+ public Expression expandExpression(Environment env,
+ Expression expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandExpression(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandExpression(env, expr);
+ }
+
+ public Statement expandVariableDeclaration(Environment env,
+ VariableDeclaration decl) {
+ Statement result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandVariableDeclaration(env, decl);
+ if (result != decl) return result;
+ }
+ return super.expandVariableDeclaration(env, decl);
+ }
+
+ public Expression expandCastExpression(Environment env,
+ CastExpression expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandCastExpression(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandCastExpression(env, expr);
+ }
+
+ public Expression expandCastedExpression(Environment env,
+ CastExpression expr) {
+ Expression result;
+ for (int i = 0; i < substances.length; ++i) {
+ result = substances[i].expandCastedExpression(env, expr);
+ if (result != expr) return result;
+ }
+ return super.expandCastedExpression(env, expr);
+ }
+
+ /* -- Error handlings -- */
+
+ public OJField resolveException(NoSuchMemberException nmex, String name)
+ throws NoSuchMemberException
+ {
+ for (int i = 0; i < substances.length; ++i) {
+ try {
+ return substances[i].resolveException(nmex, name);
+ } catch (NoSuchMemberException ex) {}
+ }
+ return super.resolveException(nmex, name);
+ }
+
+ public OJMethod resolveException( NoSuchMemberException nmex,
+ String name, OJClass[] argtypes)
+ throws NoSuchMemberException
+ {
+ for (int i = 0; i < substances.length; ++i) {
+ try {
+ return substances[i].resolveException(nmex, name, argtypes);
+ } catch (NoSuchMemberException ex) {}
+ }
+ return super.resolveException(nmex, name, argtypes);
+ }
+
+}
diff --git a/tutorial/examples/multimeta/MyPerson.oj b/tutorial/examples/multimeta/MyPerson.oj
new file mode 100644
index 0000000..2fccfa0
--- /dev/null
+++ b/tutorial/examples/multimeta/MyPerson.oj
@@ -0,0 +1,15 @@
+package examples.multimeta;
+
+
+import examples.verbose.VerboseClass;
+import examples.capsule.CapsuleClass;
+
+
+public class MyPerson instantiates CombinedClass
+ extends Object implements Runnable
+ obeys VerboseClass, CapsuleClass
+{
+ public String name;
+ public int age;
+ public void run() {}
+}
diff --git a/tutorial/examples/multimeta/MyPerson2.oj b/tutorial/examples/multimeta/MyPerson2.oj
new file mode 100644
index 0000000..3a13f8c
--- /dev/null
+++ b/tutorial/examples/multimeta/MyPerson2.oj
@@ -0,0 +1,15 @@
+package examples.multimeta;
+
+
+import examples.verbose.VerboseClass;
+import examples.orcheck.OverridingClass;
+
+
+public class MyPerson2 instantiates CombinedClass
+ extends Object implements Runnable
+ obeys VerboseClass, OverridingClass
+{
+ public String name;
+ public int age;
+ public overriding void run() {}
+}
diff --git a/tutorial/examples/multimeta/MyPerson3.oj b/tutorial/examples/multimeta/MyPerson3.oj
new file mode 100644
index 0000000..484e003
--- /dev/null
+++ b/tutorial/examples/multimeta/MyPerson3.oj
@@ -0,0 +1,14 @@
+package examples.multimeta;
+
+
+import examples.verbose.VerboseClass;
+
+
+public class MyPerson3 instantiates CombinedClass
+ extends Object implements Runnable
+ obeys VerboseClass, VerboseClass, VerboseClass, VerboseClass
+{
+ public String name;
+ public int age;
+ public void run() {}
+}
diff --git a/tutorial/examples/multimethod/MultimethodClass.java b/tutorial/examples/multimethod/MultimethodClass.java
new file mode 100644
index 0000000..4a81938
--- /dev/null
+++ b/tutorial/examples/multimethod/MultimethodClass.java
@@ -0,0 +1,169 @@
+/*
+ * MultimethodClass.oj
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.multimethod;
+
+
+import java.util.*;
+import openjava.mop.*;
+import openjava.ptree.*;
+
+
+/**
+ * The class <code>MultimethodClass</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: MultimethodClass.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class MultimethodClass extends OJClass
+{
+ private static final String MULTIFORM = "multiform";
+ private static final String RUNTIME_EXCEPTION
+ = "examples.multimethod.NoAddaptableMethodException";
+
+ public void translateDefinition() throws MOPException {
+ Hashtable table = new Hashtable();
+ OJMethod[] m = getDeclaredMethods();
+
+ for (int i = 0; i < m.length; ++i) {
+ if (! m[i].getModifiers().has( MULTIFORM )) continue;
+ ParameterSetTree set
+ = (ParameterSetTree) table.get( makeHashkey( m[i] ) );
+ if (set != null) {
+ set.add( m[i] );
+ } else {
+ set = new ParameterSetTree( m[i].getParameterTypes(), m[i] );
+ }
+ table.put( makeHashkey( m[i] ), set );
+ }
+
+ Enumeration ite = table.elements();
+ while (ite.hasMoreElements()) {
+ ParameterSetTree set = (ParameterSetTree) ite.nextElement();
+ modifyToBeGeneric( set );
+ System.out.println( set );
+ }
+ }
+
+ private void modifyToBeGeneric( ParameterSetTree set )
+ throws MOPException
+ {
+ if (! set.hasChildren()) return;
+
+ OJMethod method = set.getValue();
+ if (method == null) addMethod( (method = genSelector( set )) );
+
+ StatementList result = new StatementList();
+ ParameterSetTree[] children = set.getChildren();
+ for (int i = 0; i < children.length; ++i) {
+ Expression cond
+ = makeCond( method, children[i].getParameterTypes() );
+ StatementList ifbody
+ = makeQualifiedCall( method, children[i].getParameterTypes() );
+ result.add( new IfStatement( cond, ifbody ) );
+ modifyToBeGeneric( children[i] );
+ }
+ result.addAll( method.getBody() );
+ method.addExceptionType( OJClass.forName( RUNTIME_EXCEPTION ) );
+ method.setBody( result );
+ }
+
+ /* generates a method only for testing params to invoke another */
+ private OJMethod genSelector( ParameterSetTree set )
+ throws MOPException
+ {
+ /* representer of other features such as throwing exceptions */
+ OJMethod rep = pickupOne( set );
+ return new OJMethod(
+ this, rep.getModifiers(), rep.getReturnType(), rep.getName(),
+ set.getParameterTypes(), rep.getExceptionTypes(),
+ makeStatementList( "throw new " + RUNTIME_EXCEPTION + "();" )
+ );
+ }
+
+ private static Expression makeCond( OJMethod holder, OJClass[] ptypes )
+ throws MOPException
+ {
+ String[] params = holder.getParameters();
+ StringBuffer strbuf = new StringBuffer();
+ for (int i = 0; i < ptypes.length; ++i) {
+ if (i != 0) strbuf.append( " && " );
+ strbuf.append( "(" );
+ strbuf.append( params[i] );
+ strbuf.append( " instanceof " );
+ strbuf.append( ptypes[i].getName() );
+ strbuf.append( ")" );
+ }
+ return makeExpression( holder.getEnvironment(), strbuf.toString() );
+ }
+
+ private static StatementList
+ makeQualifiedCall( OJMethod holder, OJClass[] ptypes )
+ throws MOPException
+ {
+ String[] params = holder.getParameters();
+ StringBuffer strbuf = new StringBuffer();
+ strbuf.append( "this." ).append( holder.getName() ).append( "( " );
+ for (int i = 0; i < ptypes.length; ++i) {
+ if (i != 0) strbuf.append( ", " );
+ strbuf.append( "(" ).append( ptypes[i].getName() ).append( ") " );
+ strbuf.append( params[i] );
+ }
+ strbuf.append( " )" );
+ Expression mtdcall
+ = makeExpression( holder.getEnvironment(), strbuf.toString() );
+
+ StatementList result = new StatementList();
+ if (holder.getReturnType() == OJSystem.VOID) {
+ result.add( new ExpressionStatement( mtdcall ) );
+ result.add( new ReturnStatement() );
+ } else {
+ result.add( new ReturnStatement( mtdcall ) );
+ }
+ return result;
+ }
+
+ private static String makeHashkey( OJMethod method ) {
+ return method.getReturnType().getName() + "%" + method.getName() +
+ "%" + method.getParameterTypes().length;
+ }
+
+ private static OJMethod pickupOne( ParameterSetTree set ) {
+ while (set.getChildren().length != 0) set = set.getChildren()[0];
+ return set.getValue();
+ }
+
+ /* syntax extension */
+
+ public static boolean isRegisteredModifier( String keyword ) {
+ return keyword.equals( MULTIFORM );
+ }
+
+ /* constructors */
+
+ public MultimethodClass( Environment outer_env, OJClass declarer,
+ ClassDeclaration ptree )
+ {
+ super( outer_env, declarer, ptree );
+ }
+
+ public MultimethodClass( Class javaclass, MetaInfo minfo ) {
+ super( javaclass, minfo );
+ }
+
+}
diff --git a/tutorial/examples/multimethod/NoAddaptableMethodException.java b/tutorial/examples/multimethod/NoAddaptableMethodException.java
new file mode 100644
index 0000000..c51b2c0
--- /dev/null
+++ b/tutorial/examples/multimethod/NoAddaptableMethodException.java
@@ -0,0 +1,24 @@
+/*
+ * NoAddaptableMethodException.java
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.multimethod;
+
+
+import java.lang.Exception;
+
+
+/**
+ * The exception <code>NoAddaptableMethodException</code> is thrown
+ * in case that there is no method addaptable to given parameters.
+ * <p>
+ *
+ * @see examples.multimethod.MultiMethodClass
+ */
+public class NoAddaptableMethodException extends Exception
+{}
diff --git a/tutorial/examples/multimethod/ParameterSetTree.java b/tutorial/examples/multimethod/ParameterSetTree.java
new file mode 100644
index 0000000..ad2845b
--- /dev/null
+++ b/tutorial/examples/multimethod/ParameterSetTree.java
@@ -0,0 +1,215 @@
+/*
+ * ParameterSetTree.java
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.multimethod;
+
+
+import java.util.*;
+import java.io.*;
+import openjava.mop.*;
+import openjava.ptree.*;
+
+
+/**
+ * The class <code>ParameterSetTree</code> sorts parameters set of method
+ * and hold it.
+ *
+ * @author Michiaki Tatsubori
+ * @see openjava.mop.OJMethod
+ */
+public class ParameterSetTree implements Cloneable
+{
+ private OJClass[] params;
+ private OJMethod value = null;
+ private ParameterSetTree[] children = new ParameterSetTree[0];
+
+ public ParameterSetTree( OJClass[] params, OJMethod value ) {
+ this.params = params;
+ this.value = value;
+ }
+
+ ParameterSetTree( OJClass[] params ) {
+ this( params, null );
+ }
+
+ public OJClass[] getParameterTypes() {
+ OJClass[] result = new OJClass[params.length];
+ System.arraycopy( params, 0, result, 0, params.length );
+ return result;
+ }
+
+ public OJMethod getValue() {
+ return value;
+ }
+
+ public ParameterSetTree[] getChildren() {
+ if (children.length == 0) return children;
+ ParameterSetTree[] result = new ParameterSetTree[children.length];
+ System.arraycopy( children, 0, result, 0, children.length );
+ return result;
+ }
+
+ public boolean hasChildren() {
+ return children.length != 0;
+ }
+
+ public String toString() {
+ StringWriter str_writer = new StringWriter();
+ PrintWriter out = new PrintWriter( str_writer );
+ writeState( out );
+ out.flush();
+ return str_writer.toString();
+ }
+
+ public void writeState( PrintWriter out ) {
+ writeState( out, 0 );
+ }
+
+ private void writeState( PrintWriter out, int level ) {
+ for (int i = 0; i < level; ++i) out.print( " " );
+
+ out.print( "{ ");
+ out.print( params[0].getName() );
+ for (int i = 1; i < params.length; ++i) {
+ out.print( "," );
+ out.print( params[i].getName() );
+ }
+ out.print( " } " );
+ out.println( value != null );
+
+ for (int i = 0; i < children.length; ++i) {
+ children[i].writeState( out, level + 1 );
+ }
+ }
+
+ /* must adjust tree */
+ OJMethod add( OJMethod method ) {
+ OJClass[] params = method.getParameterTypes();
+
+ if (this.isSameAs( params )) {
+ /* exactly same */
+ OJMethod result = this.value;
+ this.value = method;
+ return result;
+ }
+ if (this.isAssignableFrom( params )) {
+ /* a subset of this */
+ for (int i = 0; i < children.length; ++i) {
+ if (children[i].isAssignableFrom( params )) {
+ /* a subset of one of children */
+ return children[i].add( method );
+ }
+ }
+ addChild( new ParameterSetTree( params, method ) );
+ return null;
+ }
+
+ /* a superset or an independent order set of this */
+ ParameterSetTree copy = shallowCopy();
+ OJClass[] common = commonBaseTypes( this.params, params );
+ this.params = common;
+ this.value = null;
+ if (isAssignable( params, common )) {
+ /* a superset */
+ this.params = params;
+ this.value = method;
+ this.children = new ParameterSetTree[]{ copy };
+ } else {
+ /* a subset of the common superset */
+ this.params = common;
+ this.value = null;
+ this.children = new ParameterSetTree[]{
+ copy,
+ new ParameterSetTree( params, method ) };
+ }
+ return null;
+ }
+
+ private ParameterSetTree shallowCopy() {
+ try {
+ return (ParameterSetTree) clone();
+ } catch ( CloneNotSupportedException e ){
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ /**
+ * Childrens must not have any smaller common set than this set.
+ */
+ private void addChild( ParameterSetTree newbie ) {
+ int tobelong = 0;
+ OJClass[] subcommon = null;
+
+ for (; tobelong < children.length; ++tobelong) {
+ subcommon = commonBaseTypes( newbie.params,
+ children[tobelong].params );
+ if (! isSameAs( subcommon )) break;
+ }
+
+ if (tobelong == children.length) {
+ /* simply add */
+ ParameterSetTree[] result
+ = new ParameterSetTree[children.length + 1];
+ System.arraycopy( children, 0, result, 0, children.length );
+ result[children.length] = newbie;
+ children = result;
+ return;
+ }
+
+ /* at least two has a sub common signature */
+ if (children[tobelong].isSameAs( subcommon )) {
+ /* newbie is a subset */
+ children[tobelong].addChild( newbie );
+ } else {
+ ParameterSetTree common_set = new ParameterSetTree( subcommon );
+ common_set.addChild( children[tobelong] );
+ common_set.addChild( newbie );
+ children[tobelong] = common_set;
+ }
+ }
+
+ public boolean isAssignableFrom( OJClass[] params ) {
+ return isAssignable( this.params, params );
+ }
+
+ public boolean isSameAs( OJClass[] params ) {
+ if (this.params.length != params.length) return false;
+ for (int i = 0; i < this.params.length; ++i) {
+ if (this.params[i] != params[i]) return false;
+ }
+ return true;
+ }
+
+ private static boolean isAssignable( OJClass[] p1, OJClass[] p2 ) {
+ if (p1.length != p2.length) return false;
+ for (int i = 0; i < p1.length; ++i) {
+ if (! p1[i].isAssignableFrom( p2[i] )) return false;
+ }
+ return true;
+ }
+
+ private static OJClass[] commonBaseTypes( OJClass[] a, OJClass b[] ) {
+ OJClass[] result = new OJClass[a.length];
+ for (int i = 0; i < a.length; ++i) {
+ result[i] = commonBaseType( a[i], b[i] );
+ }
+ return result;
+ }
+
+ /**
+ * this is also available in the class <code>Signature</code>
+ */
+ private static OJClass commonBaseType( OJClass a, OJClass b ) {
+ if (a.isAssignableFrom( b )) return a;
+ if (b.isAssignableFrom( a )) return b;
+ return commonBaseType( a.getSuperclass(), b.getSuperclass() );
+ }
+
+}
diff --git a/tutorial/examples/multimethod/Test.oj b/tutorial/examples/multimethod/Test.oj
new file mode 100644
index 0000000..49521a9
--- /dev/null
+++ b/tutorial/examples/multimethod/Test.oj
@@ -0,0 +1,52 @@
+package examples.multimethod;
+
+import java.awt.*;
+
+public class Test instantiates MultimethodClass
+{
+
+ public multiform void foo( Panel a ) {
+ System.out.println( "panel" );
+ }
+
+ public multiform void foo( Button a ) {
+ System.out.println( "button" );
+ }
+
+ public multiform void foo( Canvas a ) {
+ System.out.println( "canvas" );
+ }
+
+ public String toString() {
+ 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 multiform void foo( Panel a, Window b ) {
+ System.out.println( "panel" );
+ }
+
+ public multiform void foo( Button a, Dialog b ) {
+ System.out.println( "button" );
+ }
+
+ public multiform void foo( Canvas a, Dialog b ) {
+ System.out.println( "canvas" );
+ }
+
+ public multiform void foo( Canvas a, FileDialog b ) {
+ System.out.println( "canvas" );
+ }
+
+}
diff --git a/tutorial/examples/multimethod/Test2.oj b/tutorial/examples/multimethod/Test2.oj
new file mode 100644
index 0000000..e714e89
--- /dev/null
+++ b/tutorial/examples/multimethod/Test2.oj
@@ -0,0 +1,20 @@
+package examples.multimethod;
+
+import java.awt.*;
+
+public class Test2 instantiates MultimethodClass
+{
+
+ public multiform void foo( Panel a ) {
+ System.out.println( "panel" );
+ }
+
+ public multiform void foo( Button a ) {
+ System.out.println( "button" );
+ }
+
+ public multiform void foo( Canvas a ) {
+ System.out.println( "canvas" );
+ }
+
+}
diff --git a/tutorial/examples/operator/OperatorOverridable.oj b/tutorial/examples/operator/OperatorOverridable.oj
new file mode 100644
index 0000000..de952cf
--- /dev/null
+++ b/tutorial/examples/operator/OperatorOverridable.oj
@@ -0,0 +1,7 @@
+public interface
+{
+ public Object operateAdd(Object right);
+ public Object operateSubtract(Object right);
+ public Object operateMultiply(Object right);
+ public Object operateDivide(Object right);
+}
diff --git a/tutorial/examples/operator/OperatorOverridableClass.oj b/tutorial/examples/operator/OperatorOverridableClass.oj
new file mode 100644
index 0000000..e5d6abc
--- /dev/null
+++ b/tutorial/examples/operator/OperatorOverridableClass.oj
@@ -0,0 +1,97 @@
+/*
+ * FreeArgsClass.oj
+ *
+ * Apr 29, 1999, by Michiaki Tatsubori
+ * Feb 2, 1999, by Michiaki Tatsubori
+ */
+package examples.freeargs;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>OperatorOverridableClass</code> provides its
+ * base classes with an ability of overriding its operation like
+ * '+', '-', '*' and '/'.
+ *
+ * <p>
+ * For example, for the class:
+ * <pre>
+ * class MyCollection instantiates FreeArgsClass {
+ * public generous add( Object[] arg ) { .. }
+ * }
+ * </pre>
+ * We can use the class above as follows:
+ * <pre>
+ * MyCollection collection = ..;
+ * collection.add( a, b, null, c, d );
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @see java.lang.OJClass
+ */
+public class OperatorOverridableClass instantiates Metaclass extends OJClass
+{
+ private static final String GENEROUS = "generous";
+ /** Translates definition */
+
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (! methods[i].getModifiers().has( GENEROUS )) continue;
+ System.err.println( methods[i] );
+ OJClass[] paramtypes = methods[i].getParameterTypes();
+ if (paramtypes.length != 1 || ! paramtypes[0].isArray()) {
+ System.err.println( "illegal parameter, ignored." );
+ continue;
+ }
+ putMetaInfo( methods[i].getName(), paramtypes[0].getName() );
+ }
+ }
+
+ public OJMethod resolveException( NoSuchMemberException e,
+ String name, OJClass[] params )
+ throws NoSuchMemberException
+ {
+ try {
+ String argtypename = getMetaInfo( name );
+ if (argtypename != null) {
+ OJClass paramtype = OJClass.forName( argtypename );
+ return getMethod( name, new OJClass[]{ paramtype }, this );
+ }
+ } catch ( OJClassNotFoundException e2 ) {
+ System.err.println( e2 );
+ }
+ return super.resolveException( e, name, params );
+ }
+
+ /** Translates allocation parts */
+ public Expression expandMethodCall( Environment env, MethodCall expr ) {
+ String argtypename = getMetaInfo( expr.getName() );
+ if (argtypename == null) return expr;
+ OJClass comptype;
+ try {
+ comptype = OJClass.forName( argtypename ).getComponentType();
+ } catch ( OJClassNotFoundException e ) {
+ System.err.println( e );
+ return expr;
+ }
+ ExpressionList dim = new ExpressionList( null );
+ ArrayInitializer ainit = new ArrayInitializer( expr.getArguments() );
+ ArrayAllocationExpression carrier
+ = new ArrayAllocationExpression( comptype, dim, ainit );
+ expr.setArguments( new ExpressionList( carrier ) );
+ return expr;
+ }
+
+ public static boolean isRegisteredModifier( String keyword ) {
+ if (keyword.equals( GENEROUS )) return true;
+ return false;
+ }
+
+}
diff --git a/tutorial/examples/orcheck/OverrideCheckerClass.java b/tutorial/examples/orcheck/OverrideCheckerClass.java
new file mode 100644
index 0000000..6631dc6
--- /dev/null
+++ b/tutorial/examples/orcheck/OverrideCheckerClass.java
@@ -0,0 +1,82 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * OverrideCheckerClass.oj
+ *
+ * Apr 29, 1999, by Michiaki Tatsubori
+ * Feb 2, 1999, by Michiaki Tatsubori
+ */
+package examples.orcheck;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>OverloadCheckerClass</code> provides classes
+ * with a facility of checking if a method overrides the method of
+ * its superclass.
+ * <p>
+ * The class <code>MyObject</code> following is a use-case of
+ * this metaclass:
+ * <pre>
+ * class MyObject instantiates OverrideCheckerClass {
+ * public overriding tostring( Object[] arg ) { .. }
+ * }
+ * </pre>
+ * Here, you intend to override the method <tt>toString()</tt> surely.
+ * Compilation of this class shows warning that you do not
+ * override any method. This can help you to become aware of potential
+ * bugs.
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @see openjava.mop.OJClass#translateDefinition()
+ * @see openjava.mop.OJClass#isRegisteredModifier()
+ */
+public class OverrideCheckerClass extends OJClass
+{
+
+ private static final String OVERRIDING = "overriding";
+
+ public void translateDefinition()
+ throws MOPException
+ {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (!methods[i].getModifiers().has( OVERRIDING )) {
+ continue;
+ }
+ OJClass[] paramtypes = methods[i].getParameterTypes();
+ String name = methods[i].getName();
+ OJClass[] ptypes = methods[i].getParameterTypes();
+ try {
+ getSuperclass().getMethod( name, ptypes, this );
+ } catch ( Exception e ) {
+ System.err.println( "WARNING: " + methods[i] + " doesn't " + "override any method in superclasses." );
+ }
+ }
+ }
+
+ public static boolean isRegisteredModifier( String keyword )
+ {
+ if (keyword.equals( OVERRIDING )) {
+ return true;
+ }
+ return false;
+ }
+
+ public OverrideCheckerClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public OverrideCheckerClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/orcheck/OverridingClass.oj b/tutorial/examples/orcheck/OverridingClass.oj
new file mode 100644
index 0000000..2743ad4
--- /dev/null
+++ b/tutorial/examples/orcheck/OverridingClass.oj
@@ -0,0 +1,62 @@
+/*
+ * OverridingClass.oj
+ *
+ * Apr 29, 1999, by Michiaki Tatsubori
+ * Feb 2, 1999, by Michiaki Tatsubori
+ */
+package examples.orcheck;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The metaclass <code>OverloadCheckerClass</code> provides classes
+ * with a facility of checking if a method overrides the method of
+ * its superclass.
+ * <p>
+ * The class <code>MyObject</code> following is a use-case of
+ * this metaclass:
+ * <pre>
+ * class MyObject instantiates OverridingClass {
+ * public overriding tostring( Object[] arg ) { .. }
+ * }
+ * </pre>
+ * Here, you intend to override the method <tt>toString()</tt> surely.
+ * Compilation of this class shows warning that you do not
+ * override any method. This can help you to become aware of potential
+ * bugs.
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @see openjava.mop.OJClass#translateDefinition()
+ * @see openjava.mop.OJClass#isRegisteredModifier()
+ */
+public class OverridingClass instantiates Metaclass extends OJClass
+{
+ private static final String OVERRIDING = "overriding";
+
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ if (! methods[i].getModifiers().has( OVERRIDING )) continue;
+ OJClass[] paramtypes = methods[i].getParameterTypes();
+ String name = methods[i].getName();
+ OJClass[] ptypes = methods[i].getParameterTypes();
+ try {
+ getSuperclass().getMethod( name, ptypes, this );
+ } catch (Exception e) {
+ System.err.println( "WARNING: " + methods[i] + " doesn't " +
+ "override any method in superclasses." );
+ }
+ }
+ }
+
+ public static boolean isRegisteredModifier( String keyword ) {
+ if (keyword.equals( OVERRIDING )) return true;
+ return false;
+ }
+
+}
diff --git a/tutorial/examples/orcheck/Test.java b/tutorial/examples/orcheck/Test.java
new file mode 100644
index 0000000..bbf1460
--- /dev/null
+++ b/tutorial/examples/orcheck/Test.java
@@ -0,0 +1,15 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.orcheck;
+
+
+public class Test
+{
+
+ public String toString()
+ {
+ return "Hello";
+ }
+
+}
diff --git a/tutorial/examples/orcheck/Test.oj b/tutorial/examples/orcheck/Test.oj
new file mode 100644
index 0000000..cd8e6a0
--- /dev/null
+++ b/tutorial/examples/orcheck/Test.oj
@@ -0,0 +1,9 @@
+package examples.orcheck;
+
+
+public class Test instantiates OverrideCheckerClass
+{
+ public overriding String toString() {
+ return "Hello";
+ }
+}
diff --git a/tutorial/examples/orcheck/TestWithError.oj b/tutorial/examples/orcheck/TestWithError.oj
new file mode 100644
index 0000000..2a59d45
--- /dev/null
+++ b/tutorial/examples/orcheck/TestWithError.oj
@@ -0,0 +1,10 @@
+package examples.orcheck;
+
+
+public class TestWithError instantiates OverrideCheckerClass
+{
+ /** typemiss! */
+ public overriding String tostring() {
+ return "Hello";
+ }
+}
diff --git a/tutorial/examples/order/OrderKeeperClass.java b/tutorial/examples/order/OrderKeeperClass.java
new file mode 100644
index 0000000..90460b5
--- /dev/null
+++ b/tutorial/examples/order/OrderKeeperClass.java
@@ -0,0 +1,65 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * OrderKeeperClass.oj
+ *
+ */
+package examples.order;
+
+
+import openjava.mop.*;
+import openjava.ptree.ClassDeclaration;
+import openjava.syntax.*;
+
+
+public class OrderKeeperClass extends openjava.mop.OJClass
+{
+
+ private static final java.lang.String DEPEND = "dependsOn";
+
+ public void translateDefinition()
+ throws openjava.mop.MOPException
+ {
+ openjava.mop.OJClass base = getDepended();
+ System.out.println( "I'm " + getName() + ". " + "After You, " + base.getName() + "." );
+ try {
+ waitTranslation( base );
+ } catch ( java.lang.Exception e ) {
+ System.err.println( e.toString() );
+ }
+ System.out.println( getName() + " is finished." );
+ }
+
+ private openjava.mop.OJClass getDepended()
+ throws openjava.mop.MOPException
+ {
+ return OJClass.forName( getSuffix( DEPEND ).toString() );
+ }
+
+ public static boolean isRegisteredKeyword( java.lang.String keyword )
+ {
+ return keyword.equals( DEPEND );
+ }
+
+ public static openjava.syntax.SyntaxRule getDeclSuffixRule( java.lang.String keyword )
+ {
+ return keyword.equals( DEPEND ) ? new openjava.syntax.TypeNameRule() : null;
+ }
+
+ public java.lang.String toString()
+ {
+ return super.toString() + "(mc : OrderKeeper)";
+ }
+
+ public OrderKeeperClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public OrderKeeperClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/order/OrderKeeperClass.oj b/tutorial/examples/order/OrderKeeperClass.oj
new file mode 100644
index 0000000..dca208f
--- /dev/null
+++ b/tutorial/examples/order/OrderKeeperClass.oj
@@ -0,0 +1,46 @@
+/*
+ * OrderKeeperClass.oj
+ *
+ */
+package examples.order;
+
+
+import openjava.mop.*;
+import openjava.ptree.ClassDeclaration;
+import openjava.syntax.*;
+
+
+public class OrderKeeperClass instantiates Metaclass extends OJClass
+{
+ private static final String DEPEND = "dependsOn";
+
+ public void translateDefinition() throws MOPException {
+ OJClass base = getDepended();
+ System.out.println( "I'm " + getName() + ". " +
+ "After You, " + base.getName() + "." );
+ try {
+ waitTranslation( base );
+ } catch ( Exception e ) {
+ System.err.println( e.toString() );
+ }
+
+ System.out.println( getName() + " is finished." );
+ }
+
+ private OJClass getDepended() throws MOPException {
+ return OJClass.forName( getSuffix( DEPEND ).toString() );
+ }
+
+ public static boolean isRegisteredKeyword( String keyword ) {
+ return keyword.equals( DEPEND );
+ }
+
+ public static SyntaxRule getDeclSuffixRule( String keyword ) {
+ return keyword.equals( DEPEND ) ? new TypeNameRule() : null;
+ }
+
+ public String toString() {
+ return super.toString() + "(mc : OrderKeeper)";
+ }
+
+}
diff --git a/tutorial/examples/order/Test.java b/tutorial/examples/order/Test.java
new file mode 100644
index 0000000..3714254
--- /dev/null
+++ b/tutorial/examples/order/Test.java
@@ -0,0 +1,21 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.order;
+
+
+public class Test
+{
+}
+
+
+class B
+{
+}
+
+
+//class C instantiates OrderKeeperClass dependsOn B {}
+
+class A
+{
+}
diff --git a/tutorial/examples/order/Test.oj b/tutorial/examples/order/Test.oj
new file mode 100644
index 0000000..a4a00f1
--- /dev/null
+++ b/tutorial/examples/order/Test.oj
@@ -0,0 +1,12 @@
+package examples.order;
+
+public class Test instantiates OrderKeeperClass
+ dependsOn java.util.Vector
+{
+}
+
+
+class B instantiates OrderKeeperClass dependsOn A {}
+//class C instantiates OrderKeeperClass dependsOn B {}
+class A instantiates OrderKeeperClass dependsOn Test {}
+//class D instantiates OrderKeeperClass dependsOn C {}
diff --git a/tutorial/examples/order2/Printer.java b/tutorial/examples/order2/Printer.java
new file mode 100644
index 0000000..5e2994d
--- /dev/null
+++ b/tutorial/examples/order2/Printer.java
@@ -0,0 +1,46 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * Printer.java
+ *
+ */
+package examples.order2;
+
+
+import openjava.mop.*;
+
+
+public class Printer extends openjava.mop.OJClass
+{
+
+ public void translateDefinition()
+ {
+ openjava.mop.OJClass base = getSuperclass();
+ System.out.println( "I'm " + getName() + "." );
+ System.out.println( getName() + " finished." );
+ }
+
+ public void translateDefinition0()
+ {
+ openjava.mop.OJClass base = getSuperclass();
+ System.out.println( "I'm " + getName() + "." + " " + "After You, " + base.getName() + "." );
+ try {
+ waitTranslation( base );
+ } catch ( java.lang.Exception e ) {
+ System.err.println( e.toString() );
+ }
+ System.out.println( getName() + " finished." );
+ }
+
+ public Printer( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public Printer( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/order2/Printer.oj b/tutorial/examples/order2/Printer.oj
new file mode 100644
index 0000000..2bb433e
--- /dev/null
+++ b/tutorial/examples/order2/Printer.oj
@@ -0,0 +1,33 @@
+/*
+ * Printer.java
+ *
+ */
+package examples.order2;
+
+
+import openjava.mop.*;
+
+
+public class Printer instantiates Metaclass extends OJClass
+{
+ public void translateDefinition() {
+ OJClass base = getSuperclass();
+ System.out.println("I'm " + getName() + ".");
+
+ System.out.println(getName() + " finished.");
+ }
+
+ public void translateDefinition0() {
+ OJClass base = getSuperclass();
+ System.out.println( "I'm " + getName() + "." + " " +
+ "After You, " + base.getName() + "." );
+
+ try {
+ waitTranslation( base );
+ } catch ( Exception e ) {
+ System.err.println( e.toString() );
+ }
+
+ System.out.println( getName() + " finished." );
+ }
+}
diff --git a/tutorial/examples/order2/Test.java b/tutorial/examples/order2/Test.java
new file mode 100644
index 0000000..81cb268
--- /dev/null
+++ b/tutorial/examples/order2/Test.java
@@ -0,0 +1,34 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.order2;
+
+
+public class Test extends examples.order2.E
+{
+}
+
+
+class B extends examples.order2.A
+{
+}
+
+
+class E extends examples.order2.D
+{
+}
+
+
+class C extends examples.order2.B
+{
+}
+
+
+class D extends examples.order2.C
+{
+}
+
+
+class A extends java.lang.Object
+{
+}
diff --git a/tutorial/examples/order2/Test.oj b/tutorial/examples/order2/Test.oj
new file mode 100644
index 0000000..0d3284a
--- /dev/null
+++ b/tutorial/examples/order2/Test.oj
@@ -0,0 +1,11 @@
+package examples.order2;
+
+public class Test instantiates Printer extends E
+{
+}
+
+class B instantiates Printer extends A {}
+class E instantiates Printer extends D {}
+class C instantiates Printer extends B {}
+class D instantiates Printer extends C {}
+class A extends Object {}
diff --git a/tutorial/examples/print/MyClass.java b/tutorial/examples/print/MyClass.java
new file mode 100644
index 0000000..bbd1481
--- /dev/null
+++ b/tutorial/examples/print/MyClass.java
@@ -0,0 +1,30 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.print;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+
+
+public class MyClass extends OJClass
+{
+
+ public MyClass( Environment outer_env, OJClass declarer, ClassDeclaration ptree )
+ {
+ super( outer_env, declarer, ptree );
+ }
+
+ public MyClass( Class javaclass, MetaInfo minfo )
+ {
+ super( javaclass, minfo );
+ }
+
+ protected void pro()
+ {}
+
+ public void pub()
+ {}
+
+}
diff --git a/tutorial/examples/print/MyClass.oj b/tutorial/examples/print/MyClass.oj
new file mode 100644
index 0000000..0b689ea
--- /dev/null
+++ b/tutorial/examples/print/MyClass.oj
@@ -0,0 +1,21 @@
+package examples.print;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+
+
+public class MyClass instantiates TestPrinter extends OJClass
+{
+ public MyClass( Environment outer_env, OJClass declarer,
+ ClassDeclaration ptree ) {
+ super( outer_env, declarer, ptree );
+ }
+
+ public MyClass( Class javaclass, MetaInfo minfo ) {
+ super( javaclass, minfo );
+ }
+
+ protected void pro() {}
+ public void pub() {}
+}
diff --git a/tutorial/examples/print/Printer.java b/tutorial/examples/print/Printer.java
new file mode 100644
index 0000000..4de9203
--- /dev/null
+++ b/tutorial/examples/print/Printer.java
@@ -0,0 +1,64 @@
+/*
+ * Printer.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.print;
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.ClassDeclaration;
+import openjava.syntax.*;
+
+/**
+ * The class <code>Printer</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: Printer.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class Printer extends OJClass {
+ public void translateDefinition() throws MOPException {
+ System.out.println("CONSTRUCTORS");
+ OJConstructor[] c = getConstructors();
+ for (int i = 0; i < c.length; ++i) {
+ System.out.println(c[i].toString());
+ }
+
+ System.out.println("FIELDS");
+ OJField[] f = getAllFields();
+ for (int i = 0; i < f.length; ++i) {
+ System.out.println(f[i].toString());
+ }
+
+ System.out.println("METHODS");
+ OJMethod[] m = getAllMethods();
+ for (int i = 0; i < m.length; ++i) {
+ System.out.println(m[i].toString());
+ }
+ }
+
+ public Printer(
+ Environment outer_env,
+ OJClass declarer,
+ ClassDeclaration ptree) {
+ super(outer_env, declarer, ptree);
+ }
+
+ public Printer(Class javaclass, MetaInfo minfo) {
+ super(javaclass, minfo);
+ }
+
+}
diff --git a/tutorial/examples/print/Test.java b/tutorial/examples/print/Test.java
new file mode 100644
index 0000000..77238e9
--- /dev/null
+++ b/tutorial/examples/print/Test.java
@@ -0,0 +1,119 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * Test.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.print;
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+/**
+ * The class <code>Test</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: Test.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class Test extends Panel {
+
+ private int iii = 0;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ public Test() {
+ 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");
+ Test n = new Test();
+ java.lang.System.err.println("done");
+ }
+
+ public void hoge() {
+ Local l = new Local();
+ System.out.println(l.foo);
+ System.out.println(l.bar.str);
+ }
+
+ public Test(String str) {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo(int iii) {
+ switch (iii) {
+ case 0 :
+ return 0;
+
+ case 1 :
+ {
+ String str = null;
+ }
+
+ case 2 :
+ case 3 :
+ case 4 :
+ {
+ String ppp = null;
+ }
+
+ default :
+
+ }
+ return iii;
+ }
+
+ public String toString() {
+ if (n == null) {
+ return str;
+ }
+ return str + n;
+ }
+
+}
+
+class Local {
+
+ String foo = null;
+
+ Local2 bar = new Local2();
+
+ public final String getFoo(Integer i) {
+ return foo;
+ }
+
+}
+
+class Local2 {
+
+ String str = "" + "TEST";
+
+}
diff --git a/tutorial/examples/print/Test.oj b/tutorial/examples/print/Test.oj
new file mode 100644
index 0000000..7b1061a
--- /dev/null
+++ b/tutorial/examples/print/Test.oj
@@ -0,0 +1,107 @@
+/*
+ * Test.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.print;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+/**
+ * The class <code>Test</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since %SOFTWARE% 1.0
+ * @see java.lang.Object
+ */
+public class Test instantiates Printer
+ extends Panel
+{
+ private int iii = 0;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ public Test() {
+ 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" );
+ Test n = new Test();
+ java.lang.System.err.println( "done" );
+ }
+
+ public void hoge() {
+ Local l = new Local();
+ System.out.println( l.foo );
+ System.out.println( l.bar.str );
+ }
+
+ public Test( String str ) {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo( int iii ) {
+ switch (iii) {
+ case 0:
+ return 0;
+ case 1: {
+ String str = null;
+ }
+ case 2:
+ case 3:
+ case 4: {
+ String ppp = null;
+ }
+ default:
+ }
+ return iii;
+ }
+
+ public String toString() {
+ if (n == null) return str;
+ return str + n;
+ }
+
+}
+
+class Local instantiates Printer
+{
+ String foo = null;
+ Local2 bar = new Local2();
+ public final String getFoo( Integer i ) {
+ return foo;
+ }
+}
+
+class Local2
+{
+ String str = "" + "TEST";
+}
diff --git a/tutorial/examples/print/TestPrinter.java b/tutorial/examples/print/TestPrinter.java
new file mode 100644
index 0000000..bd6d359
--- /dev/null
+++ b/tutorial/examples/print/TestPrinter.java
@@ -0,0 +1,99 @@
+/*
+ * TestPrinter.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.print;
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.ClassDeclaration;
+import openjava.syntax.*;
+
+/**
+ * The class <code>TestPrinter</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: TestPrinter.java,v 1.2 2003/02/19 02:55:01 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class TestPrinter extends OJClass {
+ public void translateDefinition() throws MOPException {
+ OJMethod[] m;
+
+ /*
+ System.out.println( "SELF" );
+ m = getInheritedMethods();
+ for (int i = 0; i < m.length; ++i) {
+ System.out.println( m[i].toString() );
+ }
+ */
+
+ System.out.println("STATEMENTLIST");
+ OJClass clazz = OJClass.forName("openjava.ptree.StatementList");
+
+ m = clazz.getMethods(this);
+ /*
+ for (int i = 0; i < m.length; ++i) {
+ System.out.println( m[i].toString() );
+ }
+ */
+
+ System.out.println("INSERTELEMENTAT");
+ OJMethod method;
+ try {
+ OJClass[] params =
+ new OJClass[] {
+ OJClass.forName("openjava.ptree.Statement"),
+ OJClass.forName("int")};
+ method = clazz.getMethod("insertElementAt", params);
+ m = Toolbox.pickupMethodsByName(m, "insertElementAt");
+ System.out.println("name matches : " + m.length);
+ System.err.println(m[0].toString());
+ OJClass[] mparams = m[0].getParameterTypes();
+ System.err.println("M " + mparams[0] + " " + mparams[1]);
+ System.err.println("P " + params[0] + " " + params[1]);
+ boolean assign0 = mparams[0].isAssignableFrom(params[0]);
+ System.out.println("assignable0 : " + assign0);
+ boolean assign1 = mparams[1].isAssignableFrom(params[1]);
+ System.out.println("assignable1 : " + assign1);
+ System.out.println("equality : " + (mparams[0] == params[0]));
+
+ boolean isa = Toolbox.isAcceptable(mparams, params);
+ System.out.println("acceptable : " + isa);
+ m = Toolbox.pickupAcceptableMethodsByParameterTypes(m, params);
+ System.out.println("param matches : " + m.length);
+ } catch (NoSuchMethodException e) {
+ method = null;
+ }
+ if (method == null) {
+ System.out.println("NOT FOUND");
+ } else {
+ System.out.println(method.toString());
+ }
+ }
+
+ public TestPrinter(
+ Environment outer_env,
+ OJClass declarer,
+ ClassDeclaration ptree) {
+ super(outer_env, declarer, ptree);
+ }
+
+ public TestPrinter(Class javaclass, MetaInfo minfo) {
+ super(javaclass, minfo);
+ }
+
+}
diff --git a/tutorial/examples/rtrefl/Point.java b/tutorial/examples/rtrefl/Point.java
new file mode 100644
index 0000000..708c5ea
--- /dev/null
+++ b/tutorial/examples/rtrefl/Point.java
@@ -0,0 +1,107 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * Point.oj
+ */
+package examples.rtrefl;
+
+
+public class Point implements examples.rtrefl.RTMetaLevel
+{
+
+ public int x;
+
+ public int y;
+
+ public String name;
+
+ public Point( String name, int x, int y )
+ {
+ this.x = x;
+ this.y = y;
+ this.name = name;
+ }
+
+ public Point( int x, int y )
+ {
+ this( "DefaultName", x, y );
+ }
+
+ public String org_toString()
+ {
+ return "(" + x + "," + y + ")";
+ }
+
+ public void org_move( int dx, int dy )
+ {
+ x += dx;
+ y += dy;
+ }
+
+ public double org_distanceFromOrigin()
+ {
+ return Math.sqrt( (double) x * x + y * y );
+ }
+
+
+ public examples.rtrefl.RTMetaObject mt;
+
+
+ public java.lang.String toString()
+ {
+ return (java.lang.String) mt.trapMethodCall( "org_toString", new java.lang.Class[]{ }, new java.lang.Object[]{ } );
+ }
+
+
+ public void move( int oj_param0, int oj_param1 )
+ {
+ mt.trapMethodCall( "org_move", new java.lang.Class[]{ int.class, int.class }, new java.lang.Object[]{ new java.lang.Integer( oj_param0 ), new java.lang.Integer( oj_param1 ) } );
+ }
+
+
+ public double distanceFromOrigin()
+ {
+ return ((java.lang.Double) mt.trapMethodCall( "org_distanceFromOrigin", new java.lang.Class[]{ }, new java.lang.Object[]{ } )).doubleValue();
+ }
+
+
+ public int read_x()
+ {
+ return ((java.lang.Integer) mt.trapFieldRead( "x" )).intValue();
+ }
+
+
+ public int write_x( int oj_param0 )
+ {
+ mt.trapFieldWrite( "x", new java.lang.Integer( oj_param0 ) );
+ return oj_param0;
+ }
+
+
+ public int read_y()
+ {
+ return ((java.lang.Integer) mt.trapFieldRead( "y" )).intValue();
+ }
+
+
+ public int write_y( int oj_param0 )
+ {
+ mt.trapFieldWrite( "y", new java.lang.Integer( oj_param0 ) );
+ return oj_param0;
+ }
+
+
+ public java.lang.String read_name()
+ {
+ return (java.lang.String) mt.trapFieldRead( "name" );
+ }
+
+
+ public java.lang.String write_name( java.lang.String oj_param0 )
+ {
+ mt.trapFieldWrite( "name", oj_param0 );
+ return oj_param0;
+ }
+
+}
diff --git a/tutorial/examples/rtrefl/Point.oj b/tutorial/examples/rtrefl/Point.oj
new file mode 100644
index 0000000..e15b607
--- /dev/null
+++ b/tutorial/examples/rtrefl/Point.oj
@@ -0,0 +1,35 @@
+/*
+ * Point.oj
+ */
+package examples.rtrefl;
+
+
+public class Point instantiates RTReflClass
+{
+ public int x, y;
+ public String name;
+
+ public Point( String name, int x, int y ) {
+ this.x = x;
+ this.y = y;
+ this.name = name;
+ }
+
+ public Point( int x, int y ) {
+ this( "DefaultName", x, y );
+ }
+
+ public String toString() {
+ return "(" + x + "," + y + ")";
+ }
+
+ public void move( int dx, int dy ) {
+ x += dx;
+ y += dy;
+ }
+
+ public double distanceFromOrigin() {
+ return Math.sqrt( (double) x * x + y * y );
+ }
+
+}
diff --git a/tutorial/examples/rtrefl/PointUser.java b/tutorial/examples/rtrefl/PointUser.java
new file mode 100644
index 0000000..42ddee8
--- /dev/null
+++ b/tutorial/examples/rtrefl/PointUser.java
@@ -0,0 +1,25 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * PointUser.oj
+ */
+package examples.rtrefl;
+
+
+public class PointUser
+{
+
+ public static void main( String[] args )
+ {
+ Point p = new Point( 1, 2 ){
+ };
+ p.mt = new VerboseRTMetaObject( p ){
+ };
+ p.write_name( "MyFavorite" );
+ int x = p.read_x() + 1;
+ p.write_y( x * 2 + p.read_y() );
+ System.out.println( "distance = " + p.distanceFromOrigin() );
+ }
+
+}
diff --git a/tutorial/examples/rtrefl/PointUser.oj b/tutorial/examples/rtrefl/PointUser.oj
new file mode 100644
index 0000000..3ab9edc
--- /dev/null
+++ b/tutorial/examples/rtrefl/PointUser.oj
@@ -0,0 +1,19 @@
+/*
+ * PointUser.oj
+ */
+package examples.rtrefl;
+
+
+public class PointUser
+{
+
+ public static void main( String[] args ) {
+ Point p = new Point( 1, 2 );
+ p.mt = new VerboseRTMetaObject( p );
+ p.name = "MyFavorite";
+ int x = p.x + 1;
+ p.y = x * 2 + p.y;
+ System.out.println( "distance = " + p.distanceFromOrigin() );
+ }
+
+}
diff --git a/tutorial/examples/rtrefl/RTMetaLevel.java b/tutorial/examples/rtrefl/RTMetaLevel.java
new file mode 100644
index 0000000..0daf0be
--- /dev/null
+++ b/tutorial/examples/rtrefl/RTMetaLevel.java
@@ -0,0 +1,6 @@
+package examples.rtrefl;
+
+
+public interface RTMetaLevel
+{
+}
diff --git a/tutorial/examples/rtrefl/RTMetaObject.java b/tutorial/examples/rtrefl/RTMetaObject.java
new file mode 100644
index 0000000..13486ae
--- /dev/null
+++ b/tutorial/examples/rtrefl/RTMetaObject.java
@@ -0,0 +1,81 @@
+package examples.rtrefl;
+
+
+import java.lang.reflect.*;
+
+
+/**
+ * The class RTMetaObject
+ * Exception handling is not implemented.
+ */
+public class RTMetaObject
+{
+ private RTMetaLevel baseObj;
+
+ public RTMetaObject(RTMetaLevel base_obj) {
+ this.baseObj = base_obj;
+ }
+
+ public Object trapMethodCall(String name, Class[] paramTypes, Object[] args)
+ {
+ try {
+ Method method = baseObj.getClass().getMethod(name, paramTypes);
+ return method.invoke(baseObj, args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public Object trapFieldRead(String name) {
+ try {
+ Field field = baseObj.getClass().getField(name);
+ return field.get(baseObj);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public void trapFieldWrite(String name, Object rvalue) {
+ try {
+ Field field = baseObj.getClass().getField(name);
+ field.set(baseObj, rvalue);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
+
+
+/*****
+class Foo {
+ int f(int a) {}
+ int l;
+}
+...
+Foo foo; foo.l = expr; a = foo.l;
+
+->
+
+class Foo implements Metalevel {
+ public examples.rtrefl.RTMetaObject mt;
+ int org_f(int a) {}
+ int f(int a) {
+ Object[] args = new Object[]{ new Integer(a) };
+ Class[] argTypes = new Class[]{ int.class };
+ Object result = mt.trapMethodCall("org_f", argTypes, args);
+ return ((Integer) result).intValue();
+ }
+ int read_l() {
+ Object result = mt.trapFieldRead("l");
+ return ((Integer) result).intValue();
+ }
+ int write_l(int rvalue) {
+ mt.trapFieldWrite("l", new Integer(rvalue));
+ return rvalue;
+ }
+}
+...
+Foo foo; foo.write_l(expr); a = foo.read_l();
+*****/
diff --git a/tutorial/examples/rtrefl/RTReflClass.java b/tutorial/examples/rtrefl/RTReflClass.java
new file mode 100644
index 0000000..4486241
--- /dev/null
+++ b/tutorial/examples/rtrefl/RTReflClass.java
@@ -0,0 +1,229 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * RTReflClass.oj
+ *
+ * Oct 29, 1999 by Michiaki Tatsubori
+ */
+package examples.rtrefl;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The class <code>RTReflClass</code> is a metaclass which
+ * provides hooks for runtime class metaobject.
+ * <p>
+ * All the fields in the class are hidden instead the readers and
+ * writers methods for fields are provided. Furthermore, accesses
+ * to fields of the class is to be replaced with these methods.
+ * Note that member accesses in its class body are not captured.
+ */
+public class RTReflClass extends OJClass
+{
+
+ protected static String RTMETAOBJ_FIELD = "mt";
+
+ protected static Expression METAFIELD_ACCESS = new FieldAccess( RTMETAOBJ_FIELD );
+
+ protected static final String originalMethodName( String name )
+ {
+ return "org_" + name;
+ }
+
+ protected static final String fieldReaderName( String name )
+ {
+ return "read_" + name;
+ }
+
+ protected static final String fieldWriterName( String name )
+ {
+ return "write_" + name;
+ }
+
+ /** Overrides to translate definition */
+ public void translateDefinition()
+ throws MOPException
+ {
+ addInterface( openjava.mop.OJClass.forClass( RTMetaLevel.class ) );
+ OJMethod[] methods = getDeclaredMethods();
+ OJField[] fields = getDeclaredFields();
+ OJField rtmobj_field = new OJField( this, OJModifier.forModifier( OJModifier.PUBLIC ), openjava.mop.OJClass.forClass( RTMetaObject.class ), RTMETAOBJ_FIELD );
+ addField( rtmobj_field );
+ for (int i = 0; i < methods.length; ++i) {
+ OJModifier modif = methods[i].getModifiers();
+ if (modif.isPublic()) {
+ provideMethod( methods[i] );
+ }
+ }
+ for (int i = 0; i < fields.length; ++i) {
+ OJModifier modif = fields[i].getModifiers();
+ if (modif.isPublic()) {
+ provideField( fields[i] );
+ }
+ }
+ }
+
+ private void provideMethod( OJMethod method )
+ throws MOPException
+ {
+ System.err.println( "Providing a method : " + method.toString() );
+ OJMethod trapper = OJMethod.makePrototype( method );
+ method.setName( originalMethodName( method.getName() ) );
+ addMethod( trapper );
+ Expression trapexpr = generateTrappingMethodCall( trapper );
+ StatementList body = new StatementList();
+ OJClass retType = trapper.getReturnType();
+ if (retType == OJSystem.VOID) {
+ body.add( new ExpressionStatement( trapexpr ) );
+ } else {
+ Expression unwrapexpr = generateUnwrapping( retType, trapexpr );
+ body.add( new ReturnStatement( unwrapexpr ) );
+ }
+ trapper.setBody( body );
+ }
+
+ private static MethodCall generateTrappingMethodCall( OJMethod method )
+ throws MOPException
+ {
+ ExpressionList params = method.getParameterVariables();
+ OJClass[] paramTypes = method.getParameterTypes();
+ ExpressionList typeinfo_args = new ExpressionList();
+ ExpressionList args = new ExpressionList();
+ for (int i = 0; i < paramTypes.length; ++i) {
+ typeinfo_args.add( new ClassLiteral( paramTypes[i] ) );
+ args.add( generateWrapping( paramTypes[i], params.get( i ) ) );
+ }
+ Expression namearg = Literal.makeLiteral( originalMethodName( method.getName() ) );
+ Expression mrsld_typearg = new ArrayAllocationExpression( openjava.mop.OJClass.forClass( java.lang.Class.class ), new ExpressionList( null ), new ArrayInitializer( typeinfo_args ) );
+ Expression mrsld_arg = new ArrayAllocationExpression( openjava.mop.OJClass.forClass( java.lang.Object.class ), new ExpressionList( null ), new ArrayInitializer( args ) );
+ ExpressionList metaargs = new ExpressionList( namearg, mrsld_typearg, mrsld_arg );
+ return new MethodCall( METAFIELD_ACCESS, "trapMethodCall", metaargs );
+ }
+
+ private void provideField( OJField field )
+ throws MOPException
+ {
+ System.err.println( "Providing a field : " + field.toString() );
+ generateReaderMethod( field );
+ generateWriterMethod( field );
+ }
+
+ /**
+ * int read_l() {
+ * return ((Integer) mt.trapFieldRead("l")).intValue();
+ * }
+ */
+ private void generateReaderMethod( OJField field )
+ throws MOPException
+ {
+ Expression metafld = new FieldAccess( RTMETAOBJ_FIELD );
+ ExpressionList args = new ExpressionList( Literal.makeLiteral( field.getName() ) );
+ Expression trapexpr = new MethodCall( METAFIELD_ACCESS, "trapFieldRead", args );
+ Expression unwrapping = generateUnwrapping( field.getType(), trapexpr );
+ OJMethod reader = new OJMethod( this, field.getModifiers(), field.getType(), fieldReaderName( field.getName() ), (OJClass[]) null, null, new StatementList( new ReturnStatement( unwrapping ) ) );
+ addMethod( reader );
+ }
+
+ /**
+ * int write_l(int rvalue) {
+ * mt.trapFieldWrite("l", new Integer(rvalue));
+ * return rvalue;
+ * }
+ */
+ private void generateWriterMethod( OJField field )
+ throws MOPException
+ {
+ OJMethod writer = new OJMethod( this, field.getModifiers(), field.getType(), fieldWriterName( field.getName() ), new OJClass[]{ field.getType() }, null, null );
+ Expression param = writer.getParameterVariables().get( 0 );
+ ExpressionList args = new ExpressionList( Literal.makeLiteral( field.getName() ), generateWrapping( field.getType(), param ) );
+ Expression trapexpr = new MethodCall( METAFIELD_ACCESS, "trapFieldWrite", args );
+ StatementList body = new StatementList( new ExpressionStatement( trapexpr ), new ReturnStatement( param ) );
+ writer.setBody( body );
+ addMethod( writer );
+ }
+
+ /** new Integer(expr) for expr */
+ private static Expression generateWrapping( OJClass realType, Expression expr )
+ {
+ if (!realType.isPrimitive()) {
+ return expr;
+ }
+ OJClass wrapperType = realType.primitiveWrapper();
+ return new AllocationExpression( wrapperType, new ExpressionList( expr ) );
+ }
+
+ /** ((Integer) expr).intValue() for expr */
+ private static Expression generateUnwrapping( OJClass realType, Expression expr )
+ {
+ expr = new CastExpression( realType.primitiveWrapper(), expr );
+ if (!realType.isPrimitive()) {
+ return expr;
+ }
+ return new MethodCall( expr, realType.getName() + "Value", null );
+ }
+
+ /** Allows references to private fields */
+ public OJField resolveException( NoSuchMemberException e, String name )
+ throws NoSuchMemberException
+ {
+ try {
+ return getDeclaredField( name );
+ } catch ( NoSuchMemberException e2 ) {
+ }
+ return super.resolveException( e, name );
+ }
+
+ /** Overrides to expand fields to be read */
+ public Expression expandFieldRead( Environment env, FieldAccess expr )
+ {
+ if (expr.getName().equals( RTMETAOBJ_FIELD )) {
+ return expr;
+ }
+ Expression ref = expr.getReferenceExpr();
+ String name = fieldReaderName( expr.getName() );
+ Expression result;
+ if (ref != null) {
+ result = new MethodCall( ref, name, null );
+ } else {
+ result = new MethodCall( expr.getReferenceType(), name, null );
+ }
+ System.err.println( "Patch FR : " + expr + "\tto\t" + result );
+ return result;
+ }
+
+ /** Overrides to expand fields to be written */
+ public Expression expandFieldWrite( Environment env, AssignmentExpression expr )
+ {
+ FieldAccess fldac = (FieldAccess) expr.getLeft();
+ if (fldac.getName().equals( RTMETAOBJ_FIELD )) {
+ return expr;
+ }
+ ExpressionList args = new ExpressionList( expr.getRight() );
+ Expression ref = fldac.getReferenceExpr();
+ String name = fieldWriterName( fldac.getName() );
+ Expression result;
+ if (ref != null) {
+ result = new MethodCall( ref, name, args );
+ } else {
+ result = new MethodCall( fldac.getReferenceType(), name, args );
+ }
+ System.err.println( "Patch FW : " + expr + "\tto\t" + result );
+ return result;
+ }
+
+ public RTReflClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public RTReflClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/rtrefl/RTReflClass.oj b/tutorial/examples/rtrefl/RTReflClass.oj
new file mode 100644
index 0000000..a75760b
--- /dev/null
+++ b/tutorial/examples/rtrefl/RTReflClass.oj
@@ -0,0 +1,247 @@
+/*
+ * RTReflClass.oj
+ *
+ * Oct 29, 1999 by Michiaki Tatsubori
+ */
+package examples.rtrefl;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The class <code>RTReflClass</code> is a metaclass which
+ * provides hooks for runtime class metaobject.
+ * <p>
+ * All the fields in the class are hidden instead the readers and
+ * writers methods for fields are provided. Furthermore, accesses
+ * to fields of the class is to be replaced with these methods.
+ * Note that member accesses in its class body are not captured.
+ */
+public class RTReflClass instantiates Metaclass extends OJClass
+{
+ protected static String RTMETAOBJ_FIELD = "mt";
+ protected static Expression METAFIELD_ACCESS
+ = new FieldAccess( RTMETAOBJ_FIELD );
+
+ protected static final String originalMethodName( String name ) {
+ return "org_" + name;
+ }
+
+ protected static final String fieldReaderName( String name ) {
+ return "read_" + name;
+ }
+
+ protected static final String fieldWriterName( String name ) {
+ return "write_" + name;
+ }
+
+ /** Overrides to translate definition */
+ public convenient void translateDefinition() throws MOPException {
+ addInterface( RTMetaLevel.class );
+
+ /* Gets all the declared fields and methods */
+ OJMethod[] methods = getDeclaredMethods();
+ OJField[] fields = getDeclaredFields();
+
+ OJField rtmobj_field
+ = new OJField( this, OJModifier.forModifier( OJModifier.PUBLIC ),
+ RTMetaObject.class, RTMETAOBJ_FIELD );
+ addField( rtmobj_field );
+
+ /* Generates trapping methods for each public method */
+ for (int i = 0; i < methods.length; ++i) {
+ OJModifier modif = methods[i].getModifiers();
+ if (modif.isPublic()) provideMethod( methods[i] );
+ }
+
+ /* Generates wrappers for each public field */
+ for (int i = 0; i < fields.length; ++i) {
+ OJModifier modif = fields[i].getModifiers();
+ if (modif.isPublic()) provideField( fields[i] );
+ }
+ }
+
+ private void provideMethod( OJMethod method ) throws MOPException {
+ System.err.println( "Providing a method : " + method.toString() );
+ OJMethod trapper = OJMethod.makePrototype( method );
+ method.setName( originalMethodName( method.getName() ) );
+ addMethod( trapper );
+
+ /* marshalling and trapping */
+ Expression trapexpr = generateTrappingMethodCall( trapper );
+
+ StatementList body = new StatementList();
+ OJClass retType = trapper.getReturnType();
+ if (retType == OJSystem.VOID) {
+ body.add( new ExpressionStatement( trapexpr ) );
+ } else {
+ Expression unwrapexpr = generateUnwrapping( retType, trapexpr );
+ body.add( new ReturnStatement( unwrapexpr ) );
+ }
+ trapper.setBody( body );
+ }
+
+ private static convenient MethodCall
+ generateTrappingMethodCall( OJMethod method ) throws MOPException {
+ ExpressionList params = method.getParameterVariables();
+ OJClass[] paramTypes = method.getParameterTypes();
+
+ /* wrapping arguments */
+ ExpressionList typeinfo_args = new ExpressionList();
+ ExpressionList args = new ExpressionList();
+ for (int i = 0; i < paramTypes.length; ++i) {
+ typeinfo_args.add( new ClassLiteral( paramTypes[i] ) );
+ args.add( generateWrapping( paramTypes[i], params.get( i ) ));
+ }
+
+ /* marshalling arguments */
+ Expression namearg
+ = Literal.makeLiteral( originalMethodName( method.getName() ) );
+ Expression mrsld_typearg = new ArrayAllocationExpression(
+ java.lang.Class.class, new ExpressionList( null ),
+ new ArrayInitializer( typeinfo_args )
+ );
+ Expression mrsld_arg = new ArrayAllocationExpression(
+ java.lang.Object.class, new ExpressionList( null ),
+ new ArrayInitializer( args )
+ );
+
+ ExpressionList metaargs
+ = new ExpressionList( namearg, mrsld_typearg, mrsld_arg );
+ return new MethodCall( METAFIELD_ACCESS, "trapMethodCall", metaargs );
+ }
+
+ private void provideField( OJField field ) throws MOPException {
+ System.err.println( "Providing a field : " + field.toString() );
+ generateReaderMethod( field );
+ generateWriterMethod( field );
+ }
+
+ /**
+ * int read_l() {
+ * return ((Integer) mt.trapFieldRead("l")).intValue();
+ * }
+ */
+ private void generateReaderMethod( OJField field ) throws MOPException {
+ //Expression trapexpr = makeExpression(
+ // "mt.trapFieldRead(\"" + field.getName() + "\")"
+ //);
+ Expression metafld = new FieldAccess( RTMETAOBJ_FIELD );
+ ExpressionList args = new ExpressionList(
+ Literal.makeLiteral( field.getName() )
+ );
+ Expression trapexpr
+ = new MethodCall( METAFIELD_ACCESS, "trapFieldRead", args );
+ Expression unwrapping
+ = generateUnwrapping( field.getType(), trapexpr );
+ OJMethod reader = new OJMethod( this,
+ field.getModifiers(), field.getType(),
+ fieldReaderName( field.getName() ),
+ (OJClass[]) null, null,
+ new StatementList( new ReturnStatement( unwrapping ) )
+ );
+ addMethod( reader );
+ }
+
+ /**
+ * int write_l(int rvalue) {
+ * mt.trapFieldWrite("l", new Integer(rvalue));
+ * return rvalue;
+ * }
+ */
+ private void generateWriterMethod( OJField field ) throws MOPException {
+ OJMethod writer = new OJMethod( this,
+ field.getModifiers(), field.getType(),
+ fieldWriterName( field.getName() ),
+ new OJClass[]{ field.getType() }, null, null
+ );
+ Expression param = writer.getParameterVariables().get( 0 );
+ //StatementList body = makeStatementList( writer.getEnvironment(),
+ // "mt.trapFieldWrite(\"" + field.getName() + "\");" +
+ // "return " + field.getName() + "=" + param + ";"
+ // );
+ ExpressionList args = new ExpressionList(
+ Literal.makeLiteral( field.getName() ),
+ generateWrapping( field.getType(), param )
+ );
+ Expression trapexpr
+ = new MethodCall( METAFIELD_ACCESS, "trapFieldWrite", args );
+ StatementList body = new StatementList(
+ new ExpressionStatement( trapexpr ),
+ new ReturnStatement( param )
+ );
+ writer.setBody( body );
+ addMethod( writer );
+ }
+
+ /** new Integer(expr) for expr */
+ private static Expression
+ generateWrapping(OJClass realType, Expression expr) {
+ if (! realType.isPrimitive()) return expr;
+ OJClass wrapperType = realType.primitiveWrapper();
+ return new AllocationExpression( wrapperType,
+ new ExpressionList( expr ) );
+ }
+
+ /** ((Integer) expr).intValue() for expr */
+ private static Expression
+ generateUnwrapping(OJClass realType, Expression expr) {
+ expr = new CastExpression( realType.primitiveWrapper(), expr );
+ if (! realType.isPrimitive()) return expr;
+ return new MethodCall( expr, realType.getName() + "Value", null );
+ }
+
+ /* overrides */
+
+ /** Allows references to private fields */
+ public OJField resolveException(NoSuchMemberException e, String name)
+ throws NoSuchMemberException
+ {
+ try {
+ return getDeclaredField( name );
+ } catch ( NoSuchMemberException e2 ) {}
+ return super.resolveException( e, name );
+ }
+
+ /** Overrides to expand fields to be read */
+ public Expression expandFieldRead(
+ Environment env,
+ FieldAccess expr )
+ {
+ if (expr.getName().equals( RTMETAOBJ_FIELD )) return expr;
+ Expression ref = expr.getReferenceExpr();
+ String name = fieldReaderName( expr.getName() );
+ Expression result;
+ if (ref != null) {
+ result = new MethodCall( ref, name, null );
+ } else {
+ result = new MethodCall( expr.getReferenceType(), name, null );
+ }
+ System.err.println( "Patch FR : " + expr + "\tto\t" + result );
+ return result;
+ }
+
+ /** Overrides to expand fields to be written */
+ public Expression expandFieldWrite(
+ Environment env,
+ AssignmentExpression expr )
+ {
+ FieldAccess fldac = (FieldAccess) expr.getLeft();
+ if (fldac.getName().equals( RTMETAOBJ_FIELD )) return expr;
+ ExpressionList args = new ExpressionList( expr.getRight() );
+ Expression ref = fldac.getReferenceExpr();
+ String name = fieldWriterName( fldac.getName() );
+ Expression result;
+ if (ref != null) {
+ result = new MethodCall( ref, name, args );
+ } else {
+ result = new MethodCall( fldac.getReferenceType(), name, args );
+ }
+ System.err.println( "Patch FW : " + expr + "\tto\t" + result );
+ return result;
+ }
+
+}
diff --git a/tutorial/examples/rtrefl/VerboseRTMetaObject.java b/tutorial/examples/rtrefl/VerboseRTMetaObject.java
new file mode 100644
index 0000000..2870eab
--- /dev/null
+++ b/tutorial/examples/rtrefl/VerboseRTMetaObject.java
@@ -0,0 +1,38 @@
+package examples.rtrefl;
+
+
+import java.lang.reflect.*;
+
+
+/**
+ * The class VerboseRTMetaObject
+ * Exception handling is not implemented.
+ */
+public class VerboseRTMetaObject extends RTMetaObject
+{
+ RTMetaLevel baseObj;
+
+ public VerboseRTMetaObject(RTMetaLevel base_obj) {
+ super(base_obj);
+ this.baseObj = base_obj;
+ }
+
+ public Object trapMethodCall(String name, Class[] paramTypes, Object[] args)
+ {
+ System.out.println(baseObj.getClass().getName() + "." +
+ name + "()" + " is called." );
+ return super.trapMethodCall(name, paramTypes, args);
+ }
+
+ public Object trapFieldRead(String name) {
+ System.out.println(baseObj.getClass().getName() + "." +
+ name + " is read." );
+ return super.trapFieldRead(name);
+ }
+
+ public void trapFieldWrite(String name, Object rvalue) {
+ System.out.println(baseObj.getClass().getName() + "." +
+ name + " is written." );
+ super.trapFieldWrite(name, rvalue);
+ }
+}
diff --git a/tutorial/examples/serialize/BIND b/tutorial/examples/serialize/BIND
new file mode 100644
index 0000000..7a57297
--- /dev/null
+++ b/tutorial/examples/serialize/BIND
@@ -0,0 +1,5 @@
+examples.serialize.SerializableClass examples.serialize.Point
+examples.serialize.SerializableClass examples.serialize.Color
+examples.serialize.SerializableClass examples.serialize.ColoredPoint
+examples.serialize.SerializableClass examples.serialize.Colored3DPoint
+examples.serialize.SerializableClass examples.serialize.*
diff --git a/tutorial/examples/serialize/Color.oj b/tutorial/examples/serialize/Color.oj
new file mode 100644
index 0000000..dbce37f
--- /dev/null
+++ b/tutorial/examples/serialize/Color.oj
@@ -0,0 +1,44 @@
+package examples.serialize;
+
+import java.io.*;
+
+public class Color
+{
+ public Color(byte r, byte g, byte b) {
+ this.r = r; this.g = g; this.b = b;
+ }
+ byte r;
+ byte g;
+ byte b;
+}
+
+/*
+public class Color implements Marshalable
+{
+ byte r;
+ byte g;
+ byte b;
+
+ public Color(byte r, byte g, byte b) {
+ this.r = r; this.g = g; this.b = b;
+ }
+
+ public Color() {
+ }
+
+ public void readObject(ObjectIn is) throws IOException {
+ r = is.readByte();
+ g = is.readByte();
+ b = is.readByte();
+ }
+
+ public void writeObject(ObjectOut os) throws IOException {
+ os.writeUTF("Color");
+ os.writeByte(r);
+ os.writeByte(g);
+ os.writeByte(b);
+ }
+
+}
+*/
+
diff --git a/tutorial/examples/serialize/Colored3DPoint.oj b/tutorial/examples/serialize/Colored3DPoint.oj
new file mode 100644
index 0000000..54c0db0
--- /dev/null
+++ b/tutorial/examples/serialize/Colored3DPoint.oj
@@ -0,0 +1,19 @@
+package examples.serialize;
+
+public class Colored3DPoint
+{
+ public Color color = new Color((byte) 0, (byte) 0, (byte) 0);
+ public int x;
+ public int y;
+ public int z;
+}
+
+/*
+public class Colored3DPoint
+{
+ public Color color = new Color((byte) 0, (byte) 0, (byte) 0);
+ private int x;
+ private int y;
+ private int z;
+}
+*/
diff --git a/tutorial/examples/serialize/ColoredPoint.oj b/tutorial/examples/serialize/ColoredPoint.oj
new file mode 100644
index 0000000..30e534c
--- /dev/null
+++ b/tutorial/examples/serialize/ColoredPoint.oj
@@ -0,0 +1,28 @@
+package examples.serialize;
+
+import java.io.*;
+
+public class ColoredPoint
+{
+ public Color color = new Color((byte) 0, (byte) 0, (byte) 0);
+ public Point point = new Point();
+}
+
+/*
+public class ColoredPoint implements Marshalable
+{
+ public Color color = new Color((byte) 1, (byte) 3, (byte) 5);
+ public Point point = new Point();
+
+ public void writeObject(ObjectOut os) throws IOException {
+ os.writeUTF("ColoredPoint");
+ os.writeObject(color);
+ os.writeObject(point);
+ }
+
+ public void readObject(ObjectIn is) throws IOException {
+ color = (Color) is.readObject();
+ point = (Point) is.readObject();
+ }
+}
+*/
diff --git a/tutorial/examples/serialize/Marshalable.java b/tutorial/examples/serialize/Marshalable.java
new file mode 100644
index 0000000..5924c4b
--- /dev/null
+++ b/tutorial/examples/serialize/Marshalable.java
@@ -0,0 +1,9 @@
+package examples.serialize;
+
+import java.io.*;
+
+public interface Marshalable
+{
+ void readObject(ObjectIn is) throws IOException;
+ void writeObject(ObjectOut os) throws IOException;
+}
diff --git a/tutorial/examples/serialize/OIOTest.java b/tutorial/examples/serialize/OIOTest.java
new file mode 100644
index 0000000..717707f
--- /dev/null
+++ b/tutorial/examples/serialize/OIOTest.java
@@ -0,0 +1,56 @@
+package examples.serialize;
+
+import javax.microedition.midlet.MIDlet;
+import java.io.*;
+
+public class OIOTest extends MIDlet
+{
+
+ public void startApp() {
+ try {
+ main();
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ public static void main() throws IOException {
+ ColoredPoint p = new ColoredPoint();
+ p.point.x = 10; p.point.y = 20;
+
+ /* Writes objects */
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOut oos = new ObjectOut(baos);
+
+ oos.writeObject(p);
+ p.color.g = (byte)2;
+ oos.writeObject(p);
+ oos.flush();
+
+ byte[] buf = baos.toByteArray();
+
+ /* Reads objects */
+ ByteArrayInputStream bais = new ByteArrayInputStream(buf);
+ ObjectIn ois = new ObjectIn(bais);
+
+ ColoredPoint p2 = (ColoredPoint) ois.readObject();
+ ColoredPoint p3 = (ColoredPoint) ois.readObject();
+
+ System.out.println("p2.color.r = " + p2.color.r);
+ System.out.println("p2.color.g = " + p2.color.g);
+ System.out.println("p2.color.b = " + p2.color.b);
+ System.out.println("p2.point.x = " + p2.point.x);
+ System.out.println("p2.point.y = " + p2.point.y);
+ System.out.println("p3.color.r = " + p3.color.r);
+ System.out.println("p3.color.g = " + p3.color.g);
+ System.out.println("p3.color.b = " + p3.color.b);
+
+ }
+
+ public void pauseApp() {
+ }
+
+ public void destroyApp(boolean unconditional) {
+ }
+
+}
diff --git a/tutorial/examples/serialize/ObjectIn.java b/tutorial/examples/serialize/ObjectIn.java
new file mode 100644
index 0000000..4a3e1f1
--- /dev/null
+++ b/tutorial/examples/serialize/ObjectIn.java
@@ -0,0 +1,34 @@
+package examples.serialize;
+
+import java.io.*;
+import java.util.*;
+
+public class ObjectIn extends DataInputStream
+{
+ private Vector readObjects = new Vector();
+
+ public ObjectIn(InputStream is) {
+ super(is);
+ }
+
+ public Marshalable readObject() throws IOException {
+ int id = readInt();
+ if (id == -1) return null; /* -1 implies null */
+ if (id == -2) {
+ id = readInt();
+ return (Marshalable) readObjects.elementAt(id);
+ }
+
+ String classname = readUTF();
+ Marshalable obj;
+ try {
+ obj = (Marshalable) Class.forName(classname).newInstance();
+ } catch (Exception ex) {
+ throw new IOException(ex.toString());
+ }
+ readObjects.addElement(obj);
+ obj.readObject(this);
+
+ return obj;
+ }
+}
diff --git a/tutorial/examples/serialize/ObjectOut.java b/tutorial/examples/serialize/ObjectOut.java
new file mode 100644
index 0000000..eb482c2
--- /dev/null
+++ b/tutorial/examples/serialize/ObjectOut.java
@@ -0,0 +1,36 @@
+package examples.serialize;
+
+import java.io.*;
+import java.util.*;
+
+class ObjectOut extends DataOutputStream
+{
+ private Vector writtenObjects = new Vector();
+
+ public ObjectOut(OutputStream os) {
+ super(os);
+ }
+
+ public void writeObject(Marshalable obj) throws IOException {
+ if (obj == null) {
+ writeInt(-1);
+ } else {
+ int id = 0;
+ int size = writtenObjects.size();
+ for (; id < size; ++id) {
+ if (writtenObjects.elementAt(id) == obj) break;
+ }
+ if (id < size) {
+ /* this object is already written to this stream */
+ writeInt(-2);
+ writeInt(id);
+ } else {
+ /* this object is not regisered in the table */
+ writeInt(id);
+ writtenObjects.addElement(obj);
+ obj.writeObject(this);
+ }
+ }
+ }
+
+}
diff --git a/tutorial/examples/serialize/Point.oj b/tutorial/examples/serialize/Point.oj
new file mode 100644
index 0000000..e7db5f9
--- /dev/null
+++ b/tutorial/examples/serialize/Point.oj
@@ -0,0 +1,29 @@
+package examples.serialize;
+
+import java.io.*;
+
+public class Point
+{
+ int x;
+ int y;
+}
+
+/*
+public class Point implements Marshalable
+{
+ int x;
+ int y;
+
+ public void readObject(ObjectIn is) throws IOException {
+ x = is.readInt();
+ y = is.readInt();
+ }
+
+ public void writeObject(ObjectOut os) throws IOException {
+ os.writeUTF("Point");
+ os.writeInt(x);
+ os.writeInt(y);
+
+ }
+}
+*/
diff --git a/tutorial/examples/serialize/SerializableClass.oj b/tutorial/examples/serialize/SerializableClass.oj
new file mode 100644
index 0000000..b054a78
--- /dev/null
+++ b/tutorial/examples/serialize/SerializableClass.oj
@@ -0,0 +1,121 @@
+package examples.serialize;
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+/**
+ * The class <code>CapsuleClass</code> is a metaclass which
+ * adds methods for serialization of the instances of the class.
+ */
+public class SerializableClass instantiates Metaclass extends OJClass
+{
+ /** Overrides to translate definition of the class */
+ public void translateDefinition() throws MOPException {
+ OJClass baseClass = getSuperclass();
+
+ OJField[] fields = getDeclaredFields();
+
+ addReaderMethod(fields);
+ addWriterMethod(fields);
+ }
+
+ convenient void addReaderMethod(OJField[] fieldsToWrite)
+ throws MOPException
+ {
+ OJClass declaringClass = this;
+ OJModifier modifier = OJModifier.constantEmpty().setPublic();
+ OJClass returnType = OJSystem.VOID;
+ String methodName = "readObject";
+ OJClass[] paramTypes = new OJClass[]{ObjectIn.class};
+ String[] paramNames = new String[]{"in"};
+ OJClass[] exepTypes = new OJClass[]{java.io.IOException.class};
+ OJMethod reader
+ = new OJMethod(this, modifier, returnType, methodName,
+ paramTypes, paramNames, exepTypes, null);
+ addMethod(reader);
+
+ Environment env = reader.getEnvironment();
+ StatementList body = new StatementList();
+ for (int i = 0; i < fieldsToWrite.length; ++i) {
+ body.add(createReadExprFor(env, fieldsToWrite[i]));
+ }
+ reader.setBody(body);
+ }
+
+ Statement createReadExprFor(Environment env, OJField field)
+ throws MOPException
+ {
+ OJClass type = field.getType();
+ String name = field.getName();
+ if (type == OJSystem.STRING) {
+ return makeStatement(env, name + " = in.readUTF();");
+ } else if (type == OJSystem.BYTE) {
+ return makeStatement(env, name + " = in.readByte();");
+ } else if (type == OJSystem.BOOLEAN) {
+ return makeStatement(env, name + " = in.readBoolean();");
+ } else if (type == OJSystem.CHAR) {
+ return makeStatement(env, name + " = in.readChar();");
+ } else if (type == OJSystem.INT) {
+ return makeStatement(env, name + " = in.readInt();");
+ } else if (type == OJSystem.LONG) {
+ return makeStatement(env, name + " = in.readLong();");
+ } else if (type.isArray()) {
+ return null; /* not implemented yet. */
+ } else if (! type.isPrimitive()) {
+ return makeStatement(env, name + " = in.readObject();");
+ }
+ return null;
+ }
+
+ convenient void addWriterMethod(OJField[] fieldsToWrite)
+ throws MOPException
+ {
+ OJClass declaringClass = this;
+ OJModifier modifier = OJModifier.constantEmpty().setPublic();
+ OJClass returnType = OJSystem.VOID;
+ String methodName = "writeObject";
+ OJClass[] paramTypes = new OJClass[]{ObjectOut.class};
+ String[] paramNames = new String[]{"out"};
+ OJClass[] exepTypes = new OJClass[]{java.io.IOException.class};
+ OJMethod writer
+ = new OJMethod(this, modifier, returnType, methodName,
+ paramTypes, paramNames, exepTypes, null);
+ addMethod(writer);
+
+ Environment env = writer.getEnvironment();
+ StatementList body = new StatementList();
+ body.add(makeStatement(env, "out.writeUTF(\"" + getName() + "\");"));
+ for (int i = 0; i < fieldsToWrite.length; ++i) {
+ body.add(createWriteExprFor(env, fieldsToWrite[i]));
+ }
+ writer.setBody(body);
+ }
+
+ Statement createWriteExprFor(Environment env, OJField field)
+ throws MOPException
+ {
+ OJClass type = field.getType();
+ String name = field.getName();
+ if (type == OJSystem.STRING) {
+ return makeStatement(env, "out.writeUTF(" + name + ");");
+ } else if (type == OJSystem.BYTE) {
+ return makeStatement(env, "out.writeByte(" + name + ");");
+ } else if (type == OJSystem.BOOLEAN) {
+ return makeStatement(env, "out.writeBoolean(" + name + ");");
+ } else if (type == OJSystem.CHAR) {
+ return makeStatement(env, "out.writeChar(" + name + ");");
+ } else if (type == OJSystem.INT) {
+ return makeStatement(env, "out.writeInt(" + name + ");");
+ } else if (type == OJSystem.LONG) {
+ return makeStatement(env, "out.writeLong(" + name + ");");
+ } else if (type.isArray()) {
+ return null; /* not implemented yet. */
+ } else if (! type.isPrimitive()) {
+ return makeStatement(env, "out.writeObject(" + name + ");");
+ }
+ return null;
+ }
+
+}
diff --git a/tutorial/examples/syntax/ErrorTest.java b/tutorial/examples/syntax/ErrorTest.java
new file mode 100644
index 0000000..2dbff68
--- /dev/null
+++ b/tutorial/examples/syntax/ErrorTest.java
@@ -0,0 +1,97 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * Simple.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.syntax;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class ErrorTest extends Panel
+{
+
+ private int iii = 0;
+
+ private Vector v;
+
+ private ErrorTest n = null;
+
+ private String str = "string";
+
+ private static final String DEF = "<default>";
+
+ public ErrorTest()
+ {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main( String[] args )
+ {}
+
+ public String toString()
+ {
+ if (n == null) {
+ return str;
+ }
+ return str + n;
+ }
+
+ public void hoge()
+ throws Exception
+ {}
+
+ public void hoge1()
+ {}
+
+ public void hoge2()
+ {}
+
+ public void hoge2( String[] args )
+ {}
+
+ public void f()
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f1()
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f2()
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f3()
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void g1()
+ {}
+
+ public void g2()
+ {}
+
+}
diff --git a/tutorial/examples/syntax/ErrorTest.oj b/tutorial/examples/syntax/ErrorTest.oj
new file mode 100644
index 0000000..78b54b7
--- /dev/null
+++ b/tutorial/examples/syntax/ErrorTest.oj
@@ -0,0 +1,96 @@
+/*
+ * Simple.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.syntax;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class ErrorTest instantiates RichSyntaxClass
+ extends Panel
+ loves CreamPuff[]
+ hates Pimento/*, Apple*/
+ adapts Vector in v to Stack
+{
+ private int iii = 0;
+ private Vector v;
+
+ private ErrorTest n = null;
+
+ private String str = "string";
+ private final static String DEF = "<default>";
+
+ public ErrorTest() {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static remote void main( String[] args ) loves Apple
+ {
+ }
+
+ public String toString() forwards Apple Power Macintosh {
+ if (n == null) return str;
+ return str + n;
+ }
+
+ public void hoge() throws Exception keeps (iii == 0) {}
+ public void hoge1() keeps DEF.equals( "string" ) {}
+ public void hoge2() keeps ErrorTest.DEF.equals( "string" ) {}
+ public void hoge2( String[] args ) keeps (args.length == 1) {}
+
+ public void f() {
+ System.out.println( "Hello" );
+ }
+
+ public void f1()
+ before {
+ System.out.println( "before" );
+ . errorhere;
+ }
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f2()
+ after {
+ System.out.println( "after" );
+ }
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f3()
+ after {
+ System.out.println( "after" );
+ }
+ before {
+ System.out.println( "before" );
+ }
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void g1() chooses { System.out.println( "ErrorTest" ); }
+ {}
+
+ public void g2() chooses Object[]
+ {}
+
+}
diff --git a/tutorial/examples/syntax/RichSyntaxClass.java b/tutorial/examples/syntax/RichSyntaxClass.java
new file mode 100644
index 0000000..ca22914
--- /dev/null
+++ b/tutorial/examples/syntax/RichSyntaxClass.java
@@ -0,0 +1,129 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * RichSyntaxClass.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.syntax;
+
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+public class RichSyntaxClass extends OJClass
+{
+
+ public void translateDefinition()
+ {
+ String[] str = new String[]{ "hates", "loves", "keeps", "forwards", "before", "after", "chooses", "adapts" };
+ for (int i = 0; i < str.length; ++i) {
+ ParseTree suffix;
+ suffix = this.getSuffix( str[i] );
+ if (suffix != null) {
+ System.out.println( this.toString() + " involves a suffix " + " ( " + str[i] + " ):" );
+ System.out.println( "\t" + suffix );
+ }
+ OJMethod[] methods = getDeclaredMethods();
+ for (int j = 0; j < methods.length; ++j) {
+ suffix = methods[j].getSuffix( str[i] );
+ if (suffix != null) {
+ System.out.println( methods[j].toString() + " involves a suffix " + " ( " + str[i] + " ):" );
+ System.out.println( "\t" + suffix );
+ }
+ }
+ }
+ }
+
+ public static boolean isRegisteredKeyword( String keyword )
+ {
+ if (keyword.equals( "hates" )) {
+ return true;
+ }
+ if (keyword.equals( "loves" )) {
+ return true;
+ }
+ if (keyword.equals( "keeps" )) {
+ return true;
+ }
+ if (keyword.equals( "forwards" )) {
+ return true;
+ }
+ if (keyword.equals( "before" )) {
+ return true;
+ }
+ if (keyword.equals( "after" )) {
+ return true;
+ }
+ if (keyword.equals( "chooses" )) {
+ return true;
+ }
+ if (keyword.equals( "adapts" )) {
+ return true;
+ }
+ return OJClass.isRegisteredKeyword( keyword );
+ }
+
+ public static SyntaxRule getDeclSuffixRule( String keyword )
+ {
+ if (keyword.equals( "hates" )) {
+ return new NameRule();
+ }
+ if (keyword.equals( "loves" )) {
+ return new TypeNameRule();
+ }
+ if (keyword.equals( "keeps" )) {
+ return new ExpressionRule();
+ }
+ if (keyword.equals( "forwards" )) {
+ return new IterationRule( new TypeNameRule(), false );
+ }
+ if (keyword.equals( "before" ) || keyword.equals( "after" )) {
+ return new BlockRule();
+ }
+ if (keyword.equals( "chooses" ) || keyword.equals( "after" )) {
+ return new SelectionRule( new TypeNameRule(), new BlockRule() );
+ }
+ if (keyword.equals( "adapts" ) || keyword.equals( "after" )) {
+ return new CompositeRule( new NameRule(), new PrepPhraseRule( "in", new NameRule() ), new PrepPhraseRule( "to", new NameRule() ) );
+ }
+ return OJClass.getDeclSuffixRule( keyword );
+ }
+
+ public static SyntaxRule getTypeSuffixRule( String keyword )
+ {
+ return OJClass.getTypeSuffixRule( keyword );
+ }
+
+ public static boolean isRegisteredModifier( String keyword )
+ {
+ if (keyword.equals( "remote" )) {
+ return true;
+ }
+ if (keyword.equals( "crazy" )) {
+ return true;
+ }
+ return false;
+ }
+
+ public RichSyntaxClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public RichSyntaxClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/syntax/RichSyntaxClass.oj b/tutorial/examples/syntax/RichSyntaxClass.oj
new file mode 100644
index 0000000..61005a7
--- /dev/null
+++ b/tutorial/examples/syntax/RichSyntaxClass.oj
@@ -0,0 +1,102 @@
+/*
+ * RichSyntaxClass.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.syntax;
+
+
+import java.lang.Object;
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+public class RichSyntaxClass instantiates Metaclass extends OJClass
+{
+ public void translateDefinition() {
+ String[] str = new String[] {
+ "hates", "loves", "keeps", "forwards", "before", "after",
+ "chooses", "adapts", "pre" };
+ for (int i = 0; i < str.length; ++i) {
+ ParseTree suffix;
+ suffix = this.getSuffix( str[i] );
+ if (suffix != null) {
+ System.out.println( this.toString() + " involves a suffix " +
+ " \"" + str[i] + "\" :" );
+ System.out.println( "\t" + suffix );
+ }
+ OJMethod[] methods = getDeclaredMethods();
+ for (int j = 0; j < methods.length; ++j) {
+ suffix = methods[j].getSuffix( str[i] );
+ if (suffix != null) {
+ System.out.println( methods[j].toString() +
+ " involves a suffix " +
+ " ( " + str[i] + " ):" );
+ System.out.println( "\t" + suffix );
+ }
+ }
+ }
+ }
+
+ public static boolean isRegisteredKeyword( String keyword ) {
+ if (keyword.equals( "replacedBy" )) return true;
+ if (keyword.equals( "hates" )) return true;
+ if (keyword.equals( "loves" )) return true;
+ if (keyword.equals( "keeps" )) return true;
+ if (keyword.equals( "forwards" )) return true;
+ if (keyword.equals( "before" )) return true;
+ if (keyword.equals( "after" )) return true;
+ if (keyword.equals( "chooses" )) return true;
+ if (keyword.equals( "adapts" )) return true;
+ if (keyword.equals( "pre" )) return true;
+ return OJClass.isRegisteredKeyword( keyword );
+ }
+
+ public static SyntaxRule getDeclSuffixRule( String keyword ) {
+ if (keyword.equals( "hates" )) return new NameRule();
+ if (keyword.equals( "loves" )) return new TypeNameRule();
+ if (keyword.equals( "keeps" )) return new ExpressionRule();
+ if (keyword.equals( "forwards" )) {
+ return new IterationRule( new TypeNameRule(), false );
+ }
+ if (keyword.equals( "before" ) || keyword.equals( "after" )) {
+ return new BlockRule();
+ }
+ if (keyword.equals( "chooses" ) || keyword.equals( "after" )) {
+ return new SelectionRule( new TypeNameRule(), new BlockRule() );
+ }
+ if (keyword.equals( "adapts" ) || keyword.equals( "after" )) {
+ return new CompositeRule(
+ new NameRule(),
+ new PrepPhraseRule( "in", new NameRule() ),
+ new PrepPhraseRule( "to", new NameRule() ) );
+ }
+ return OJClass.getDeclSuffixRule( keyword );
+ }
+
+ public static SyntaxRule getDeclSuffixRule(Environment env,
+ String keyword)
+ {
+ if (keyword.equals("pre")) return new ExpressionRule(env);
+ return OJClass.getDeclSuffixRule(env, keyword);
+ }
+
+ public static SyntaxRule getTypeSuffixRule( String keyword ) {
+ if (keyword.equals( "replacedBy" )) return new TypeNameRule();
+ return OJClass.getTypeSuffixRule( keyword );
+ }
+
+ public static boolean isRegisteredModifier( String keyword ) {
+ if (keyword.equals( "remote" )) return true;
+ if (keyword.equals( "crazy" )) return true;
+ return false;
+ }
+
+}
diff --git a/tutorial/examples/syntax/Test.java b/tutorial/examples/syntax/Test.java
new file mode 100644
index 0000000..f9ad1c5
--- /dev/null
+++ b/tutorial/examples/syntax/Test.java
@@ -0,0 +1,97 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * Simple.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.syntax;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test extends Panel
+{
+
+ private int iii = 0;
+
+ private Vector v;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ private static final String DEF = "<default>";
+
+ public Test()
+ {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main( String[] args )
+ {}
+
+ public String toString()
+ {
+ if (n == null) {
+ return str;
+ }
+ return str + n;
+ }
+
+ public void hoge()
+ throws Exception
+ {}
+
+ public void hoge1()
+ {}
+
+ public void hoge2()
+ {}
+
+ public void hoge2( String[] args )
+ {}
+
+ public void f()
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f1()
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f2()
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f3()
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void g1()
+ {}
+
+ public void g2()
+ {}
+
+}
diff --git a/tutorial/examples/syntax/Test.oj b/tutorial/examples/syntax/Test.oj
new file mode 100644
index 0000000..763945a
--- /dev/null
+++ b/tutorial/examples/syntax/Test.oj
@@ -0,0 +1,96 @@
+/*
+ * Simple.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.syntax;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test instantiates RichSyntaxClass
+ extends Panel
+ loves CreamPuff[]
+ hates Pimento/*, Apple*/
+ adapts Vector in v to Stack
+{
+ private int iii = 0;
+ private Vector v;
+
+ private Test n = null;
+
+ private String str = "string";
+ private final static String DEF = "<default>";
+
+ public Test() {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static remote void main( String[] args ) loves Apple
+ {
+ }
+
+ public String toString() forwards Apple Power Macintosh {
+ if (n == null) return str;
+ return str + n;
+ }
+
+ public void hoge() throws Exception keeps (iii == 0) {}
+ public void hoge1() keeps DEF.equals( "string" ) {}
+ public void hoge2() keeps Test.DEF.equals( "string" ) {}
+ public void hoge2( String[] args ) keeps (args.length == 1) {}
+ public void hoge3(int arg) pre arg > 1 {}
+
+ public void f() {
+ System.out.println( "Hello" );
+ }
+
+ public void f1()
+ before {
+ System.out.println( "before" );
+ }
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f2()
+ after {
+ System.out.println( "after" );
+ }
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void f3()
+ before {
+ System.out.println( "before" );
+ }
+ after {
+ System.out.println( "after" );
+ }
+ {
+ System.out.println( "Hello" );
+ }
+
+ public void g1() chooses { System.out.println( "Test" ); }
+ {}
+
+ public void g2() chooses Object[]
+ {}
+
+}
diff --git a/tutorial/examples/verbose/Hello.java b/tutorial/examples/verbose/Hello.java
new file mode 100644
index 0000000..4f6cebb
--- /dev/null
+++ b/tutorial/examples/verbose/Hello.java
@@ -0,0 +1,22 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.verbose;
+
+
+public class Hello
+{
+
+ public static void main( java.lang.String[] argv )
+ {
+ java.lang.System.out.println( "public static void examples.verbose.Hello.main(java.lang.String[]) was called" );
+ hello();
+ }
+
+ static void hello()
+ {
+ java.lang.System.out.println( "static void examples.verbose.Hello.hello() was called" );
+ System.out.println( "Hello, world." );
+ }
+
+}
diff --git a/tutorial/examples/verbose/Hello.oj b/tutorial/examples/verbose/Hello.oj
new file mode 100644
index 0000000..0267289
--- /dev/null
+++ b/tutorial/examples/verbose/Hello.oj
@@ -0,0 +1,13 @@
+package examples.verbose;
+
+
+public class Hello instantiates VerboseClass
+{
+ public static void main(String[] argv) {
+ hello();
+ }
+
+ static void hello() {
+ System.out.println("Hello, world.");
+ }
+}
diff --git a/tutorial/examples/verbose/Test.java b/tutorial/examples/verbose/Test.java
new file mode 100644
index 0000000..7b60da7
--- /dev/null
+++ b/tutorial/examples/verbose/Test.java
@@ -0,0 +1,98 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.verbose;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test extends java.awt.Panel
+{
+
+ private int iii = 0;
+
+ private examples.verbose.Test n = null;
+
+ private java.lang.String str = "string";
+
+ public Test()
+ {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main( java.lang.String[] argv )
+ {
+ java.lang.System.out.println( "public static void examples.verbose.Test.main(java.lang.String[]) was called" );
+ java.io.PrintStream out = System.out;
+ java.io.PrintStream error = java.lang.System.err;
+ out.println( "Hello" + " " + "World" );
+ examples.verbose.Test n = new examples.verbose.Test();
+ java.lang.System.err.println( "done. " );
+ examples.verbose.Test test = new examples.verbose.Test();
+ test.hoge();
+ test.foo();
+ }
+
+ public void hoge()
+ {
+ java.lang.System.out.println( "public void examples.verbose.Test.hoge() was called" );
+ examples.verbose.Local l = new examples.verbose.Local();
+ System.out.println( l.foo );
+ System.out.println( l.bar.str );
+ }
+
+ public Test( java.lang.String str )
+ {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo()
+ {
+ java.lang.System.out.println( "public int examples.verbose.Test.foo() was called" );
+ return iii;
+ }
+
+ public java.lang.String toString()
+ {
+ java.lang.System.out.println( "public java.lang.String examples.verbose.Test.toString() was called" );
+ if (n == null) {
+ return str;
+ }
+ return str + n;
+ }
+
+}
+
+
+class Local
+{
+
+ java.lang.String foo = null;
+
+ examples.verbose.Local2 bar = new examples.verbose.Local2();
+
+ public final java.lang.String getFoo( java.lang.Integer i )
+ {
+ java.lang.System.out.println( "public final java.lang.String examples.verbose.Local.getFoo(java.lang.Integer) was called" );
+ return foo;
+ }
+
+}
+
+
+class Local2
+{
+
+ java.lang.String str = "" + "TEST";
+
+}
diff --git a/tutorial/examples/verbose/Test.oj b/tutorial/examples/verbose/Test.oj
new file mode 100644
index 0000000..24de2ea
--- /dev/null
+++ b/tutorial/examples/verbose/Test.oj
@@ -0,0 +1,73 @@
+package examples.verbose;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test instantiates VerboseClass
+ extends Panel
+{
+ private int iii = 0;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ public Test() {
+ 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" );
+ Test n = new Test();
+ java.lang.System.err.println( "done. " );
+ Test test = new Test();
+ test.hoge();
+ test.foo();
+ }
+
+ public void hoge() {
+ Local l = new Local();
+ System.out.println( l.foo );
+ System.out.println( l.bar.str );
+ }
+
+ public Test( String str ) {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo() {
+ return iii;
+ }
+
+ public String toString() {
+ if (n == null) return str;
+ return str + n;
+ }
+
+}
+
+class Local instantiates VerboseClass
+{
+ String foo = null;
+ Local2 bar = new Local2();
+ public final String getFoo( Integer i ) {
+ return foo;
+ }
+}
+
+class Local2
+{
+ String str = "" + "TEST";
+}
diff --git a/tutorial/examples/verbose/VerboseClass.java b/tutorial/examples/verbose/VerboseClass.java
new file mode 100644
index 0000000..ef74480
--- /dev/null
+++ b/tutorial/examples/verbose/VerboseClass.java
@@ -0,0 +1,45 @@
+/*
+ * This code was generated by ojc.
+ */
+/*
+ * VerboseClass.java
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.verbose;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+public class VerboseClass extends openjava.mop.OJClass
+{
+
+ /* overrides for translation */
+ public void translateDefinition()
+ throws openjava.mop.MOPException
+ {
+ openjava.mop.OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ openjava.ptree.Statement printer = makeStatement( "java.lang.System.out.println( \"" + methods[i].toString() + " was called\" );" );
+ methods[i].getBody().insertElementAt( printer, 0 );
+ }
+ }
+
+ public VerboseClass( openjava.mop.Environment oj_param0, openjava.mop.OJClass oj_param1, openjava.ptree.ClassDeclaration oj_param2 )
+ {
+ super( oj_param0, oj_param1, oj_param2 );
+ }
+
+ public VerboseClass( java.lang.Class oj_param0, openjava.mop.MetaInfo oj_param1 )
+ {
+ super( oj_param0, oj_param1 );
+ }
+
+}
diff --git a/tutorial/examples/verbose/VerboseClass.oj b/tutorial/examples/verbose/VerboseClass.oj
new file mode 100644
index 0000000..a6ac099
--- /dev/null
+++ b/tutorial/examples/verbose/VerboseClass.oj
@@ -0,0 +1,30 @@
+/*
+ * VerboseClass.java
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.verbose;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+
+
+public class VerboseClass instantiates Metaclass extends OJClass
+{
+ /* 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/tutorial/examples/verbose2/Test.java b/tutorial/examples/verbose2/Test.java
new file mode 100644
index 0000000..50848fb
--- /dev/null
+++ b/tutorial/examples/verbose2/Test.java
@@ -0,0 +1,98 @@
+/*
+ * This code was generated by ojc.
+ */
+package examples.verbose2;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test extends Panel
+{
+
+ private int iii = 0;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ public Test()
+ {
+ super();
+ }
+
+ /**
+ * @param
+ * @return
+ * @exception
+ * @see java.lang.Object
+ */
+ public static void main( String[] argv )
+ {
+ java.lang.System.out.println( "main is called." );
+ PrintStream out = System.out;
+ PrintStream error = java.lang.System.err;
+ out.println( "Hello" + " " + "World" );
+ Test n = new Test();
+ java.lang.System.err.println( "done. " );
+ Test test = new Test();
+ test.hoge();
+ test.foo();
+ }
+
+ public void hoge()
+ {
+ java.lang.System.out.println( "hoge is called." );
+ Local l = new Local();
+ System.out.println( l.foo );
+ System.out.println( l.bar.str );
+ }
+
+ public Test( String str )
+ {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo()
+ {
+ java.lang.System.out.println( "foo is called." );
+ return iii;
+ }
+
+ public String toString()
+ {
+ java.lang.System.out.println( "toString is called." );
+ if (n == null) {
+ return str;
+ }
+ return str + n;
+ }
+
+}
+
+
+class Local
+{
+
+ String foo = null;
+
+ Local2 bar = new Local2();
+
+ public final String getFoo( Integer i )
+ {
+ java.lang.System.out.println( "getFoo is called." );
+ return foo;
+ }
+
+}
+
+
+class Local2
+{
+
+ String str = "" + "TEST";
+
+}
diff --git a/tutorial/examples/verbose2/Test.oj b/tutorial/examples/verbose2/Test.oj
new file mode 100644
index 0000000..c882183
--- /dev/null
+++ b/tutorial/examples/verbose2/Test.oj
@@ -0,0 +1,73 @@
+package examples.verbose2;
+
+
+import java.awt.Panel;
+import java.util.*;
+import java.io.PrintStream;
+
+
+public class Test instantiates VerboseClass
+ extends Panel
+{
+ private int iii = 0;
+
+ private Test n = null;
+
+ private String str = "string";
+
+ public Test() {
+ 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" );
+ Test n = new Test();
+ java.lang.System.err.println( "done. " );
+ Test test = new Test();
+ test.hoge();
+ test.foo();
+ }
+
+ public void hoge() {
+ Local l = new Local();
+ System.out.println( l.foo );
+ System.out.println( l.bar.str );
+ }
+
+ public Test( String str ) {
+ this.str = str;
+ n = null;
+ }
+
+ public int foo() {
+ return iii;
+ }
+
+ public String toString() {
+ if (n == null) return str;
+ return str + n;
+ }
+
+}
+
+class Local instantiates VerboseClass
+{
+ String foo = null;
+ Local2 bar = new Local2();
+ public final String getFoo( Integer i ) {
+ return foo;
+ }
+}
+
+class Local2
+{
+ String str = "" + "TEST";
+}
diff --git a/tutorial/examples/verbose2/VerboseClass.java b/tutorial/examples/verbose2/VerboseClass.java
new file mode 100644
index 0000000..1e6cdf0
--- /dev/null
+++ b/tutorial/examples/verbose2/VerboseClass.java
@@ -0,0 +1,50 @@
+/*
+ * VerboseClass.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1999 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package examples.verbose2;
+
+
+import openjava.mop.*;
+import openjava.ptree.*;
+import openjava.syntax.*;
+import openjava.ptree.util.PartialParser;
+
+
+public class VerboseClass extends OJClass
+{
+
+ /* overrides for translation */
+ public void translateDefinition() throws MOPException {
+ OJMethod[] methods = getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ StatementList body = methods[i].getBody();
+ String str = PartialParser.replace(
+ "java.lang.System.out.println( \"#s\" );",
+ methods[i].getName() + " is called."
+ );
+ Statement printer = makeStatement( str );
+ body.insertElementAt( printer, 0 );
+ }
+ }
+
+ /* constructor */
+
+ public VerboseClass( Environment outer_env, OJClass declarer,
+ ClassDeclaration ptree ) {
+ super( outer_env, declarer, ptree );
+ }
+
+ public VerboseClass( Class javaclass, MetaInfo minfo ) {
+ super( javaclass, minfo );
+ }
+
+}
+
diff --git a/tutorial/images/comflow.gif b/tutorial/images/comflow.gif
new file mode 100644
index 0000000..f995bb2
--- /dev/null
+++ b/tutorial/images/comflow.gif
Binary files differ
diff --git a/tutorial/index.html b/tutorial/index.html
new file mode 100644
index 0000000..353f999
--- /dev/null
+++ b/tutorial/index.html
@@ -0,0 +1,83 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+
+
+<head>
+<title>OpenJava : Tutorial</title>
+<meta http-equiv="Keywords" content="java, openjava, reflection">
+</head>
+
+
+<body bgcolor="white"
+ text="#000000" link="#007fff" vlink="#006fdf" alink="#ff0000">
+
+
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+<h1><font color="Blue">OpenJava Tutorial</font></h1>
+
+</center>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+<h2><font color="blue">Index</font></h2>
+
+
+<ul>
+<li><a href="Introduction.html"
+ >1. Introduction</a><br>
+<li><a href="VerboseClass.html"
+ >2. Hello World</a><br>
+<li><a href="Overview.html"
+ >3. API and Framework at a Glance</a><br>
+<li><a href="Override.html"
+ >4. Example : Override Checker</a><br>
+ A simple syntax extension example of custom modifiers.
+<li><a href="AutoImpl.html"
+ >5. Example : Automatic Methods Implementation</a><br>
+ A callee-side translation example.
+<li><a href="FreeArgs.html"
+ >6. (Under Construction) Example : Free Arguments</a><br>
+ A caller-side translation example.
+<li><a href="Synchronize.html"
+ >7. Synchronization of Translation</a><br>
+ A synchronization of translation among several class metaobjects.
+<li><a href="Syntax.html"
+ >8. (Not Written) Syntax Customization</a><br>
+<li><a href="Adapter.html"
+ >9. (Not Written) Example : Adapter Pattern Support</a><br>
+</ul>
+
+
+<!---------------------------------------------------------------------->
+<hr width="100%">
+<!---------------------------------------------------------------------->
+
+
+<center>
+
+Please send any message to :
+<address>
+mich@acm.org
+</address><BR>
+
+</center>
+
+
+<font size=1>Copyright (C) 1999 by Michaki Tatsubori.</font><br>
+<font size=1>Java(TM) is a trademark of Sun Microsystems, Inc.</font>
+
+
+<!---------------------------------------------------------------------->
+
+
+</body>
+
+
+</html>