aboutsummaryrefslogtreecommitdiffstats
path: root/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/ExpressionConverter.java
blob: 231f6fb7598e7a9c2f2395bbb7808fa7bf1da75e (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.indexinglanguage;

import com.yahoo.vespa.indexinglanguage.expressions.Expression;

/**
 * @author Simon Thoresen Hult
 */
public abstract class ExpressionConverter implements Cloneable {

    public final Expression convert(Expression expression) {
        if (expression == null) return null;
        if (shouldConvert(expression))
            return doConvert(expression);
        else
            return expression.convertChildren(this);
    }

    public ExpressionConverter branch() {
        return this;
    }

    @Override
    public ExpressionConverter clone() {
        try {
            return (ExpressionConverter)super.clone();
        } catch (CloneNotSupportedException e) {
            throw new UnsupportedOperationException(e);
        }
    }

    protected abstract boolean shouldConvert(Expression exp);

    protected abstract Expression doConvert(Expression exp);

}