Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 10:35 Go to next message
Vittorio Niespolo is currently offline Vittorio NiespoloFriend
Messages: 10
Registered: May 2019
Junior Member
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 13:39 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6440
Registered: July 2009
Senior Member
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 11:38 Go to previous messageGo to next message
Vittorio Niespolo is currently offline Vittorio NiespoloFriend
Messages: 10
Registered: May 2019
Junior Member
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 11:38]

Report message to a moderator

Re: [Acceleo] For loop on Set<Class> is not working [message #1808604 is a reply to message #1808588] Thu, 27 June 2019 16:56 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6440
Registered: July 2009
Senior Member
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 Aug 24 17:31:36 GMT 2019

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

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

Back to the top