使用语义模型编写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;
语法a
和b
是VariableName
的{{1}}和int
的实例。
如何解决异常?
更新 堆栈跟踪:
Type
答案 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
]
}