Skip to content

Package: MethodReference

MethodReference

nameinstructionbranchcomplexitylinemethod
MethodReference(Object, MethodInfo, Annotation[], Object[])
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
equals(Object)
M: 69 C: 0
0%
M: 22 C: 0
0%
M: 12 C: 0
0%
M: 22 C: 0
0%
M: 1 C: 0
0%
getAnnotations()
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%
getBase()
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%
getEvaluatedParameters()
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%
getMethodInfo()
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%
hashCode()
M: 48 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2021 Contributors to the Eclipse Foundation
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: package jakarta.el;
17:
18: import java.lang.annotation.Annotation;
19: import java.util.Arrays;
20:
21: /**
22: * Provides information about the method to which a method expression resolves.
23: *
24: * Two MethodReference instances are considered equal if the reference the same
25: * method on the same base object.
26: */
27: public class MethodReference {
28:
29: private final Object base;
30: private final MethodInfo methodInfo;
31: private final Annotation[] annotations;
32: private final Object[] evaluatedParameters;
33:
34:
35: public MethodReference(Object base, MethodInfo methodInfo, Annotation[] annotations, Object[] evaluatedParameters) {
36: this.base = base;
37: this.methodInfo = methodInfo;
38: this.annotations = annotations;
39: this.evaluatedParameters = evaluatedParameters;
40: }
41:
42:
43: /**
44: * Obtain the base object on which the method will be invoked.
45: *
46: * @return The base object on which the method will be invoked or
47: * {@code null} for literal method expressions.
48: */
49: public Object getBase() {
50: return base;
51: }
52:
53:
54: /**
55: * Obtain the {@link MethodInfo} for the {@link MethodExpression} for which
56: * this {@link MethodReference} has been generated.
57: *
58: * @return The {@link MethodInfo} for the {@link MethodExpression} for which
59: * this {@link MethodReference} has been generated.
60: */
61: public MethodInfo getMethodInfo() {
62: return this.methodInfo;
63: }
64:
65:
66: /**
67: * Obtain the annotations on the method to which the associated expression
68: * resolves.
69: *
70: * @return The annotations on the method to which the associated expression
71: * resolves. If the are no annotations, then an empty array is
72: * returned.
73: */
74: public Annotation[] getAnnotations() {
75: return annotations;
76: }
77:
78:
79: /**
80: * Obtain the evaluated parameter values that will be passed to the method
81: * to which the associated expression resolves.
82: *
83: * @return The evaluated parameters.
84: */
85: public Object[] getEvaluatedParameters() {
86: return evaluatedParameters;
87: }
88:
89:
90: @Override
91: public int hashCode() {
92: final int prime = 31;
93: int result = 1;
94: result = prime * result + Arrays.hashCode(annotations);
95:• result = prime * result + ((base == null) ? 0 : base.hashCode());
96: result = prime * result + Arrays.deepHashCode(evaluatedParameters);
97:• result = prime * result + ((methodInfo == null) ? 0 : methodInfo.hashCode());
98: return result;
99: }
100:
101:
102: @Override
103: public boolean equals(Object obj) {
104:• if (this == obj) {
105: return true;
106: }
107:• if (obj == null) {
108: return false;
109: }
110:• if (getClass() != obj.getClass()) {
111: return false;
112: }
113: MethodReference other = (MethodReference) obj;
114:• if (!Arrays.equals(annotations, other.annotations)) {
115: return false;
116: }
117:• if (base == null) {
118:• if (other.base != null) {
119: return false;
120: }
121:• } else if (!base.equals(other.base)) {
122: return false;
123: }
124:• if (!Arrays.deepEquals(evaluatedParameters, other.evaluatedParameters)) {
125: return false;
126: }
127:• if (methodInfo == null) {
128:• if (other.methodInfo != null) {
129: return false;
130: }
131:• } else if (!methodInfo.equals(other.methodInfo)) {
132: return false;
133: }
134: return true;
135: }
136: }