Community
Participate
Working Groups
Here's the problem. We have successfully separated each template class from each other (they don't extend one another) by having them all extend JavaTemplate and use the ctx.invoke and ctx.invokeSuper methods. So far, so good. When a new generator (Gen1) comes along that wants to extend an existing one (JavaGen for instance), then that new generator is forced to do 1 of 2 things for each class being extended: 1) must either extend JavaGen's, or 2) duplicate every method that the JavaGen's generator provides (if it doesn't extend). The problem with this, is that if they use the extend technique, then if there is a new generator (Gen2) that wants to extend Gen1, then Gen2 is caught in the same trap we found with trying to extend JavaGen originally. They won't be able to extend any classes in Gen1, except for leaf classes. If they don't use the extend clause, and instead duplicate every method in the class, then any updates won't get picked up, which is also bad. There is a solution to this, but it would complicated and I need Tim to look into it. Here's how it would work: We take as an example Gen2 extending Gen1 that extends JavaGen. Each generator (Gen1, Gen2 and JavaGen) would always extend JavaTemplate (and not extend anything else). When any method is wanted to be invoked, it would have to use ctx.invoke and invokeSuper, just like JavaGen does now. The current problem with doing this is that for each template class, only 1 class is currently loaded by the getTemplateMethod logic. If Gen2 has a version of AssignmentTemplate, then its version of AssignmenTemplate will be the only one available. Gen1's and JavaGen's will not be loaded. For this to work, we need to load (in proper order) all AssignmentTemplate classes from each template. The problem with loading all of these AssignmentTemplate classes will be when invokeSuper is used. It goes to the super class of the current template and starts looking for a method from there. That is fine and should remain the same. However there is no way for Gen2 to get to any AssignmentTemplate method in Gen1 or JavaGen. In order for this to work, we need to do these 2 items: 1) make getTemplateMethod load all AssignmentTemplate classes instead of the 1st one and search them all when looking for a method 2) introduce ctx.invokeSame which will use the current generator's class and search for the same method but in the next generator's (could be multiple) classes. For example: if we are in Gen2 and issue ctx.invokeSame, then it looks for the method in Gen1 and if not found, then JavaGen.
As per discussion with Tim. This should not be a problem, because of the original work in javagen or javascriptgen. This original work separated each of the classes from one another making each of the templates independent. When a user generator comes along to extend the original, they are merely extending this independent class. They are not creating any kind of structure. This means that this extended independent class can still be extended by yet another generator. There shouldn't be any problem showing up.
Closing this work item