4

I have an XPT template that generates text from a UML model. This is the excerpt I use on the attributes of a class

«FOREACH attribute AS a»
    Id: «a.name»
    Type: «a.type.name»
«ENDFOREACH»

All works well as long as the type is a class from the model itself. But if it is a primitive type, then all of the fields, including the name, is set to null. If I change «a.type.name» to «a.type», then the response is something like this:

org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl@6e315086 (eProxyURI:
     pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String)

The debugger shows that only the eStorage private field is set on the object that is why the toString() produces the output above.

Interestingly the same expression in Acceleo is evaluated correctly:

[query public getType(t : Type) : String = t.name /]

Question: how can I get the type field of attributes be filled in for primitive uml types in Xtend?

EDIT: Issue narrowed down to this question: EProxy URI does not resolve in ecore model

Community
  • 1
  • 1
allprog
  • 16,540
  • 9
  • 56
  • 97

2 Answers2

1

The code generated by Acceleo can resolve the unusual pathmap:// eProxyURIs. By default, a simple Xpand template or Xtend code can't resolve them. See this question for more details and the solution.

Community
  • 1
  • 1
thSoft
  • 21,755
  • 5
  • 88
  • 103
  • I got exactly the same problem today with Acceleo. But this solution didn't worked for me. In my model.uml file I tried to replace using a text editor all the occurrences of `pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml` with `http://www.eclipse.org/uml2/4.0.0/Types`. I also tried to replace with `http://www.eclipse.org/uml2/5.0.0/Types` and `http://www.omg.org/spec/UML/20161101/PrimitiveTypes.xmi` without success. Any idea of what's going wrong? @thSoft – lecoqlibre Apr 10 '22 at 10:01
1

My original solution is here.

After two days of searching, I found the solution.

The solution is write here: http://kompilatory.iiar.pwr.edu.pl/wiki/index.php/Acceleo/Getting_Started_33#Generating_java_beans

I had to modify the MANIFEST.MF and the Generate.java file in the following way.

  1. I had to add the org.eclipse.uml2.uml.resources as a new dependency.

  2. Moreover, I had to modify the Generate.java file in the following way.

2.1. The registerResourceFactories(ResourceSet resourceSet) method had to be set to "@generated NOT"

2.2. and the last line of the method had to be uncommented and added a semicolon ";" to the end of the line. UMLResourcesUtil.init(resourceSet);

2.3. And finally, had to be added a new import line. "import org.eclipse.uml2.uml.resources.util.UMLResourcesUtil;"