[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Java 1.5



Hi Duarte,

Is there any specific reason for you to want to modify the tree? Why not directly generate the text of modified classes using a tree walker?

e.g.

/* Note: I am using approximate names; I have not looked at the Java 1.5 grammar
   to select the appropriate names. */

... void inAClassDeclaration(...) {
  String className = node.getName();
  print(className + "_Validate extends " + className);
  node.getClassBody().apply(this);
}

That would seem much easier, to me, than modifying the tree.

Etienne

Duarte Martins wrote:
Hey there! I'm working with Java 1.5 Grammar provided by SableCC in its web page. My goal in this step is kind of duplicating each class which appears in a Java File, changing it's name and inheriting from the class itself.

For example

class A { }
class B { }

would generate the following classes:

class A_Validate extends A { }
class B_Validate extends B { }

I am creating a ANormalClassDeclaration node, to represent each of this new classes, and setting it's parameters equals to each main class. The problem is that when I make "newClass.setClassBody( mainClass.getClassBody() )" , the main class will no more have this class body. I mean, I don't want to remove main classes, only to add the new ones to the tree. I want to keep the same body in each pair of classes (main and generated one), but I think I must clone somehow the classes' bodies. Is there any easy way to solve my problem?

(for each class, final result in my program is now: class A class A_Validate extends A { } )

--
Etienne M. Gagnon, Ph.D.
SableCC:                                            http://sablecc.org