Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Type of UML attribute/property (Acceleo 4.3.0, Eclipse SR2)?
[Acceleo] Type of UML attribute/property (Acceleo 4.3.0, Eclipse SR2)? [message #1265583] Thu, 06 March 2014 09:25 Go to next message
Joost Kraaijeveld is currently offline Joost KraaijeveldFriend
Messages: 273
Registered: July 2009
Senior Member
Hi,

I have a Papyrus model in which a class has an attribute with of the
type String from the UML Primitive Types. Based on the getting started
tutorial I expected the following to work and to result in "String
attributeName":

[for (p: Property | aClass.attribute) separator('\n')]
[p.type.name/] [p.name/];
[/for]

But "[p.type.name/]" does not result in any output. Am I missing
something? What should I do?

TIA


Joost


Cheers,

Joost
Re: [Acceleo] Type of UML attribute/property (Acceleo 4.3.0, Eclipse SR2)? [message #1402835 is a reply to message #1265583] Thu, 17 July 2014 17:37 Go to previous messageGo to next message
Béla Boda is currently offline Béla BodaFriend
Messages: 1
Registered: July 2014
Junior Member
Yes you do.

Saidly it is a bit ugly, but you need to do as it is described here:
https://wiki.eclipse.org/MDT/UML2/FAQ#What.27s_required_to_load_a_UML_.28.uml.29_resource_from_a_standalone_application.3F

Don't forget the
@generated NOT


It works for me, customize your eclipse location and the versions:
    /**
     * This can be used to update the resource set's package registry with all needed EPackages.
     * 
     * @param resourceSet
     *            The resource set which registry has to be updated.
     * @generated NOT
     */
    @Override
    public void registerPackages(ResourceSet resourceSet) {
        super.registerPackages(resourceSet);
        if (!isInWorkspace(org.eclipse.uml2.uml.UMLPackage.class)) {
            resourceSet.getPackageRegistry().put(org.eclipse.uml2.uml.UMLPackage.eINSTANCE.getNsURI(), org.eclipse.uml2.uml.UMLPackage.eINSTANCE);
        }
        
        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
        Map uriMap = resourceSet.getURIConverter().getURIMap();
        URI uri = URI.createURI("jar:file:/c:/eclipse/eclipse-modeling-luna-R-win32-x86_64/plugins/org.eclipse.uml2.uml.resources_5.0.0.v20140602-0749.jar!/"); // for example
        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(""));
...
}
Re: [Acceleo] Type of UML attribute/property (Acceleo 4.3.0, Eclipse SR2)? [message #1402841 is a reply to message #1402835] Thu, 17 July 2014 18:44 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

As of Luna UMLReourcesUtil.init(ResourceSet) does all the setup scanning
the classpath top discover the JAR spelling. Acceleo could call it for
you but it doesn't.

(In Kepler the pathmap assignments were still needed.)

Regards

Ed Willink


On 17/07/2014 19:12, Béla Boda wrote:
> Yes you do.
>
> Saidly it is a bit ugly, but you need to do as it is described here:
> https://wiki.eclipse.org/MDT/UML2/FAQ#What.27s_required_to_load_a_UML_.28.uml.29_resource_from_a_standalone_application.3F
>
>
> Don't forget the @generated NOT
>
> It works for me, customize your eclipse location and the versions:
>
> /**
> * This can be used to update the resource set's package registry
> with all needed EPackages.
> * * @param resourceSet
> * The resource set which registry has to be updated.
> * @generated NOT
> */
> @Override
> public void registerPackages(ResourceSet resourceSet) {
> super.registerPackages(resourceSet);
> if (!isInWorkspace(org.eclipse.uml2.uml.UMLPackage.class)) {
> resourceSet.getPackageRegistry().put(org.eclipse.uml2.uml.UMLPackage.eINSTANCE.getNsURI(),
> org.eclipse.uml2.uml.UMLPackage.eINSTANCE);
> }
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> Map uriMap = resourceSet.getURIConverter().getURIMap();
> URI uri =
> URI.createURI("jar:file:/c:/eclipse/eclipse-modeling-luna-R-win32-x86_64/plugins/org.eclipse.uml2.uml.resources_5.0.0.v20140602-0749.jar!/");
> // for example
> 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(""));
> ..
> }
>
Re: [Acceleo] Type of UML attribute/property (Acceleo 4.3.0, Eclipse SR2)? [message #1405548 is a reply to message #1402841] Thu, 07 August 2014 15:44 Go to previous messageGo to next message
Ol Reak is currently offline Ol ReakFriend
Messages: 2
Registered: August 2014
Junior Member
Hi,

I have exactly the same problem but the given solution did not solve the problem for me.
Below, the code of my "registerPackages" function (with suggested moficiations):
    /**
     * This can be used to update the resource set's package registry with all needed EPackages.
     * 
     * @param resourceSet
     *            The resource set which registry has to be updated.
     * @generated NOT
     */
    @Override
    public void registerPackages(ResourceSet resourceSet) {
        super.registerPackages(resourceSet);

        if (!isInWorkspace(org.eclipse.uml2.uml.UMLPackage.class)) {
            resourceSet.getPackageRegistry().put(org.eclipse.uml2.uml.UMLPackage.eINSTANCE.getNsURI(), org.eclipse.uml2.uml.UMLPackage.eINSTANCE);
            
            resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(org.eclipse.uml2.uml.resource.UMLResource.FILE_EXTENSION, org.eclipse.uml2.uml.resource.UMLResource.Factory.INSTANCE);
            Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
            URI uri = URI.createURI("jar:file:/C:/Users/.../eclipse/plugins/org.eclipse.uml2.uml.resources.source_5.0.0.v20140519-1951.jar!/"); // for example
            uriMap.put(URI.createURI(org.eclipse.uml2.uml.resource.UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
            uriMap.put(URI.createURI(org.eclipse.uml2.uml.resource.UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
            uriMap.put(URI.createURI(org.eclipse.uml2.uml.resource.UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));
        }

        if (!isInWorkspace(org.eclipse.papyrus.C_Cpp.C_CppPackage.class)) {
            resourceSet.getPackageRegistry().put(org.eclipse.papyrus.C_Cpp.C_CppPackage.eINSTANCE.getNsURI(), org.eclipse.papyrus.C_Cpp.C_CppPackage.eINSTANCE);
            
            resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(org.eclipse.uml2.uml.resource.UMLResource.FILE_EXTENSION, org.eclipse.uml2.uml.resource.UMLResource.Factory.INSTANCE);
            Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
            URI uri = URI.createURI("jar:file:/C:/Users/.../eclipse/plugins/org.eclipse.papyrus.cpp.profile_1.0.0.v201406250859.jar!/"); // for example
            uriMap.put(URI.createURI(org.eclipse.uml2.uml.resource.UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
            uriMap.put(URI.createURI(org.eclipse.uml2.uml.resource.UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
            uriMap.put(URI.createURI(org.eclipse.uml2.uml.resource.UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));
        }

        if (!isInWorkspace(org.eclipse.emf.ecore.EcorePackage.class)) {
            resourceSet.getPackageRegistry().put(org.eclipse.emf.ecore.EcorePackage.eINSTANCE.getNsURI(), org.eclipse.emf.ecore.EcorePackage.eINSTANCE);
            
            resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(org.eclipse.uml2.uml.resource.UMLResource.FILE_EXTENSION, org.eclipse.uml2.uml.resource.UMLResource.Factory.INSTANCE);
            Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
            URI uri = URI.createURI("jar:file:/C:/Users/.../eclipse/plugins/org.eclipse.emf.ecore.source_2.10.0.v20140514-1158.jar!/"); // for example
            uriMap.put(URI.createURI(org.eclipse.uml2.uml.resource.UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
            uriMap.put(URI.createURI(org.eclipse.uml2.uml.resource.UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
            uriMap.put(URI.createURI(org.eclipse.uml2.uml.resource.UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));
        }

         /*
         * If you want to change the content of this method, do NOT forget to change the "@generated"
         * tag in the Javadoc of this method to "@generated NOT". Without this new tag, any compilation
         * of the Acceleo module with the main template that has caused the creation of this class will
         * revert your modifications.
         */
        
        /*
         * If you need additional package registrations, you can register them here. The following line
         * (in comment) is an example of the package registration for UML.
         * 
         * You can use the method  "isInWorkspace(Class c)" to check if the package that you are about to
         * register is in the workspace.
         * 
         * To register a package properly, please follow the following conventions:
         *
         * If the package is located in another plug-in, already installed in Eclipse. The following content should
         * have been generated at the beginning of this method. Do not register the package using this mechanism if
         * the metamodel is located in the workspace.
         *  
         * if (!isInWorkspace(UMLPackage.class)) {
         *     // The normal package registration if your metamodel is in a plugin.
         *     resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
         * }
         * 
         * If the package is located in another project in your workspace, the plugin containing the package has not
         * been register by EMF and Acceleo should register it automatically. If you want to use the generator in
         * stand alone, the regular registration (seen a couple lines before) is needed.
         * 
         * To learn more about Package Registration, have a look at the Acceleo documentation (Help -> Help Contents).
         */
    }


Any other idea?

Thanks
Re: [Acceleo] Type of UML attribute/property (Acceleo 4.3.0, Eclipse SR2)? [message #1405940 is a reply to message #1405548] Fri, 08 August 2014 15:00 Go to previous messageGo to next message
Ol Reak is currently offline Ol ReakFriend
Messages: 2
Registered: August 2014
Junior Member
Hi,

I finally found how to make it works. I am not sure how I did it, but here is the code of my "registerPackages" function now:
    /**
     * This can be used to update the resource set's package registry with all needed EPackages.
     * 
     * @param resourceSet
     *            The resource set which registry has to be updated.
     * @generated NOT
     */
    @Override
    public void registerPackages(ResourceSet resourceSet) {
        super.registerPackages(resourceSet);
        if (!isInWorkspace(org.eclipse.uml2.types.TypesPackage.class)) {
            resourceSet.getPackageRegistry().put(org.eclipse.uml2.types.TypesPackage.eINSTANCE.getNsURI(), org.eclipse.uml2.types.TypesPackage.eINSTANCE);
        }
        if (!isInWorkspace(org.eclipse.uml2.uml.UMLPackage.class)) {
            resourceSet.getPackageRegistry().put(org.eclipse.uml2.uml.UMLPackage.eINSTANCE.getNsURI(), org.eclipse.uml2.uml.UMLPackage.eINSTANCE);
        }
        if (!isInWorkspace(org.eclipse.papyrus.C_Cpp.C_CppPackage.class)) {
            resourceSet.getPackageRegistry().put(org.eclipse.papyrus.C_Cpp.C_CppPackage.eINSTANCE.getNsURI(), org.eclipse.papyrus.C_Cpp.C_CppPackage.eINSTANCE);
        }
        if (!isInWorkspace(org.eclipse.emf.ecore.EcorePackage.class)) {
            resourceSet.getPackageRegistry().put(org.eclipse.emf.ecore.EcorePackage.eINSTANCE.getNsURI(), org.eclipse.emf.ecore.EcorePackage.eINSTANCE);
        }
        
        
        Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
        URI uri = URI.createURI("jar:file:/C:/Users/.../eclipse/plugins/org.eclipse.uml2.uml.resources_5.0.0.v20140519-1951.jar!/");
        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(""));
    }


I have also modified the "registerResourceFactories" function (because I am loading .uml files, not .xmi files), I do not know if it has really an effect:
    /**
     * This can be used to update the resource set's resource factory registry with all needed factories.
     * 
     * @param resourceSet
     *            The resource set which registry has to be updated.
     * @generated NOT
     */
    @Override
    public void registerResourceFactories(ResourceSet resourceSet) {
        super.registerResourceFactories(resourceSet);
        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("uml", new org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl());
    }
Re: [Acceleo] Type of UML attribute/property (Acceleo 4.3.0, Eclipse SR2)? [message #1756221 is a reply to message #1405940] Tue, 14 March 2017 09:29 Go to previous messageGo to next message
Maya Retno is currently offline Maya RetnoFriend
Messages: 1
Registered: March 2017
Junior Member
Hi,
I got the same problem.

The type of attributes or operations can't be accessed by [p.type.name/].
I tried the solutions provided in this thread, but there are some errors in the Generate.Java.

I also changed the Runner from Java Application to Acceleo plugin, but it didn't work.

Previously, my Acceleo code running well on Eclipse Modeling Juno.
I attempted to run on Eclipse Neon and this problem happened

Any idea what should I do?

regards,
Maya
Re: [Acceleo] Type of UML attribute/property (Acceleo 4.3.0, Eclipse SR2)? [message #1756270 is a reply to message #1756221] Tue, 14 March 2017 18:21 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Three years later you probably do not have the same problem.

Some errors in Generate.java sound like it needs investigating.

Regards

Ed Willink
Re: [Acceleo] Type of UML attribute/property (Acceleo 4.3.0, Eclipse SR2)? [message #1756275 is a reply to message #1756221] Tue, 14 March 2017 19:27 Go to previous messageGo to next message
louis andia. is currently offline louis andia.Friend
Messages: 47
Registered: November 2016
Member
Maya Retno wrote on Tue, 14 March 2017 09:29

The type of attributes or operations can't be accessed by [p.type.name/].

Have you an error in console? Are you certain that p is in the good type and not undefined?
Re: [Acceleo] Type of UML attribute/property (Acceleo 4.3.0, Eclipse SR2)? [message #1758042 is a reply to message #1756275] Wed, 22 March 2017 22:56 Go to previous message
Philip Schröder is currently offline Philip SchröderFriend
Messages: 28
Registered: January 2017
Junior Member
Hello guys,
I had the same problem right now and solved it (I have Eclipse Mars 2 with Acceleo 3.7).

First of all, I copied the code from Ol Reak into my java file, the one which got the same name as my main ".mtl" generator file and changed everything according to my system

URI uri = URI.createURI("jar:file:/C:/Users/.../eclipse/plugins/org.eclipse.uml2.uml.resources_5.0.0.v20140519-1951.jar!/");


Here you have to fill in the path where your eclipse is installed and find out the actual name of the jar file with your version, for instance for me it is

URI uri = URI.createURI("jar:file:/C:/eclipse-php-mars-R-win32/eclipse/plugins/org.eclipse.uml2.uml.resources_5.1.0.v20160201-0816.jar!/"); 


Then the compiler nagged, that he didn't know Map and UMLResource,
so I added to the imports at the top of my file

import java.util.Map;
import org.eclipse.uml2.uml.resource.UMLResource;


Then, last not least, he told me that in registerPackages concerning

if (!isInWorkspace(org.eclipse.papyrus.C_Cpp.C_CppPackage.class)) {
    resourceSet.getPackageRegistry().put(org.eclipse.papyrus.C_Cpp.C_CppPackage.eINSTANCE.getNsURI(), org.eclipse.papyrus.C_Cpp.C_CppPackage.eINSTANCE);
        }


org.eclipse.papyrus.C_Cpp.C_CppPackage couldn't be used as a type, or something like that.

But I found this

https://git.eclipse.org/c/papyrus/org.eclipse.papyrus.git/commit/?id=8825c18b6e8926b45269c40d9af43c3c064b0048

It seems the project org.eclipse.papyrus.C_Cpp was remodeled to be part of
org.eclipse.papyrus.cpp.

So I tried to add that in my MANIFEST at Dependencies, turned out, you need
org.eclipse.papyrus.cpp.profile to get it working.

[Updated on: Wed, 22 March 2017 23:02]

Report message to a moderator

Previous Topic:modelToSysml
Next Topic:add [
Goto Forum:
  


Current Time: Tue Apr 16 12:50:12 GMT 2024

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

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

Back to the top