/*
* 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 RTReflClass
patches the class
* implementing Writable
to implement Printable
.
*/
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 );
}
}