Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » problem with remove method of xpand(problem with remove method of xpand)
problem with remove method of xpand [message #1848966] Mon, 27 December 2021 13:03 Go to next message
Mera Mera is currently offline Mera MeraFriend
Messages: 4
Registered: November 2021
Junior Member
Hi all,

«LET (List[type]){} AS list»
«FOREACH play AS e»
«play .add(e) -> ""»
«ENDFOREACH-»

«IF !list.isEmpty»
«FOREACH list AS out ITERATOR i»
«out.name»
«list .remove(out) -> ""»
«ENDFOREACH»
«ENDIF»
«ENDLET»

when i use the remove method i have an exception as see attached:


-
java.util.ConcurrentModificationException
at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1013)
at java.base/java.util.ArrayList$Itr.next(ArrayList.java:967)
at org.eclipse.internal.xpand2.ast.ForEachStatement.evaluateInternal(ForEachStatement.java:117)
at org.eclipse.internal.xpand2.ast.Statement.evaluate(Statement.java:41)
at org.eclipse.internal.xpand2.ast.IfStatement.evaluateInternal(IfStatement.java:93)
at org.eclipse.internal.xpand2.ast.Statement.evaluate(Statement.java:41)
at org.eclipse.internal.xpand2.ast.ForEachStatement.evaluateInternal(ForEachStatement.java:121)
at org.eclipse.internal.xpand2.ast.Statement.evaluate(Statement.java:41)
at org.eclipse.internal.xpand2.ast.IfStatement.evaluateInternal(IfStatement.java:93)
at org.eclipse.internal.xpand2.ast.Statement.evaluate(Statement.java:41)
at org.eclipse.internal.xpand2.ast.LetStatement.evaluateInternal(LetStatement.java:66)
at org.eclipse.internal.xpand2.ast.Statement.evaluate(Statement.java:41)

please help me
thank's
Re: problem with remove method of xpand [message #1848968 is a reply to message #1848966] Mon, 27 December 2021 14:25 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Not sure about the exposition in Xpand but it looks like a standard Java problem.

You cannot modify a collection while you are iterating over it with incurring a risk/probablility of a CME.

If you cannot restructure to avoid it, the easiest workaround is to iterate over an ArrayList copy.

If the iteration is over a list, it can be effective to reverse iterate so that changes occur after the cursor.

Or for a list you can forward iterate an index and loop so long as the index is smaller than the size.

Sometimes you can use a list iterator and its prune() method.

Alternatively maintain a worklist/set and loop for as long as new work was found.

Regards

Ed Willink
Re: problem with remove method of xpand [message #1848974 is a reply to message #1848966] Mon, 27 December 2021 18:38 Go to previous messageGo to next message
Mera Mera is currently offline Mera MeraFriend
Messages: 4
Registered: November 2021
Junior Member
Thanks Ed for the quick response,
in my "code generation" project I use an xpand template, Arraylist does not work with Xpand, and for deletion the Xpand syntax as follows:
removeAll (Collection) and remove (Object) but I don't understand their uses with exceptions

SVP example of use on lists and method of deletion with Xpand
Thank's
Re: problem with remove method of xpand [message #1848978 is a reply to message #1848974] Mon, 27 December 2021 20:12 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I'm not sure that I have ever used Xpand; just Xtend that supersedes it. Even in Xtend, I try to use only the Xpand-based String templates; the rest I do in Java whose tooling is more predictable.

There is surely an Xpand escape to Java capability. Use it / practice in Java.

Migrate to Xtend. Xpand is dead; https://projects.eclipse.org/projects/modeling.m2t.xpand shows no release for 5.5 years and no commits in the last year. Expect problems with Java 11.

Regards

Ed Willink
Re: problem with remove method of xpand [message #1849000 is a reply to message #1848978] Tue, 28 December 2021 22:13 Go to previous message
Mera Mera is currently offline Mera MeraFriend
Messages: 4
Registered: November 2021
Junior Member
how to remove a traversed item from a browsed list so as not to be repeated
Previous Topic:problem with oclIsKindOf()
Next Topic:getLabel() behavior
Goto Forum:
  


Current Time: Thu Apr 25 21:33:24 GMT 2024

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

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

Back to the top