Skip to content

Commit

Permalink
Update the implementation for generics changes
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed May 25, 2021
1 parent b5d244c commit bee8477
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
5 changes: 3 additions & 2 deletions impl/src/main/java/com/sun/el/ExpressionFactoryImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -63,7 +64,7 @@ public ExpressionFactoryImpl(Properties properties) {
* "jakarta.el.bc2.2" set to true.
*/
@Override
public Object coerceToType(Object obj, Class<?> type) {
public <T> T coerceToType(Object obj, Class<T> type) {
try {
return ELSupport.coerceToType(obj, type, isBackwardCompatible22);
} catch (IllegalArgumentException ex) {
Expand Down
21 changes: 11 additions & 10 deletions impl/src/main/java/com/sun/el/lang/ELSupport.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -334,14 +335,14 @@ public final static void checkType(final Object obj, final Class<?> type) throws
}
}

public final static Object coerceToType(final Object obj, final Class<?> type) throws IllegalArgumentException {
public final static <T> T coerceToType(final Object obj, final Class<T> type) throws IllegalArgumentException {
return coerceToType(obj, type, false);
}

public final static Object coerceToType(final Object obj, final Class<?> type, boolean isEL22Compatible) throws IllegalArgumentException {
public final static <T> T coerceToType(final Object obj, final Class<T> type, boolean isEL22Compatible) throws IllegalArgumentException {

if (type == null || Object.class.equals(type) || (obj != null && type.isAssignableFrom(obj.getClass()))) {
return obj;
return (T) obj;
}

// New in 3.0
Expand All @@ -350,19 +351,19 @@ public final static Object coerceToType(final Object obj, final Class<?> type, b
}

if (String.class.equals(type)) {
return coerceToString(obj);
return (T) coerceToString(obj);
}
if (ELArithmetic.isNumberType(type)) {
return coerceToNumber(obj, type);
return (T) coerceToNumber(obj, type);
}
if (Character.class.equals(type) || Character.TYPE == type) {
return coerceToCharacter(obj);
return (T) coerceToCharacter(obj);
}
if (Boolean.class.equals(type) || Boolean.TYPE == type) {
return coerceToBoolean(obj);
return (T) coerceToBoolean(obj);
}
if (type.isEnum()) {
return coerceToEnum(obj, type);
return (T) coerceToEnum(obj, type);
}

if (obj == null) {
Expand All @@ -376,7 +377,7 @@ public final static Object coerceToType(final Object obj, final Class<?> type, b
PropertyEditor editor = PropertyEditorManager.findEditor(type);
if (editor != null) {
editor.setAsText((String) obj);
return editor.getValue();
return (T) editor.getValue();
}
}
throw new IllegalArgumentException(MessageFactory.get("error.convert", obj, obj.getClass(), type));
Expand Down
5 changes: 3 additions & 2 deletions impl/src/main/java/com/sun/el/lang/EvaluationContext.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -133,7 +134,7 @@ public void exitLambdaScope() {
}

@Override
public Object convertToType(Object obj, Class<?> targetType) {
public <T> T convertToType(Object obj, Class<T> targetType) {
return elContext.convertToType(obj, targetType);
}

Expand Down

0 comments on commit bee8477

Please sign in to comment.