|
|
Re: annotate a parameter in method [message #1053141 is a reply to message #1053092] |
Thu, 02 May 2013 16:15 |
Dirk Deyne Messages: 8 Registered: May 2013 |
Junior Member |
|
|
solved
def fooMethod(Foo foo){
foo.toMethod(
"foo",
foo.newTypeRef(Void::TYPE),
[
var fooPar = toParameter(foo.bar.simpleName.toFirstLower,form.bar)
foorPar.annotations.add(foo.toAnnotation("foo.annotation.MyBar","foo"))
parameters += fooPar
body=[append('''this.bar = bar;''')]
annotations.add(foo.toAnnotation("foo.annotation.MyFoo"))
])
}
thx Christian
before I tried
var fooPar = toParameter(foo.bar.simpleName.toFirstLower,form.bar)
foorPar.annotations.add(toAnnotation("foo.annotation.MyBar","foo"))
and
var fooPar = toParameter(foo.bar.simpleName.toFirstLower,form.bar)
foorPar.annotations.add(fooPar.toAnnotation("foo.annotation.MyBar","foo"))
still learning
[Updated on: Thu, 02 May 2013 16:24] Report message to a moderator
|
|
|
|
|
|
|
Re: annotate a parameter in method [message #1053180 is a reply to message #1053179] |
Thu, 02 May 2013 21:41 |
|
Btw you may digg into
org.eclipse.xtext.xbase.compiler.JvmModelGenerator.toJava(JvmAnnotationValue, ITreeAppendable, GeneratorConfig)
org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.toAnnotation(EObject, String, Object)
and create your own toAnnotation
that sets an JvmAnnotationValue.operation
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Re: annotate a parameter in method [message #1053250 is a reply to message #1053179] |
Fri, 03 May 2013 11:42 |
Dirk Deyne Messages: 8 Registered: May 2013 |
Junior Member |
|
|
Christian Dietrich wrote on Thu, 02 May 2013 17:30Hi,
isnt that the same?
Yes, it is the same... in this simplified example.
I'm learning in small steps
But I will eventualy need a convertion to something like
@Column(name="T_NAME", updatable=false)
and
@RequestMapping(value="/welcome", method = RequestMethod.GET)
I will surely have a look at
Quote:
org.eclipse.xtext.xbase.compiler.JvmModelGenerator.toJava(JvmAnnotationValue, ITreeAppendable, GeneratorConfig)
org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.toAnnotation(EObject, String, Object)
and create your own toAnnotation
that sets an JvmAnnotationValue.operation
[Updated on: Fri, 03 May 2013 11:43] Report message to a moderator
|
|
|
Re: annotate a parameter in method [message #1053257 is a reply to message #1053250] |
Fri, 03 May 2013 12:10 |
Thomas Fritsch Messages: 28 Registered: April 2013 Location: Germany |
Junior Member |
|
|
Actually, a few weeks ago I digged through the api for solving similar problems, and finally came up with my own utilities.
class Utils {
@Inject extension JvmTypesBuilder
@Inject extension TypesFactory
def addStringValue(JvmAnnotationReference annoRef, String name, String value) {
val op = annoRef.findOperationByName(name)
annoRef.values += createJvmStringAnnotationValue => [
operation = op
values += value
]
annoRef
}
// Similar methods (left to the reader as an exercise ;-) )
// addIntValue(JvmAnnotationReference annoRef, String name, int value)
// addBooleanValue(JvmAnnotationReference annoRef, String name, boolean value)
// addAnnotationValue(JvmAnnotationReference annoRef, String name, JvmAnnotationReference value)
// addEnumValue(JvmAnnotationReference annoRef, EObject context, String name, Enum<?> value)
// addTypeValue(JvmAnnotationReference annoRef, EObject context, String name, Class<?> value)
// ...
def private findOperationByName(JvmAnnotationReference annoRef, String name) {
annoRef.annotation.declaredOperations.findFirst[it.simpleName == name]
}
}
For example, for building the annotation
@NamedQuery(name="Printer.findAll", query="SELECT x FROM Printer AS x")
I can write
@Inject extension JvmTypesBuilder
@Inject extension Utils
val a = e.toAnnotation("javax.persistence.NamedQuery")
.addStringValue("name", "Printer.findAll")
.addStringValue("query", "SELECT x FROM Printer AS x")
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07060 seconds