jdk/src/share/classes/com/sun/beans/finder/AbstractFinder.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 22,31 ****
--- 22,34 ----
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.finder;
+ import java.lang.reflect.Executable;
+ import java.lang.reflect.Modifier;
+
import java.util.HashMap;
import java.util.Map;
/**
* This abstract class provides functionality
*** 35,45 ****
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
! abstract class AbstractFinder<T> {
private final Class<?>[] args;
/**
* Creates finder for array of classes of arguments.
* If a particular element of array equals {@code null},
--- 38,48 ----
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
! abstract class AbstractFinder<T extends Executable> {
private final Class<?>[] args;
/**
* Creates finder for array of classes of arguments.
* If a particular element of array equals {@code null},
*** 51,89 ****
protected AbstractFinder(Class<?>[] args) {
this.args = args;
}
/**
- * Returns an array of {@code Class} objects
- * that represent the formal parameter types of the method.
- * Returns an empty array if the method takes no parameters.
- *
- * @param method the object that represents method
- * @return the parameter types of the method
- */
- protected abstract Class<?>[] getParameters(T method);
-
- /**
- * Returns {@code true} if and only if the method
- * was declared to take a variable number of arguments.
- *
- * @param method the object that represents method
- * @return {@code true} if the method was declared
- * to take a variable number of arguments;
- * {@code false} otherwise
- */
- protected abstract boolean isVarArgs(T method);
-
- /**
* Checks validness of the method.
* At least the valid method should be public.
*
* @param method the object that represents method
* @return {@code true} if the method is valid,
* {@code false} otherwise
*/
! protected abstract boolean isValid(T method);
/**
* Performs a search in the {@code methods} array.
* The one method is selected from the array of the valid methods.
* The list of parameters of the selected method shows
--- 54,73 ----
protected AbstractFinder(Class<?>[] args) {
this.args = args;
}
/**
* Checks validness of the method.
* At least the valid method should be public.
*
* @param method the object that represents method
* @return {@code true} if the method is valid,
* {@code false} otherwise
*/
! protected boolean isValid(T method) {
! return Modifier.isPublic(method.getModifiers());
! }
/**
* Performs a search in the {@code methods} array.
* The one method is selected from the array of the valid methods.
* The list of parameters of the selected method shows
*** 107,138 ****
Class<?>[] oldParams = null;
boolean ambiguous = false;
for (T newMethod : methods) {
if (isValid(newMethod)) {
! Class<?>[] newParams = getParameters(newMethod);
if (newParams.length == this.args.length) {
PrimitiveWrapperMap.replacePrimitivesWithWrappers(newParams);
if (isAssignable(newParams, this.args)) {
if (oldMethod == null) {
oldMethod = newMethod;
oldParams = newParams;
} else {
boolean useNew = isAssignable(oldParams, newParams);
boolean useOld = isAssignable(newParams, oldParams);
if (useOld == useNew) {
ambiguous = true;
} else if (useNew) {
oldMethod = newMethod;
oldParams = newParams;
ambiguous = false;
}
}
}
}
! if (isVarArgs(newMethod)) {
int length = newParams.length - 1;
if (length <= this.args.length) {
Class<?>[] array = new Class<?>[this.args.length];
System.arraycopy(newParams, 0, array, 0, length);
if (length < this.args.length) {
--- 91,127 ----
Class<?>[] oldParams = null;
boolean ambiguous = false;
for (T newMethod : methods) {
if (isValid(newMethod)) {
! Class<?>[] newParams = newMethod.getParameterTypes();
if (newParams.length == this.args.length) {
PrimitiveWrapperMap.replacePrimitivesWithWrappers(newParams);
if (isAssignable(newParams, this.args)) {
if (oldMethod == null) {
oldMethod = newMethod;
oldParams = newParams;
} else {
boolean useNew = isAssignable(oldParams, newParams);
boolean useOld = isAssignable(newParams, oldParams);
+ if (useOld && useNew) {
+ // only if parameters are equal
+ useNew = !newMethod.isSynthetic();
+ useOld = !oldMethod.isSynthetic();
+ }
if (useOld == useNew) {
ambiguous = true;
} else if (useNew) {
oldMethod = newMethod;
oldParams = newParams;
ambiguous = false;
}
}
}
}
! if (newMethod.isVarArgs()) {
int length = newParams.length - 1;
if (length <= this.args.length) {
Class<?>[] array = new Class<?>[this.args.length];
System.arraycopy(newParams, 0, array, 0, length);
if (length < this.args.length) {
*** 158,167 ****
--- 147,161 ----
oldParams = newParams;
} else {
boolean useNew = isAssignable(oldParams, newParams);
boolean useOld = isAssignable(newParams, oldParams);
+ if (useOld && useNew) {
+ // only if parameters are equal
+ useNew = !newMethod.isSynthetic();
+ useOld = !oldMethod.isSynthetic();
+ }
if (useOld == useNew) {
if (oldParams == map.get(oldMethod)) {
ambiguous = true;
}
} else if (useNew) {