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 @ 47190
History | View | Annotate | Download (3.09 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 final int UNDEFINED = -1; |
15 |
public static final int CONSTANT = 0; |
16 |
public static final int IDENTIFIER = 1; |
17 |
public static final int CALLABLE = 2; |
18 |
public static final int METHOD = 3; |
19 |
public static final int CODES = 4; |
20 |
|
21 |
public interface Constant extends Code { |
22 |
|
23 |
public static Object value(Code code) { |
24 |
if( code instanceof Constant ) { |
25 |
return ((Constant)code).value();
|
26 |
} |
27 |
return null; |
28 |
} |
29 |
|
30 |
public Object value(); |
31 |
|
32 |
} |
33 |
|
34 |
public interface Identifier extends Code { |
35 |
|
36 |
public static String name(Code code) { |
37 |
if( code instanceof Identifier ) { |
38 |
return ((Identifier)code).name();
|
39 |
} |
40 |
return null; |
41 |
} |
42 |
|
43 |
public String name(); |
44 |
|
45 |
} |
46 |
|
47 |
public interface Callable extends Code { |
48 |
|
49 |
public static String name(Code code) { |
50 |
if( code instanceof Callable ) { |
51 |
return ((Callable)code).name(); |
52 |
} |
53 |
return null; |
54 |
} |
55 |
|
56 |
public static Codes parameters(Code code) { |
57 |
if( code instanceof Callable ) { |
58 |
return ((Callable)code).parameters(); |
59 |
} |
60 |
return null; |
61 |
} |
62 |
|
63 |
public static final int FUNCTION = 0; |
64 |
public static final int BINARY_OPERATOR = 1; |
65 |
public static final int UNARY_OPERATOR = 2; |
66 |
|
67 |
|
68 |
public String name(); |
69 |
|
70 |
public Object call(Interpreter interpreter, Object[] args) throws Exception; |
71 |
|
72 |
public Function function();
|
73 |
|
74 |
public Function function(Function function);
|
75 |
|
76 |
public Codes parameters();
|
77 |
|
78 |
public int type(); |
79 |
|
80 |
} |
81 |
|
82 |
public interface Method extends Callable { |
83 |
public Code instance();
|
84 |
|
85 |
public String methodname(); |
86 |
|
87 |
@Override
|
88 |
public Codes parameters();
|
89 |
|
90 |
@Override
|
91 |
public Object call(Interpreter interpreter, Object[] args) throws Exception; |
92 |
} |
93 |
|
94 |
public static final Formatter<Code> EMPTY_FORMATTER = new Formatter<Code>() { |
95 |
@Override
|
96 |
public boolean canApply(Code value) { |
97 |
return false; |
98 |
} |
99 |
|
100 |
@Override
|
101 |
public String format(Code value) { |
102 |
return ""; |
103 |
} |
104 |
}; |
105 |
|
106 |
public int code(); |
107 |
|
108 |
public Value toValue();
|
109 |
|
110 |
public Value toValue(ExpressionBuilder builder);
|
111 |
|
112 |
public String toString(Formatter<Code> formatter); |
113 |
|
114 |
public void link(SymbolTable symbolTable); |
115 |
|
116 |
public void link(); |
117 |
|
118 |
public void replace(Code target, Code replacement); |
119 |
|
120 |
@Override
|
121 |
public Code clone() throws CloneNotSupportedException; |
122 |
|
123 |
} |