Search in sources :

Example 1 with RuleCall

use of org.eclipse.xtext.RuleCall in project ow by vtst.

the class EasySemanticHighlightingCalculator method printDebugInformation.

private void printDebugInformation(INode node) {
    EObject grammarElement = node.getGrammarElement();
    System.out.println("TEXT: " + node.getText());
    System.out.println("GRAMMAR: " + grammarElement.getClass().getName());
    if (node.getSemanticElement().eContainer() != null)
        System.out.println("SEMANTIC CONTAINER: " + node.getSemanticElement().eContainer().getClass().getName());
    if (node.getSemanticElement().eContainmentFeature() != null)
        System.out.println("SEMANTIC CONTAINMENT: " + node.getSemanticElement().eContainmentFeature().getName());
    System.out.println("SEMANTIC RESOURCE: " + node.getSemanticElement().eResource().getClass().getName());
    System.out.println("SEMANTIC: " + node.getSemanticElement().getClass().getName());
    if (grammarElement != null)
        System.out.println("GRAMMAR ELEMENT CLASS:" + grammarElement.getClass().getName());
    if (grammarElement instanceof RuleCall) {
        System.out.println("RULE: " + ((RuleCall) grammarElement).getRule().getName());
        System.out.println("CLASS: " + ((RuleCall) grammarElement).getRule().eClass().getName());
    } else if (grammarElement instanceof Action) {
        System.out.println("CARDINALITY: " + ((Action) grammarElement).getCardinality());
        System.out.println("FEATURE: " + ((Action) grammarElement).getFeature());
        System.out.println("OPERATOR: " + ((Action) grammarElement).getOperator());
    }
    System.out.println("");
}
Also used : Action(org.eclipse.xtext.Action) EObject(org.eclipse.emf.ecore.EObject) RuleCall(org.eclipse.xtext.RuleCall)

Example 2 with RuleCall

use of org.eclipse.xtext.RuleCall in project xtext-xtend by eclipse.

the class XtendLocationInFileProvider method getSignificantTextRegion.

@Override
public ITextRegion getSignificantTextRegion(EObject element) {
    if (element instanceof RichStringLiteral) {
        ICompositeNode elementNode = findNodeFor(element);
        if (elementNode == null) {
            return ITextRegion.EMPTY_REGION;
        }
        ITextRegion result = ITextRegion.EMPTY_REGION;
        for (INode node : elementNode.getLeafNodes()) {
            if (isHidden(node)) {
                continue;
            }
            EObject grammarElement = node.getGrammarElement();
            if (!(grammarElement instanceof RuleCall)) {
                continue;
            }
            RuleCall ruleCall = (RuleCall) grammarElement;
            ITextRegionWithLineInformation region = node.getTextRegionWithLineInformation();
            int offset = region.getOffset();
            int length = region.getLength();
            if (grammarAccess.getRICH_TEXTRule() == ruleCall.getRule()) {
                offset += 3;
                length -= 6;
            } else if (grammarAccess.getRICH_TEXT_STARTRule() == ruleCall.getRule()) {
                offset += 3;
                length -= 4;
            } else if (grammarAccess.getRICH_TEXT_ENDRule() == ruleCall.getRule()) {
                offset += 1;
                length -= 4;
            } else if (grammarAccess.getRICH_TEXT_INBETWEENRule() == ruleCall.getRule()) {
                offset += 1;
                length -= 2;
            } else if (grammarAccess.getCOMMENT_RICH_TEXT_ENDRule() == ruleCall.getRule()) {
                offset += 2;
                length -= 5;
            } else if (grammarAccess.getCOMMENT_RICH_TEXT_INBETWEENRule() == ruleCall.getRule()) {
                offset += 2;
                length -= 3;
            } else {
                continue;
            }
            result = result.merge(toZeroBasedRegion(new TextRegionWithLineInformation(offset, length, region.getLineNumber(), region.getEndLineNumber())));
        }
        return result;
    }
    return super.getSignificantTextRegion(element);
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation) ITextRegion(org.eclipse.xtext.util.ITextRegion) EObject(org.eclipse.emf.ecore.EObject) RichStringLiteral(org.eclipse.xtend.core.xtend.RichStringLiteral) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) RuleCall(org.eclipse.xtext.RuleCall) TextRegionWithLineInformation(org.eclipse.xtext.util.TextRegionWithLineInformation) ITextRegionWithLineInformation(org.eclipse.xtext.util.ITextRegionWithLineInformation)

Example 3 with RuleCall

use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.

the class RequiredRuleNameComputer method getRequiredRuleNames.

/**
 * @since 2.14
 */
protected String[][] getRequiredRuleNames(Param param, AbstractElement elementToParse) {
    if (elementToParse instanceof RuleCall) {
        RuleCall call = (RuleCall) elementToParse;
        if (call.getRule() instanceof ParserRule) {
            String antlrRuleName = ruleNames.getAntlrRuleName(call.getRule());
            if (!call.getArguments().isEmpty()) {
                Set<Parameter> context = param.getAssignedParametes();
                Set<Parameter> arguments = getAssignedArguments(call, context);
                int config = getParameterConfig(arguments);
                antlrRuleName = ruleNames.getAntlrRuleName(call.getRule(), config);
            }
            return new String[][] { { antlrRuleName } };
        }
    }
    return EMPTY_ARRAY;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Parameter(org.eclipse.xtext.Parameter) RuleCall(org.eclipse.xtext.RuleCall)

Example 4 with RuleCall

use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.

the class BaseContentAssistParser method getFollowElements.

protected Collection<FE> getFollowElements(InternalParser parser, AbstractElement entryPoint) {
    String ruleName = getRuleName(entryPoint);
    if (ruleName == null) {
        if (entryPoint instanceof RuleCall) {
            RuleCall call = (RuleCall) entryPoint;
            AbstractRule rule = call.getRule();
            if (rule instanceof ParserRule) {
                ruleName = getRuleNames().getAntlrRuleName(rule);
            }
        }
    }
    if (ruleName == null) {
        throw new IllegalStateException("entryPoint: " + entryPoint);
    }
    return getFollowElements(parser, ruleName);
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) AbstractRule(org.eclipse.xtext.AbstractRule) RuleCall(org.eclipse.xtext.RuleCall)

Example 5 with RuleCall

use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.

the class AssignmentQuantityAllocator method allowTransient.

protected boolean allowTransient(EObject obj, EStructuralFeature feature, Collection<ISyntaxConstraint> constraint) {
    if (feature.getEType() instanceof EEnum)
        return true;
    Object value = obj.eGet(feature);
    List<RuleCall> ruleCalls = GrammarUtil.containedRuleCalls(constraint.iterator().next().getGrammarElement());
    if (ruleCalls.isEmpty())
        return false;
    return valueSerializer.isValid(obj, ruleCalls.get(0), value, null);
}
Also used : EObject(org.eclipse.emf.ecore.EObject) EEnum(org.eclipse.emf.ecore.EEnum) RuleCall(org.eclipse.xtext.RuleCall)

Aggregations

RuleCall (org.eclipse.xtext.RuleCall)95 ParserRule (org.eclipse.xtext.ParserRule)41 AbstractRule (org.eclipse.xtext.AbstractRule)36 EObject (org.eclipse.emf.ecore.EObject)33 Test (org.junit.Test)33 Grammar (org.eclipse.xtext.Grammar)28 AbstractElement (org.eclipse.xtext.AbstractElement)26 Assignment (org.eclipse.xtext.Assignment)22 TerminalRule (org.eclipse.xtext.TerminalRule)19 Action (org.eclipse.xtext.Action)17 CrossReference (org.eclipse.xtext.CrossReference)13 Group (org.eclipse.xtext.Group)13 TypeRef (org.eclipse.xtext.TypeRef)13 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)13 ArrayList (java.util.ArrayList)11 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)11 InternalEObject (org.eclipse.emf.ecore.InternalEObject)10 Keyword (org.eclipse.xtext.Keyword)10 EClass (org.eclipse.emf.ecore.EClass)9 EnumRule (org.eclipse.xtext.EnumRule)9