#7 OpenJava1.1_20020522: Problems with generating inner classes

open
nobody
None
5
2003-03-08
2003-03-08
Kurt Stephens
No

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

Discussion