Generically accessing Java (stub) classes during generation
We have a set of java stubs (based on generated types represented in Google protocol buffers Java API), which we want to use for java code generation. The concrete classes to include in the generated output are determined at generation time based on some other, more general concepts. Therefore, no explicit mapping between concepts and java stubs exists and the classes and methods are determined dynamically. We cannot find a way to achieve this generically.
What we have tried for static methods is the following to generate a static method call based on a name of the method and an annotation for the class (previously determined by string comparison):
<StaticMethodCall(
classConcept: # node.message.@language mapping.javaClass,
staticMethodDeclaration: # node.message.@language mapping.javaClass.getMembers().where({~it => it.isInstanceOf(StaticMethodDeclaration) && it:StaticMethodDeclaration.name.equals("newBuilder"); }).first:StaticMethodDeclaration)>
This is extremely brtile due to potential overloading of methods etc. and we only found a solution for static methods. We coudn't find any solution to acquire subclasses, methods calls based on specified names etc. In any case, this solution looks completely broken and we are wondering whether there is a more systematic solution to this problem.
Please sign in to leave a comment.
Could you please provide a bit more detailed example?
If you got a node<A>, with annotation className="some.google.class", with a child node<B>, with annotation factoryMethod="newBuilder", and you'd like to generate a code from B to look somewhat like:
then what's the issue with reference macros for the places inside <> in the sample above?
Reference macro would pick proper node pointer to a target stub based on your input model.
Thank you for your answer! So basically there sadly is no other way than tagging custom nodes myself, with something similar to what you suggested with @className, to establish the association.