Top Description Methods
org.eclipse.xtend.lib.macro.services

public Interface Associator

Known Direct Subinterfaces
org.eclipse.xtend.lib.macro.TransformationContext
Imports
org.eclipse.xtend.lib.macro.declaration.Element, .MutableElement

Associates generated Java elements with their source Xtend elements
Since
2.7
See Also
Tracability

Method Summary

Modifier and TypeMethod and Description
public void
setPrimarySourceElement(MutableElement
the generated Java element
javaElement
,
Element
the source element that the secondaryElement was derived from
sourceElement
)

Associates the generate element with the Xtend source code.

Method Detail

setPrimarySourceElementback to summary
public void setPrimarySourceElement(MutableElement javaElement, Element sourceElement)

Associates the generate element with the Xtend source code. Every generated element should have a source element. This information is used by features like "Go to Declaration" and the outline view. A typical use case (generating a getter for a field) would look like this:

myClass.declaredFields.forEach[field|
 myClass.addMethod("get" + field.simpleName.toFirstUpper) [
  primarySourceElement = field
  // return type, body etc...
 ]
]
This way, the getter generated in the active annotation above would be associated with the field in the Xtend source code. Notice that we passed the field from the Java AST as a source element. This is a shortcut for
primarySourceElement = field.primarySourceElement
Parameters
javaElement:MutableElement

the generated Java element

sourceElement:Element

the source element that the secondaryElement was derived from