Author: violetagg Date: Tue Aug 20 08:38:29 2013 New Revision: 1515744 URL: http://svn.apache.org/r1515744 Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=55442 Handle calls to a constructor of an imported class or to a static method, imported statically. Unit test based on a patch provided by Daniel Mikusa.
Added: tomcat/trunk/test/org/apache/el/parser/TestAstFunction.java (with props) Modified: tomcat/trunk/java/org/apache/el/parser/AstFunction.java Modified: tomcat/trunk/java/org/apache/el/parser/AstFunction.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/AstFunction.java?rev=1515744&r1=1515743&r2=1515744&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/el/parser/AstFunction.java (original) +++ tomcat/trunk/java/org/apache/el/parser/AstFunction.java Tue Aug 20 08:38:29 2013 @@ -21,6 +21,7 @@ package org.apache.el.parser; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import javax.el.ELClass; import javax.el.ELException; import javax.el.FunctionMapper; import javax.el.LambdaExpression; @@ -130,6 +131,18 @@ public final class AstFunction extends S } return obj; } + + // Call to a constructor or a static method + obj = ctx.getImportHandler().resolveClass(this.localName); + if (obj != null) { + return ctx.getELResolver().invoke(ctx, new ELClass((Class<?>) obj), "<init>", null, + ((AstMethodParameters) this.children[0]).getParameters(ctx)); + } + obj = ctx.getImportHandler().resolveStatic(this.localName); + if (obj != null) { + return ctx.getELResolver().invoke(ctx, new ELClass((Class<?>) obj), this.localName, + null, ((AstMethodParameters) this.children[0]).getParameters(ctx)); + } } if (m == null) { Added: tomcat/trunk/test/org/apache/el/parser/TestAstFunction.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/el/parser/TestAstFunction.java?rev=1515744&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/el/parser/TestAstFunction.java (added) +++ tomcat/trunk/test/org/apache/el/parser/TestAstFunction.java Tue Aug 20 08:38:29 2013 @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.el.parser; + +import javax.el.ELProcessor; + +import org.junit.Assert; +import org.junit.Test; + +public class TestAstFunction { + + @Test + public void testImport01() { + ELProcessor processor = new ELProcessor(); + Object result = processor.getValue("Integer(1000)", Integer.class); + Assert.assertEquals(Integer.valueOf(1000), result); + } + + @Test + public void testImport02() { + ELProcessor processor = new ELProcessor(); + processor.getELManager().getELContext().getImportHandler() + .importStatic("java.lang.Integer.valueOf"); + Object result = processor.getValue("valueOf(1000)", Integer.class); + Assert.assertEquals(Integer.valueOf(1000), result); + } +} Propchange: tomcat/trunk/test/org/apache/el/parser/TestAstFunction.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org