Search in sources :

Example 1 with PrintDirectiveDeclaration

use of net.vtst.ow.eclipse.soy.soy.PrintDirectiveDeclaration 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

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 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)1 INode (org.eclipse.xtext.nodemodel.INode)1 HiddenLeafNode (org.eclipse.xtext.nodemodel.impl.HiddenLeafNode)1 Check (org.eclipse.xtext.validation.Check)1