Empty MutableClassDeclaration during doTransform

25 views
Skip to first unread message

Thomas Driessen

unread,
May 18, 2017, 4:33:29 PM5/18/17
to Xtend Programming Language
Hi,

my situation is the following. In Xtend I have one file with:

@ParentClass
class Parent{
@Child
Child1 child1
@Child
Child2 child2
@Connection(
source = 'child1.out',
target = 'child2.in'
)
Object con
}

@ChildClass
class Child1{
@Out
Object out
}


@ChildClass
class Child2{
@In
Object in
}

Now in the processor of @ParentClass I try to find the fields in/out in Child1/Child2.
Therefore, on the FieldDeclaration for child1 I call:

val child1 = field.type.type as ClassDeclaration

which returns a MutableTypeDeclaration.
Now I tried to find the corresponding field through:

child1.findDeclaredField('out')

which returns null.

I checked all the 'declaredXXX' methods and all of them returned empty Lists.

Is this an intended behavior? Do I have to retrieve the ClassDeclaration on another way?

Kind regards,
Thomas


Sven Efftinge (sven@efftinge.de)

unread,
May 22, 2017, 10:06:54 AM5/22/17
to xtend...@googlegroups.com
The Xtend compiler translates the source AST to a Java-like AST (the Mutable*Declaration). It is done in one pass so for multiple types in the same file it goes from top to down initializing them. If you are participating in the first, the following ones are not processed and therefore empty. 
You can always use the source AST instead which will be complete from the beginning.

--
You received this message because you are subscribed to the Google Groups "Xtend Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas Driessen

unread,
May 23, 2017, 4:03:55 AM5/23/17
to Xtend Programming Language
Hi Sven,

thanks for your answer. 

How do I get elements of the source AST from within the doTransform methods? Is the source AST normal Java reflection, or do you mean e.g. ClassDeclarations without the "Mutable" part?

Thomas
To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+...@googlegroups.com.

Sven Efftinge (sven@efftinge.de)

unread,
May 23, 2017, 7:56:46 AM5/23/17
to xtend...@googlegroups.com
You get them through `org.eclipse.xtend.lib.macro.declaration.CompilationUnit.getSourceTypeDeclarations()`
or `Tracability.getPrimarySourceElement(Element)` which is supported by the passed TransformationContext.


To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+unsubscribe@googlegroups.com.

Thomas Driessen

unread,
May 23, 2017, 8:52:02 AM5/23/17
to Xtend Programming Language
Thank you so much ! :)
Reply all
Reply to author
Forward
0 new messages