Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Xcore] Default value of a DataType
[Xcore] Default value of a DataType [message #1738190] Sun, 17 July 2016 23:11 Go to next message
Aurélien Mora is currently offline Aurélien MoraFriend
Messages: 38
Registered: July 2014
Member
Hello,

I'm trying to set the default value of a wrapped class (I want to avoid the default null value). A little example :

class PositionObject
{
	PointF position = "1;2" // new Vector2f(1, 2)
}

type PointF wraps Vector2f 
create
{
	if(it != null)
	{
		val String[] split = it.split(";")
		if(split.length == 2)
		{
			new Vector2f(Float.valueOf(split.get(0)), Float.valueOf(split.get(1)))
		}
	}
	new Vector2f
}
convert
{
	it.x + ";" + it.y
}



Unfortunately, Xcore doesn't allows the PointF position = "1;2" (the error message : "The default value literal '1;2' must be a valid literal of the attribute's type").

But : if I remove the create and convert parts, the error message disappears (but the generated code no longer knows how to parse my string Sad ).

Did I missed something ?

If I can't do that, how can I just set a default value like PointF position = new Vector2f() ?

[Updated on: Mon, 18 July 2016 09:15]

Report message to a moderator

Re: [Xcore] [message #1738240 is a reply to message #1738190] Mon, 18 July 2016 10:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31961
Registered: July 2009
Senior Member
Where is Vector2f defined/implemented?

Looking at the logic in
org.eclipse.emf.ecore.util.EcoreValidator.validateEStructuralFeature_ValidDefaultValueLiteral(EStructuralFeature,
DiagnosticChain, Map<Object, Object>) there's code like this:

// If there is a conversion delegate then the lack of a
default value really does indicate that there is a problem converting
the literal to a value.
//
EDataType.Internal.ConversionDelegate conversionDelegate =
((EDataType.Internal)eDataType).getConversionDelegate();
if (conversionDelegate != null)
{

And Xcore does set the conversion delegate, which needs to be able to
run your code. That happens in
org.eclipse.emf.ecore.impl.EFactoryImpl.createFromString(EDataType, String)

EDataType.Internal.ConversionDelegate conversionDelegate =
((EDataType.Internal)eDataType).getConversionDelegate();
if (conversionDelegate != null)
{
return conversionDelegate.createFromString(stringValue);
}

Perhaps this isn't working because the class can't be loaded. So I
wonder is the class in that project, or is it from some library in
another project, or what?


On 18.07.2016 01:11, ealrann xor wrote:
> Hello,
> I'm trying to set the default value of a wrapped class (I want to
> avoid the default null value). A little example :
>
>
> class PositionObject
> {
> PointF position = "1;2" // new Vector2f(1, 2)
> }
>
> type PointF wraps Vector2f create
> {
> if(it != null)
> {
> val String[] split = it.split(";")
> if(split.length == 2)
> {
> new Vector2f(Float.valueOf(split.get(0)),
> Float.valueOf(split.get(1)))
> }
> }
> new Vector2f
> }
> convert
> {
> it.x + ";" + it.y
> }
>
>
>
> Unfortunately, Xcore doesn't allow the PointF position = "1;2" (the
> error message : "The default value literal '1;2' must be a valid
> literal of the attribute's type").
>
> But : if I remove the create and convert part, the error message
> disappears (but the generated code no longer knows how to parse my
> string :( ).
> Did I missed something ?
>
> If I can't do that, how can I just set a default value like PointF
> position = new Vector2f() ?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Xcore] [message #1738244 is a reply to message #1738240] Mon, 18 July 2016 11:10 Go to previous messageGo to next message
Aurélien Mora is currently offline Aurélien MoraFriend
Messages: 38
Registered: July 2014
Member
Thanks for the fast reply.

The Vector2f is on the same project :

http://tof.canardpc.com/view/0ea51e25-83b2-41fd-8c99-5a110d8d35cf.jpg

http://tof.canardpc.com/view/4584152f-1834-4063-a09c-7b388c2ac2a1.jpg

When I remove the create and convert, no more errors :
http://tof.canardpc.com/view/67c9a6d2-0432-4d9f-965e-2fe25a669e08.jpg

[Updated on: Mon, 18 July 2016 11:16]

Report message to a moderator

Re: [Xcore] [message #1738270 is a reply to message #1738244] Mon, 18 July 2016 14:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31961
Registered: July 2009
Senior Member
The attached project in which I try to reproduce your problem works for
me in my development environment. It shows an error only if the literal
isn't well formed...


On 18.07.2016 13:10, ealrann xor wrote:
> Thanks for the fast reply.
>
> The Vector2f is on the same project :
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Xcore] [message #1738272 is a reply to message #1738270] Mon, 18 July 2016 15:08 Go to previous messageGo to next message
Aurélien Mora is currently offline Aurélien MoraFriend
Messages: 38
Registered: July 2014
Member
That's really weird.

I'm not at home and I don't have my development environment, so I imported your project on a Eclipse EMF Mars : the problem is still here :

http://img11.hostingpics.net/pics/201925problem.jpg

A clean does not resolve the error. But, the code is well generated (that is not the case on my Project).


I'll try deeply when I'd back to home.

[Updated on: Mon, 18 July 2016 15:08]

Report message to a moderator

Re: [Xcore] [message #1738278 is a reply to message #1738272] Mon, 18 July 2016 15:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31961
Registered: July 2009
Senior Member
I'm using the Neon version. Perhaps something has been fixed in the
latest year.


On 18.07.2016 17:08, ealrann xor wrote:
> That's really weird.
> I'm not at home and I don't have my development environment, so I
> imported your project on a Eclipse EMF Mars : the problem is still here :
> http://img11.hostingpics.net/pics/201925problem.jpg
>
> A clean does not resolve the error. But, the code is well generated
> (that is not the case on my Project).
>
>
> I'll try deeply when I'd back to home.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Xcore] [message #1738293 is a reply to message #1738278] Mon, 18 July 2016 17:26 Go to previous messageGo to next message
Aurélien Mora is currently offline Aurélien MoraFriend
Messages: 38
Registered: July 2014
Member
Better with Neon, but I still have the error :

At first look, your sample project is working on Neon, but the error still appears when you clean the project. At this time, the only way to remove the error is to edit the .xcore and save it.

I tried with a clean install of Neon EMF (windows x64), with xcore from update site.
Re: [Xcore] [message #1738298 is a reply to message #1738293] Mon, 18 July 2016 18:53 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31961
Registered: July 2009
Senior Member
Yes, I noticed that too. Feel free to open a Bugzilla for that. There's
already a bugzilla about cyclic rebuilds. In this case, it seems as if
two builds are really needed because until the class wrapped by the data
type is built, it can't be loaded and resolved by the Xcore model. It
sounds like a tricky problem for sure...


On 18.07.2016 19:26, ealrann xor wrote:
> Better with Neon, but I still have the error :
>
> At first look, your sample project is working on Neon, but the error
> still appears when you clean the project. At this time, the only way
> to remove the error is to edit the .xcore and save it.
>
> I tried with a clean install of Neon EMF (windows x64), with xcore
> from update site.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Xcore] [message #1738424 is a reply to message #1738298] Tue, 19 July 2016 16:08 Go to previous message
Aurélien Mora is currently offline Aurélien MoraFriend
Messages: 38
Registered: July 2014
Member
Ok, about the clean problem : I have opened a Bugzilla : https://bugs.eclipse.org/bugs/show_bug.cgi?id=498138


And finally : about my default value problem :
The error was systematic on my project : I was never able to set a default value, but I finally figured out why : I use BNDTools in my projects, and it seems to interrupt the xcore generation (something like this). So the EDatatype default value was always in error.
I finally solve it by editing the nature of the eclipse project, to prioritize the XText nature over the BNDTools nature.


Thank you for your help (and thank you for EMF Smile )
Previous Topic:[CDO] delete object of removed class
Next Topic:Resolve eProxy with custom URI
Goto Forum:
  


Current Time: Sat Jul 31 23:21:02 GMT 2021

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

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

Back to the top