In attempting to work around the anonymous class problem. I decided to generate inner classes for the attributes' Event classes instead of using anonymous classes.
I found "OJClass.addClass(OJClass cls)" but no "Class makeClass(Environment env, String expr)" method exists in OJClass, analogous to the "Statement makeStatement(Environment env, String expr)" method. So I attempted to create my own:
protected OJClass
makeClass(Environment env, String str)
throws MOPException
{
Parser parser = new Parser(new StringReader(str));
OJClass result;
try {
ClassEnvironment cenv = new ClassEnvironment(env, env.currentClassName());
ClassDeclaration ptree = parser.ClassDeclaration(cenv);
result = new OJClass(env, this, ptree);
} catch (Exception e) {
System.err.println("makeClass(" + env + ", " + str + ")");
System.err.println( "partial parsing failed for : " + str );
System.err.println( e );
System.err.println( env.toString() );
throw new MOPException( e );
}
return result;
}
I get the following error:
OJClass.forNameAnyway() failed for : sonema.mutate.test.Color openjava.mop.OJClassNotFoundException: sonema.mutate.test.Color
Am I constructing the ClassEnvironment for parser.ClassDeclaration(cenv) incorrectly?
In attempting to work around the anonymous class problem. I decided to generate inner classes for the attributes' Event classes instead of using anonymous classes.
I found "OJClass.addClass(OJClass cls)" but no "Class makeClass(Environment env, String expr)" method exists in OJClass, analogous to the "Statement makeStatement(Environment env, String expr)" method. So I attempted to create my own:
protected OJClass
makeClass(Environment env, String str)
throws MOPException
{
Parser parser = new Parser(new StringReader(str));
OJClass result;
try {
ClassEnvironment cenv = new ClassEnvironment(env, env.currentClassName());
ClassDeclaration ptree = parser.ClassDeclaration(cenv);
result = new OJClass(env, this, ptree);
} catch (Exception e) {
System.err.println("makeClass(" + env + ", " + str + ")");
System.err.println( "partial parsing failed for : " + str );
System.err.println( e );
System.err.println( env.toString() );
throw new MOPException( e );
}
return result;
}
I get the following error:
OJClass.forNameAnyway() failed for : sonema.mutate.test.Color openjava.mop.OJClassNotFoundException: sonema.mutate.test.Color
Am I constructing the ClassEnvironment for parser.ClassDeclaration(cenv) incorrectly?
Thanks Again,
Kurt Stephens
=================================================================================
Kurt Stephens wrote:
> OpenJava1.1_20020522
>
> I have designed a metaclass that generates anonymous classes for undo/redo support of instance variables by generating setter methods.
>
> OpenJava fails when translating callee side assignments into setter methods and generates errors at openjava/ptree/util/MemberAccessCorrector.java:74 :
>
> unknown field or variable : __oj_newValue
> unknown field or variable : __oj_oldValue
>
> Using -calleroff does not change anything.
>
>
> The generated setter method for "int sonema.mutate.test.Point.x" that fails to be reparsed:
>
> public int set_x( int oj_param0 )
> {
> if (x == oj_param0) {
> return x;
> } else {
> sonema.mutate.Event __oj_event = new sonema.mutate.Event(){
> int __oj_oldValue = x;
>
> int __oj_newValue = oj_param0;
>
> public void redo()
> {
> x = __oj_newValue;
> }
>
> public void undo()
> {
> x = __oj_oldValue;
> }
> };
> x = oj_param0;
> sonema.mutate.EventConsumer.dispatchMutation( __oj_event );
> return x;
> }
> }
>
> OpenJava seems to have a problem with scoping anonymous class' instance variables inside its method bodies.
>
> Here's the output of ojc.sh:
> =====================================================================================
>
> + ojc.sh -d=../../gumo/JVM/od sonema/mutate/test/ColoredPoint.oj sonema/mutate/test/Color.oj sonema/mutate/test/Point.oj
> java openjava.ojc.Main -d=../../gumo/JVM/od sonema/mutate/test/ColoredPoint.oj sonema/mutate/test/Color.oj sonema/mutate/test/Point.oj
> OpenJava Compiler Version 1.0a build 20011127
> Generating parse tree.
> ..done.
>
> Initializing parse tree.
> ..done.
>
> Translating callee side
> Tracing field mutation : public int sonema.mutate.test.Point.x
> expr = if ( x == oj_param0 ) { return x; } else { sonema.mutate.Event __oj_event = new sonema.mutate.Event() { int __oj_oldValue = x; int __oj_newValue = oj_param0; public void redo() { x = (__oj_newValue); } public void undo() { x = (__oj_oldValue); } } ; x = oj_param0; sonema.mutate.EventConsumer.dispatchMutation(__oj_event); return x; }
> unknown field or variable : __oj_newValue
> ClosedEnvironment
> class object table : {}
> binding table : {}
> parent env : ClosedEnvironment
> class object table : {}
> binding table : {__oj_event=class sonema.mutate.Event}
> parent env : ClosedEnvironment
> class object table : {}
> binding table : {}
> parent env : ClosedEnvironment
> class object table : {}
> binding table : {oj_param0=int}
> parent env : ClassEnvironment
> class : Point
> member classes : []
> parent env : FileEnvironment
> package : sonema.mutate.test
> main class : Point
> local classes : imported classes : sonema.mutate.TraceableClass imported packages : java.lang local class table : {}
> parent env : GlobalEnvironment
> class object table : {sonema.mutate.test.ColoredPoint=class sonema.mutate.test.ColoredPoint, char=char, sonema.mutate.test.Color=class sonema.mutate.test.Color, long=long, float=float, short=short, sonema.mutate.Traceable=class sonema.mutate.Traceable, void=void, int=int, sonema.mutate.test.Point=class sonema.mutate.test.Point, java.lang.Object=class java.lang.Object, <type>null=<type>null, double=double, java.lang.String=class java.lang.String, boolean=boolean, sonema.mutate.Event=class sonema.mutate.Event, byte=byte}
>
>
>
>
>
> unknown field or variable : __oj_oldValue
> ClosedEnvironment
> class object table : {}
> binding table : {}
> parent env : ClosedEnvironment
> class object table : {}
> binding table : {__oj_event=class sonema.mutate.Event}
> parent env : ClosedEnvironment
> class object table : {}
> binding table : {}
> parent env : ClosedEnvironment
> class object table : {}
> binding table : {oj_param0=int}
> parent env : ClassEnvironment
> class : Point
> member classes : []
> parent env : FileEnvironment
> package : sonema.mutate.test
> main class : Point
> local classes : imported classes : sonema.mutate.TraceableClass imported packages : java.lang local class table : {}
> parent env : GlobalEnvironment
> class object table : {sonema.mutate.test.ColoredPoint=class sonema.mutate.test.ColoredPoint, char=char, sonema.mutate.test.Color=class sonema.mutate.test.Color, long=long, float=float, short=short, sonema.mutate.Traceable=class sonema.mutate.Traceable, void=void, int=int, sonema.mutate.test.Point=class sonema.mutate.test.Point, java.lang.Object=class java.lang.Object, <type>null=<type>null, double=double, java.lang.String=class java.lang.String, boolean=boolean, sonema.mutate.Event=class sonema.mutate.Event, byte=byte}
>
>
> =====================================================================================
>
>
> Any ideas or pointers on what might need fixing?
> BTW: What is the best way to generate unique identifiers for generated code in OpenJava? I've just be prefixing them with "__oj_".
>
> Thanks,
> Kurt Stephens
> ks.javaMAPSPAM@kurtstephens.com
>
>
>