This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 2a61a91  Add the remaining generics for EL 5.0
2a61a91 is described below

commit 2a61a91f7efb4eb278880dc21b9bf9a1b06b2e07
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue May 25 15:11:00 2021 +0100

    Add the remaining generics for EL 5.0
---
 java/jakarta/el/ELProcessor.java                  |  2 +-
 java/jakarta/el/ValueExpression.java              |  4 ++-
 java/org/apache/el/ValueExpressionImpl.java       |  5 +--
 java/org/apache/el/ValueExpressionLiteral.java    |  5 +--
 java/org/apache/jasper/el/JspValueExpression.java | 40 ++++++++++++++++-------
 webapps/docs/changelog.xml                        |  4 +++
 6 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/java/jakarta/el/ELProcessor.java b/java/jakarta/el/ELProcessor.java
index 7abf7fc..98ff6a3 100644
--- a/java/jakarta/el/ELProcessor.java
+++ b/java/jakarta/el/ELProcessor.java
@@ -55,7 +55,7 @@ public class ELProcessor {
     }
 
 
-    public Object getValue(String expression, Class<?> expectedType) {
+    public <T> T getValue(String expression, Class<T> expectedType) {
         ValueExpression ve = factory.createValueExpression(
                 context, bracket(expression), expectedType);
         return ve.getValue(context);
diff --git a/java/jakarta/el/ValueExpression.java 
b/java/jakarta/el/ValueExpression.java
index 528f7c2..cbaba0c 100644
--- a/java/jakarta/el/ValueExpression.java
+++ b/java/jakarta/el/ValueExpression.java
@@ -21,6 +21,8 @@ public abstract class ValueExpression extends Expression {
     private static final long serialVersionUID = 8577809572381654673L;
 
     /**
+     * @param <T> The expected type for the result of evaluating this value
+     *            expression
      * @param context The EL context for this evaluation
      *
      * @return The result of evaluating this value expression
@@ -34,7 +36,7 @@ public abstract class ValueExpression extends Expression {
      *              Wraps any exception throw whilst resolving a property or
      *              variable
      */
-    public abstract Object getValue(ELContext context);
+    public abstract <T> T getValue(ELContext context);
 
     /**
      * @param context The EL context for this evaluation
diff --git a/java/org/apache/el/ValueExpressionImpl.java 
b/java/org/apache/el/ValueExpressionImpl.java
index 91b3e1d..e4c434e 100644
--- a/java/org/apache/el/ValueExpressionImpl.java
+++ b/java/org/apache/el/ValueExpressionImpl.java
@@ -181,8 +181,9 @@ public final class ValueExpressionImpl extends 
ValueExpression implements
      *
      * @see jakarta.el.ValueExpression#getValue(jakarta.el.ELContext)
      */
+    @SuppressWarnings("unchecked")
     @Override
-    public Object getValue(ELContext context) throws PropertyNotFoundException,
+    public <T> T getValue(ELContext context) throws PropertyNotFoundException,
             ELException {
         EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
                 this.varMapper);
@@ -192,7 +193,7 @@ public final class ValueExpressionImpl extends 
ValueExpression implements
             value = context.convertToType(value, this.expectedType);
         }
         context.notifyAfterEvaluation(getExpressionString());
-        return value;
+        return (T) value;
     }
 
     /*
diff --git a/java/org/apache/el/ValueExpressionLiteral.java 
b/java/org/apache/el/ValueExpressionLiteral.java
index ca87e15..2ecfe8d 100644
--- a/java/org/apache/el/ValueExpressionLiteral.java
+++ b/java/org/apache/el/ValueExpressionLiteral.java
@@ -48,8 +48,9 @@ public final class ValueExpressionLiteral extends 
ValueExpression implements
         this.expectedType = expectedType;
     }
 
+    @SuppressWarnings("unchecked")
     @Override
-    public Object getValue(ELContext context) {
+    public <T> T getValue(ELContext context) {
         context.notifyBeforeEvaluation(getExpressionString());
         Object result;
         if (this.expectedType != null) {
@@ -58,7 +59,7 @@ public final class ValueExpressionLiteral extends 
ValueExpression implements
             result = this.value;
         }
         context.notifyAfterEvaluation(getExpressionString());
-        return result;
+        return (T) result;
     }
 
     @Override
diff --git a/java/org/apache/jasper/el/JspValueExpression.java 
b/java/org/apache/jasper/el/JspValueExpression.java
index 9fbea5f..64f6ccd 100644
--- a/java/org/apache/jasper/el/JspValueExpression.java
+++ b/java/org/apache/jasper/el/JspValueExpression.java
@@ -62,10 +62,14 @@ public final class JspValueExpression extends 
ValueExpression implements
             context.notifyAfterEvaluation(getExpressionString());
             return result;
         } catch (PropertyNotFoundException e) {
-            if (e instanceof JspPropertyNotFoundException) throw e;
+            if (e instanceof JspPropertyNotFoundException) {
+                throw e;
+            }
             throw new JspPropertyNotFoundException(this.mark, e);
         } catch (ELException e) {
-            if (e instanceof JspELException) throw e;
+            if (e instanceof JspELException) {
+                throw e;
+            }
             throw new JspELException(this.mark, e);
         }
     }
@@ -79,10 +83,14 @@ public final class JspValueExpression extends 
ValueExpression implements
             context.notifyAfterEvaluation(getExpressionString());
             return result;
         } catch (PropertyNotFoundException e) {
-            if (e instanceof JspPropertyNotFoundException) throw e;
+            if (e instanceof JspPropertyNotFoundException) {
+                throw e;
+            }
             throw new JspPropertyNotFoundException(this.mark, e);
         } catch (ELException e) {
-            if (e instanceof JspELException) throw e;
+            if (e instanceof JspELException) {
+                throw e;
+            }
             throw new JspELException(this.mark, e);
         }
     }
@@ -96,30 +104,40 @@ public final class JspValueExpression extends 
ValueExpression implements
             this.target.setValue(context, value);
             context.notifyAfterEvaluation(getExpressionString());
         } catch (PropertyNotWritableException e) {
-            if (e instanceof JspPropertyNotWritableException) throw e;
+            if (e instanceof JspPropertyNotWritableException) {
+                throw e;
+            }
             throw new JspPropertyNotWritableException(this.mark, e);
         } catch (PropertyNotFoundException e) {
-            if (e instanceof JspPropertyNotFoundException) throw e;
+            if (e instanceof JspPropertyNotFoundException) {
+                throw e;
+            }
             throw new JspPropertyNotFoundException(this.mark, e);
         } catch (ELException e) {
-            if (e instanceof JspELException) throw e;
+            if (e instanceof JspELException) {
+                throw e;
+            }
             throw new JspELException(this.mark, e);
         }
     }
 
     @Override
-    public Object getValue(ELContext context) throws NullPointerException,
+    public <T> T getValue(ELContext context) throws NullPointerException,
             PropertyNotFoundException, ELException {
         context.notifyBeforeEvaluation(getExpressionString());
         try {
-            Object result = this.target.getValue(context);
+            T result = this.target.getValue(context);
             context.notifyAfterEvaluation(getExpressionString());
             return result;
         } catch (PropertyNotFoundException e) {
-            if (e instanceof JspPropertyNotFoundException) throw e;
+            if (e instanceof JspPropertyNotFoundException) {
+                throw e;
+            }
             throw new JspPropertyNotFoundException(this.mark, e);
         } catch (ELException e) {
-            if (e instanceof JspELException) throw e;
+            if (e instanceof JspELException) {
+                throw e;
+            }
             throw new JspELException(this.mark, e);
         }
     }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 01412cf..818fbe1 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -187,6 +187,10 @@
         a tag handler, only define the local variable <code>JspWriter 
out</code>
         when it is going to be used. (markt)
       </fix>
+      <scode>
+        Add generics to the EL 5.0 API to align with the current EL 5.0
+        development branch. (markt)
+      </scode>
     </changelog>
   </subsection>
   <subsection name="WebSocket">

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to