Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » strange behavior in my dsl editor
strange behavior in my dsl editor [message #1756083] Fri, 10 March 2017 17:13 Go to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
I create this metamodel
import ecore : 'http://www.eclipse.org/emf/2002/Ecore' ;

package metamodel : metamodel = 'http://metamodel/2.0'
{
	class Extension
	{
		property types : ecore::EClassifier[*|1] { ordered composes };
	}
	class Kind extends ecore::EClassifier
	{
		attribute ktitle : String[?];
	}
}

The only specific thing is that Kind extends EClassifier.
I generate EMF projects (emf, edit editor and tests).

When I want to create a conforming model, the kind instance doesn't appear correctly in my editor.
It appears like that "metamodel.impl.KindImpl@7c9eb178 (name: null) (instanceClassName: null) (ktitle: null)

I think it's because of the "extend EClassifier"

Any suggestion/code/feedback please?

best regards









Re: strange behavior in my dsl editor [message #1756096 is a reply to message #1756083] Sat, 11 March 2017 06:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33139
Registered: July 2009
Senior Member
Of course extending Ecore is highly discouraged. In any case, this Xcore analog works for me:
@GenModel(editDirectory="/org.example.extension.edit/src", editorDirectory="/org.example.extension.editor/src")
package org.example.^extension

import org.eclipse.emf.ecore.EClassifier

class Extension
{
	contains EClassifier types
}

class Kind extends EClassifier
{
	String ktitle
}
The org.example.extension.provider.KindItemProvider.getText(Object) method looks like this:
  public String getText(Object object)
  {
    String label = ((Kind)object).getName();
    return label == null || label.length() == 0 ?
      getString("_UI_Kind_type") :
      getString("_UI_Kind_type") + " " + label;
  }

So the question, what does your KindItemProviderAdapter's getText look like and perhaps why isn't it used to produce the label? (And where in the editor are you seeing this?)


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: strange behavior in my dsl editor [message #1756097 is a reply to message #1756096] Sat, 11 March 2017 07:06 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

While struggling with an OCL aspect of your example as part of https://bugs.eclipse.org/bugs/show_bug.cgi?id=513479 I found that there seems to be something magic about "Extension" whereby Extension.xmi was determinedly loaded even after I renamed everything and restarted Eclipse. I couldn't reproduce in a nested Eclipse and so couldn't debug further.

While endeavoring to repro this problem I get clobbered by Extension.xmi again. But I think what you observe is correct. The default editor will use a default naming for a multi-String class. I suspect that you misleadingly refer to the dsl editor implying the generated editor for use in a nested Eclipse when you mean the default editor in the current Eclipse.

Anyway, as Ed M reminds you, extending Ecore is really bad. Bug 513479 points out that your Extension-contains-EClassifier-but-does-not-extend-EPackage breaks Ecore practice.

If you want a new metamodel, design it independently of Ecore. If you want something horrendously extensible use XML. But much better, rethink your problem and use Ecore conventionally.

Regads

Ed Willink
Re: strange behavior in my dsl editor [message #1756112 is a reply to message #1756096] Sat, 11 March 2017 14:24 Go to previous messageGo to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Hi Ed Merks,
thanks for ur reply

my KindItemProviderAdapter's getText look like
	@Override
	public String getText(Object object) {
		String label = ((Kind)object).getName();
		return label == null || label.length() == 0 ?
			getString("_UI_Kind_type") :
			getString("_UI_Kind_type") + " " + label;
	}


So, the done scenario was
1- I create a metamodel
2- I create emf project
3- I generate projects (edit editor and test)
4- I run Runtime Eclipse (EMF project right click run as Eclipse Application)
5- I create a model using the DSL editor (metamodel editor) in the runtime eclipse
6- I create a model
7- I create an extension instance
8- Then extension -> "New Child" Kind
9-The strange behavior appears (Please see the joined image).

index.php/fa/28735/0/

You can find my code (emf projets) in the zipped attachment.

Best regards

Faiez
  • Attachment: metamodel.png
    (Size: 110.59KB, Downloaded 428 times)
  • Attachment: Archive.zip
    (Size: 148.25KB, Downloaded 98 times)

[Updated on: Sat, 11 March 2017 14:26]

Report message to a moderator

Re: strange behavior in my dsl editor [message #1756120 is a reply to message #1756112] Sun, 12 March 2017 06:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33139
Registered: July 2009
Senior Member
If you're going to extend Ecore's class (i.e., not just reference classifiers as type type of a typed elements), you should reconsider. If you feel you must go against that advice, then you must use the development time version of the Ecore model and your GenModel must use Ecore's GenModel. So your Ecore model must look like this:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="metamodel" nsURI="http://metamodel/2.0" nsPrefix="metamodel">
  <eAnnotations source="http://www.eclipse.org/OCL/Import">
    <details key="ecore" value="http://www.eclipse.org/emf/2002/Ecore"/>
  </eAnnotations>
  <eClassifiers xsi:type="ecore:EClass" name="Extension">
    <eStructuralFeatures xsi:type="ecore:EReference" name="types" upperBound="-1"
        eType="ecore:EClass ../../org.eclipse.emf.ecore/model/Ecore.ecore#//EClassifier"
        containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Kind" eSuperTypes="../../org.eclipse.emf.ecore/model/Ecore.ecore#//EClassifier">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="ktitle" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
</ecore:EPackage>

Note in particular the reference to ../../org.eclipse.emf.ecore/model/Ecore.ecore#//EClassifier (resolves in the development time version in the workspace or target platform) rather than the reference to http://www.eclipse.org/emf/2002/Ecore#//EString which resolves to the runtime instance (EcorePackage.eINSTANCE in the running IDE). When done this way, the GenModel will include usedGenPackages="../../org.eclipse.emf.ecore/model/Ecore.genmodel#//ecore" (i.e., it will reference Ecore's GenModel) and the generated KindItemProvider will extend org.eclipse.emf.ecore.provider.EClassifierItemProvider.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: strange behavior in my dsl editor [message #1756162 is a reply to message #1756120] Mon, 13 March 2017 10:09 Go to previous messageGo to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Hi Ed Merks,
Thank you for ur answer.
It works perfectly.
Thank you for the explanation

Faiez
Re: strange behavior in my dsl editor [message #1756192 is a reply to message #1756162] Mon, 13 March 2017 17:12 Go to previous messageGo to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Ed,
please another question.
I create metamodel with reference to ../../org.eclipse.emf.ecore/model/Ecore.ecore#//EClassifier and It works perfectly.
However, when I open the metamodel with OCLinEcore editor and I do some changes, the reference changes automatically to http://www.eclipse.org/emf/2002/Ecore##//EClassifier.

Is it normal?

Best regards
Re: strange behavior in my dsl editor [message #1756193 is a reply to message #1756192] Mon, 13 March 2017 17:40 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Please the OCL newsgroup for OCL questions.

I suspect this is a bug in the OCLinEcore editor. Probably https://bugs.eclipse.org/bugs/show_bug.cgi?id=427289, but the repro has been elusive.

To what extent does ../../org.eclipse.emf.ecore/model/Ecore.ecore actually exist in your file system.

Regards

Ed Willink
Re: strange behavior in my dsl editor [message #1756194 is a reply to message #1756193] Mon, 13 March 2017 18:04 Go to previous messageGo to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Hi Ed,
Sorry for this error.
Frankly, I don't understand What do you mean by "To what extent does ../../org.eclipse.emf.ecore/model/Ecore.ecore actually exist in your file system."

You can find in attachment a demo (demo.mov) that explains how OCLinEcore editor changes relative URIs.

best regards
  • Attachment: demo.mov
    (Size: 16.17MB, Downloaded 114 times)
Re: strange behavior in my dsl editor [message #1756195 is a reply to message #1756194] Mon, 13 March 2017 18:23 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I meant, is there an org.eclipse.emf.ecore/model/Ecore.ecore in an open project. Is there an org.eclipse.emf.ecore/model/Ecore.ecore in a closed project?

One of EMF's weaknesses is the ability to refer to the same model element in too many different ways leading to multiple model loading and confusing X is not equal to X diagnostics. OCL tooling fights this metamodel schizophrenia by 'merging' all EPackages with identical nsURIs. This is often helpful, but needs enhancement to allow distinct user/tooling merges (Bug 510503).

In your case, by referring to ../../org.eclipse.emf.ecore/model/Ecore.ecore, you are using a potentially locally modified version of Ecore. If you are developing Ecore, this may be appropriate. However since I presume that you are just using Ecore, you should not stress tools by pretending that you are using a variant. Use http://www.eclipse.org/emf/2002/Ecore.

Regards

Ed Willink
Re: strange behavior in my dsl editor [message #1756202 is a reply to message #1756195] Mon, 13 March 2017 19:30 Go to previous messageGo to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Quote:
you are using a potentially locally modified version of Ecore

We don't use a modified version of Ecore.
We use Ecore and its plugins

Quote:
Use http://www.eclipse.org/emf/2002/Ecore.

I can't use it because I it damages the code generation as explained previously.

The question is very simple
as shown in the demo, Why OCLinEcore editor changes URIs? Is it a bug?
or we must do something to overcome this behavior?
Re: strange behavior in my dsl editor [message #1756204 is a reply to message #1756202] Mon, 13 March 2017 20:07 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You have been very strongly advised not to extend Ecore. Yet you continue to do so. This is probably why it 'damages' your code generation.

Since you ignore our advice you should expect to resolve the problems that your greater expertise creates yourself.

Regards

Ed Willink
Re: strange behavior in my dsl editor [message #1756206 is a reply to message #1756204] Mon, 13 March 2017 20:58 Go to previous message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
the code generation issue is resolved. The problem was identified and solved.

I provided a video demo that shows why there is a problem.
The strange behavior is because the OCLinEcore editor (as you have admitted it in a previous post).

I can reply subjectively but I don't prefer this manner to discuss.
Previous Topic:difflrents instances
Next Topic:Containment references are not shown in the ecore diagram
Goto Forum:
  


Current Time: Sat Apr 20 15:35:52 GMT 2024

Powered by FUDForum. Page generated in 0.04970 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top