diff options
author | Kenny Ballou <kballou@devnulllabs.io> | 2018-11-19 22:59:50 -0700 |
---|---|---|
committer | Kenny Ballou <kballou@devnulllabs.io> | 2018-11-19 22:59:50 -0700 |
commit | ea3e1b949dcbdc09518f17eee0bcf21d41d76896 (patch) | |
tree | 7ec7a7fb4df67815a9b7bb0e4d95d67c4050e2a2 /tutorial/examples/bca/AutoAdaptationClass.oj | |
download | openjava-ea3e1b949dcbdc09518f17eee0bcf21d41d76896.tar.gz openjava-ea3e1b949dcbdc09518f17eee0bcf21d41d76896.tar.xz |
OJ (aka OpenJava) modernization/mirroring
Signed-off-by: Kenny Ballou <kballou@devnulllabs.io>
Diffstat (limited to 'tutorial/examples/bca/AutoAdaptationClass.oj')
-rw-r--r-- | tutorial/examples/bca/AutoAdaptationClass.oj | 48 |
1 files changed, 48 insertions, 0 deletions
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 );
+ }
+}
|