Search in sources :

Example 46 with Parameter

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);
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Parameter(org.eclipse.xtext.Parameter)

Example 47 with Parameter

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);
                    }
                }
            }
        }
    }
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Parameter(org.eclipse.xtext.Parameter) NamedArgument(org.eclipse.xtext.NamedArgument) AbstractRule(org.eclipse.xtext.AbstractRule) Check(org.eclipse.xtext.validation.Check)

Example 48 with 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));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) ModelFeatures(org.eclipse.xtext.xtext.ecoreInference.unassignedRuleCallTestLanguage.ModelFeatures) Model(org.eclipse.xtext.xtext.ecoreInference.unassignedRuleCallTestLanguage.Model) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage)

Example 49 with Parameter

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));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Statemachine(org.eclipse.xtext.testlanguages.fowlerdsl.Statemachine) Action(org.eclipse.xtext.Action) Command(org.eclipse.xtext.testlanguages.fowlerdsl.Command) State(org.eclipse.xtext.testlanguages.fowlerdsl.State) Transition(org.eclipse.xtext.testlanguages.fowlerdsl.Transition) Parameter(org.eclipse.xtext.Parameter) Event(org.eclipse.xtext.testlanguages.fowlerdsl.Event) EPackage(org.eclipse.emf.ecore.EPackage)

Example 50 with Parameter

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));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Greeting(org.eclipse.xtext.testlanguages.optionalEmpty.Greeting) Action(org.eclipse.xtext.Action) Model(org.eclipse.xtext.testlanguages.optionalEmpty.Model) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage)

Aggregations

Parameter (org.eclipse.xtext.Parameter)146 ParserRule (org.eclipse.xtext.ParserRule)137 Action (org.eclipse.xtext.Action)127 EPackage (org.eclipse.emf.ecore.EPackage)123 NamedArgument (org.eclipse.xtext.NamedArgument)7 EClass (org.eclipse.emf.ecore.EClass)6 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)6 AbstractElement (org.eclipse.xtext.AbstractElement)5 AbstractRule (org.eclipse.xtext.AbstractRule)5 RuleCall (org.eclipse.xtext.RuleCall)5 EObject (org.eclipse.emf.ecore.EObject)4 ParserRuleParameters (org.eclipse.xtext.parser.parameters.parametersTestLanguage.ParserRuleParameters)4 Scenario (org.eclipse.xtext.parser.parameters.parametersTestLanguage.Scenario)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 Group (org.eclipse.xtext.Group)3 ConditionEvaluator (org.eclipse.xtext.xtext.ConditionEvaluator)3 Set (java.util.Set)2 Assignment (org.eclipse.xtext.Assignment)2 EnumRule (org.eclipse.xtext.EnumRule)2 Grammar (org.eclipse.xtext.Grammar)2