Skip to content

Package: AstIdentifier

AstIdentifier

nameinstructionbranchcomplexitylinemethod
AstIdentifier(int)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getMethodExpression(EvaluationContext)
M: 58 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
getMethodInfo(EvaluationContext, Class[])
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getType(EvaluationContext)
M: 44 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
getValue(EvaluationContext)
M: 69 C: 0
0%
M: 12 C: 0
0%
M: 7 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
getValueReference(EvaluationContext)
M: 24 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
invoke(EvaluationContext, Class[], Object[])
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isReadOnly(EvaluationContext)
M: 44 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
setValue(EvaluationContext, Object)
M: 52 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package com.sun.el.parser;
18:
19: import jakarta.el.ELClass;
20: import jakarta.el.ELException;
21: import jakarta.el.ELResolver;
22: import jakarta.el.MethodExpression;
23: import jakarta.el.MethodInfo;
24: import jakarta.el.MethodNotFoundException;
25: import jakarta.el.PropertyNotWritableException;
26: import jakarta.el.ValueExpression;
27: import jakarta.el.ValueReference;
28: import jakarta.el.VariableMapper;
29:
30: import com.sun.el.lang.ELSupport;
31: import com.sun.el.lang.EvaluationContext;
32: import com.sun.el.util.MessageFactory;
33:
34: /**
35: * @author Jacob Hookom [jacob@hookom.net]
36: * @author Kin-man Chung
37: * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: kchung $
38: */
39: public final class AstIdentifier extends SimpleNode {
40: public AstIdentifier(int id) {
41: super(id);
42: }
43:
44: @Override
45: public Class getType(EvaluationContext ctx) throws ELException {
46: // First check if this is a lambda argument
47:• if (ctx.isLambdaArgument(this.image)) {
48: return Object.class;
49: }
50: VariableMapper varMapper = ctx.getVariableMapper();
51:• if (varMapper != null) {
52: ValueExpression expr = varMapper.resolveVariable(this.image);
53:• if (expr != null) {
54: return expr.getType(ctx.getELContext());
55: }
56: }
57: ctx.setPropertyResolved(false);
58: Class ret = ctx.getELResolver().getType(ctx, null, this.image);
59:• if (!ctx.isPropertyResolved()) {
60: ELSupport.throwUnhandled(null, this.image);
61: }
62: return ret;
63: }
64:
65: @Override
66: public ValueReference getValueReference(EvaluationContext ctx) throws ELException {
67: VariableMapper varMapper = ctx.getVariableMapper();
68:• if (varMapper != null) {
69: ValueExpression expr = varMapper.resolveVariable(this.image);
70:• if (expr != null) {
71: return expr.getValueReference(ctx.getELContext());
72: }
73: }
74: return new ValueReference(null, this.image);
75: }
76:
77: @Override
78: public Object getValue(EvaluationContext ctx) throws ELException {
79: // First check if this is a lambda argument
80:• if (ctx.isLambdaArgument(this.image)) {
81: return ctx.getLambdaArgument(this.image);
82: }
83: VariableMapper varMapper = ctx.getVariableMapper();
84:• if (varMapper != null) {
85: ValueExpression expr = varMapper.resolveVariable(this.image);
86:• if (expr != null) {
87: return expr.getValue(ctx.getELContext());
88: }
89: }
90: ctx.setPropertyResolved(false);
91: Object ret = ctx.getELResolver().getValue(ctx, null, this.image);
92:• if (!ctx.isPropertyResolved()) {
93: // Check if this is an imported static field
94:• if (ctx.getImportHandler() != null) {
95: Class<?> c = ctx.getImportHandler().resolveStatic(this.image);
96:• if (c != null) {
97: return ctx.getELResolver().getValue(ctx, new ELClass(c), this.image);
98: }
99: }
100: ELSupport.throwUnhandled(null, this.image);
101: }
102: return ret;
103: }
104:
105: @Override
106: public boolean isReadOnly(EvaluationContext ctx) throws ELException {
107: // Lambda arguments are read only.
108:• if (ctx.isLambdaArgument(this.image)) {
109: return true;
110: }
111: VariableMapper varMapper = ctx.getVariableMapper();
112:• if (varMapper != null) {
113: ValueExpression expr = varMapper.resolveVariable(this.image);
114:• if (expr != null) {
115: return expr.isReadOnly(ctx.getELContext());
116: }
117: }
118: ctx.setPropertyResolved(false);
119: boolean ret = ctx.getELResolver().isReadOnly(ctx, null, this.image);
120:• if (!ctx.isPropertyResolved()) {
121: ELSupport.throwUnhandled(null, this.image);
122: }
123: return ret;
124: }
125:
126: @Override
127: public void setValue(EvaluationContext ctx, Object value) throws ELException {
128: // First check if this is a lambda argument
129:• if (ctx.isLambdaArgument(this.image)) {
130: throw new PropertyNotWritableException(MessageFactory.get("error.lambda.parameter.readonly", this.image));
131: }
132: VariableMapper varMapper = ctx.getVariableMapper();
133:• if (varMapper != null) {
134: ValueExpression expr = varMapper.resolveVariable(this.image);
135:• if (expr != null) {
136: expr.setValue(ctx.getELContext(), value);
137: return;
138: }
139: }
140: ctx.setPropertyResolved(false);
141: ELResolver elResolver = ctx.getELResolver();
142: elResolver.setValue(ctx, null, this.image, value);
143:• if (!ctx.isPropertyResolved()) {
144: ELSupport.throwUnhandled(null, this.image);
145: }
146: }
147:
148: @Override
149: public Object invoke(EvaluationContext ctx, Class[] paramTypes, Object[] paramValues) throws ELException {
150: return this.getMethodExpression(ctx).invoke(ctx.getELContext(), paramValues);
151: }
152:
153: @Override
154: public MethodInfo getMethodInfo(EvaluationContext ctx, Class[] paramTypes) throws ELException {
155: return this.getMethodExpression(ctx).getMethodInfo(ctx.getELContext());
156: }
157:
158: private MethodExpression getMethodExpression(EvaluationContext ctx) throws ELException {
159: Object obj = null;
160:
161: // case A: ValueExpression exists, getValue which must
162: // be a MethodExpression
163: VariableMapper varMapper = ctx.getVariableMapper();
164: ValueExpression ve = null;
165:• if (varMapper != null) {
166: ve = varMapper.resolveVariable(this.image);
167:• if (ve != null) {
168: obj = ve.getValue(ctx);
169: }
170: }
171:
172: // case B: evaluate the identity against the ELResolver, again, must be
173: // a MethodExpression to be able to invoke
174:• if (ve == null) {
175: ctx.setPropertyResolved(false);
176: obj = ctx.getELResolver().getValue(ctx, null, this.image);
177: }
178:
179: // finally provide helpful hints
180:• if (obj instanceof MethodExpression) {
181: return (MethodExpression) obj;
182:• } else if (obj == null) {
183: throw new MethodNotFoundException("Identity '" + this.image + "' was null and was unable to invoke");
184: } else {
185: throw new ELException("Identity '" + this.image + "' does not reference a MethodExpression instance, returned type: " + obj.getClass().getName());
186: }
187: }
188: }