Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Cannot Access Stereotypes
Cannot Access Stereotypes [message #1730246] Fri, 22 April 2016 14:27 Go to next message
Daniel Clarke is currently offline Daniel ClarkeFriend
Messages: 24
Registered: March 2016
Junior Member
Hi,

I am new to Acceleo and am trying to access stereotypes, but it does not seem to work.

I have used Papyrus to generate a UML Profile and then created a model (which applies the profile) whereby I have used some of the stereotypes.

I am then trying to use Acceleo to simply print a list of stereotypes applied to an element of the model using the following code:

    
[for (aST : Stereotype | aClass.getAppliedStereotypes())]
      stereotype = [aST.name/]
[/for]


However, this does not return any stereotypes when I am expecting it to.

Have I missed something?

I was following this guide:
http://devsolstice.blogspot.co.uk/2012/04/acceleo-uml-profiles-papyrus-good.html

Regards,
Dan
Re: Cannot Access Stereotypes [message #1730347 is a reply to message #1730246] Mon, 25 April 2016 08:31 Go to previous messageGo to next message
Eclipse UserFriend
Hi Daniel,
Did you include 'http://www.eclipse.org/uml2/5.0.0/UML' in the
definition of the module?

Best,

Víctor

El 22/04/2016 a las 16:27, Daniel Clarke escribió:
> Hi,
>
> I am new to Acceleo and am trying to access stereotypes, but it does not
> seem to work.
>
> I have used Papyrus to generate a UML Profile and then created a model
> (which applies the profile) whereby I have used some of the stereotypes.
>
> I am then trying to use Acceleo to simply print a list of stereotypes
> applied to an element of the model using the following code:
>
> [for (aST : Stereotype | aClass.getAppliedStereotypes())]
> stereotype = [aST.name/]
> [/for]
>
>
> However, this does not return any stereotypes when I am expecting it to.
>
> Have I missed something?
>
> I was following this guide:
> http://devsolstice.blogspot.co.uk/2012/04/acceleo-uml-profiles-papyrus-good.html
>
>
> Regards,
> Dan
Re: Cannot Access Stereotypes [message #1730352 is a reply to message #1730347] Mon, 25 April 2016 08:55 Go to previous messageGo to next message
Daniel Clarke is currently offline Daniel ClarkeFriend
Messages: 24
Registered: March 2016
Junior Member
Víctor,

Yes, I had included the definition as you suggest:

[comment encoding = UTF-8 /]
[module generate('http://www.eclipse.org/uml2/5.0.0/UML')]


However, I was going to post a simplified version of my module code for information but in simplifying it, it now works! I must have an error elsewhere, but at least I can now in principle access my stereotypes Smile

For information, my simplified module code (which works) is:

[comment encoding = UTF-8 /]
[module generate('http://www.eclipse.org/uml2/5.0.0/UML')]

[template public generate(aPackage : Package)]
[comment @main/]

[file (aPackage.name.concat('.txt'), false, 'UTF-8')]

[for (anElement : Element | aPackage.ownedElement)]
  [if (anElement.oclIsTypeOf(Class))]
    [let aClass : Class = anElement]
    ***aClass name =! [aClass.name/]

    [for (aST : Stereotype | aClass.getAppliedStereotypes())]
      ***stereotype = [aST.name/]
    [/for]

    [/let]
  [/if]

[/for]

[/file]
[/template]


Thanks for the response!
Re: Cannot Access Stereotypes [message #1730370 is a reply to message #1730352] Mon, 25 April 2016 10:56 Go to previous messageGo to next message
Daniel Clarke is currently offline Daniel ClarkeFriend
Messages: 24
Registered: March 2016
Junior Member
After further investigation it seems to be related to the run-configuration options:

If I launch using the default "Java application" runner, the stereotypes are not found.
If I launch using the "Acceleo Plug-in Application" runner (which shows a warning "Due to changes in the Eclipse platform in Luna, the Acceleo Plug-in Application strategy may not work."), the stereotypes are found.

However, if I try to use a Java Service to get the stereotypes then it does not work (with either runner).

I'm using Eclipse Mars and Acceleo 3.6.3 and have looked at many posts which seem to indicate a problem with the runner in Luna onwards, but I am unsure as how to fix the issue.

I've tried registering packages (in registerPackages method) as described in one of the posts; but no matter what I try, I cannot get the stereotypes to be detected when using the "Java Application" runner.

Any help would be appreciated.
Re: Cannot Access Stereotypes [message #1730399 is a reply to message #1730370] Mon, 25 April 2016 13:04 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The most important thing with UML is to make sure that
UMLResourcesUtil.init is being called.

I suspect that it isn't.

It seems that your use case offers many opportunities for Acceleo to
provide you with some diagnostics. I suggest raising some BUgzillas.

Regards

Ed Willink


On 25/04/2016 11:56, Daniel Clarke wrote:
> After further investigation it seems to be related to the
> run-configuration options:
>
> If I launch using the default "Java application" runner, the
> stereotypes are not found.
> If I launch using the "Acceleo Plug-in Application" runner (which
> shows a warning "Due to changes in the Eclipse platform in Luna, the
> Acceleo Plug-in Application strategy may not work."), the stereotypes
> are found.
>
> However, if I try to use a Java Service to get the stereotypes then it
> does not work (with either runner).
>
> I'm using Eclipse Mars and Acceleo 3.6.3 and have looked at many posts
> which seem to indicate a problem with the runner in Luna onwards, but
> I am unsure as how to fix the issue.
>
> I've tried registering packages (in registerPackages method) as
> described in one of the posts; but no matter what I try, I cannot get
> the stereotypes to be detected when using the "Java Application" runner.
>
> Any help would be appreciated.
Re: Cannot Access Stereotypes [message #1730421 is a reply to message #1730399] Mon, 25 April 2016 15:50 Go to previous messageGo to next message
Daniel Clarke is currently offline Daniel ClarkeFriend
Messages: 24
Registered: March 2016
Junior Member
Ed,

Sorry I don't follow what you mean.

I currently have:

resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);

in registerResourceFactories() and:

		 
		 Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
		 
		 // UML2 profiles
		 URI uri = URI.createURI("platform:/plugin/org.eclipse.uml2.uml.resources");
		 uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
		 uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
		 uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment("")); 

in registerPackages().

Are you suggesting I add the "UMLResourcesUtil.init(resourceSet); " line also into registerPackages? I've tried doing this but can an error as follows: "org.eclipse.uml2.uml.resources cannot be resolved".

Again, guidance appreciated Smile
Re: Cannot Access Stereotypes [message #1730423 is a reply to message #1730421] Mon, 25 April 2016 16:28 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

UMLResourcesUtil.init(resourceSet) should replace all the code you have
quoted.

When the UML2 project added UML 2.4.1 and 2.5 support, the required
initializations were too complex even for experts. Hence the new single
routine that just does it.

If you can't use it add org.eclipse.uml2.uml.resources to your required
bundles.

Regards

Ed Willink


On 25/04/2016 16:50, Daniel Clarke wrote:
> Ed,
>
> Sorry I don't follow what you mean.
>
> I currently have:
>
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
>
> in registerResourceFactories() and:
>
> Map<URI, URI> uriMap =
> resourceSet.getURIConverter().getURIMap();
> // UML2 profiles
> URI uri =
> URI.createURI("platform:/plugin/org.eclipse.uml2.uml.resources");
> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
> uri.appendSegment("libraries").appendSegment(""));
> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
> uri.appendSegment("metamodels").appendSegment(""));
> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
> uri.appendSegment("profiles").appendSegment(""));
> in registerPackages().
>
> Are you suggesting I add the "UMLResourcesUtil.init(resourceSet); "
> line also into registerPackages? I've tried doing this but can an
> error as follows: "org.eclipse.uml2.uml.resources cannot be resolved".
>
> Again, guidance appreciated :)
Re: Cannot Access Stereotypes [message #1730627 is a reply to message #1730423] Wed, 27 April 2016 08:26 Go to previous messageGo to next message
Daniel Clarke is currently offline Daniel ClarkeFriend
Messages: 24
Registered: March 2016
Junior Member
Ed,

Thanks, I can now get something to generate and access stereotypes (only when using the Acceleo Plug-in Application runner - I cannot get it to run using the default Java Application runner).

However, I'm seeing some very strange behaviour - when I run the first time (after starting Eclipse) it generates as expected, but every subsequent run generates a number of errors (and warnings):

java.lang.NullPointerException
	at org.eclipse.osgi.internal.loader.BundleLoader.findRequiredSource(BundleLoader.java:1114)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:392)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:352)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:344)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Unsafe.defineClass(Native Method)
	at sun.reflect.ClassDefiner.defineClass(Unknown Source)
	at sun.reflect.MethodAccessorGenerator$1.run(Unknown Source)
	at sun.reflect.MethodAccessorGenerator$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)

and this warning....

org.eclipse.acceleo.engine.AcceleoEvaluationException: Invalid result for expression self.invoke('ecoa.transformation.common.UML2Services', 'hasStereotype(org.eclipse.uml2.uml.Element, java.lang.String)', Sequence {arg0, arg1}) at line 0 in Module uml2services for query hasStereotype(Element,String). Last recorded value of self was org.eclipse.uml2.uml.internal.impl.DataTypeImpl@56035798 (name: value_type, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false). Problem found while generating the file 'D:\test.xml'.


If I close and restart Eclipse, the generation again works the first time; every subsequent time fails with a set of the above NPE and warning pairs. It is a real pain having to restart Eclipse every time I want to re-run... Any thoughts?

Thanks again.
Re: Cannot Access Stereotypes [message #1730630 is a reply to message #1730627] Wed, 27 April 2016 08:38 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The debugger is always your friend.

Regards

Ed Willink


On 27/04/2016 09:26, Daniel Clarke wrote:
> Ed,
>
> Thanks, I can now get something to generate and access stereotypes
> (only when using the Acceleo Plug-in Application runner - I cannot get
> it to run using the default Java Application runner).
>
> However, I'm seeing some very strange behaviour - when I run the first
> time (after starting Eclipse) it generates as expected, but every
> subsequent run generates a number of errors (and warnings):
>
>
> java.lang.NullPointerException
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findRequiredSource(BundleLoader.java:1114)
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:392)
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:352)
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:344)
> at
> org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
> at java.lang.ClassLoader.loadClass(Unknown Source)
> at sun.misc.Unsafe.defineClass(Native Method)
> at sun.reflect.ClassDefiner.defineClass(Unknown Source)
> at sun.reflect.MethodAccessorGenerator$1.run(Unknown Source)
> at sun.reflect.MethodAccessorGenerator$1.run(Unknown Source)
> at java.security.AccessController.doPrivileged(Native Method)
>
> and this warning....
>
> org.eclipse.acceleo.engine.AcceleoEvaluationException: Invalid result
> for expression self.invoke('ecoa.transformation.common.UML2Services',
> 'hasStereotype(org.eclipse.uml2.uml.Element, java.lang.String)',
> Sequence {arg0, arg1}) at line 0 in Module uml2services for query
> hasStereotype(Element,String). Last recorded value of self was
> org.eclipse.uml2.uml.internal.impl.DataTypeImpl@56035798 (name:
> value_type, visibility: <unset>) (isLeaf: false, isAbstract: false,
> isFinalSpecialization: false). Problem found while generating the file
> 'D:\test.xml'.
>
>
> If I close and restart Eclipse, the generation again works the first
> time; every subsequent time fails with a set of the above NPE and
> warning pairs. It is a real pain having to restart Eclipse every time
> I want to re-run... Any thoughts?
>
> Thanks again.
Re: Cannot Access Stereotypes [message #1730748 is a reply to message #1730630] Thu, 28 April 2016 08:57 Go to previous messageGo to next message
Daniel Clarke is currently offline Daniel ClarkeFriend
Messages: 24
Registered: March 2016
Junior Member
Ed,

After much debugging (which only works using the the Java Runner), I figured out that it was silently failing to find my UML Profile. The profile was generated using Papyrus, and it seems that the location of the profile was not being set properly. The location was set to "/My_Profile/my.profile.uml". It looks like if you apply a profile when you create a new Papyrus model (using the new Papyrus model wizard) it sets the location in this fashion, but if you apply a profile after you have created a model (i.e. not using the wizard) it sets it in the form "platform:/resource/My_Profile/my.profile.uml".

I'm not sure if this is a bug in Papyrus, but updating to the "platform:/" form has fixed my issue and now it runs OK using the Java Runner.

I don't know why the Acceleo Plug-in Runner is behaving strangely still (i.e. generates only the first time after starting Eclipse - and I can't debug it to investigate) but I'm happy enough to use the Java Runner now which is working alright.

Thanks for your support!
Re: Cannot Access Stereotypes [message #1730779 is a reply to message #1730748] Thu, 28 April 2016 12:33 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You can always debug by running in a nested Eclipse, or by connecting a
remote Eclipse.

Silently ignoring things is very unhelpful. Probably worth raising a
Buzilla on Acceleo for the silence and Papyrus for the inconsistency.

I have found that it is difficult to make Acceleo URI resolution
useable; one reason I no longer use Acceleo.

The plugin launcher has been broken for at least a few years and its
confusing presence should end soon.

Regards

Ed Willink

On 28/04/2016 09:57, Daniel Clarke wrote:
> Ed,
>
> After much debugging (which only works using the the Java Runner), I
> figured out that it was silently failing to find my UML Profile. The
> profile was generated using Papyrus, and it seems that the location of
> the profile was not being set properly. The location was set to
> "/My_Profile/my.profile.uml". It looks like if you apply a profile
> when you create a new Papyrus model (using the new Papyrus model
> wizard) it sets the location in this fashion, but if you apply a
> profile after you have created a model (i.e. not using the wizard) it
> sets it in the form "platform:/resource/My_Profile/my.profile.uml".
>
> I'm not sure if this is a bug in Papyrus, but updating to the
> "platform:/" form has fixed my issue and now it runs OK using the Java
> Runner.
>
> I don't know why the Acceleo Plug-in Runner is behaving strangely
> still (i.e. generates only the first time after starting Eclipse -
> and I can't debug it to investigate) but I'm happy enough to use the
> Java Runner now which is working alright.
>
> Thanks for your support!
Previous Topic:acceleo launching
Next Topic:Acceleo does not regenerate
Goto Forum:
  


Current Time: Thu Apr 18 15:02:14 GMT 2024

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

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

Back to the top