This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new 14ac6a8 BeanStore refactoring.
14ac6a8 is described below
commit 14ac6a8c27ae81209cc4dc26013e300cf0aeee13
Author: JamesBognar <[email protected]>
AuthorDate: Sat Jan 22 14:56:11 2022 -0500
BeanStore refactoring.
---
.../org/apache/juneau/internal/ClassUtils.java | 14 +++++++-
.../java/org/apache/juneau/reflect/ClassInfo.java | 40 ----------------------
.../org/apache/juneau/reflect/ExecutableInfo.java | 23 +++++++++++++
.../apache/juneau/reflection/ClassInfoTest.java | 6 ----
4 files changed, 36 insertions(+), 47 deletions(-)
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ClassUtils.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ClassUtils.java
index 5aa99b5..5592b60 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ClassUtils.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ClassUtils.java
@@ -141,7 +141,7 @@ public final class ClassUtils {
if (mi != null)
return mi.invoke(null,
getMatchingArgs(mi.getParamTypes(), args));
- con =
c3.getPublicConstructorFuzzy(args);
+ con = getPublicConstructorFuzzy(c3,
args);
if (con != null)
return con.<T>invokeFuzzy(args);
}
@@ -157,6 +157,18 @@ public final class ClassUtils {
}
}
+ private static ConstructorInfo getPublicConstructorFuzzy(ClassInfo c,
Object...args) {
+ int bestCount = -1;
+ ConstructorInfo bestMatch = null;
+ for (ConstructorInfo n : c.getPublicConstructors()) {
+ int m = n.fuzzyArgsMatch(args);
+ if (m > bestCount) {
+ bestCount = m;
+ bestMatch = n;
+ }
+ }
+ return bestMatch;
+ }
private static MethodInfo getStaticCreatorFuzzy(ClassInfo c,
Object...args) {
int bestCount = -1;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
index 504abce..7e44d15 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
@@ -660,18 +660,6 @@ public final class ClassInfo {
return new UnmodifiableArray<>(_getDeclaredConstructors());
}
- /**
- * Finds the public constructor that can take in the specified
arguments using fuzzy-arg matching.
- *
- * @param args The arguments we want to pass into the constructor.
- * @return
- * The constructor, or <jk>null</jk> if a public constructor could
not be found that takes in the specified
- * arguments.
- */
- public ConstructorInfo getPublicConstructorFuzzy(Object...args) {
- return _getConstructor(Visibility.PUBLIC, true,
ClassUtils.getClasses(args));
- }
-
private ConstructorInfo[] _getPublicConstructors() {
if (publicConstructors == null) {
Constructor<?>[] cc = c == null ? new Constructor[0] :
c.getConstructors();
@@ -696,34 +684,6 @@ public final class ClassInfo {
return declaredConstructors;
}
- private ConstructorInfo _getConstructor(Visibility vis, boolean
fuzzyArgs, Class<?>...argTypes) {
- if (fuzzyArgs) {
- int bestCount = -1;
- ConstructorInfo bestMatch = null;
- for (ConstructorInfo n : _getDeclaredConstructors()) {
- if (vis.isVisible(n.inner())) {
- int m = n.fuzzyArgsMatch(argTypes);
- if (m > bestCount) {
- bestCount = m;
- bestMatch = n;
- }
- }
- }
- return bestMatch;
- }
-
- boolean isMemberClass = isNonStaticMemberClass();
- for (ConstructorInfo n : _getDeclaredConstructors()) {
- List<ClassInfo> paramTypes = n.getParamTypes();
- if (isMemberClass)
- paramTypes = paramTypes.subList(1,
paramTypes.size());
- if (n.hasMatchingParamTypes(argTypes) &&
vis.isVisible(n.inner()))
- return n;
- }
-
- return null;
- }
-
//-----------------------------------------------------------------------------------------------------------------
// Special constructors
//-----------------------------------------------------------------------------------------------------------------
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java
index f9d0f48..857c5d5 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java
@@ -623,6 +623,29 @@ public abstract class ExecutableInfo {
return matches;
}
+ /**
+ * Returns how well this method matches the specified arg types.
+ *
+ * <p>
+ * The number returned is the number of method arguments that match the
passed in arg types.
+ * <br>Returns <c>-1</c> if the method cannot take in one or more of
the specified arguments.
+ *
+ * @param argTypes The arg types to check against.
+ * @return How many parameters match or <c>-1</c> if method cannot
handle one or more of the arguments.
+ */
+ public int fuzzyArgsMatch(Object... argTypes) {
+ int matches = 0;
+ outer: for (ClassInfo pi : getParamTypes()) {
+ for (Object a : argTypes) {
+ if (pi.canAcceptArg(a)) {
+ matches++;
+ continue outer;
+ }
+ }
+ return -1;
+ }
+ return matches;
+ }
/**
* Returns <jk>true</jk> if this method has at most only this arguments
in any order.
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/reflection/ClassInfoTest.java
b/juneau-utest/src/test/java/org/apache/juneau/reflection/ClassInfoTest.java
index 4156728..89131c4 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/reflection/ClassInfoTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/reflection/ClassInfoTest.java
@@ -479,12 +479,6 @@ public class ClassInfoTest {
}
@Test
- public void getPublicConstructorFuzzy() {
- check("E1(String)", e1.getPublicConstructorFuzzy("foo", new
HashMap<>()));
- check("E1()", e1.getPublicConstructorFuzzy(new HashMap<>()));
- }
-
- @Test
public void getNoArgConstructor() {
check("E2()", e2.getNoArgConstructor(Visibility.PRIVATE));
check("E2()", e2.getNoArgConstructor(Visibility.PROTECTED));