Xtext:quickfix 给出一个 ConcurrentModificationException 异常

Xtext: quickfix give an ConcurrentModificationException Exception

使用语义模型编写快速修复路由来修复和错误,创建了一个ConcurrentModificationException

org.eclipse.emf.common.util.WrappedException: java.util.ConcurrentModificationException
    at org.eclipse.xtext.ui.editor.quickfix.IssueResolution.apply(IssueResolution.java:78)
    at org.eclipse.xtext.ui.editor.quickfix.QuickAssistCompletionProposal.apply(QuickAssistCompletionProposal.java:36)
...

实现的方法:

@Fix(DslValidator.INVALID_NORMALISED_FLOW)
    def fixNormalised_ParameterDeclarations(Issue issue, IssueResolutionAcceptor acceptor) {
    acceptor.accept(issue, 'Normalize the parameters', 'Capitalize the name.', 'upcase.png') [ element, context |
        var param = element as ParameterDeclarations            
        //var index_s = issue.data // index provided from the validator
        var index = 1 // dummy index
        for (name : param.declare.get(index).identifier) {
            param.declare.get(index - 1).identifier.add(name)
        }
        param.declare.drop(index)
    ]
}

输入语法类似于 a:int, b:int,必须转换为 a, b:int,其中

ParameterDeclarations:
(
    declare+=VariableDeclare
    (',' declare+=VariableDeclare)*
) | (
    connection=ConnectionName
) | (
    not_connected?='void'?
);

VariableDeclare:
identifier+=VariableName (',' identifier+=VariableName)* ':' type=Type;

在语法中 abVariableNameintType 的实例。 如何解决异常?

更新: 堆栈跟踪:

 eclipse.buildId=4.7.3.M20180301-0715
 java.version=1.8.0_161
 java.vendor=Oracle Corporation
 BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_ZA
 Framework arguments:  -product org.eclipse.platform.ide
 Command-line arguments:  -product org.eclipse.platform.ide -data   /home/johan/workspace/sofl_dsl_2018_April/../runtime-EclipseXtext -dev  file:/home/johan/workspace/sofl_dsl_2018_April/.metadata/.plugins /org.eclipse.pde.core/Launch Runtime Eclipse/dev.properties -os linux -ws gtk -arch x86_64

 org.eclipse.ui
 Error
 Sun Apr 08 18:29:26 SAST 2018
 Unhandled event loop exception

 org.eclipse.emf.common.util.WrappedException:    java.util.ConcurrentModificationException
at org.eclipse.xtext.ui.editor.quickfix.IssueResolution.apply(IssueResolution.java:78)
at org.eclipse.xtext.ui.editor.quickfix.QuickAssistCompletionProposal.apply(QuickAssistCompletionProposal.java:36)
at org.eclipse.xtext.ui.editor.hover.AnnotationWithQuickFixesHover$AnnotationInformationControl.apply(AnnotationWithQuickFixesHover.java:536)
at org.eclipse.xtext.ui.editor.hover.AnnotationWithQuickFixesHover$AnnotationInformationControl.access(AnnotationWithQuickFixesHover.java:513)
at org.eclipse.xtext.ui.editor.hover.AnnotationWithQuickFixesHover$AnnotationInformationControl.widgetSelected(AnnotationWithQuickFixesHover.java:507)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:249)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5348)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1348)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1374)
at org.eclipse.swt.widgets.Widget.sendSelectionEvent(Widget.java:1488)
at org.eclipse.swt.widgets.Link.gtk_button_release_event(Link.java:384)
at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:1957)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:6193)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:5608)
at org.eclipse.swt.internal.gtk.OS._gtk_main_do_event(Native Method)
at org.eclipse.swt.internal.gtk.OS.gtk_main_do_event(OS.java:9282)
at org.eclipse.swt.widgets.Display.eventProc(Display.java:1328)
at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:2116)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4181)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1150)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1039)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
at org.eclipse.ui.internal.Workbench.lambda(Workbench.java:680)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:594)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:151)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
at org.eclipse.equinox.launcher.Main.run(Main.java:1499)
at org.eclipse.equinox.launcher.Main.main(Main.java:1472)

Caused by: java.util.ConcurrentModificationException
at org.eclipse.emf.common.util.AbstractEList$EIterator.checkModCount(AbstractEList.java:760)
at org.eclipse.emf.common.util.AbstractEList$EIterator.doNext(AbstractEList.java:714)
at org.eclipse.emf.common.util.AbstractEList$EIterator.next(AbstractEList.java:694)
at tuks.sofl.ui.quickfix.DslQuickfixProvider.lambda[=13=](DslQuickfixProvider.java:41)
at org.eclipse.xtext.ui.editor.model.edit.SemanticModificationWrapper.process(SemanticModificationWrapper.java:36)
at org.eclipse.xtext.ui.editor.model.edit.SemanticModificationWrapper.process(SemanticModificationWrapper.java:1)
at org.eclipse.xtext.util.concurrent.IUnitOfWork$Void.exec(IUnitOfWork.java:37)
at org.eclipse.xtext.ui.editor.model.edit.ReconcilingUnitOfWork.exec(ReconcilingUnitOfWork.java:56)
at org.eclipse.xtext.ui.editor.model.edit.ReconcilingUnitOfWork.exec(ReconcilingUnitOfWork.java:1)
at org.eclipse.xtext.resource.OutdatedStateManager.exec(OutdatedStateManager.java:91)
at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.modify(XtextDocument.java:428)
at org.eclipse.xtext.ui.editor.model.XtextDocument.internalModify(XtextDocument.java:162)
at org.eclipse.xtext.ui.editor.model.XtextDocument.modify(XtextDocument.java:155)
at org.eclipse.xtext.ui.editor.model.edit.SemanticModificationWrapper.apply(SemanticModificationWrapper.java:32)
at org.eclipse.xtext.ui.editor.quickfix.IssueResolution.apply(IssueResolution.java:76)
... 42 more

复制列表(正确的方法)并使用正确的方法删除列表中的元素:

@Fix(DslValidator.INVALID_NORMALISED_FLOW)
def fixNormalised_ParameterDeclarations(Issue issue, IssueResolutionAcceptor acceptor) {
    acceptor.accept(issue, 'Normalize the parameters', 'Capitalize the name.', 'upcase.png') [ element, context |
        var param = element as ParameterDeclarations
        var index = 1 // dummy index
        val copier = new EcoreUtil.Copier();
        var names_to_add = copier.copyAll(param.declare.get(index).identifier)  
        //for (name : param.declare.get(index).identifier) {
        for (name : names_to_add) {
            param.declare.get(index - 1).identifier.add(name)
        }
        param.declare.remove(index) // Also fix here use remove and not drop
    ]
}