use of org.eclipse.xtext.Keyword in project xtext-eclipse by eclipse.
the class ParameterContextInformationProvider method getParameterListOffset.
protected int getParameterListOffset(XExpression containerCall) {
List<XExpression> arguments = getArguments(containerCall);
if (arguments.isEmpty()) {
Keyword parameterListOpenParenthesis = getParameterListOpenParenthesis(containerCall);
for (ILeafNode leafNode : NodeModelUtils.findActualNodeFor(containerCall).getLeafNodes()) {
if (leafNode.getGrammarElement() == parameterListOpenParenthesis) {
return leafNode.getEndOffset();
}
}
int offset = 0;
for (INode node : NodeModelUtils.findNodesForFeature(containerCall, getCalledFeatureReference(containerCall))) offset = Math.max(offset, node.getEndOffset());
return offset;
} else {
INode node = NodeModelUtils.findActualNodeFor(arguments.get(0));
return node.getOffset();
}
}
use of org.eclipse.xtext.Keyword in project xtext-eclipse by eclipse.
the class XtextLocationInFileProviderTest method testKeywordLocation.
@Test
public void testKeywordLocation() {
Keyword keyword = (Keyword) grammar.getRules().get(0).getAlternatives();
ITextRegion region = locationInFileProvider.getFullTextRegion(keyword);
String fullRegion = grammarText.substring(region.getOffset(), region.getOffset() + region.getLength());
assertEquals("'keyword'*", fullRegion);
region = locationInFileProvider.getSignificantTextRegion(keyword);
String significantRegion = grammarText.substring(region.getOffset(), region.getOffset() + region.getLength());
assertEquals("'keyword'*", significantRegion);
}
use of org.eclipse.xtext.Keyword in project xtext-eclipse by eclipse.
the class GrammarAccessExtensions method toStringLiteral.
public CharSequence toStringLiteral(final AbstractElement it) {
CharSequence _switchResult = null;
boolean _matched = false;
if (it instanceof RuleCall) {
AbstractRule _rule = ((RuleCall) it).getRule();
boolean _tripleNotEquals = (_rule != null);
if (_tripleNotEquals) {
_matched = true;
StringConcatenation _builder = new StringConcatenation();
_builder.append("\"");
String _name = ((RuleCall) it).getRule().getName();
_builder.append(_name);
_builder.append("\"");
_switchResult = _builder;
}
}
if (!_matched) {
if (it instanceof Keyword) {
_matched = true;
StringConcatenation _builder = new StringConcatenation();
_builder.append("\"");
String _stringInAntlrAction = AntlrGrammarGenUtil.toStringInAntlrAction(((Keyword) it).getValue());
_builder.append(_stringInAntlrAction);
_builder.append("\"");
_switchResult = _builder;
}
}
if (!_matched) {
_switchResult = "null";
}
return _switchResult;
}
use of org.eclipse.xtext.Keyword in project n4js by eclipse.
the class ContentAssistTokenTypeMapper method getInternalTokenType.
/**
* Converts a grammar element to an Antlr token type (int).
*/
public int getInternalTokenType(EObject grammarElement) {
Integer type = grammarElements.get(grammarElement);
if (type == null) {
if (grammarElement instanceof Keyword) {
String keyword = ((Keyword) grammarElement).getValue();
type = tokenTypes.get("'" + keyword + "'");
} else if (grammarElement instanceof RuleCall) {
AbstractRule rule = ((RuleCall) grammarElement).getRule();
type = tokenTypes.get("RULE_" + rule.getName().toUpperCase());
} else if (grammarElement instanceof AbstractRule) {
AbstractRule rule = (AbstractRule) grammarElement;
type = tokenTypes.get("RULE_" + rule.getName().toUpperCase());
} else if (grammarElement instanceof EnumLiteralDeclaration) {
String keyword = ((EnumLiteralDeclaration) grammarElement).getLiteral().getValue();
type = tokenTypes.get("'" + keyword + "'");
} else if (grammarElement instanceof CrossReference) {
type = getInternalTokenType(((CrossReference) grammarElement).getTerminal());
} else {
throw new IllegalArgumentException(String.valueOf(grammarElement));
}
grammarElements.put(grammarElement, type);
}
return type;
}
use of org.eclipse.xtext.Keyword in project n4js by eclipse.
the class TokenTypeRewriter method rewriteKeywords.
private static void rewriteKeywords(AbstractRule rule, N4JSKeywords keywords, ImmutableMap.Builder<AbstractElement, Integer> builder) {
for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
if (obj instanceof Keyword) {
Keyword keyword = (Keyword) obj;
Integer type = keywords.getTokenType(keyword);
if (type != null) {
if (keyword.eContainer() instanceof EnumLiteralDeclaration) {
builder.put((AbstractElement) keyword.eContainer(), type);
} else {
builder.put(keyword, type);
}
}
}
}
}
Aggregations