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);
}
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);
}
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);
});
}
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);
}
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();
}
Aggregations