use of org.eclipse.xtext.Keyword in project n4js by eclipse.
the class GrammarLinter method printKeywordsOnlyInDatatypeRules.
private void printKeywordsOnlyInDatatypeRules() {
Grammar grammar = grammarAccess.getGrammar();
ListMultimap<String, Keyword> allKeywords = getAllKeywords(grammar);
System.out.println("Keywords which do not occur in production rules: ");
outer: for (Collection<Keyword> chunk : allKeywords.asMap().values()) {
for (Keyword keyword : chunk) {
AbstractRule rule = EcoreUtil2.getContainerOfType(keyword, AbstractRule.class);
if (!GrammarUtil.isDatatypeRule(rule)) {
continue outer;
}
}
System.out.println(" " + ((List<Keyword>) chunk).get(0).getValue());
}
System.out.println();
}
use of org.eclipse.xtext.Keyword in project n4js by eclipse.
the class GrammarLinter method getAllKeywords.
private static ListMultimap<String, Keyword> getAllKeywords(Grammar g) {
ListMultimap<String, Keyword> keywords = ArrayListMultimap.create();
List<ParserRule> rules = GrammarUtil.allParserRules(g);
for (ParserRule parserRule : rules) {
List<Keyword> list = typeSelect(eAllContentsAsList(parserRule), Keyword.class);
for (Keyword keyword : list) {
keywords.put(keyword.getValue(), keyword);
}
}
List<EnumRule> enumRules = GrammarUtil.allEnumRules(g);
for (EnumRule enumRule : enumRules) {
List<Keyword> list = typeSelect(eAllContentsAsList(enumRule), Keyword.class);
for (Keyword keyword : list) {
keywords.put(keyword.getValue(), keyword);
}
}
return keywords;
}
use of org.eclipse.xtext.Keyword in project dsl-devkit by dsldevkit.
the class GrammarElementReferenceImpl method setKeyword.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setKeyword(Keyword newKeyword) {
Keyword oldKeyword = keyword;
keyword = newKeyword;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, FormatPackage.GRAMMAR_ELEMENT_REFERENCE__KEYWORD, oldKeyword, keyword));
}
use of org.eclipse.xtext.Keyword in project dsl-devkit by dsldevkit.
the class ExportFormatter method configureFormatting.
/**
* {@inheritDoc}
*/
@Override
protected void configureFormatting(final FormattingConfig config) {
// NOPMD NPathComplexity by wth on 24.11.10 07:39
final ExportGrammarAccess grammar = (ExportGrammarAccess) getGrammarAccess();
config.setAutoLinewrap(MAXIMUM_LINE_LENGTH);
// Comments
config.setLinewrap(0, 1, 2).before(grammar.getSL_COMMENTRule());
config.setLinewrap(0, 1, 2).before(grammar.getML_COMMENTRule());
config.setLinewrap(0, 1, 1).after(grammar.getML_COMMENTRule());
// general keywords
for (final Pair<Keyword, Keyword> pair : grammar.findKeywordPairs("(", ")")) {
// $NON-NLS-1$ //$NON-NLS-2$
config.setNoSpace().before(pair.getFirst());
config.setNoSpace().after(pair.getFirst());
config.setNoSpace().before(pair.getSecond());
}
for (final Pair<Keyword, Keyword> pair : grammar.findKeywordPairs("[", "]")) {
// $NON-NLS-1$ //$NON-NLS-2$
config.setNoSpace().after(pair.getFirst());
config.setNoSpace().before(pair.getSecond());
}
for (final Pair<Keyword, Keyword> pair : grammar.findKeywordPairs("{", "}")) {
// $NON-NLS-1$ //$NON-NLS-2$
if (pair.getFirst() == grammar.getListLiteralAccess().getLeftCurlyBracketKeyword_1()) {
continue;
}
config.setLinewrap().after(pair.getFirst());
config.setIndentationIncrement().after(pair.getFirst());
config.setLinewrap().before(pair.getSecond());
config.setIndentationDecrement().before(pair.getSecond());
config.setLinewrap().after(pair.getSecond());
}
for (final Keyword delimiter : grammar.findKeywords("@", "+")) {
// $NON-NLS-1$ //$NON-NLS-2$
if (delimiter == grammar.getAdditiveExpressionAccess().getNamePlusSignKeyword_1_1_0_0()) {
continue;
}
config.setNoSpace().after(delimiter);
}
for (final Keyword delimiter : grammar.findKeywords(",")) {
// $NON-NLS-1$
config.setNoSpace().before(delimiter);
}
for (final Keyword delimiter : grammar.findKeywords(";")) {
// $NON-NLS-1$
config.setNoSpace().before(delimiter);
config.setLinewrap().after(delimiter);
}
for (final Keyword delimiter : grammar.findKeywords("#", "::", ".")) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
config.setNoSpace().around(delimiter);
}
// ExportSection
final ExportModelElements exportModelElements = grammar.getExportModelAccess();
config.setLinewrap(1).after(exportModelElements.getImportsAssignment_1());
config.setLinewrap(2).between(exportModelElements.getImportsAssignment_1(), exportModelElements.getExtensionsAssignment_2());
config.setLinewrap(1).before(exportModelElements.getExtensionsAssignment_2());
config.setLinewrap(2).before(exportModelElements.getExportsAssignment_4());
config.setLinewrap(2).before(exportModelElements.getGroup_3());
// Extension
final ExtensionElements extensionsElements = grammar.getExtensionAccess();
config.setLinewrap().after(extensionsElements.getGroup());
// Export
final ExportElements exportElements = grammar.getExportAccess();
config.setLinewrap(2).before(exportElements.getGroup());
}
use of org.eclipse.xtext.Keyword in project statecharts by Yakindu.
the class STextProposalProvider method completeKeyword.
/**
* Validates if a keyword should be viewed by the proposal view.
*
* Builds dependent on the ContentAssistContext a list with keywords which
* shouldn't be displayed by the proposal view.
*/
@Override
public void completeKeyword(Keyword keyword, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) {
List<Keyword> suppressKeywords = new ArrayList<Keyword>();
EObject rootModel = contentAssistContext.getRootModel();
if (rootModel instanceof TransitionSpecification) {
suppressKeywords(suppressKeywords, (TransitionSpecification) rootModel);
} else if (rootModel instanceof SimpleScope) {
suppressKeywords(suppressKeywords, (SimpleScope) rootModel);
} else if (rootModel instanceof StatechartSpecification) {
suppressKeywords(suppressKeywords, (StatechartSpecification) rootModel);
}
EObject currentModel = contentAssistContext.getCurrentModel();
if (currentModel instanceof InterfaceScope) {
suppressKeywords(suppressKeywords, (InterfaceScope) currentModel);
}
if (currentModel instanceof FeatureCall) {
suppressKeywords(suppressKeywords, (FeatureCall) currentModel);
}
if (currentModel instanceof ElementReferenceExpression) {
suppressKeywords(suppressKeywords, (ElementReferenceExpression) currentModel);
}
if (currentModel instanceof InternalScope) {
suppressKeywords(suppressKeywords, (InternalScope) currentModel);
}
if (!suppressKeywords.contains(keyword)) {
super.completeKeyword(keyword, contentAssistContext, new AcceptorDelegate(acceptor));
}
}
Aggregations