Search in sources :

Example 56 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 57 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 58 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 59 with Keyword

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

the class EnumLiteralSerializer method equalsOrReplacesNode.

@Override
public boolean equalsOrReplacesNode(EObject context, RuleCall ruleCall, Object value, INode node) {
    Keyword nodeLit = getLiteral(node);
    Keyword modelLit = getLiteral(context, ruleCall, value);
    return nodeLit != null && nodeLit.equals(modelLit);
}
Also used : Keyword(org.eclipse.xtext.Keyword)

Example 60 with Keyword

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

the class XtextFormatterJava method format.

protected void format(Grammar grammar, IFormattableDocument doc) {
    doc.prepend(regionFor(grammar).keyword("("), this::noSpace);
    formatParens(grammar, doc);
    regionFor(grammar).keywords(",").forEach(s -> doc.prepend(s, this::noSpace));
    regionFor(grammar).keywords(",").forEach(s -> doc.append(s, this::oneSpace));
    boolean first = true;
    for (AbstractMetamodelDeclaration decl : grammar.getMetamodelDeclarations()) {
        doc.set(previousHiddenRegion(decl), first ? it -> it.setNewLines(2) : it -> it.setNewLines(1));
        first = false;
        doc.format(decl);
    }
    for (AbstractRule rule : grammar.getRules()) {
        doc.set(previousHiddenRegion(rule), it -> it.setNewLines(2));
        doc.format(rule);
    }
    doc.set(nextHiddenRegion(grammar), it -> it.setNewLines(0, 0, 1));
}
Also used : CompoundElement(org.eclipse.xtext.CompoundElement) AbstractElement(org.eclipse.xtext.AbstractElement) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) Action(org.eclipse.xtext.Action) AbstractJavaFormatter(org.eclipse.xtext.formatting2.AbstractJavaFormatter) Disjunction(org.eclipse.xtext.Disjunction) EnumLiteralDeclaration(org.eclipse.xtext.EnumLiteralDeclaration) Annotation(org.eclipse.xtext.Annotation) CrossReference(org.eclipse.xtext.CrossReference) Assignment(org.eclipse.xtext.Assignment) EnumRule(org.eclipse.xtext.EnumRule) Wildcard(org.eclipse.xtext.Wildcard) Conjunction(org.eclipse.xtext.Conjunction) Group(org.eclipse.xtext.Group) EObject(org.eclipse.emf.ecore.EObject) CharacterRange(org.eclipse.xtext.CharacterRange) EList(org.eclipse.emf.common.util.EList) Alternatives(org.eclipse.xtext.Alternatives) TypeRef(org.eclipse.xtext.TypeRef) NamedArgument(org.eclipse.xtext.NamedArgument) RuleCall(org.eclipse.xtext.RuleCall) Keyword(org.eclipse.xtext.Keyword) UntilToken(org.eclipse.xtext.UntilToken) Grammar(org.eclipse.xtext.Grammar) TerminalRule(org.eclipse.xtext.TerminalRule) ParserRule(org.eclipse.xtext.ParserRule) Parameter(org.eclipse.xtext.Parameter) AbstractMetamodelDeclaration(org.eclipse.xtext.AbstractMetamodelDeclaration) AbstractRule(org.eclipse.xtext.AbstractRule) NegatedToken(org.eclipse.xtext.NegatedToken) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) AbstractMetamodelDeclaration(org.eclipse.xtext.AbstractMetamodelDeclaration) AbstractRule(org.eclipse.xtext.AbstractRule)

Aggregations

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