Skip to content

Commit

Permalink
Add generics to the EL API
Browse files Browse the repository at this point in the history
These are the obvious ones. More generics may be added after further
discussion. See #157
  • Loading branch information
markt-asf committed May 25, 2021
1 parent d8dc58b commit 824741b
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions api/src/main/java/jakarta/el/CompositeELResolver.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019 Oracle and/or its affiliates and others.
* Copyright (c) 1997, 2021 Oracle and/or its affiliates and others.
* All rights reserved.
* Copyright 2004 The Apache Software Foundation
*
Expand Down Expand Up @@ -468,10 +468,10 @@ public Class<?> getCommonPropertyType(ELContext context, Object base) {
* @since Jakarta Expression Language 3.0
*/
@Override
public Object convertToType(ELContext context, Object obj, Class<?> targetType) {
public <T> T convertToType(ELContext context, Object obj, Class<T> targetType) {
context.setPropertyResolved(false);

Object value = null;
T value = null;
for (int i = 0; i < size; i++) {
value = elResolvers[i].convertToType(context, obj, targetType);
if (context.isPropertyResolved()) {
Expand Down
6 changes: 3 additions & 3 deletions api/src/main/java/jakarta/el/ELContext.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates and others.
* Copyright (c) 1997, 2021 Oracle and/or its affiliates and others.
* All rights reserved.
* Copyright 2004 The Apache Software Foundation
*
Expand Down Expand Up @@ -418,13 +418,13 @@ public void exitLambdaScope() {
*
* @since Jakarta Expression Language 3.0
*/
public Object convertToType(Object obj, Class<?> targetType) {
public <T> T convertToType(Object obj, Class<T> targetType) {
boolean propertyResolvedSave = isPropertyResolved();
try {
setPropertyResolved(false);
ELResolver elResolver = getELResolver();
if (elResolver != null) {
Object res = elResolver.convertToType(this, obj, targetType);
T res = elResolver.convertToType(this, obj, targetType);
if (isPropertyResolved()) {
return res;
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/jakarta/el/ELProcessor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2019 Oracle and/or its affiliates and others.
* Copyright (c) 2012, 2021 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -103,7 +103,7 @@ public Object eval(String expression) {
* @param expectedType Specifies the type that the resultant evaluation will be coerced to.
* @return The result of the expression evaluation.
*/
public Object getValue(String expression, Class<?> expectedType) {
public <T> T getValue(String expression, Class<T> expectedType) {
ValueExpression exp = factory.createValueExpression(elManager.getELContext(), bracket(expression), expectedType);
return exp.getValue(elManager.getELContext());
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/jakarta/el/ELResolver.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019 Oracle and/or its affiliates and others.
* Copyright (c) 1997, 2021 Oracle and/or its affiliates and others.
* All rights reserved.
* Copyright 2004 The Apache Software Foundation
*
Expand Down Expand Up @@ -326,7 +326,7 @@ public Object invoke(ELContext context, Object base, Object method, Class<?>[] p
* @return object converted to <code>targetType</code>
* @throws ELException thrown if errors occur.
*/
public Object convertToType(ELContext context, Object obj, Class<?> targetType) {
public <T> T convertToType(ELContext context, Object obj, Class<T> targetType) {
return null;
}
}
4 changes: 2 additions & 2 deletions api/src/main/java/jakarta/el/ExpressionFactory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates and others.
* Copyright (c) 1997, 2021 Oracle and/or its affiliates and others.
* All rights reserved.
* Copyright 2004 The Apache Software Foundation
*
Expand Down Expand Up @@ -235,7 +235,7 @@ public static ExpressionFactory newInstance(Properties properties) {
*
* @throws ELException thrown if an error results from applying the conversion rules.
*/
public abstract Object coerceToType(Object obj, Class<?> targetType);
public abstract <T> T coerceToType(Object obj, Class<T> targetType);

/**
* Retrieves an ELResolver that implements the operations in collections.
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/jakarta/el/TypeConverter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2019 Oracle and/or its affiliates and others.
* Copyright (c) 2012, 2021 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -87,5 +87,5 @@ public Class<?> getCommonPropertyType(ELContext context, Object base) {
* @throws ELException thrown if errors occur.
*/
@Override
abstract public Object convertToType(ELContext context, Object obj, Class<?> targetType);
abstract public <T> T convertToType(ELContext context, Object obj, Class<T> targetType);
}
4 changes: 2 additions & 2 deletions api/src/main/java/jakarta/el/ValueExpression.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019 Oracle and/or its affiliates and others.
* Copyright (c) 1997, 2021 Oracle and/or its affiliates and others.
* All rights reserved.
* Copyright 2004 The Apache Software Foundation
*
Expand Down Expand Up @@ -80,7 +80,7 @@ public abstract class ValueExpression extends Expression {
* @throws ELException if an exception was thrown while performing property or variable resolution. The thrown exception
* must be included as the cause property of this exception, if available.
*/
public abstract Object getValue(ELContext context);
public abstract <T> T getValue(ELContext context);

/**
* Evaluates the expression relative to the provided context, and sets the result to the provided value.
Expand Down

0 comments on commit 824741b

Please sign in to comment.