Skip to main content



      Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] For loop on Set<Class> is not working
[Acceleo] For loop on Set<Class> is not working [message #1808532] Wed, 26 June 2019 06:35 Go to next message
Eclipse UserFriend
I made a for loop in the main template that should print HELLO: WORLD for each class in my model using function getClasses.
The problem is that it is written only once.

GetClasses:
public Set<Class> getClasses(Model model) {
		Set<Class> classi = new HashSet<>();
		List<Type> types = model.getOwnedTypes();

		for (Type type : types) {
			if (type instanceof Class) {
				classi.add((Class) type);
			}
		}
		for(Class classe : classi)
		{
			System.out.println(classe);
		}
		return classi;
	}


MAIN:
[for(aClass : Class | getClasses(aModel))]
	[consoleMessage('HELLO', 'WORLD')/]
[/for]


RESULT:
org.eclipse.uml2.uml.internal.impl.ClassImpl@33aeca0b (name: Prodotto, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)

org.eclipse.uml2.uml.internal.impl.ClassImpl@5b1f29fa (name: Ordine, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)

org.eclipse.uml2.uml.internal.impl.ClassImpl@4b7e96a (name: CategoriaProdotto, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)

org.eclipse.uml2.uml.internal.impl.ClassImpl@6b44435b (name: ProdottoPerOrdine, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)

HELLO: WORLD


From the result is clear that the Set is properly filled but the for is not properly iterating.
Re: [Acceleo] For loop on Set<Class> is not working [message #1808539 is a reply to message #1808532] Wed, 26 June 2019 09:39 Go to previous messageGo to next message
Eclipse UserFriend
Hi

It's weird but since you haven't shown us how you declared your Java for use by Acceleo it is impossible to do more than say you probably got it wrong.

Regards

Ed Willink
Re: [Acceleo] For loop on Set<Class> is not working [message #1808588 is a reply to message #1808539] Thu, 27 June 2019 07:38 Go to previous messageGo to next message
Eclipse UserFriend
This is the way i access to Java services:


[query public getClasses(arg0 : Model) : Set(Class)
	= invoke('it.mice.acceleogenerator.javaservice.ModelJavaUtils', 'getClasses(org.eclipse.uml2.uml.Model)', Sequence{arg0})
/]



This query is correctly called as you can see from "RESULT" snippet. The problem is the for iterator.

[Updated on: Thu, 27 June 2019 07:38] by Moderator

Re: [Acceleo] For loop on Set<Class> is not working [message #1808604 is a reply to message #1808588] Thu, 27 June 2019 12:56 Go to previous message
Eclipse UserFriend
Hi

When you provide a repro, I may look at it. See e.g. https://wiki.eclipse.org/OCL/ForumNetiquette

Regards

Ed Willink
Previous Topic:Best way to use "separator" in an if chain
Next Topic:Read the value of properties of stereotype in Acceleo
Goto Forum:
  


Current Time: Sat Jun 14 19:25:26 EDT 2025

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

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

Back to the top