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