Search in sources :

Example 41 with Keyword

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

the class XtendSyntacticSequencer method emit_XBlockExpression_SemicolonKeyword_2_1_q.

/**
 * Syntax:
 *     ';'?
 */
@Override
protected void emit_XBlockExpression_SemicolonKeyword_2_1_q(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
    if (semicolonBeforeNextExpressionRequired) {
        ILeafNode node = nodes != null && nodes.size() == 1 && nodes.get(0) instanceof ILeafNode ? (ILeafNode) nodes.get(0) : null;
        Keyword kw = grammarAccess.getXBlockExpressionAccess().getSemicolonKeyword_2_1();
        acceptUnassignedKeyword(kw, kw.getValue(), node);
    } else
        acceptNodes(transition, nodes);
}
Also used : ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) Keyword(org.eclipse.xtext.Keyword)

Example 42 with Keyword

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

the class XtendSyntacticSequencer method emit_XParenthesizedExpression_LeftParenthesisKeyword_0_a.

/**
 * Syntax: '('*
 */
@Override
protected void emit_XParenthesizedExpression_LeftParenthesisKeyword_0_a(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
    Keyword kw = grammarAccess.getXParenthesizedExpressionAccess().getLeftParenthesisKeyword_0();
    if (nodes == null) {
        if (semanticObject instanceof XIfExpression || semanticObject instanceof XTryCatchFinallyExpression) {
            EObject cnt = semanticObject.eContainer();
            if (cnt instanceof XExpression && !(cnt instanceof XBlockExpression) && !(cnt instanceof XForLoopExpression))
                acceptUnassignedKeyword(kw, kw.getValue(), null);
        }
        if (semanticObject instanceof XConstructorCall) {
            XConstructorCall call = (XConstructorCall) semanticObject;
            if (!call.isExplicitConstructorCall() && call.getArguments().isEmpty()) {
                acceptUnassignedKeyword(kw, kw.getValue(), null);
            }
        }
    }
    acceptNodes(transition, nodes);
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XIfExpression(org.eclipse.xtext.xbase.XIfExpression) Keyword(org.eclipse.xtext.Keyword) EObject(org.eclipse.emf.ecore.EObject) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) XExpression(org.eclipse.xtext.xbase.XExpression) XTryCatchFinallyExpression(org.eclipse.xtext.xbase.XTryCatchFinallyExpression) XForLoopExpression(org.eclipse.xtext.xbase.XForLoopExpression)

Example 43 with Keyword

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

the class CreateMemberQuickfixes method getFirstOffsetOfKeyword.

/**
 * @since 2.3
 */
protected int getFirstOffsetOfKeyword(EObject object, String keyword) {
    int offset = -1;
    ICompositeNode node = NodeModelUtils.getNode(object);
    if (node != null) {
        for (ILeafNode leafNode : node.getLeafNodes()) {
            if (leafNode.getGrammarElement() instanceof Keyword && equal(keyword, ((Keyword) leafNode.getGrammarElement()).getValue())) {
                return leafNode.getOffset() + 1;
            }
        }
    }
    return offset;
}
Also used : ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) Keyword(org.eclipse.xtext.Keyword) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 44 with Keyword

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

the class ContentAssistContextFactory method isLikelyToBeValidProposal.

protected boolean isLikelyToBeValidProposal(INode lastCompleteNode, Iterable<ContentAssistContext> contexts) {
    for (ContentAssistContext context : contexts) {
        for (AbstractElement element : context.getFirstSetGrammarElements()) {
            if (element instanceof Keyword) {
                String keywordValue = ((Keyword) element).getValue();
                String lastText = ((ILeafNode) lastCompleteNode).getText();
                if (keywordValue.equals(lastText))
                    return true;
            }
        }
    }
    return false;
}
Also used : ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) AbstractElement(org.eclipse.xtext.AbstractElement) Keyword(org.eclipse.xtext.Keyword) ContentAssistContext(org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext)

Example 45 with Keyword

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

the class AbstractSyntacticSequencer method accept.

@SuppressWarnings("deprecation")
protected void accept(ISynState emitter, INode node, RuleCallStack stack) {
    switch(emitter.getType()) {
        case UNASSIGNED_PARSER_RULE_ENTER:
            RuleCall rc1 = (RuleCall) emitter.getGrammarElement();
            delegate.enterUnassignedParserRuleCall(rc1);
            stack.push(rc1);
            return;
        case UNASSIGNED_PARSER_RULE_EXIT:
            RuleCall rc2 = (RuleCall) emitter.getGrammarElement();
            delegate.leaveUnssignedParserRuleCall(rc2);
            RuleCall lastRc = stack.pop();
            if (lastRc != rc2) {
                if (errorAcceptor != null)
                    errorAcceptor.accept(diagnosticProvider.createUnexpectedStackStateDiagnostic(contexts.get(contexts.size() - 1).semanticObject, stack, lastRc, emitter));
            }
            return;
        case UNASSIGEND_ACTION_CALL:
            delegate.acceptUnassignedAction((Action) emitter.getGrammarElement());
            return;
        case UNASSIGEND_KEYWORD:
            Keyword keyword = (Keyword) emitter.getGrammarElement();
            String token = node != null ? node.getText() : keyword.getValue();
            delegate.acceptUnassignedKeyword(keyword, token, (ILeafNode) node);
            return;
        case UNASSIGNED_DATATYPE_RULE_CALL:
            RuleCall rc3 = (RuleCall) emitter.getGrammarElement();
            String value3 = getUnassignedRuleCallToken(rc3, node);
            delegate.acceptUnassignedDatatype(rc3, value3, (ICompositeNode) node);
            return;
        case UNASSIGNED_TERMINAL_RULE_CALL:
            RuleCall rc4 = (RuleCall) emitter.getGrammarElement();
            String value4 = getUnassignedRuleCallToken(rc4, node);
            delegate.acceptUnassignedTerminal(rc4, value4, (ILeafNode) node);
            return;
        case ASSIGNED_ACTION_CALL:
        case ASSIGNED_BOOLEAN_KEYWORD:
        case ASSIGNED_CROSSREF_DATATYPE_RULE_CALL:
        case ASSIGNED_CROSSREF_ENUM_RULE_CALL:
        case ASSIGNED_CROSSREF_KEYWORD:
        case ASSIGNED_CROSSREF_TERMINAL_RULE_CALL:
        case ASSIGNED_DATATYPE_RULE_CALL:
        case ASSIGNED_ENUM_RULE_CALL:
        case ASSIGNED_KEYWORD:
        case ASSIGNED_PARSER_RULE_CALL:
        case ASSIGNED_TERMINAL_RULE_CALL:
        case START:
        case STOP:
        case TRANSITION:
    }
    throw new RuntimeException("invalid state for emitting: " + emitter + " (" + emitter.getType() + ")");
}
Also used : Keyword(org.eclipse.xtext.Keyword) RuleCall(org.eclipse.xtext.RuleCall)

Aggregations

Keyword (org.eclipse.xtext.Keyword)67 EObject (org.eclipse.emf.ecore.EObject)15 RuleCall (org.eclipse.xtext.RuleCall)15 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)14 INode (org.eclipse.xtext.nodemodel.INode)13 AbstractElement (org.eclipse.xtext.AbstractElement)9 AbstractRule (org.eclipse.xtext.AbstractRule)9 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)9 Test (org.junit.Test)9 Grammar (org.eclipse.xtext.Grammar)8 ParserRule (org.eclipse.xtext.ParserRule)8 Action (org.eclipse.xtext.Action)7 CrossReference (org.eclipse.xtext.CrossReference)7 Assignment (org.eclipse.xtext.Assignment)6 EnumLiteralDeclaration (org.eclipse.xtext.EnumLiteralDeclaration)6 EnumRule (org.eclipse.xtext.EnumRule)6 Alternatives (org.eclipse.xtext.Alternatives)5 ArrayList (java.util.ArrayList)4 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)4 TerminalRule (org.eclipse.xtext.TerminalRule)4