|
|
|
|
|
Re: determine containment of EObject [message #1081749 is a reply to message #1081555] |
Wed, 07 August 2013 16:38 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Mauro,
Oops, I forgot the hit send on this reply...
On 07/08/2013 1:25 PM, Mauro Candarelli wrote:
> Thanks Ed.
> I'm getting there.
>
> On 07/08/2013 12:30, Ed Merks wrote:
>> ...
>>> sb.append(eo.getClass().getCanonicalName());
>> I'm not sure anyone would want to see the implementation class' name...
> You are absolutely right (as always).
> How do I get the name of the Interface from the implementation?
> I would like to avoid stupid tricks like editing the string to cut out
> the various "impl".
> Should I filter result of eo.getESuperTypes() or is there a better way?
>
>>> ...
>>> The test is ok, but I would like to print a non-containment
>>> reference as " => <containing EClass>.<containing EFeature>".
>> So you want er.eContainer() (which could be null if it's a root object
>>> If <containing EFeature> is a list I would add "@<index>"
>>>
>>> I seem unable to get the right containing EClass/EFeature and
>>> extract their names.
>> I think you should be processing each EObject in "value", where
>> "value" is of course either an EObject or a list of EObject if the
>> feature is an EReference. Perhaps have a look at EcoreUtil.Copier
>> for some insights...
>
> Code is now in a much better shape (not finished yet, as I still get
> some "???"):
>
> if (feature instanceof EReference) {
> EReference er = (EReference) feature;
> String s;
> if (!er.isContainment()) {
> sb.append(" => ");
You probably should use feature.isMany to determine whether to expect a
single value or a list of values.
> if (value == null) {
> sb.append("(");
> s = er.getEType().getName();
> sb.append(s);
> sb.append(") <null>");
> } else {
> if (value instanceof EObject) {
> EObject evalue = (EObject) value;
> EObject ceo = evalue.eContainer();
> EStructuralFeature cf = evalue.eContainingFeature();
> s = ceo.getClass().getCanonicalName();
> sb.append(s);
> sb.append(" . ");
> s = cf.getName();
> sb.append(s);
> Object cr = ceo.eGet(cf);
> if (cr instanceof EList<?>) {
> EList<?> cl = (EList<?>) cr;
> int i = cl.indexOf(value);
> sb.append("@");
> sb.append(i);
> }
> } else {
This must be the list of values case.
> sb.append("???");
> }
> }
> done = true;
> }
> }
>
> Side question: should I post here (or somewhere else) resulting code,
> when complete and reasonably polished?
> I have no problems sharing and it could be useful to someone else.
> What is the recommended policy?
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03452 seconds