Skip to main content



      Home
Home » Modeling » EMF » [Xcore] invoking constructor for Data Type
[Xcore] invoking constructor for Data Type [message #801028] Fri, 17 February 2012 15:46 Go to next message
Eclipse UserFriend
Next problem Smile

Using xcore I defined a domain model which I edit using the reflective editor for testing purposes. The domain model contains a defined data type similiar to the Date data type found in the small example by Ed Merks.

However if I define my own data type which resides in x.y.z.util (same project,just the src and not the srcgen folder), everytime I enter a value in the reflective editor I get an exception IllegalStateException: could not invoke Constructor MyType(String). Of course it has a public constructor with a String parameter. I also tried to use a static method (same problem) and to be exactly like the Date example I added a class which constructs the datatype, but I never can invoke any methods.

the datatype is also listed among the resources when I open reflective editor, so it seems to be "known".

Any ideas?
Markus
Re: [Xcore] invoking constructor for Data Type [message #801320 is a reply to message #801028] Sat, 18 February 2012 02:13 Go to previous messageGo to next message
Eclipse UserFriend
Markus,

Comments below.



On 17/02/2012 9:46 PM, Markus Klink wrote:
> Next problem :)
>
> Using xcore I defined a domain model which I edit using the reflective
> editor for testing purposes. The domain model contains a defined data
> type similiar to the Date data type found in the small example by Ed
> Merks.
>
> However if I define my own data type which resides in x.y.z.util (same
> project,just the src and not the srcgen folder), everytime I enter a
> value in the reflective editor I get an exception
> IllegalStateException: could not invoke Constructor MyType(String). Of
> course it has a public constructor with a String parameter. I also
> tried to use a static method (same problem) and to be exactly like the
> Date example I added a class which constructs the datatype, but I
> never can invoke any methods.
The class loader in the running IDE itself would need to be able to find
the class so if it's only in your workspace, you can't use it in the
IDE's reflective editor.
>
> the datatype is also listed among the resources when I open reflective
> editor, so it seems to be "known".
Is there something in the resource?

I can't think of a good way to make this even more flexible. The class
does need to be loaded, so we'd need to be able to load classes that are
only in the workspace...
>
> Any ideas?
> Markus
>
Re: [Xcore] invoking constructor for Data Type [message #801478 is a reply to message #801320] Sat, 18 February 2012 08:00 Go to previous messageGo to next message
Eclipse UserFriend
I can't get it to run unfortunately. I stripped down the model to a barebones sample and now it even crashes when I try to enter a value into the reflective editor. this is my xcore file:

package x.y.z

import x.y.z.util.Test
import java.util.Date
import java.text.SimpleDateFormat

class SomeClass {

Test something
Date date

}

type Date wraps Date
create {
try {
new SimpleDateFormat("yyyy-MM-dd").parse(it)
} catch (Exception e) {
throw new RuntimeException(e)
}
}
convert {
new SimpleDateFormat("yyyy-MM-dd").format(it)
}

type Test wraps Test
create {
new Test(it)
}
convert {
it.toString
}

In the src folder I have the class x.y.z.util.Test
package x.y.z.util;

public class Test {
private String text;
public Test(String text) {
this.text = text;
}

@Override
public String toString() {
return text;
}

}


I create a dynamic instance of SomeClass and view it in the reflective editor. I see the do fields, but neither in the Date nor in the test field I can enter something. If I do I see the spinning wheel of death and have to shutdown eclipse. I guess I am doing something really stupid which I am missing, or maybe the combinations of my plugins does not cut it? If I can provide any other kind of debug information, please let me know.
Re: [Xcore] invoking constructor for Data Type [message #801487 is a reply to message #801478] Sat, 18 February 2012 08:23 Go to previous messageGo to next message
Eclipse UserFriend
Appendum: it works when I just create the model programmatically and serialize/deserialize the Resource. I guess, I am doing something wrong with the reflective editor.
Re: [Xcore] invoking constructor for Data Type [message #802599 is a reply to message #801478] Mon, 20 February 2012 01:44 Go to previous message
Eclipse UserFriend
Markus,

Comments below.

On 18/02/2012 2:00 PM, Markus Klink wrote:
> I can't get it to run unfortunately. I stripped down the model to a
> barebones sample and now it even crashes when I try to enter a value
> into the reflective editor. this is my xcore file:
>
> package x.y.z
>
> import x.y.z.util.Test
> import java.util.Date
> import java.text.SimpleDateFormat
>
> class SomeClass {
>
> Test something
> Date date
>
> }
>
> type Date wraps Date create {
> try {
> new SimpleDateFormat("yyyy-MM-dd").parse(it)
> } catch (Exception e) {
> throw new RuntimeException(e)
> }
> }
> convert {
> new SimpleDateFormat("yyyy-MM-dd").format(it)
> }
>
> type Test wraps Test
> create {
> new Test(it)
> }
> convert {
> it.toString
> }
>
> In the src folder I have the class x.y.z.util.Test
> package x.y.z.util;
>
> public class Test {
> private String text;
> public Test(String text) {
> this.text = text;
> }
>
> @Override
> public String toString() {
> return text;
> }
>
> }
I mentioned already that classes not actually installed in the
already-running IDE will not work in the reflective editor, so I don't
expect Test to work. Perhaps in the future we can play class loader
games (as I've done with dynamic JET templates), but that's not a
priority...
>
>
> I create a dynamic instance of SomeClass and view it in the reflective
> editor. I see the do fields, but neither in the Date nor in the test
> field I can enter something.
If I try the above, the stack trace from the error log is quite informative:

Caused by: java.lang.NullPointerException
at java.util.Calendar.setTime(Calendar.java:1106)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:955)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:948)
at java.text.DateFormat.format(DateFormat.java:336)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

That makes it clear that the case of "it" being null isn't handled.
> If I do I see the spinning wheel of death and have to shutdown eclipse.
That is the danger of running things in the IDE process itself. Rogue
behavior can kill the process.
> I guess I am doing something really stupid
Overlooked handling null and expecting data types to work reflectively
for classes not reflectively accessible in the IDE...
> which I am missing, or maybe the combinations of my plugins does not
> cut it? If I can provide any other kind of debug information, please
> let me know.
When things go wrong, be sure to check the Error Log view for causes.
Previous Topic:[Xcore] specifying GenModel annotations
Next Topic:[CDO] preferred DBStore DB vendor.
Goto Forum:
  


Current Time: Sat Nov 01 18:49:31 EDT 2025

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

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

Back to the top