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 @ 47734

History | View | Annotate | Download (4.02 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.expressionevaluator.spi.PrettyFormaterImpl;
6
import org.gvsig.tools.visitor.FilteredVisitable;
7

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

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

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

    
38
    }
39

    
40
    public interface Identifier extends Code {
41

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

    
51
    }
52

    
53
    public interface Callable extends Code {
54

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

    
73

    
74
        public String name();
75

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

    
78
        public Function function();
79

    
80
        public Function function(Function function);
81

    
82
        public Codes parameters();
83

    
84
        public int type();
85

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

    
93
        @Override
94
        public Codes parameters();
95

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

    
100
    public static class EmptyFormatter  extends PrettyFormaterImpl implements Formatter<Code> {
101
        
102
        public EmptyFormatter() {
103
            
104
        }
105
        
106
        public EmptyFormatter(boolean useNl, int indentSize) {
107
            super.setIndentSize(indentSize);
108
            super.setUseNl(useNl);
109
        }
110
        
111
        @Override
112
        public boolean canApply(Code value) {
113
            return false;
114
        }
115

    
116
        @Override
117
        public String format(Code value) {
118
            return "";
119
        }
120

    
121
        @Override
122
        public void setIndentSize(int indentSize) {
123
            throw new UnsupportedOperationException();
124
        }
125

    
126
        @Override
127
        public void setUseNl(boolean useNl) {
128
            throw new UnsupportedOperationException();
129
        }
130
        
131
    }
132
    
133
    public static final Formatter<Code> EMPTY_FORMATTER = new EmptyFormatter();
134

    
135
    public int code();
136

    
137
    public Value toValue();
138

    
139
    public Value toValue(ExpressionBuilder builder);
140
    
141
    public String toString(Formatter<Code> formatter);
142
    
143
    public void link(SymbolTable symbolTable);
144
    
145
    public void link(SymbolTable symbolTable, boolean force);
146
    
147
    public void link();
148
    
149
    public void replace(Code target, Code replacement);
150

    
151
    @Override
152
    public Code clone() throws CloneNotSupportedException;
153

    
154
}