Java Code Examples for org.eclipse.xtext.RuleCall#getRule()

The following examples show how to use org.eclipse.xtext.RuleCall#getRule() . These examples are extracted from open source projects. 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
@Check
public void checkTerminalFragmentCalledFromTerminalRule(final RuleCall call) {
	if (call.getRule() != null && !call.getRule().eIsProxy()) {
		if (call.getRule() instanceof TerminalRule && ((TerminalRule) call.getRule()).isFragment()) {
			AbstractRule container = GrammarUtil.containingRule(call);
			if (!(container instanceof TerminalRule)) {
				getMessageAcceptor().acceptError(
						"Only terminal rules may use terminal fragments.", 
						call, 
						XtextPackage.Literals.RULE_CALL__RULE,
						ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
						null);
			}
		}
	}
}
 
Example 2
protected void acceptRuleCall(RuleCall rc, Object value, String token, int index, INode node) {
	CrossReference crossRef = GrammarUtil.containingCrossReference(rc);
	if (crossRef != null) {
		if (rc.getRule() instanceof ParserRule)
			sequenceAcceptor.acceptAssignedCrossRefDatatype(rc, token, (EObject) value, index,
					getCompositeNode(node));
		else if (rc.getRule() instanceof TerminalRule)
			sequenceAcceptor.acceptAssignedCrossRefTerminal(rc, token, (EObject) value, index, getLeafNode(node));
		else if (rc.getRule() instanceof EnumRule)
			sequenceAcceptor.acceptAssignedCrossRefEnum(rc, token, (EObject) value, index, getCompositeNode(node));
	} else {
		if (rc.getRule() instanceof ParserRule) {
			AbstractRule rule = rc.getRule();
			if (rule.getType() != null && rule.getType().getClassifier() instanceof EClass)
				acceptEObjectRuleCall(rc, (EObject) value, getCompositeNode(node));
			else
				sequenceAcceptor.acceptAssignedDatatype(rc, token, value, index, getCompositeNode(node));
		} else if (rc.getRule() instanceof TerminalRule)
			sequenceAcceptor.acceptAssignedTerminal(rc, token, value, index, getLeafNode(node));
		else if (rc.getRule() instanceof EnumRule)
			sequenceAcceptor.acceptAssignedEnum(rc, token, value, index, getCompositeNode(node));
	}
}
 
Example 3
@Override
protected String getUnassignedRuleCallToken(EObject semanticObject, RuleCall ruleCall, INode node) {
	if (ruleCall.getRule() == grammarAccess.getCaseInsensitiveKeywordRule())
		return getCaseInsensitiveKeywordToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getDatatypeRule())
		return getDatatypeToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getGroupDataTypeRuleRule())
		return getGroupDataTypeRuleToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getIDRule())
		return getIDToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getINTRule())
		return getINTToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getMultiRule())
		return getMultiToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getPluralRule())
		return getPluralToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getSTRINGRule())
		return getSTRINGToken(semanticObject, ruleCall, node);
	return "";
}
 
Example 4
@Override
protected String getUnassignedRuleCallToken(RuleCall ruleCall, INode node) {
	if (node != null)
		return node.getText().trim();
	AbstractRule rule = ruleCall.getRule();
	if (GrammarUtil.isDatatypeRule(rule)) {
		if (rule.getAlternatives() instanceof Keyword)
			return ((Keyword) rule.getAlternatives()).getValue();
		if (rule.getAlternatives() instanceof Alternatives)
			for (AbstractElement ele : ((Alternatives) rule.getAlternatives()).getElements())
				if (ele instanceof Keyword)
					return ((Keyword) ele).getValue();
	}
	return "";
}
 
Example 5
@Override
protected String getUnassignedRuleCallToken(EObject semanticObject, RuleCall ruleCall, INode node) {
	if (ruleCall.getRule() == grammarAccess.getArrayBracketsRule())
		return getArrayBracketsToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getOpSingleAssignRule())
		return getOpSingleAssignToken(semanticObject, ruleCall, node);
	return "";
}
 
Example 6
@Override
protected String getUnassignedRuleCallToken(EObject semanticObject, RuleCall ruleCall, INode node) {
	if (ruleCall.getRule() == grammarAccess.getEND_TAG_SHORTRule())
		return getEND_TAG_SHORTToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getEQRule())
		return getEQToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getGTRule())
		return getGTToken(semanticObject, ruleCall, node);
	return "";
}
 
Example 7
@Override
protected String getUnassignedRuleCallToken(EObject semanticObject, RuleCall ruleCall, INode node) {
	if (ruleCall.getRule() == grammarAccess.getINTRule())
		return getINTToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getIntegerRule())
		return getIntegerToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getMaybeEmptyRule())
		return getMaybeEmptyToken(semanticObject, ruleCall, node);
	return "";
}
 
Example 8
@Override
protected String getUnassignedRuleCallToken(EObject semanticObject, RuleCall ruleCall, INode node) {
	if (ruleCall.getRule() == grammarAccess.getNO_LINE_TERMINATORRule())
		return getNO_LINE_TERMINATORToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getSemiRule())
		return getSemiToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getTemplateExpressionEndRule())
		return getTemplateExpressionEndToken(semanticObject, ruleCall, node);
	return "";
}
 
Example 9
@Override
public Boolean caseRuleCall(RuleCall object) {
	EClassifier wasType = currentType;
	AbstractRule calledRule = object.getRule();
	if (currentType == null) {
		if (calledRule instanceof ParserRule && !GrammarUtil.isDatatypeRule((ParserRule) calledRule)) {
			ParserRule parserRule = (ParserRule) calledRule;
			if (parserRule.isFragment()) {
				if (context.getType() != null)
					currentType = context.getType().getClassifier();
				if (!parserRule.isWildcard()) {
					doSwitch(parserRule);
				}
			} else {
				TypeRef returnType = calledRule.getType();
				if (returnType != null) {
					currentType = returnType.getClassifier();
				}
			}
		}
	} else if (isFragmentButNotWildcard(calledRule)) {
		doSwitch(calledRule);
	}
	if (object == stopElement)
		return true;
	if (GrammarUtil.isOptionalCardinality(object))
		currentType = getCompatibleType(currentType, wasType, object);
	return false;
}
 
Example 10
@Override
protected String getUnassignedRuleCallToken(EObject semanticObject, RuleCall ruleCall, INode node) {
	if (ruleCall.getRule() == grammarAccess.getArrayBracketsRule())
		return getArrayBracketsToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getOpSingleAssignRule())
		return getOpSingleAssignToken(semanticObject, ruleCall, node);
	return "";
}
 
Example 11
@Check
public void checkCallToDeprecatedParserRule(RuleCall ruleCall) {
	AbstractRule calledRule = ruleCall.getRule();
	if(hasAnnotation(calledRule, AnnotationNames.DEPRECATED)) {
		addIssue("The called rule is marked as deprecated.", ruleCall, XtextPackage.eINSTANCE.getRuleCall_Rule(), XtextConfigurableIssueCodes.USAGE_OF_DEPRECATED_RULE);
	}
}
 
Example 12
@Override
protected void _createProposals(final RuleCall ruleCall, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  AbstractRule _rule = ruleCall.getRule();
  boolean _matched = false;
  ParserRule _xExpressionRule = this._xbaseGrammarAccess.getXExpressionRule();
  if (Objects.equal(_rule, _xExpressionRule)) {
    _matched=true;
    if (((ruleCall.eContainer() instanceof Group) && Objects.equal(GrammarUtil.containingRule(ruleCall).getName(), "XParenthesizedExpression"))) {
      this.createLocalVariableAndImplicitProposals(context.getCurrentModel(), IExpressionScope.Anchor.WITHIN, context, acceptor);
    }
  }
  if (!_matched) {
    super._createProposals(ruleCall, context, acceptor);
  }
}
 
Example 13
@Override
public String caseRuleCall(RuleCall object) {
	AbstractRule rule = object.getRule();
	String ruleName;
	if (rule != null && !rule.eIsProxy())
		ruleName = rule.getName();
	else
		ruleName = "unresolved_rule";
	return addCrossRefOrAssignemnt(ruleName, object) + card(object);
}
 
Example 14
Source Project: sarl   File: SARLSyntacticSequencer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected String getUnassignedRuleCallToken(EObject semanticObject, RuleCall ruleCall, INode node) {
	if (ruleCall.getRule() == grammarAccess.getArrayBracketsRule())
		return getArrayBracketsToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getOpSingleAssignRule())
		return getOpSingleAssignToken(semanticObject, ruleCall, node);
	return "";
}
 
Example 15
@Override
protected String getUnassignedRuleCallToken(EObject semanticObject, RuleCall ruleCall, INode node) {
	if (ruleCall.getRule() == grammarAccess.getDataTypeRuleRule())
		return getDataTypeRuleToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getINTRule())
		return getINTToken(semanticObject, ruleCall, node);
	return "";
}
 
Example 16
@Override
protected String getUnassignedRuleCallToken(EObject semanticObject, RuleCall ruleCall, INode node) {
	if (ruleCall.getRule() == grammarAccess.getNLRule())
		return getNLToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getWSRule())
		return getWSToken(semanticObject, ruleCall, node);
	return "";
}
 
Example 17
public void completeNestedAssignment(Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor, TemplateData data) {
	String proposalText = "${" + assignment.getFeature() + "}";
	StyledString displayText;
	if (assignment.getTerminal() instanceof RuleCall) {
		RuleCall ruleCall = (RuleCall) assignment.getTerminal();
		AbstractRule calledRule = ruleCall.getRule();
		displayText = new StyledString("${", StyledString.DECORATIONS_STYLER)
			.append(assignment.getFeature(), null)
			.append("}", StyledString.DECORATIONS_STYLER)
			.append(" - ", StyledString.QUALIFIER_STYLER)
			.append(calledRule.getName(), StyledString.COUNTER_STYLER)
			.append(" - Create a new template variable", StyledString.QUALIFIER_STYLER);
	} else {
		displayText = new StyledString("${", StyledString.DECORATIONS_STYLER)
			.append(assignment.getFeature(), null)
			.append("}", StyledString.DECORATIONS_STYLER)
			.append(" - Create a new template variable", StyledString.QUALIFIER_STYLER);
	}
	ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context);
	if (proposal instanceof ConfigurableCompletionProposal) {
		ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
		configurable.setSelectionStart(configurable.getReplacementOffset() + 2);
		configurable.setSelectionLength(proposalText.length() - 3);
		configurable.setAutoInsertable(false);
		configurable.setSimpleLinkedMode(context.getViewer(), '\t');
		configurable.setPriority(configurable.getPriority() * 2);
	}
	acceptor.accept(proposal);
}
 
Example 18
@Override
protected String getUnassignedRuleCallToken(EObject semanticObject, RuleCall ruleCall, INode node) {
	if (ruleCall.getRule() == grammarAccess.getDEDENTRule())
		return getDEDENTToken(semanticObject, ruleCall, node);
	else if (ruleCall.getRule() == grammarAccess.getINDENTRule())
		return getINDENTToken(semanticObject, ruleCall, node);
	return "";
}
 
Example 19
@Override
protected String getUnassignedRuleCallToken(EObject semanticObject, RuleCall ruleCall, INode node) {
	if (ruleCall.getRule() == grammarAccess.getWSRule())
		return getWSToken(semanticObject, ruleCall, node);
	return "";
}
 
Example 20
@Override
public Void caseRuleCall(RuleCall object) {
	if (object.getRule() != null)
		return doSwitch(object.getRule());
	return null;
}