aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/main/java/com/yahoo/document/select/NowCheckVisitor.java
blob: 9aa87601d92b3bc87ce28d77bc0b94ca6c4eb997 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.select;

import com.yahoo.document.select.rule.ArithmeticNode;
import com.yahoo.document.select.rule.AttributeNode;
import com.yahoo.document.select.rule.ComparisonNode;
import com.yahoo.document.select.rule.DocumentNode;
import com.yahoo.document.select.rule.DocumentTypeNode;
import com.yahoo.document.select.rule.EmbracedNode;
import com.yahoo.document.select.rule.IdNode;
import com.yahoo.document.select.rule.LiteralNode;
import com.yahoo.document.select.rule.LogicNode;
import com.yahoo.document.select.rule.NegationNode;
import com.yahoo.document.select.rule.NowNode;
import com.yahoo.document.select.rule.VariableNode;

/**
 * Traverse and check if there exists any now() function in the expression tree.
 *
 * @author Ulf Lilleengen
 */
public class NowCheckVisitor implements Visitor {

    private int nowNodeCount = 0;

    public boolean requiresConversion() {
        return (nowNodeCount > 0);
    }

    public void visit(ArithmeticNode node) {
        for (ArithmeticNode.NodeItem item : node.getItems()) {
            item.getNode().accept(this);
        }
    }

    public void visit(AttributeNode node) {
        node.getValue().accept(this);
    }

    public void visit(ComparisonNode node) {
        node.getLHS().accept(this);
        node.getRHS().accept(this);
    }

    public void visit(DocumentNode node) {}

    public void visit(DocumentTypeNode node) {}

    public void visit(EmbracedNode node) {
        node.getNode().accept(this);
    }

    public void visit(IdNode node) {}

    public void visit(LiteralNode node) {}

    public void visit(LogicNode node) {
        for (LogicNode.NodeItem item : node.getItems()) {
            item.getNode().accept(this);
        }
    }

    public void visit(NegationNode node) {
        node.getNode().accept(this);
    }

    public void visit(NowNode node) {
        nowNodeCount++;
    }

    public void visit(VariableNode node) {
    }
}