Xtext:quickfix给出ConcurrentModificationException异常

时间:2018-04-08 16:39:33

标签: xtext

使用语义模型编写quickfix路由来修复和错误,创建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;

语法abVariableName的{​​{1}}和int的实例。 如何解决异常?

更新 堆栈跟踪:

Type

1 个答案:

答案 0 :(得分:0)

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

@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
    ]
}