edu.mit.ai.psg.jeva
Class GenerateRepresentationClass

java.lang.Object
  |
  +--edu.mit.ai.psg.jeva.GenerateRepresentationClass

public class GenerateRepresentationClass
extends Object
implements JevaParserConstants

Generate a file which can be compiled to generate the representation class for an interpreted object from its InterpretedClass. The representation class has the correct signature for the class, but calls interpreted methods and constructors for all its operations.

Example class: [Note: class names are shown without package names, but interpreter classes are generated with their full names. Importing the interpreter classes might override another name.]

class NamedAccount extends NamedObject implements IAccount {
int myBalance;
Account(int initBalance) { myBalance = initBalance; } // simple
Account(String name, int initBalance) throws DuplicateNameException { 
super(UI.approveUserName("Acct:"+name), name);//example multi arg super
myBalance = initBalance; 
}
synchronized int balance() { return myBalance; }
synchronized void deposit(int amount) {
myBalance += amount; }
synchronized void withdraw(int amount) throws OverdraftException {
if (amount <= myBalance) 
myBalance -= amount;
else throw new OverdraftException();
}
Example generated class:
   
class Account extends Object implements IAccount, IInterpretedObject {
private static InterpretedClass $myIClass;
int myBalance;
Account(int initBalance) { 
super();
$myIClass.evalObjectInitializers(this);
$myIClass.evalConstructorBody
(new IClass[]{String.class, int.class},
this, new Object[]{name, new Integer(initBalance)});
}
Account(final String name, final int initBalance)
throws DuplicateNameException {
super
(new Object() {
String run() throws DuplicateNameException {
try { 
return (String) 
$myIClass.evalExplicitConstructorCallParameter
(new IClass[]{
WrappedClass.wrapClass(String.class),
WrappedClass.wrapClass(int.class)}, 0,
new Object[]{name, new Integer(initBalance)});
} 
catch (ThrowException $e) {
if ($e.getThrown() instanceof DuplicateNameException)
throw (DuplicateNameException) $e.getThrown();
else throw new Error("Shouldn't reach here "+
"(undeclared exception): "+$e.getThrown());
}
}
}.run(),
new Object() {
String run() throws DuplicateNameException {
try { 
return (String) 
$myIClass.evalExplicitConstructorCallParameter
(new IClass[]{String.class, int.class}, 1,
new Object[]{name, new Integer(initBalance)})
} 
catch (ThrowException $e) {
if ($e.getThrown() instanceof DuplicateNameException)
throw (DuplicateNameException) $e.getThrown();
else throw new Error("Shouldn't reach here "+
"(undeclared exception): "+$e.getThrown());
}
}
}.run());
$myIClass.runObjectInitializers(this);
try { 
$myIClass.evalConstructorBody
(new IClass[]{String.class, int.class},
this, new Object[]{name, new Integer(initBalance)});
} 
catch (ThrowException $e) {
if ($e.getThrown() instanceof DuplicateNameException)
throw (DuplicateNameException) $e.getThrown();
else throw new Error("Shouldn't reach here "+
"(undeclared exception): "+$e.getThrown());
}
}
synchronized int balance() { 
return ((Integer)$myIClass.invokeMethod("balance", new IClass[]{},
this, new Object[]{}))
.intValue();
}
synchronized void deposit(int amount) {
$myIClass.invokeMethod("deposit", new IClass[]{TypeMethods.intIClass}, 
this, new Object[]{new Integer(amount)});       
}
synchronized void withdraw(int amount) throws OverdraftException {
try { 
$myIClass.invokeMethod("withdraw",
new Class[]{TypeMethods.intIClass}, 
this, new Object[]{new Integer(amount)});
}
catch (InvocationTargetException $e) {
if ($e.getTargetException() instanceof OverdraftException)
throw (OverdraftException) $e.getTargetException();
else throw new Error("Shouldn't reach here "+
"(undeclared exception): "+
$e.getTargetException());
}
}
}


Inner Class Summary
static interface GenerateRepresentationClass.GeneratingError
          Error used to capture context of internal errors thrown while generating.
static class GenerateRepresentationClass.IndentingPrintWriter
          PrintWriter that adds an indentation after every call to println()
 
Constructor Summary
GenerateRepresentationClass()
           
 
Method Summary
static String generateSource(InterpretedClass iClass)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenerateRepresentationClass

public GenerateRepresentationClass()
Method Detail

generateSource

public static String generateSource(InterpretedClass iClass)

Copyright (c) 1996-1999
Massachusetts Institute of Technology

Feedback: jeva-bugs@ai.mit.edu