Search in sources :

Example 1 with HiddenLeafNode

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;
        }
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) HiddenLeafNode(org.eclipse.xtext.nodemodel.impl.HiddenLeafNode)

Example 2 with HiddenLeafNode

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

Aggregations

ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)2 INode (org.eclipse.xtext.nodemodel.INode)2 HiddenLeafNode (org.eclipse.xtext.nodemodel.impl.HiddenLeafNode)2 ConfigurableCheck (net.vtst.eclipse.easyxtext.validation.config.ConfigurableCheck)1 PrintDirectiveDeclaration (net.vtst.ow.eclipse.soy.soy.PrintDirectiveDeclaration)1 EObject (org.eclipse.emf.ecore.EObject)1 Keyword (org.eclipse.xtext.Keyword)1 Check (org.eclipse.xtext.validation.Check)1