|
|
Re: [XPAND] Traverse all elements of a class [message #873640 is a reply to message #873611] |
Fri, 18 May 2012 18:32 |
Søren Qvist Messages: 3 Registered: May 2012 |
Junior Member |
|
|
Hi Christian,
thanks for your answer!
I tried a few things, but unfortunately I didn't get things done.
Could you please provide me with further instructions/documentation to keep going on?
In particular, after I type «ecore::EClass.» there's no code-completion anymore and the suggested method(s) you mentioned can't be found.
The relevant template-part looks like this:
..
«DEFINE buildWidget FOR Widget»
<«this.keyword»>
// this is where the magic should happen
</«this.keyword»>
«ENDDEFINE»
..
Maybe some background information:
I have modeled an abstract superclass "Widget" that has LOTS of subclasses. Some common attributes (id, height, width, ...) are modeled in the class Widget. It'd be a horror-scenario to write a template for every subclass, so I'm looking for a way to approach something similar with XPand:
<pseudo-code>
for (attribute : getAllAttributes()) {
print(attribute, getValue(attribute))
}
</pseudo-code>
Thanks a lot,
Søren
|
|
|
Re: [XPAND] Traverse all elements of a class [message #873652 is a reply to message #873640] |
Fri, 18 May 2012 19:11 |
|
Hi,
your snippet makes no sense to me. btw wich metamodel kind do you use? (java / emf(registry) = dynamic emf)
dynamic emf does not allow this kind of reflection. so you may have to deal with xpands reflection
this.metatype.....
or you use a javaextension
ecore::EClass getEClass(emf::EObject o):
JAVA template.Helper.getEClass(org.eclipse.emf.ecore.EObject);
Object eGet(emf::EObject o, ecore::EStructuralFeature f) :
JAVA template.Helper.eGet(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EStructuralFeature);
package template;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
public class Helper {
public static EClass getEClass(EObject o) {
return o.eClass();
}
public static Object eGet(EObject o, EStructuralFeature f) {
return o.eGet(f);
}
}
«FILE name+".txt"»
«FOREACH this.getEClass().eAllAttributes AS a»
«a.name» «eGet(a)»
«ENDFOREACH»
«ENDFILE»
alternatively: if you can use the javabeansmetamodel it will work out of the box
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Powered by
FUDForum. Page generated in 0.03004 seconds