use of org.eclipse.xtext.nodemodel.impl.HiddenLeafNode in project ow by vtst.
the class SoyJavaValidator method doCheckNoHiddenLeafNode.
/**
* Helper function that checks that the parser nodes of a semantic element do not contain
* any hidden leaf node (whitespace, comment, etc.).
* @param object The semantic element to check.
* @param error_message The ID of the error message to display in case of error.
* @param stripBegin If true, hidden leaf nodes which appear at the beginning are ignored.
*/
private void doCheckNoHiddenLeafNode(EObject object, String error_message, boolean stripBegin) {
ICompositeNode parserNode = NodeModelUtils.getNode(object);
boolean atBegin = stripBegin;
for (INode node : parserNode.getLeafNodes()) {
if ("\"".equals(node.getText()))
break;
if (node instanceof HiddenLeafNode) {
if (!atBegin)
error(messages.getString(error_message), object, null, 0);
} else {
atBegin = false;
}
}
}
use of org.eclipse.xtext.nodemodel.impl.HiddenLeafNode 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);
}
Aggregations