mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 08:48:55 +00:00
[xtext][args] Added some helpful error messages
Signed-off-by: Dennis Huebner <dennis.huebner@itemis.de>
This commit is contained in:
parent
a8df070d27
commit
2dcb254f50
1 changed files with 12 additions and 1 deletions
|
@ -163,12 +163,23 @@ public class XtextLinker extends Linker {
|
|||
if (!argument.isCalledByName()) {
|
||||
RuleCall ruleCall = EcoreUtil2.getContainerOfType(argument, RuleCall.class);
|
||||
AbstractRule calledRule = ruleCall.getRule();
|
||||
if (calledRule instanceof ParserRule && !calledRule.eIsProxy()) {
|
||||
if (!(calledRule instanceof ParserRule)) {
|
||||
producer.addDiagnostic(new DiagnosticMessage("Arguments can only be used with parser rules.", Severity.ERROR, null));
|
||||
return;
|
||||
}
|
||||
if (!calledRule.eIsProxy()) {
|
||||
ParserRule casted = (ParserRule) calledRule;
|
||||
int idx = ruleCall.getArguments().indexOf(argument);
|
||||
if (idx < casted.getParameters().size()) {
|
||||
argument.setParameter(casted.getParameters().get(idx));
|
||||
return;
|
||||
} else if (casted.getParameters().size() == 0) {
|
||||
producer.addDiagnostic(new DiagnosticMessage(
|
||||
"Rule " + calledRule.getName() + " has no arguments.", Severity.ERROR, null));
|
||||
} else {
|
||||
String message = "Invalid number of arguments for rule " + calledRule.getName() + ", expecting "
|
||||
+ casted.getParameters().size() + " but was " + (idx+1);
|
||||
producer.addDiagnostic(new DiagnosticMessage(message, Severity.ERROR, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue