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