Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 16848 invoked from network); 29 Apr 2006 14:57:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 29 Apr 2006 14:57:58 -0000 Received: (qmail 34431 invoked by uid 500); 29 Apr 2006 14:57:55 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 34403 invoked by uid 500); 29 Apr 2006 14:57:55 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 34392 invoked by uid 500); 29 Apr 2006 14:57:55 -0000 Received: (qmail 34389 invoked by uid 99); 29 Apr 2006 14:57:55 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 29 Apr 2006 07:57:55 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sat, 29 Apr 2006 07:57:53 -0700 Received: (qmail 16539 invoked by uid 65534); 29 Apr 2006 14:57:32 -0000 Message-ID: <20060429145732.16538.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r398171 - in /jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util: ./ introspection/ Date: Sat, 29 Apr 2006 14:57:30 -0000 To: commons-cvs@jakarta.apache.org From: dion@apache.org X-Mailer: svnmailer-1.0.8 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: dion Date: Sat Apr 29 07:57:29 2006 New Revision: 398171 URL: http://svn.apache.org/viewcvs?rev=398171&view=rev Log: Checkstyle Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/AbstractExecutor.java jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/ArrayIterator.java jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/BooleanPropertyExecutor.java jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/Coercion.java jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/EnumerationIterator.java jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/GetExecutor.java jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/Introspector.java jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/PropertyExecutor.java jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/ClassMap.java jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/Introspector.java jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/MethodMap.java jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/Uberspect.java jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/UberspectImpl.java Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/AbstractExecutor.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/AbstractExecutor.java?rev=398171&r1=398170&r2=398171&view=diff ============================================================================== --- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/AbstractExecutor.java (original) +++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/AbstractExecutor.java Sat Apr 29 07:57:29 2006 @@ -1,12 +1,12 @@ /* * Copyright 2000-2001,2004 The Apache Software Foundation. - * + * * Licensed 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. Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/ArrayIterator.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/ArrayIterator.java?rev=398171&r1=398170&r2=398171&view=diff ============================================================================== --- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/ArrayIterator.java (original) +++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/ArrayIterator.java Sat Apr 29 07:57:29 2006 @@ -1,12 +1,12 @@ /* * Copyright 1999-2001,2004 The Apache Software Foundation. - * + * * Licensed 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. Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/BooleanPropertyExecutor.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/BooleanPropertyExecutor.java?rev=398171&r1=398170&r2=398171&view=diff ============================================================================== --- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/BooleanPropertyExecutor.java (original) +++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/BooleanPropertyExecutor.java Sat Apr 29 07:57:29 2006 @@ -1,12 +1,12 @@ /* * Copyright 2000-2001,2004 The Apache Software Foundation. - * + * * Licensed 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. Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/Coercion.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/Coercion.java?rev=398171&r1=398170&r2=398171&view=diff ============================================================================== --- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/Coercion.java (original) +++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/Coercion.java Sat Apr 29 07:57:29 2006 @@ -1,12 +1,12 @@ /* * Copyright 2002,2004 The Apache Software Foundation. - * + * * Licensed 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. Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/EnumerationIterator.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/EnumerationIterator.java?rev=398171&r1=398170&r2=398171&view=diff ============================================================================== --- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/EnumerationIterator.java (original) +++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/EnumerationIterator.java Sat Apr 29 07:57:29 2006 @@ -1,12 +1,12 @@ /* * Copyright 1999-2001,2004 The Apache Software Foundation. - * + * * Licensed 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. Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/GetExecutor.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/GetExecutor.java?rev=398171&r1=398170&r2=398171&view=diff ============================================================================== --- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/GetExecutor.java (original) +++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/GetExecutor.java Sat Apr 29 07:57:29 2006 @@ -1,12 +1,12 @@ /* * Copyright 2000-2001,2004 The Apache Software Foundation. - * + * * Licensed 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. Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/Introspector.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/Introspector.java?rev=398171&r1=398170&r2=398171&view=diff ============================================================================== --- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/Introspector.java (original) +++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/Introspector.java Sat Apr 29 07:57:29 2006 @@ -1,12 +1,12 @@ /* * Copyright 2002,2004 The Apache Software Foundation. - * + * * Licensed 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. Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/PropertyExecutor.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/PropertyExecutor.java?rev=398171&r1=398170&r2=398171&view=diff ============================================================================== --- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/PropertyExecutor.java (original) +++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/PropertyExecutor.java Sat Apr 29 07:57:29 2006 @@ -1,12 +1,12 @@ /* * Copyright 2000-2002,2004 The Apache Software Foundation. - * + * * Licensed 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. Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/ClassMap.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/ClassMap.java?rev=398171&r1=398170&r2=398171&view=diff ============================================================================== --- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/ClassMap.java (original) +++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/ClassMap.java Sat Apr 29 07:57:29 2006 @@ -4,9 +4,9 @@ * Licensed 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. @@ -59,7 +59,7 @@ private final MethodMap methodMap = new MethodMap(); /** - * Standard constructor + * Standard constructor. */ public ClassMap(Class clazz) { this.clazz = clazz; Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/Introspector.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/Introspector.java?rev=398171&r1=398170&r2=398171&view=diff ============================================================================== --- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/Introspector.java (original) +++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/Introspector.java Sat Apr 29 07:57:29 2006 @@ -1,12 +1,12 @@ /* * Copyright 2001-2006 The Apache Software Foundation. - * + * * Licensed 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. Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/MethodMap.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/MethodMap.java?rev=398171&r1=398170&r2=398171&view=diff ============================================================================== --- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/MethodMap.java (original) +++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/MethodMap.java Sat Apr 29 07:57:29 2006 @@ -1,12 +1,12 @@ /* * Copyright 2001,2004 The Apache Software Foundation. - * + * * Licensed 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. @@ -25,7 +25,7 @@ import java.util.Map; /** - * + * * @author Jason van Zyl * @author Bob McWhirter * @author Christoph Reck @@ -34,10 +34,11 @@ * @since 1.0 * @version $Id$ */ -public class MethodMap -{ +public class MethodMap { private static final int MORE_SPECIFIC = 0; + private static final int LESS_SPECIFIC = 1; + private static final int INCOMPARABLE = 2; /** @@ -46,18 +47,15 @@ Map methodByNameMap = new Hashtable(); /** - * Add a method to a list of methods by name. - * For a particular class we are keeping track - * of all the methods with the same name. + * Add a method to a list of methods by name. For a particular class we are + * keeping track of all the methods with the same name. */ - public void add(Method method) - { + public void add(Method method) { String methodName = method.getName(); - List l = get( methodName ); + List l = get(methodName); - if ( l == null) - { + if (l == null) { l = new ArrayList(); methodByNameMap.put(methodName, l); } @@ -67,95 +65,78 @@ /** * Return a list of methods with the same name. - * + * * @param key The method name. * @return List list of methods */ - public List get(String key) - { + public List get(String key) { return (List) methodByNameMap.get(key); } /** - *

- * Find a method. Attempts to find the - * most specific applicable method using the - * algorithm described in the JLS section - * 15.12.2 (with the exception that it can't - * distinguish a primitive type argument from - * an object type argument, since in reflection - * primitive type arguments are represented by - * their object counterparts, so for an argument of - * type (say) java.lang.Integer, it will not be able - * to decide between a method that takes int and a - * method that takes java.lang.Integer as a parameter. - *

- * - *

- * This turns out to be a relatively rare case - * where this is needed - however, functionality - * like this is needed. - *

- * - * @param methodName name of method - * @param args the actual arguments with which the method is called - * @return the most specific applicable method, or null if no - * method is applicable. - * @throws AmbiguousException if there is more than one maximally - * specific applicable method + *

+ * Find a method. Attempts to find the most specific applicable method using + * the algorithm described in the JLS section 15.12.2 (with the exception + * that it can't distinguish a primitive type argument from an object type + * argument, since in reflection primitive type arguments are represented by + * their object counterparts, so for an argument of type (say) + * java.lang.Integer, it will not be able to decide between a method that + * takes int and a method that takes java.lang.Integer as a parameter. + *

+ * + *

+ * This turns out to be a relatively rare case where this is needed - + * however, functionality like this is needed. + *

+ * + * @param methodName name of method + * @param args the actual arguments with which the method is called + * @return the most specific applicable method, or null if no method is + * applicable. + * @throws AmbiguousException if there is more than one maximally specific + * applicable method */ - public Method find(String methodName, Object[] args) - throws AmbiguousException - { + public Method find(String methodName, Object[] args) throws AmbiguousException { List methodList = get(methodName); - if (methodList == null) - { + if (methodList == null) { return null; } int l = args.length; Class[] classes = new Class[l]; - for(int i = 0; i < l; ++i) - { + for (int i = 0; i < l; ++i) { Object arg = args[i]; /* - * if we are careful down below, a null argument goes in there - * so we can know that the null was passed to the method + * if we are careful down below, a null argument goes in there so we + * can know that the null was passed to the method */ - classes[i] = - arg == null ? null : arg.getClass(); + classes[i] = arg == null ? null : arg.getClass(); } return getMostSpecific(methodList, classes); } /** - * simple distinguishable exception, used when - * we run across ambiguous overloading + * simple distinguishable exception, used when we run across ambiguous + * overloading. */ - public static class AmbiguousException extends Exception - { - /** serialization version id jdk13 generated */ + public static class AmbiguousException extends Exception { + /** serialization version id jdk13 generated. */ static final long serialVersionUID = 8758118091728717367L; } - - private static Method getMostSpecific(List methods, Class[] classes) - throws AmbiguousException - { + private static Method getMostSpecific(List methods, Class[] classes) throws AmbiguousException { LinkedList applicables = getApplicables(methods, classes); - if(applicables.isEmpty()) - { + if (applicables.isEmpty()) { return null; } - if(applicables.size() == 1) - { - return (Method)applicables.getFirst(); + if (applicables.size() == 1) { + return (Method) applicables.getFirst(); } /* @@ -166,22 +147,16 @@ LinkedList maximals = new LinkedList(); - for (Iterator applicable = applicables.iterator(); - applicable.hasNext();) - { + for (Iterator applicable = applicables.iterator(); applicable.hasNext();) { Method app = (Method) applicable.next(); Class[] appArgs = app.getParameterTypes(); boolean lessSpecific = false; - for (Iterator maximal = maximals.iterator(); - !lessSpecific && maximal.hasNext();) - { + for (Iterator maximal = maximals.iterator(); !lessSpecific && maximal.hasNext();) { Method max = (Method) maximal.next(); - switch(moreSpecific(appArgs, max.getParameterTypes())) - { - case MORE_SPECIFIC: - { + switch (moreSpecific(appArgs, max.getParameterTypes())) { + case MORE_SPECIFIC: { /* * This method is more specific than the previously * known maximally specific, so remove the old maximum. @@ -191,8 +166,7 @@ break; } - case LESS_SPECIFIC: - { + case LESS_SPECIFIC: { /* * This method is less specific than some of the * currently known maximally specific methods, so we @@ -206,53 +180,43 @@ } } - if(!lessSpecific) - { + if (!lessSpecific) { maximals.addLast(app); } } - if(maximals.size() > 1) - { + if (maximals.size() > 1) { // We have more than one maximally specific method throw new AmbiguousException(); } - return (Method)maximals.getFirst(); + return (Method) maximals.getFirst(); } /** * Determines which method signature (represented by a class array) is more * specific. This defines a partial ordering on the method signatures. + * * @param c1 first signature to compare * @param c2 second signature to compare - * @return MORE_SPECIFIC if c1 is more specific than c2, LESS_SPECIFIC if - * c1 is less specific than c2, INCOMPARABLE if they are incomparable. + * @return MORE_SPECIFIC if c1 is more specific than c2, LESS_SPECIFIC if c1 + * is less specific than c2, INCOMPARABLE if they are incomparable. */ - private static int moreSpecific(Class[] c1, Class[] c2) - { + private static int moreSpecific(Class[] c1, Class[] c2) { boolean c1MoreSpecific = false; boolean c2MoreSpecific = false; - for(int i = 0; i < c1.length; ++i) - { - if(c1[i] != c2[i]) - { - c1MoreSpecific = - c1MoreSpecific || - isStrictMethodInvocationConvertible(c2[i], c1[i]); - c2MoreSpecific = - c2MoreSpecific || - isStrictMethodInvocationConvertible(c1[i], c2[i]); + for (int i = 0; i < c1.length; ++i) { + if (c1[i] != c2[i]) { + c1MoreSpecific = c1MoreSpecific || isStrictMethodInvocationConvertible(c2[i], c1[i]); + c2MoreSpecific = c2MoreSpecific || isStrictMethodInvocationConvertible(c1[i], c2[i]); } } - if(c1MoreSpecific) - { - if(c2MoreSpecific) - { + if (c1MoreSpecific) { + if (c2MoreSpecific) { /* - * Incomparable due to cross-assignable arguments (i.e. + * Incomparable due to cross-assignable arguments (i.e. * foo(String, Object) vs. foo(Object, String)) */ @@ -262,14 +226,13 @@ return MORE_SPECIFIC; } - if(c2MoreSpecific) - { + if (c2MoreSpecific) { return LESS_SPECIFIC; } /* - * Incomparable due to non-related arguments (i.e. - * foo(Runnable) vs. foo(Serializable)) + * Incomparable due to non-related arguments (i.e. foo(Runnable) vs. + * foo(Serializable)) */ return INCOMPARABLE; @@ -277,22 +240,20 @@ /** * Returns all methods that are applicable to actual argument types. + * * @param methods list of all candidate methods * @param classes the actual types of the arguments - * @return a list that contains only applicable methods (number of - * formal and actual arguments matches, and argument types are assignable - * to formal types through a method invocation conversion). + * @return a list that contains only applicable methods (number of formal + * and actual arguments matches, and argument types are assignable + * to formal types through a method invocation conversion). */ - private static LinkedList getApplicables(List methods, Class[] classes) - { + private static LinkedList getApplicables(List methods, Class[] classes) { LinkedList list = new LinkedList(); - for (Iterator imethod = methods.iterator(); imethod.hasNext();) - { + for (Iterator imethod = methods.iterator(); imethod.hasNext();) { Method method = (Method) imethod.next(); - if(isApplicable(method, classes)) - { + if (isApplicable(method, classes)) { list.add(method); } @@ -301,22 +262,18 @@ } /** - * Returns true if the supplied method is applicable to actual - * argument types. + * Returns true if the supplied method is applicable to actual argument + * types. */ - private static boolean isApplicable(Method method, Class[] classes) - { + private static boolean isApplicable(Method method, Class[] classes) { Class[] methodArgs = method.getParameterTypes(); - if(methodArgs.length != classes.length) - { + if (methodArgs.length != classes.length) { return false; } - for(int i = 0; i < classes.length; ++i) - { - if(!isMethodInvocationConvertible(methodArgs[i], classes[i])) - { + for (int i = 0; i < classes.length; ++i) { + if (!isMethodInvocationConvertible(methodArgs[i], classes[i])) { return false; } } @@ -325,76 +282,64 @@ } /** - * Determines whether a type represented by a class object is - * convertible to another type represented by a class object using a - * method invocation conversion, treating object types of primitive - * types as if they were primitive types (that is, a Boolean actual - * parameter type matches boolean primitive formal type). This behavior - * is because this method is used to determine applicable methods for - * an actual parameter list, and primitive types are represented by - * their object duals in reflective method calls. - * - * @param formal the formal parameter type to which the actual - * parameter type should be convertible + * Determines whether a type represented by a class object is convertible to + * another type represented by a class object using a method invocation + * conversion, treating object types of primitive types as if they were + * primitive types (that is, a Boolean actual parameter type matches boolean + * primitive formal type). This behavior is because this method is used to + * determine applicable methods for an actual parameter list, and primitive + * types are represented by their object duals in reflective method calls. + * + * @param formal the formal parameter type to which the actual parameter + * type should be convertible * @param actual the actual parameter type. - * @return true if either formal type is assignable from actual type, - * or formal is a primitive type and actual is its corresponding object - * type or an object type of a primitive type that can be converted to - * the formal type. + * @return true if either formal type is assignable from actual type, or + * formal is a primitive type and actual is its corresponding object + * type or an object type of a primitive type that can be converted + * to the formal type. */ - private static boolean isMethodInvocationConvertible(Class formal, - Class actual) - { + private static boolean isMethodInvocationConvertible(Class formal, Class actual) { /* * if it's a null, it means the arg was null */ - if (actual == null && !formal.isPrimitive()) - { + if (actual == null && !formal.isPrimitive()) { return true; } /* - * Check for identity or widening reference conversion + * Check for identity or widening reference conversion */ - if (actual != null && formal.isAssignableFrom(actual)) - { + if (actual != null && formal.isAssignableFrom(actual)) { return true; } /* - * Check for boxing with widening primitive conversion. Note that - * actual parameters are never primitives. + * Check for boxing with widening primitive conversion. Note that actual + * parameters are never primitives. */ - if (formal.isPrimitive()) - { - if(formal == Boolean.TYPE && actual == Boolean.class) - return true; - if(formal == Character.TYPE && actual == Character.class) - return true; - if(formal == Byte.TYPE && actual == Byte.class) - return true; - if(formal == Short.TYPE && - (actual == Short.class || actual == Byte.class)) - return true; - if(formal == Integer.TYPE && - (actual == Integer.class || actual == Short.class || - actual == Byte.class)) - return true; - if(formal == Long.TYPE && - (actual == Long.class || actual == Integer.class || - actual == Short.class || actual == Byte.class)) - return true; - if(formal == Float.TYPE && - (actual == Float.class || actual == Long.class || - actual == Integer.class || actual == Short.class || - actual == Byte.class)) - return true; - if(formal == Double.TYPE && - (actual == Double.class || actual == Float.class || - actual == Long.class || actual == Integer.class || - actual == Short.class || actual == Byte.class)) + if (formal.isPrimitive()) { + if (formal == Boolean.TYPE && actual == Boolean.class) + return true; + if (formal == Character.TYPE && actual == Character.class) + return true; + if (formal == Byte.TYPE && actual == Byte.class) + return true; + if (formal == Short.TYPE && (actual == Short.class || actual == Byte.class)) + return true; + if (formal == Integer.TYPE && (actual == Integer.class || actual == Short.class || actual == Byte.class)) + return true; + if (formal == Long.TYPE + && (actual == Long.class || actual == Integer.class || actual == Short.class || actual == Byte.class)) + return true; + if (formal == Float.TYPE + && (actual == Float.class || actual == Long.class || actual == Integer.class + || actual == Short.class || actual == Byte.class)) + return true; + if (formal == Double.TYPE + && (actual == Double.class || actual == Float.class || actual == Long.class || actual == Integer.class + || actual == Short.class || actual == Byte.class)) return true; } @@ -402,62 +347,52 @@ } /** - * Determines whether a type represented by a class object is - * convertible to another type represented by a class object using a - * method invocation conversion, without matching object and primitive - * types. This method is used to determine the more specific type when - * comparing signatures of methods. - * - * @param formal the formal parameter type to which the actual - * parameter type should be convertible + * Determines whether a type represented by a class object is convertible to + * another type represented by a class object using a method invocation + * conversion, without matching object and primitive types. This method is + * used to determine the more specific type when comparing signatures of + * methods. + * + * @param formal the formal parameter type to which the actual parameter + * type should be convertible * @param actual the actual parameter type. - * @return true if either formal type is assignable from actual type, - * or formal and actual are both primitive types and actual can be - * subject to widening conversion to formal. + * @return true if either formal type is assignable from actual type, or + * formal and actual are both primitive types and actual can be + * subject to widening conversion to formal. */ - private static boolean isStrictMethodInvocationConvertible(Class formal, - Class actual) - { + private static boolean isStrictMethodInvocationConvertible(Class formal, Class actual) { /* * we shouldn't get a null into, but if so */ - if (actual == null && !formal.isPrimitive()) - { + if (actual == null && !formal.isPrimitive()) { return true; } /* - * Check for identity or widening reference conversion + * Check for identity or widening reference conversion */ - if(formal.isAssignableFrom(actual)) - { + if (formal.isAssignableFrom(actual)) { return true; } /* - * Check for widening primitive conversion. + * Check for widening primitive conversion. */ - if(formal.isPrimitive()) - { - if(formal == Short.TYPE && (actual == Byte.TYPE)) - return true; - if(formal == Integer.TYPE && - (actual == Short.TYPE || actual == Byte.TYPE)) - return true; - if(formal == Long.TYPE && - (actual == Integer.TYPE || actual == Short.TYPE || - actual == Byte.TYPE)) - return true; - if(formal == Float.TYPE && - (actual == Long.TYPE || actual == Integer.TYPE || - actual == Short.TYPE || actual == Byte.TYPE)) - return true; - if(formal == Double.TYPE && - (actual == Float.TYPE || actual == Long.TYPE || - actual == Integer.TYPE || actual == Short.TYPE || - actual == Byte.TYPE)) + if (formal.isPrimitive()) { + if (formal == Short.TYPE && (actual == Byte.TYPE)) + return true; + if (formal == Integer.TYPE && (actual == Short.TYPE || actual == Byte.TYPE)) + return true; + if (formal == Long.TYPE && (actual == Integer.TYPE || actual == Short.TYPE || actual == Byte.TYPE)) + return true; + if (formal == Float.TYPE + && (actual == Long.TYPE || actual == Integer.TYPE || actual == Short.TYPE || actual == Byte.TYPE)) + return true; + if (formal == Double.TYPE + && (actual == Float.TYPE || actual == Long.TYPE || actual == Integer.TYPE || actual == Short.TYPE + || actual == Byte.TYPE)) return true; } return false; Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/Uberspect.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/Uberspect.java?rev=398171&r1=398170&r2=398171&view=diff ============================================================================== --- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/Uberspect.java (original) +++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/Uberspect.java Sat Apr 29 07:57:29 2006 @@ -1,12 +1,12 @@ /* * Copyright 2002,2004 The Apache Software Foundation. - * + * * Licensed 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. @@ -16,41 +16,41 @@ package org.apache.commons.jexl.util.introspection; - import java.util.Iterator; /** * 'Federated' introspection/reflection interface to allow the introspection - * behavior in Velocity to be customized. - * + * behavior in Velocity to be customized. + * * @since 1.0 * @author Geir Magusson Jr. * @version $Id$ */ -public interface Uberspect -{ +public interface Uberspect { /** - * Initializer - will be called before use + * Initializer - will be called before use. */ - public void init() throws Exception; + void init() throws Exception; /** - * To support iteratives - #foreach() + * To support iteratives - #foreach(). */ - public Iterator getIterator(Object obj, Info info) throws Exception; + Iterator getIterator(Object obj, Info info) throws Exception; /** - * Returns a general method, corresponding to $foo.bar( $woogie ) + * Returns a general method, corresponding to $foo.bar( $woogie ). */ - public VelMethod getMethod(Object obj, String method, Object[] args, Info info) throws Exception; + VelMethod getMethod(Object obj, String method, Object[] args, Info info) throws Exception; /** - * Property getter - returns VelPropertyGet appropos for #set($foo = $bar.woogie) + * Property getter - returns VelPropertyGet appropos for #set($foo = + * $bar.woogie). */ - public VelPropertyGet getPropertyGet(Object obj, String identifier, Info info) throws Exception; + VelPropertyGet getPropertyGet(Object obj, String identifier, Info info) throws Exception; /** - * Property setter - returns VelPropertySet appropos for #set($foo.bar = "geir") + * Property setter - returns VelPropertySet appropos for #set($foo.bar = + * "geir"). */ - public VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info info) throws Exception; + VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info info) throws Exception; } Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/UberspectImpl.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/UberspectImpl.java?rev=398171&r1=398170&r2=398171&view=diff ============================================================================== --- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/UberspectImpl.java (original) +++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/UberspectImpl.java Sat Apr 29 07:57:29 2006 @@ -1,12 +1,12 @@ /* * Copyright 2002,2004 The Apache Software Foundation. - * + * * Licensed 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. @@ -33,104 +33,76 @@ import java.util.ArrayList; /** - * Implementation of Uberspect to provide the default introspective - * functionality of Velocity - * + * Implementation of Uberspect to provide the default introspective + * functionality of Velocity. + * * @since 1.0 * @author Geir Magnusson Jr. * @version $Id$ */ -public class UberspectImpl implements Uberspect, UberspectLoggable -{ +public class UberspectImpl implements Uberspect, UberspectLoggable { /** - * Our runtime logger. + * Our runtime logger. */ private Log rlog; /** - * the default Velocity introspector + * the default Velocity introspector. */ private static Introspector introspector; /** - * init - does nothing - we need to have setRuntimeLogger - * called before getting our introspector, as the default - * vel introspector depends upon it. + * init - does nothing - we need to have setRuntimeLogger called before + * getting our introspector, as the default vel introspector depends upon + * it. */ - public void init() - throws Exception - { + public void init() throws Exception { } /** - * Sets the runtime logger - this must be called before anything - * else besides init() as to get the logger. Makes the pull - * model appealing... + * Sets the runtime logger - this must be called before anything else + * besides init() as to get the logger. Makes the pull model appealing... */ - public void setRuntimeLogger(Log runtimeLogger) - { + public void setRuntimeLogger(Log runtimeLogger) { rlog = runtimeLogger; introspector = new Introspector(rlog); } /** - * To support iteratives - #foreach() + * To support iteratives - #foreach(). */ - public Iterator getIterator(Object obj, Info i) - throws Exception - { - if (obj.getClass().isArray()) - { + public Iterator getIterator(Object obj, Info i) throws Exception { + if (obj.getClass().isArray()) { return new ArrayIterator(obj); - } - else if (obj instanceof Collection) - { + } else if (obj instanceof Collection) { return ((Collection) obj).iterator(); - } - else if (obj instanceof Map) - { + } else if (obj instanceof Map) { return ((Map) obj).values().iterator(); - } - else if (obj instanceof Iterator) - { - rlog.warn ("Warning! The iterative " - + " is an Iterator in the #foreach() loop at [" - + i.getLine() + "," + i.getColumn() + "]" - + " in template " + i.getTemplateName() - + ". Because it's not resetable," - + " if used in more than once, this may lead to" - + " unexpected results."); + } else if (obj instanceof Iterator) { + rlog.warn("Warning! The iterative " + " is an Iterator in the #foreach() loop at [" + i.getLine() + "," + + i.getColumn() + "]" + " in template " + i.getTemplateName() + ". Because it's not resetable," + + " if used in more than once, this may lead to" + " unexpected results."); return ((Iterator) obj); - } - else if (obj instanceof Enumeration) - { - rlog.warn ("Warning! The iterative " - + " is an Enumeration in the #foreach() loop at [" - + i.getLine() + "," + i.getColumn() + "]" - + " in template " + i.getTemplateName() - + ". Because it's not resetable," - + " if used in more than once, this may lead to" - + " unexpected results."); + } else if (obj instanceof Enumeration) { + rlog.warn("Warning! The iterative " + " is an Enumeration in the #foreach() loop at [" + i.getLine() + "," + + i.getColumn() + "]" + " in template " + i.getTemplateName() + ". Because it's not resetable," + + " if used in more than once, this may lead to" + " unexpected results."); return new EnumerationIterator((Enumeration) obj); } - /* we have no clue what this is */ - rlog.warn ("Could not determine type of iterator in " - + "#foreach loop " - + " at [" + i.getLine() + "," + i.getColumn() + "]" - + " in template " + i.getTemplateName() ); + /* we have no clue what this is */ + rlog.warn("Could not determine type of iterator in " + "#foreach loop " + " at [" + i.getLine() + "," + + i.getColumn() + "]" + " in template " + i.getTemplateName()); return null; } /** - * Method + * Method. */ - public VelMethod getMethod(Object obj, String methodName, Object[] args, Info i) - throws Exception - { + public VelMethod getMethod(Object obj, String methodName, Object[] args, Info i) throws Exception { if (obj == null) return null; @@ -143,37 +115,32 @@ } /** - * Property getter + * Property getter. */ - public VelPropertyGet getPropertyGet(Object obj, String identifier, Info i) - throws Exception - { + public VelPropertyGet getPropertyGet(Object obj, String identifier, Info i) throws Exception { AbstractExecutor executor; Class claz = obj.getClass(); /* - * first try for a getFoo() type of property - * (also getfoo() ) + * first try for a getFoo() type of property (also getfoo() ) */ - executor = new PropertyExecutor(rlog,introspector, claz, identifier); + executor = new PropertyExecutor(rlog, introspector, claz, identifier); /* - * look for boolean isFoo() + * look for boolean isFoo() */ - if( !executor.isAlive()) - { + if (!executor.isAlive()) { executor = new BooleanPropertyExecutor(rlog, introspector, claz, identifier); } /* - * if that didn't work, look for get("foo") + * if that didn't work, look for get("foo") */ - if (!executor.isAlive()) - { + if (!executor.isAlive()) { executor = new GetExecutor(rlog, introspector, claz, identifier); } @@ -183,205 +150,158 @@ /** * Property setter */ - public VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info i) - throws Exception - { + public VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info i) throws Exception { Class claz = obj.getClass(); VelMethod vm = null; - try - { + try { /* - * first, we introspect for the set setter method + * first, we introspect for the set setter method */ Object[] params = {arg}; - try - { + try { vm = getMethod(obj, "set" + identifier, params, i); - if (vm == null) - { - throw new NoSuchMethodException(); + if (vm == null) { + throw new NoSuchMethodException(); } - } - catch(NoSuchMethodException nsme2) - { + } catch (NoSuchMethodException nsme2) { StringBuffer sb = new StringBuffer("set"); sb.append(identifier); - if (Character.isLowerCase( sb.charAt(3))) - { + if (Character.isLowerCase(sb.charAt(3))) { sb.setCharAt(3, Character.toUpperCase(sb.charAt(3))); - } - else - { + } else { sb.setCharAt(3, Character.toLowerCase(sb.charAt(3))); } vm = getMethod(obj, sb.toString(), params, i); - if (vm == null) - { - throw new NoSuchMethodException(); + if (vm == null) { + throw new NoSuchMethodException(); } } - } - catch (NoSuchMethodException nsme) - { + } catch (NoSuchMethodException nsme) { /* - * right now, we only support the Map interface + * right now, we only support the Map interface */ - if (Map.class.isAssignableFrom(claz)) - { + if (Map.class.isAssignableFrom(claz)) { Object[] params = {new Object(), new Object()}; vm = getMethod(obj, "put", params, i); - if (vm!=null) + if (vm != null) return new VelSetterImpl(vm, identifier); } - } + } - return (vm ==null) ? null : new VelSetterImpl(vm); + return (vm == null) ? null : new VelSetterImpl(vm); } /** - * Implementation of VelMethod + * Implementation of VelMethod */ - public class VelMethodImpl implements VelMethod - { + public class VelMethodImpl implements VelMethod { Method method = null; - public VelMethodImpl(Method m) - { + public VelMethodImpl(Method m) { method = m; } - private VelMethodImpl() - { + private VelMethodImpl() { } - public Object invoke(Object o, Object[] params) - throws Exception - { - try - { + public Object invoke(Object o, Object[] params) throws Exception { + try { return method.invoke(o, params); - } - catch( InvocationTargetException e ) - { + } catch (InvocationTargetException e) { final Throwable t = e.getTargetException(); - if( t instanceof Exception ) - { - throw (Exception)t; - } - else if (t instanceof Error) - { - throw (Error)t; - } - else - { + if (t instanceof Exception) { + throw (Exception) t; + } else if (t instanceof Error) { + throw (Error) t; + } else { throw e; } } } - public boolean isCacheable() - { + public boolean isCacheable() { return true; } - public String getMethodName() - { + public String getMethodName() { return method.getName(); } - public Class getReturnType() - { + public Class getReturnType() { return method.getReturnType(); } } - public class VelGetterImpl implements VelPropertyGet - { + public class VelGetterImpl implements VelPropertyGet { AbstractExecutor ae = null; - public VelGetterImpl(AbstractExecutor exec) - { + public VelGetterImpl(AbstractExecutor exec) { ae = exec; } - private VelGetterImpl() - { + private VelGetterImpl() { } - public Object invoke(Object o) - throws Exception - { + public Object invoke(Object o) throws Exception { return ae.execute(o); } - public boolean isCacheable() - { + public boolean isCacheable() { return true; } - public String getMethodName() - { + public String getMethodName() { return ae.getMethod().getName(); } } - public class VelSetterImpl implements VelPropertySet - { + public class VelSetterImpl implements VelPropertySet { VelMethod vm = null; + String putKey = null; - public VelSetterImpl(VelMethod velmethod) - { + public VelSetterImpl(VelMethod velmethod) { this.vm = velmethod; } - public VelSetterImpl(VelMethod velmethod, String key) - { + public VelSetterImpl(VelMethod velmethod, String key) { this.vm = velmethod; putKey = key; } - private VelSetterImpl() - { + private VelSetterImpl() { } - public Object invoke(Object o, Object value) - throws Exception - { + public Object invoke(Object o, Object value) throws Exception { ArrayList al = new ArrayList(); - if (putKey == null) - { + if (putKey == null) { al.add(value); - } - else - { + } else { al.add(putKey); al.add(value); } - return vm.invoke(o,al.toArray()); + return vm.invoke(o, al.toArray()); } - public boolean isCacheable() - { + public boolean isCacheable() { return true; } - public String getMethodName() - { + public String getMethodName() { return vm.getMethodName(); } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org