org.eclipse.xtext.xtext.ConditionEvaluator Java Examples

The following examples show how to use org.eclipse.xtext.xtext.ConditionEvaluator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SerializationContext.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public static ISerializationContext forChild(ISerializationContext container, RuleCall ruleCall, EObject sem) {
	EClass type = sem == null ? null : sem.eClass();
	ISerializationContext result = new TypeContext(new RuleContext(null, (ParserRule) ruleCall.getRule()), type);
	EList<NamedArgument> arguments = ruleCall.getArguments();
	if (!arguments.isEmpty() && container != null) {
		Set<Parameter> params = Sets.newLinkedHashSet();
		ConditionEvaluator evaluator = new ConditionEvaluator(container.getEnabledBooleanParameters());
		for (NamedArgument argument : arguments) {
			if (evaluator.evaluate(argument.getValue())) {
				params.add(argument.getParameter());
			}
		}
		result = new SerializationContext.ParameterValueContext(result, params);
	}
	return result;
}
 
Example #2
Source File: CustomN4JSParser.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private Set<Parameter> getParamConfig(List<RuleCall> callStack) {
	Set<Parameter> assignedParams = new HashSet<>();
	for (int i = callStack.size() - 1; i >= 0; i--) {
		RuleCall rc = callStack.get(i);
		ConditionEvaluator evaluator = new ConditionEvaluator(assignedParams);
		assignedParams = new HashSet<>();
		for (NamedArgument arg : rc.getArguments()) {
			Condition value = arg.getValue();
			if (evaluator.evaluate(value)) {
				assignedParams.add(arg.getParameter());
			}
		}
	}
	return assignedParams;
}
 
Example #3
Source File: ParserBasedContentAssistContextFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Boolean caseGroup(Group object) {
	boolean more = true;
	if (object.getGuardCondition() != null) {
		Set<Parameter> parameterValues = getParameterValues(object);
		more = new ConditionEvaluator(parameterValues).evaluate(object.getGuardCondition());
	}
	if (more) {
		for(AbstractElement element: object.getElements()) {
			more = more && doSwitch(element);
		}
	}
	return more || isOptional(object);
}
 
Example #4
Source File: RequiredRuleNameComputer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns true if the given candidate is a group that is filtered due to rule parameters in the current call graph.
 */
protected boolean isFiltered(AbstractElement canddiate, Param param) {
	if (canddiate instanceof Group) {
		Group group = (Group) canddiate;
		if (group.getGuardCondition() != null) {
			Set<Parameter> context = param.getAssignedParametes();
			ConditionEvaluator evaluator = new ConditionEvaluator(context);
			if (!evaluator.evaluate(group.getGuardCondition())) {
				return true;
			}
		}
	}
	return false;
}
 
Example #5
Source File: FollowElementCalculator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Boolean caseGroup(Group object) {
	boolean more = true;
	if (object.getGuardCondition() != null) {
		Set<Parameter> parameterValues = getParameterValues(object);
		more = new ConditionEvaluator(parameterValues).evaluate(object.getGuardCondition());
	}
	if (more) {
		for(AbstractElement element: object.getElements()) {
			more = more && doSwitch(element);
		}
	}
	return more || isOptional(object);
}