use of org.eclipse.xtext.Parameter in project xtext-core by eclipse.
the class ParameterConfigHelper method getParameterConfig.
public static int getParameterConfig(Set<Parameter> params) {
if (params.isEmpty()) {
return 0;
}
Parameter firstParam = params.iterator().next();
ParserRule parserRule = GrammarUtil.containingParserRule(firstParam);
return getParameterConfig(params, parserRule);
}
use of org.eclipse.xtext.Parameter in project xtext-core by eclipse.
the class XtextValidator method checkOrderOfArguments.
@Check
public void checkOrderOfArguments(RuleCall call) {
AbstractRule rule = call.getRule();
if (rule instanceof ParserRule) {
Set<Parameter> usedParameters = Sets.newHashSet();
boolean hasError = false;
boolean hasPositionalArgument = false;
boolean hasNamedArgument = false;
for (NamedArgument argument : call.getArguments()) {
Parameter parameter = argument.getParameter();
if (parameter == null || parameter.eIsProxy()) {
hasError = true;
} else if (!usedParameters.add(parameter)) {
hasError = true;
error("Duplicate value for parameter " + parameter.getName(), argument, XtextPackage.Literals.NAMED_ARGUMENT__PARAMETER);
}
if (!argument.isCalledByName()) {
hasPositionalArgument = true;
} else {
hasNamedArgument = true;
}
}
if (hasError) {
return;
}
List<Parameter> parameters = ((ParserRule) rule).getParameters();
if (!hasPositionalArgument) {
if (usedParameters.size() != parameters.size()) {
StringBuilder missing = new StringBuilder();
int count = 0;
for (Parameter parameter : parameters) {
if (!usedParameters.contains(parameter)) {
if (count > 0) {
missing.append(", ");
}
missing.append(parameter.getName());
count++;
}
}
if (count == 1) {
error("Missing argument for parameter " + missing, call, XtextPackage.Literals.RULE_CALL__RULE);
} else {
error(count + " missing arguments for the following parameters: " + missing, call, XtextPackage.Literals.RULE_CALL__RULE);
}
}
} else {
if (usedParameters.size() != parameters.size()) {
error(String.format("Expected %d arguments but got %d", parameters.size(), usedParameters.size()), call, XtextPackage.Literals.RULE_CALL__RULE);
} else if (hasNamedArgument) {
for (int i = 0, max = usedParameters.size(); i < max; i++) {
NamedArgument argument = call.getArguments().get(i);
Parameter param = parameters.get(i);
if (argument.isCalledByName() && argument.getParameter() != param) {
error("Out of sequence named argument. Expected value for " + param.getName(), argument, XtextPackage.Literals.NAMED_ARGUMENT__PARAMETER);
}
}
}
}
}
}
use of org.eclipse.xtext.Parameter in project xtext-core by eclipse.
the class UnassignedRuleCallTestLanguageSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == UnassignedRuleCallTestLanguagePackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case UnassignedRuleCallTestLanguagePackage.MODEL:
sequence_Model(context, (Model) semanticObject);
return;
case UnassignedRuleCallTestLanguagePackage.MODEL_FEATURES:
sequence_ModelFeatures(context, (ModelFeatures) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
use of org.eclipse.xtext.Parameter in project xtext-core by eclipse.
the class FowlerDslTestLanguageSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == FowlerdslPackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case FowlerdslPackage.COMMAND:
sequence_Command(context, (Command) semanticObject);
return;
case FowlerdslPackage.EVENT:
sequence_Event(context, (Event) semanticObject);
return;
case FowlerdslPackage.STATE:
sequence_State(context, (State) semanticObject);
return;
case FowlerdslPackage.STATEMACHINE:
sequence_Statemachine(context, (Statemachine) semanticObject);
return;
case FowlerdslPackage.TRANSITION:
sequence_Transition(context, (Transition) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
use of org.eclipse.xtext.Parameter in project xtext-core by eclipse.
the class OptionalEmptyTestLanguageSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == OptionalEmptyPackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case OptionalEmptyPackage.GREETING:
sequence_Greeting(context, (Greeting) semanticObject);
return;
case OptionalEmptyPackage.MODEL:
sequence_Model(context, (Model) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Aggregations