Java Code Examples for org.eclipse.xtext.GrammarUtil#isBooleanAssignment()

The following examples show how to use org.eclipse.xtext.GrammarUtil#isBooleanAssignment() . 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: Xtext2EcoreInterpretationContext.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public void addFeature(Assignment assignment) throws TransformationException {
	final String featureName = assignment.getFeature();
	boolean isMultivalue = GrammarUtil.isMultipleAssignment(assignment);
	boolean isContainment = true;
	EClassifierInfo featureTypeInfo;

	if (GrammarUtil.isBooleanAssignment(assignment)) {
		checkNoFragmentRuleCall(assignment.getTerminal());
		EDataType eBoolean = GrammarUtil.findEBoolean(GrammarUtil.getGrammar(assignment));
		featureTypeInfo = getEClassifierInfoOrThrowException(eBoolean, assignment);
		isMultivalue = false;
	}
	else {
		AbstractElement terminal = assignment.getTerminal();
		if (terminal == null) {
			throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable, "Cannot derive type from incomplete assignment.", assignment);
		}
		checkNoFragmentRuleCall(terminal);
		EClassifier type = getTerminalType(terminal);
		isContainment = isContainmentAssignment(assignment);
		featureTypeInfo = getEClassifierInfoOrThrowException(type, assignment);
	}
	addFeature(featureName, featureTypeInfo, isMultivalue, isContainment, assignment);
}
 
Example 2
Source File: SequenceFeeder.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void accept(Keyword keyword) {
	Assignment ass = getAssignment(keyword);
	Object value = GrammarUtil.isBooleanAssignment(ass) ? Boolean.TRUE : keyword.getValue();
	EStructuralFeature feature = getFeature(ass.getFeature());
	ILeafNode node = getLeafNode(feature, value);
	String token = getToken(keyword, value, node);
	assertIndex(feature);
	acceptKeyword(ass, keyword, value, token, ISemanticSequenceAcceptor.NO_INDEX, node);
}
 
Example 3
Source File: SequenceFeeder.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String getToken(RuleCall rc, Object value, INode node) {
	CrossReference crossRef = GrammarUtil.containingCrossReference(rc);
	Assignment assignment = GrammarUtil.containingAssignment(rc);
	if (crossRef != null)
		return provider.crossRefSerializer.serializeCrossRef(semanticObject, crossRef, (EObject) value, node,
				errorAcceptor);
	else if (GrammarUtil.isEObjectRuleCall(rc) || GrammarUtil.isBooleanAssignment(assignment))
		return null;
	else if (GrammarUtil.isEnumRuleCall(rc))
		return provider.enumLiteralSerializer.serializeAssignedEnumLiteral(semanticObject, rc, value, node,
				errorAcceptor);
	else
		return provider.valueSerializer.serializeAssignedValue(semanticObject, rc, value, node, errorAcceptor);
}
 
Example 4
Source File: AssignmentFinder.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected Set<AbstractElement> findValidBooleanAssignments(EObject semanticObj,
		Iterable<AbstractElement> assignedElements, Object value) {
	Set<AbstractElement> result = Sets.newLinkedHashSet();
	for (AbstractElement ele : assignedElements)
		if (GrammarUtil.isBooleanAssignment(GrammarUtil.containingAssignment(ele))) {
			if (Boolean.TRUE.equals(value))
				result.add(ele);
		} else {
			if (ele instanceof RuleCall && valueSerializer.isValid(semanticObj, (RuleCall) ele, value, null))
				result.add(ele);
		}
	return result;
}
 
Example 5
Source File: SemanticSequencerNfaProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isBooleanAssignment() {
	if (booleanAssignment == null) {
		Assignment assignment = GrammarUtil.containingAssignment(assignedGrammarElement);
		booleanAssignment = assignment != null && GrammarUtil.isBooleanAssignment(assignment);
	}
	return booleanAssignment;
}
 
Example 6
Source File: SerializerFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isUnassignedRuleCall(final RuleCall c) {
  boolean _isEObjectRuleCall = GrammarUtil.isEObjectRuleCall(c);
  if (_isEObjectRuleCall) {
    return false;
  }
  final Assignment ass = GrammarUtil.containingAssignment(c);
  return ((ass == null) || GrammarUtil.isBooleanAssignment(ass));
}
 
Example 7
Source File: AbstractSyntacticSequencer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected String getUnassignedRuleCallToken(RuleCall ruleCall, INode node) {
	Assignment ass = GrammarUtil.containingAssignment(ruleCall);
	if (ass != null && !GrammarUtil.isBooleanAssignment(ass))
		throw new IllegalStateException("RuleCall is invalid; Can not determine token.");
	return getUnassignedRuleCallToken(contexts.peek().semanticObject, ruleCall, node);
}
 
Example 8
Source File: AntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected String _assignmentEbnf(final AbstractElement it, final Assignment assignment, final AntlrOptions options, final boolean supportActions) {
  String _xifexpression = null;
  if (supportActions) {
    StringConcatenation _builder = new StringConcatenation();
    String _localVar = this._grammarAccessExtensions.localVar(assignment, it);
    _builder.append(_localVar);
    _builder.append("=");
    String __assignmentEbnf = super._assignmentEbnf(it, assignment, options, supportActions);
    _builder.append(__assignmentEbnf);
    _builder.newLineIfNotEmpty();
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("if ($current==null) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("$current = ");
    CharSequence _createModelElement = this.createModelElement(assignment);
    _builder.append(_createModelElement, "\t\t");
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    String _setOrAdd = this._grammarAccessExtensions.setOrAdd(assignment);
    _builder.append(_setOrAdd, "\t");
    _builder.append("WithLastConsumed($current, \"");
    String _feature = assignment.getFeature();
    _builder.append(_feature, "\t");
    _builder.append("\", ");
    String _localVar_1 = this._grammarAccessExtensions.localVar(assignment, it);
    _builder.append(_localVar_1, "\t");
    {
      boolean _isBooleanAssignment = GrammarUtil.isBooleanAssignment(assignment);
      if (_isBooleanAssignment) {
        _builder.append(" != null");
      }
    }
    _builder.append(", ");
    CharSequence _stringLiteral = this._grammarAccessExtensions.toStringLiteral(assignment.getTerminal());
    _builder.append(_stringLiteral, "\t");
    _builder.append(");");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    _builder.newLine();
    _xifexpression = _builder.toString();
  } else {
    _xifexpression = super._assignmentEbnf(it, assignment, options, supportActions);
  }
  return _xifexpression;
}