Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.api / src / main / java / org / gvsig / expressionevaluator / Code.java @ 47299

History | View | Annotate | Download (3.36 KB)

1
package org.gvsig.expressionevaluator;
2

    
3
import org.apache.commons.lang3.StringUtils;
4
import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
5
import org.gvsig.tools.visitor.FilteredVisitable;
6

    
7
public interface Code extends FilteredVisitable, org.gvsig.tools.lang.Cloneable {
8

    
9
    public static boolean isFunction(Code code, String name) {
10
        return ( code.code()==Code.CALLABLE &&
11
                StringUtils.equalsIgnoreCase(name, ((Code.Callable) code).name()));
12
    } 
13
    
14
    public static boolean isIdentifier(Code code, String name) {
15
        return ( code.code()==Code.IDENTIFIER &&
16
                StringUtils.equalsIgnoreCase(name, ((Code.Identifier) code).name()));
17
    } 
18
    
19
    public static final int UNDEFINED = -1;
20
    public static final int CONSTANT = 0;
21
    public static final int IDENTIFIER = 1;
22
    public static final int CALLABLE = 2;
23
    public static final int METHOD = 3;
24
    public static final int CODES = 4;
25
    
26
    public interface Constant extends Code {
27

    
28
        public static Object value(Code code) {
29
            if( code instanceof Constant ) {
30
                return ((Constant)code).value();
31
            }
32
            return null;
33
        }
34
        
35
        public Object value();
36

    
37
    }
38

    
39
    public interface Identifier extends Code {
40

    
41
        public static String name(Code code) {
42
            if( code instanceof Identifier ) {
43
                return ((Identifier)code).name();
44
            }
45
            return null;
46
        }
47
        
48
        public String name();
49

    
50
    }
51

    
52
    public interface Callable extends Code {
53

    
54
        public static String name(Code code) {
55
            if( code instanceof Callable ) {
56
                return ((Callable)code).name();
57
            }
58
            return null;
59
        }
60
        
61
        public static Codes parameters(Code code) {
62
            if( code instanceof Callable ) {
63
                return ((Callable)code).parameters();
64
            }
65
            return null;
66
        }
67
        
68
        public static final int FUNCTION = 0;
69
        public static final int BINARY_OPERATOR = 1;
70
        public static final int UNARY_OPERATOR = 2;
71

    
72

    
73
        public String name();
74

    
75
        public Object call(Interpreter interpreter, Object[] args) throws Exception;
76

    
77
        public Function function();
78

    
79
        public Function function(Function function);
80

    
81
        public Codes parameters();
82

    
83
        public int type();
84

    
85
    }
86
    
87
    public interface Method extends Callable {
88
        public Code instance();
89
        
90
        public String methodname();
91

    
92
        @Override
93
        public Codes parameters();
94

    
95
        @Override
96
        public Object call(Interpreter interpreter, Object[] args) throws Exception;
97
    }
98

    
99
    public static final Formatter<Code> EMPTY_FORMATTER = new Formatter<Code>() {
100
        @Override
101
        public boolean canApply(Code value) {
102
            return false;
103
        }
104

    
105
        @Override
106
        public String format(Code value) {
107
            return "";
108
        }
109
    };
110

    
111
    public int code();
112

    
113
    public Value toValue();
114

    
115
    public Value toValue(ExpressionBuilder builder);
116
    
117
    public String toString(Formatter<Code> formatter);
118
    
119
    public void link(SymbolTable symbolTable);
120
    
121
    public void link(SymbolTable symbolTable, boolean force);
122
    
123
    public void link();
124
    
125
    public void replace(Code target, Code replacement);
126

    
127
    @Override
128
    public Code clone() throws CloneNotSupportedException;
129

    
130
}