Search in sources :

Example 31 with Keyword

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();
}
Also used : Keyword(org.eclipse.xtext.Keyword) Collection(java.util.Collection) EcoreUtil2.eAllContentsAsList(org.eclipse.xtext.EcoreUtil2.eAllContentsAsList) List(java.util.List) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 32 with Keyword

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;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) EnumRule(org.eclipse.xtext.EnumRule) Keyword(org.eclipse.xtext.Keyword)

Example 33 with Keyword

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));
}
Also used : Keyword(org.eclipse.xtext.Keyword) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 34 with 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());
}
Also used : ExportModelElements(com.avaloq.tools.ddk.xtext.export.services.ExportGrammarAccess.ExportModelElements) ExtensionElements(com.avaloq.tools.ddk.xtext.export.services.ExportGrammarAccess.ExtensionElements) Keyword(org.eclipse.xtext.Keyword) ExportGrammarAccess(com.avaloq.tools.ddk.xtext.export.services.ExportGrammarAccess) ExportElements(com.avaloq.tools.ddk.xtext.export.services.ExportGrammarAccess.ExportElements)

Example 35 with Keyword

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));
    }
}
Also used : Keyword(org.eclipse.xtext.Keyword) SimpleScope(org.yakindu.sct.model.stext.stext.SimpleScope) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) TransitionSpecification(org.yakindu.sct.model.stext.stext.TransitionSpecification) StatechartSpecification(org.yakindu.sct.model.stext.stext.StatechartSpecification) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression)

Aggregations

Keyword (org.eclipse.xtext.Keyword)67 EObject (org.eclipse.emf.ecore.EObject)15 RuleCall (org.eclipse.xtext.RuleCall)15 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)14 INode (org.eclipse.xtext.nodemodel.INode)13 AbstractElement (org.eclipse.xtext.AbstractElement)9 AbstractRule (org.eclipse.xtext.AbstractRule)9 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)9 Test (org.junit.Test)9 Grammar (org.eclipse.xtext.Grammar)8 ParserRule (org.eclipse.xtext.ParserRule)8 Action (org.eclipse.xtext.Action)7 CrossReference (org.eclipse.xtext.CrossReference)7 Assignment (org.eclipse.xtext.Assignment)6 EnumLiteralDeclaration (org.eclipse.xtext.EnumLiteralDeclaration)6 EnumRule (org.eclipse.xtext.EnumRule)6 Alternatives (org.eclipse.xtext.Alternatives)5 ArrayList (java.util.ArrayList)4 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)4 TerminalRule (org.eclipse.xtext.TerminalRule)4