Search in sources :

Example 36 with Keyword

use of org.eclipse.xtext.Keyword in project statecharts by Yakindu.

the class SGenFormatter method configureFormatting.

@Override
protected void configureFormatting(FormattingConfig c) {
    SGenGrammarAccess g = (SGenGrammarAccess) getGrammarAccess();
    // It's usually a good idea to activate the following three statements.
    // They will add and preserve newlines around comments
    c.setLinewrap(0, 1, 2).before(g.getSL_COMMENTRule());
    c.setLinewrap(0, 1, 2).before(g.getML_COMMENTRule());
    c.setLinewrap(0, 1, 1).after(g.getML_COMMENTRule());
    c.setLinewrap().before(g.getPropertyDefinitionRule());
    // - Line wrap before opening and after closing element
    for (Pair<Keyword, Keyword> pair : grammar.findKeywordPairs("{", "}")) {
        c.setIndentation(pair.getFirst(), pair.getSecond());
        c.setLinewrap().after(pair.getFirst());
        c.setLinewrap().around(pair.getSecond());
        Keyword openingBrace = pair.getFirst();
        Group containingGroup = (Group) openingBrace.eContainer();
        c.setLinewrap(1, 2, 2).before(containingGroup);
        c.setLinewrap(1, 1, 2).after(containingGroup);
    }
    c.setLinewrap().around(g.getFeatureConfigurationRule());
    c.setLinewrap().around(g.getFeatureParameterValueRule());
    c.setNoLinewrap().after(g.getGeneratorEntryAccess().getContentTypeAssignment_0());
    c.setNoLinewrap().after(g.getFeatureConfigurationAccess().getFeatureKeyword_1());
    c.setNoLinewrap().before(g.getGeneratorModelAccess().getGeneratorModelKeyword_0());
}
Also used : Group(org.eclipse.xtext.Group) SGenGrammarAccess(org.yakindu.sct.generator.genmodel.services.SGenGrammarAccess) Keyword(org.eclipse.xtext.Keyword)

Example 37 with Keyword

use of org.eclipse.xtext.Keyword in project dsl-devkit by dsldevkit.

the class FormatFormatter method configureFormatting.

@Override
protected void configureFormatting(final FormattingConfig config) {
    FormatGrammarAccess grammarAccess = (FormatGrammarAccess) getGrammarAccess();
    config.setAutoLinewrap(LINE_LENGTH);
    config.setLinewrap().before(grammarAccess.getFormatConfigurationAccess().getGroup_4());
    for (Pair<Keyword, Keyword> pair : grammarAccess.findKeywordPairs("{", "}")) {
        config.setIndentationIncrement().after(pair.getFirst());
        config.setLinewrap().after(pair.getFirst());
        config.setIndentationDecrement().before(pair.getSecond());
        config.setLinewrap().after(pair.getSecond());
    }
    for (Pair<Keyword, Keyword> pair : grammarAccess.findKeywordPairs("[", "]")) {
        config.setNoSpace().after(pair.getFirst());
        config.setNoSpace().before(pair.getSecond());
    }
    for (Keyword keyword : grammarAccess.findKeywords(";")) {
        config.setLinewrap().after(keyword);
        config.setNoSpace().before(keyword);
    }
    for (Keyword keyword : grammarAccess.findKeywords(",")) {
        config.setNoSpace().before(keyword);
    }
    for (Keyword keyword : grammarAccess.findKeywords("=", "@")) {
        config.setSpace("").after(keyword);
    }
    configComments(config, grammarAccess.getML_COMMENTRule(), grammarAccess.getSL_COMMENTRule());
    configConstants(config, grammarAccess);
    configGrammarRule(config, grammarAccess.getGrammarRuleAccess());
    configWildcardRule(config, grammarAccess.getWildcardRuleAccess());
    configKeywordPair(config, grammarAccess.getKeywordPairAccess());
}
Also used : Keyword(org.eclipse.xtext.Keyword) FormatGrammarAccess(com.avaloq.tools.ddk.xtext.format.services.FormatGrammarAccess)

Example 38 with Keyword

use of org.eclipse.xtext.Keyword in project dsl-devkit by dsldevkit.

the class ParseTreeUtil method getParsedStringUnchecked.

/**
 * Returns the source text assigned to the given feature of the given object. Does not work for multi-valued features. Optionally also converts the source
 * text using the corresponding value converter. Conversion is only performed for keywords, rule call or cross reference grammar rules.
 * <p>
 * This method does not perform a check to make sure the feature matches the given object.
 *
 * @param object
 *          the semantic object
 * @param feature
 *          the feature to be considered when parsing the parse tree model
 * @param convert
 *          {@code true} if the parsed string needs conversion using its value converter
 * @return the parsed string from the node model
 */
public static String getParsedStringUnchecked(final EObject object, final EStructuralFeature feature, final boolean convert) {
    INode node = Iterables.getFirst(NodeModelUtils.findNodesForFeature(object, feature), null);
    if (node != null) {
        if (convert) {
            final LazyLinkingResource res = (LazyLinkingResource) object.eResource();
            EObject grammarElement = node.getGrammarElement();
            if (res != null && (grammarElement instanceof Keyword || grammarElement instanceof RuleCall || grammarElement instanceof CrossReference)) {
                final DefaultLinkingService linkingService = (DefaultLinkingService) res.getLinkingService();
                return linkingService.getCrossRefNodeAsString(node);
            }
        }
        // result may contain escape sequences or quotes
        return NodeModelUtils.getTokenText(node);
    }
    return null;
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) Keyword(org.eclipse.xtext.Keyword) DefaultLinkingService(org.eclipse.xtext.linking.impl.DefaultLinkingService) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) EObject(org.eclipse.emf.ecore.EObject) CrossReference(org.eclipse.xtext.CrossReference) RuleCall(org.eclipse.xtext.RuleCall)

Example 39 with Keyword

use of org.eclipse.xtext.Keyword in project ow by vtst.

the class SoyJavaValidator method checkPrintDirective.

// **************************************************************************
// Print directives
/**
 * Check:
 * - There is no whitespace after the '|' in print directives,
 * - The directive name is known,
 * - The directive has the right number of parameters.
 */
@Check
public void checkPrintDirective(PrintDirective printDirective) {
    // Check there is no whitespace after the '|'
    ICompositeNode parserNode = NodeModelUtils.getNode(printDirective);
    for (INode node : parserNode.getChildren()) {
        EObject grammarElement = node.getGrammarElement();
        if (grammarElement instanceof Keyword) {
            String keywordValue = ((Keyword) grammarElement).getValue();
            if ("|".equals(keywordValue)) {
                if (node.getNextSibling() instanceof HiddenLeafNode) {
                    error(messages.getString("print_directive_whitespace_after_pipe"), printDirective, SoyPackage.eINSTANCE.getPrintDirective_Ident(), 0);
                }
            } else if (":".equals(keywordValue)) {
                if (node.getNextSibling() instanceof HiddenLeafNode) {
                    error(messages.getString("print_directive_whitespace_before_colon"), printDirective, SoyPackage.eINSTANCE.getPrintDirective_Ident(), 0);
                }
            }
        }
    }
    PrintDirectiveDeclaration printDirectiveDeclaration = printDirective.getIdent();
    // Do not validate unlinked elements
    if (printDirectiveDeclaration.getIdent() == null)
        return;
    doCheckNumberOfArguments(printDirective.getParameter().size(), printDirectiveDeclaration.getNumber_of_required_arguments(), printDirectiveDeclaration.getNumber_of_optional_arguments(), printDirectiveDeclaration.getIdent(), "print_directive_parameters", "print_directive_parameters_opt", printDirective, SoyPackage.eINSTANCE.getPrintDirective_Ident(), 0);
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) PrintDirectiveDeclaration(net.vtst.ow.eclipse.soy.soy.PrintDirectiveDeclaration) Keyword(org.eclipse.xtext.Keyword) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) HiddenLeafNode(org.eclipse.xtext.nodemodel.impl.HiddenLeafNode) Check(org.eclipse.xtext.validation.Check) ConfigurableCheck(net.vtst.eclipse.easyxtext.validation.config.ConfigurableCheck)

Example 40 with Keyword

use of org.eclipse.xtext.Keyword in project ow by vtst.

the class SoyJavaValidator method doCheckNewLineKeywords.

/**
 * Check that the keywords in {@code keywordsBeginOfLine} that appear within
 * {@code object} are all at the beginning of a line.
 * @param object
 */
private void doCheckNewLineKeywords(EObject object) {
    ICompositeNode parserNode = NodeModelUtils.getNode(object);
    INode previousNode = null;
    for (INode node : parserNode.getChildren()) {
        EObject grammarElement = node.getGrammarElement();
        if (grammarElement instanceof Keyword) {
            Keyword keyword = (Keyword) grammarElement;
            if (keywordsBeginOfLine.contains(keyword.getValue()) && !nodeEndsByNewLine(previousNode)) {
                error(messages.getString("keyword_must_be_after_newline"), node.getSemanticElement(), null, -1);
            }
        }
        previousNode = node;
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) Keyword(org.eclipse.xtext.Keyword) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

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