Skip to content

Package: Expression

Expression

nameinstructionbranchcomplexitylinemethod
Expression()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2019 Oracle and/or its affiliates and others.
3: * All rights reserved.
4: * Copyright 2004 The Apache Software Foundation
5: *
6: * Licensed under the Apache License, Version 2.0 (the "License");
7: * you may not use this file except in compliance with the License.
8: * You may obtain a copy of the License at
9: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: package jakarta.el;
20:
21: import java.io.Serializable;
22:
23: /**
24: * Base class for the expression subclasses {@link ValueExpression} and {@link MethodExpression}, implementing
25: * characteristics common to both.
26: *
27: * <p>
28: * All expressions must implement the <code>equals()</code> and <code>hashCode()</code> methods so that two expressions
29: * can be compared for equality. They are redefined abstract in this class to force their implementation in subclasses.
30: * </p>
31: *
32: * <p>
33: * All expressions must also be <code>Serializable</code> so that they can be saved and restored.
34: * </p>
35: *
36: * <p>
37: * <code>Expression</code>s are also designed to be immutable so that only one instance needs to be created for any
38: * given expression String / {@link FunctionMapper}. This allows a container to pre-create expressions and not have to
39: * re-parse them each time they are evaluated.
40: * </p>
41: *
42: * @since Jakarta Server Pages 2.1
43: */
44: public abstract class Expression implements Serializable {
45:
46: private static final long serialVersionUID = -6663767980471823812L;
47:
48: /**
49: * Returns the original String used to create this <code>Expression</code>, unmodified.
50: *
51: * <p>
52: * This is used for debugging purposes but also for the purposes of comparison (e.g. to ensure the expression in a
53: * configuration file has not changed).
54: * </p>
55: *
56: * <p>
57: * This method does not provide sufficient information to re-create an expression. Two different expressions can have
58: * exactly the same expression string but different function mappings. Serialization should be used to save and restore
59: * the state of an <code>Expression</code>.
60: * </p>
61: *
62: * @return The original expression String.
63: */
64: public abstract String getExpressionString();
65:
66: // Comparison
67:
68: /**
69: * Determines whether the specified object is equal to this <code>Expression</code>.
70: *
71: * <p>
72: * The result is <code>true</code> if and only if the argument is not <code>null</code>, is an <code>Expression</code>
73: * object that is the of the same type (<code>ValueExpression</code> or <code>MethodExpression</code>), and has an
74: * identical parsed representation.
75: * </p>
76: *
77: * <p>
78: * Note that two expressions can be equal if their expression Strings are different. For example,
79: * <code>${fn1:foo()}</code> and <code>${fn2:foo()}</code> are equal if their corresponding <code>FunctionMapper</code>s
80: * mapped <code>fn1:foo</code> and <code>fn2:foo</code> to the same method.
81: * </p>
82: *
83: * @param obj the <code>Object</code> to test for equality.
84: * @return <code>true</code> if <code>obj</code> equals this <code>Expression</code> <code>false</code> otherwise.
85: * @see java.util.Hashtable
86: * @see java.lang.Object#equals(java.lang.Object)
87: */
88: @Override
89: public abstract boolean equals(Object obj);
90:
91: /**
92: * Returns the hash code for this <code>Expression</code>.
93: *
94: * <p>
95: * See the note in the {@link #equals} method on how two expressions can be equal if their expression Strings are
96: * different. Recall that if two objects are equal according to the <code>equals(Object)</code> method, then calling the
97: * <code>hashCode</code> method on each of the two objects must produce the same integer result. Implementations must
98: * take special note and implement <code>hashCode</code> correctly.
99: * </p>
100: *
101: * @return The hash code for this <code>Expression</code>.
102: * @see #equals
103: * @see java.util.Hashtable
104: * @see java.lang.Object#hashCode()
105: */
106: @Override
107: public abstract int hashCode();
108:
109: /**
110: * Returns whether this expression was created from only literal text.
111: *
112: * <p>
113: * This method must return <code>true</code> if and only if the expression string this expression was created from
114: * contained no unescaped Jakarta Expression Language delimeters (<code>${...}</code> or <code>#{...}</code>).
115: *
116: * @return <code>true</code> if this expression was created from only literal text; <code>false</code> otherwise.
117: */
118: public abstract boolean isLiteralText();
119: }