Constructor Inference (JvmConstructor) [message #772699] |
Fri, 30 December 2011 11:31 |
Eugene Wagner Messages: 2 Registered: December 2011 |
Junior Member |
|
|
Hi,
I'm trying to add a constructor to a Java class generated by model inference. Unfortunately the constructor fails to appear in the generated Java source code.
I've tried two variations without success:
1) using TypesFactory#createJvmConstructor
2) using JvmTpesBuilder#toConstructor
I'm not sure if I've come across a bug or just using the API incorrectly. Any help would be much appreciated.
While debugging the calls appear to work successfully (i.e. I could see that an instance of "JvmConstructorImplCustom" was sitting in the members attribute of the "JvmGenericTypeImplCustom" instance. During debugging the Constructor appears as follows:
org.eclipse.xtext.common.types.impl.JvmConstructorImplCustom@67f236db (visibility: DEFAULT, simpleName: win_p1_with_T1, identifier: null) (varArgs: false)
And the JvmGenericTypeImplCustom appears as follows:
org.eclipse.xtext.common.types.impl.JvmGenericTypeImplCustom@2b9758e4 (visibility: PUBLIC, simpleName: win_p1_with_T1, identifier: null) (abstract: false, static: false, final: false, packageName: p1) (interface: false)
Below are the relevant parts of the XTend inference code:
class GuiJvmModelInferrer extends AbstractModelInferrer {
@Inject extension JvmTypesBuilder
@Inject extension TypeReferences
@Inject extension IQualifiedNameProvider
@Inject extension TypesFactory
def dispatch void infer(Window w, IAcceptor<JvmDeclaredType> acceptor, boolean isPrelinkingPhase){
val newClass = w.toClass(w.fullyQualifiedName)
//create the initializer strategy that will be invoked to set the details of the new class
[
it.superTypes += mkTypeRef(typeof(javax.swing.JFrame), w)
/* following line does not work */
it.members += mkConstructor(w)
it.members += w.toField("name", mkTypeRef(typeof(String), w), null)
it.members += w.toSetter("name", mkTypeRef(typeof(String),w))
]
acceptor.accept(newClass)
}
/* both variations of 'mkConsturctor' fail to produce a constructor in the *.java file */
def JvmConstructor mkConstructor2(Window w){
val op = createJvmConstructor()
op.simpleName = w.name
op.setBody["{ /*TODO */ }"]
associate(w, op)
return op
}
def JvmConstructor mkConstructor(Window w){
return toConstructor(w, w.name, null)
}
def dispatch void infer(PackageDecl p, IAcceptor<JvmDeclaredType> acceptor, boolean isPrelinkingPhase){
for(t : p.elements.filter([it instanceof Window])){
t.infer(acceptor, isPrelinkingPhase)
}
}
def JvmTypeReference mkTypeRef(Class<?> type, EObject context){
val typeDecl = findDeclaredType(type, context)
if(typeDecl==null)
throw new RuntimeException("could not find declaration for the type: " + type.name)
return createTypeRef(typeDecl)
}
def dispatch void infer(Model m, IAcceptor<JvmDeclaredType> acceptor, boolean isPrelinkingPhase) {
for(e : m.elements){
e.infer(acceptor, isPrelinkingPhase)
}
}
}
[Updated on: Fri, 30 December 2011 11:32] Report message to a moderator
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03545 seconds