Search in sources :

Example 1 with Keyword

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

the class AbstractTextEditComposerTest method testObjectReplacement.

@Test
public void testObjectReplacement() throws Exception {
    Resource res = getResource(newTestGrammar());
    composer.beginRecording(res);
    Grammar grammar = (Grammar) res.getContents().get(0);
    ParserRule rule = (ParserRule) grammar.getRules().get(0);
    Keyword keyword = XtextFactory.eINSTANCE.createKeyword();
    keyword.setValue("baz");
    rule.setAlternatives(keyword);
    TextEdit edit = composer.endRecording();
    assertMatches("Foo: \"baz\";", edit);
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Keyword(org.eclipse.xtext.Keyword) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) Resource(org.eclipse.emf.ecore.resource.Resource) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 2 with Keyword

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

the class AbstractTextEditComposerTest method testObjectModificationAndRemoval.

/* see https://bugs.eclipse.org/bugs/show_bug.cgi?id=292349 */
@Test
public void testObjectModificationAndRemoval() throws Exception {
    Resource res = getResource(newTestGrammar());
    composer.beginRecording(res);
    Grammar grammar = (Grammar) res.getContents().get(0);
    AbstractRule rule = grammar.getRules().get(0);
    Alternatives alternatives = (Alternatives) rule.getAlternatives();
    Keyword bazKeyword = (Keyword) alternatives.getElements().get(2);
    bazKeyword.setValue("BAZ");
    alternatives.getElements().remove(bazKeyword);
    TextEdit edit = composer.endRecording();
    assertMatches("'foo' | 'bar'", edit);
}
Also used : Keyword(org.eclipse.xtext.Keyword) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) Resource(org.eclipse.emf.ecore.resource.Resource) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) Alternatives(org.eclipse.xtext.Alternatives) Test(org.junit.Test)

Example 3 with Keyword

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

the class XtextGrammarQuickfixProvider method fixEmptyEnumLiteral.

@Fix(EMPTY_ENUM_LITERAL)
public void fixEmptyEnumLiteral(final Issue issue, IssueResolutionAcceptor acceptor) {
    acceptor.acceptMulti(issue, "Fix empty enum literal", "Fix empty enum literal", NULL_QUICKFIX_IMAGE, (EObject element) -> {
        EnumLiteralDeclaration enumLiteralDeclaration = (EnumLiteralDeclaration) element;
        Keyword keyword = XtextFactory.eINSTANCE.createKeyword();
        keyword.setValue(enumLiteralDeclaration.getEnumLiteral().getName().toLowerCase());
        enumLiteralDeclaration.setLiteral(keyword);
    });
}
Also used : EnumLiteralDeclaration(org.eclipse.xtext.EnumLiteralDeclaration) Keyword(org.eclipse.xtext.Keyword) EObject(org.eclipse.emf.ecore.EObject) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Example 4 with Keyword

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

the class XtextLabelProvider method text.

StyledString text(EnumLiteralDeclaration object) {
    String literalName = getLiteralName(object);
    Keyword kw = object.getLiteral();
    String kwValue = kw == null ? "" : " = '" + kw.getValue() + "'";
    return new StyledString(literalName + kwValue, UNKNOWN.equalsIgnoreCase(literalName) ? stylerFactory.createStyler(JFacePreferences.ERROR_COLOR, null) : null);
}
Also used : Keyword(org.eclipse.xtext.Keyword) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 5 with Keyword

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

the class XtextLabelProvider method text.

String text(Assignment object) {
    StringBuffer label = new StringBuffer();
    label.append(object.getFeature()).append(" ").append(object.getOperator()).append(" ");
    AbstractElement terminal = object.getTerminal();
    if (terminal instanceof RuleCall) {
        RuleCall ruleCall = (RuleCall) terminal;
        String string = NodeModelUtils.getNode(ruleCall).getText();
        label.append(string);
    } else if (terminal instanceof Keyword) {
        Keyword keyword = (Keyword) terminal;
        String value = "'" + keyword.getValue() + "'";
        label.append(value);
    } else if (terminal instanceof CrossReference) {
        CrossReference crossReference = (CrossReference) terminal;
        label.append(getLabel(crossReference));
    } else {
        label.append("(..)");
    }
    String cardinality = object.getCardinality();
    label.append(cardinality != null ? cardinality : "");
    return label.toString();
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) Keyword(org.eclipse.xtext.Keyword) CrossReference(org.eclipse.xtext.CrossReference) StyledString(org.eclipse.jface.viewers.StyledString) RuleCall(org.eclipse.xtext.RuleCall)

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