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
commit 98e7800182567d1da4bb648214c11b318409dd3d Author: James Bognar <[email protected]> AuthorDate: Wed Dec 3 11:16:10 2025 -0800 Unit tests --- .../apache/juneau/commons/reflect/ClassInfo.java | 25 ++++++++++ .../apache/juneau/commons/utils/ClassUtils.java | 39 --------------- .../juneau/commons/utils/ClassUtils_Test.java | 57 ---------------------- 3 files changed, 25 insertions(+), 96 deletions(-) diff --git a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/ClassInfo.java b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/ClassInfo.java index 46e1639c9e..05f880acad 100644 --- a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/ClassInfo.java +++ b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/ClassInfo.java @@ -1428,6 +1428,31 @@ public class ClassInfo extends ElementInfo implements Annotatable { } } + /** + * Checks if one generic declaration (typically a class) is an inner class of another. + * + * <p> + * This method walks up the enclosing class hierarchy of the potential inner class to determine if it's + * nested within the outer class at any level. It's used during generic type resolution to determine if + * a type variable belongs to an inner class that's nested within an outer class. + * + * @param od + * The potential outer declaration (typically an outer class). + * @param id + * The potential inner declaration (typically an inner class). + * @return + * <jk>true</jk> if <c>id</c> is nested within <c>od</c> at any level, <jk>false</jk> otherwise. + * <br>Returns <jk>false</jk> if either parameter is not a <c>Class</c>. + */ + private static boolean isInnerClass(GenericDeclaration od, GenericDeclaration id) { + if (od instanceof Class<?> oc && id instanceof Class<?> ic) { + while (nn(ic = ic.getEnclosingClass())) + if (ic == oc) + return true; + } + return false; + } + /** * Returns a list including this class and all parent classes. * diff --git a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/ClassUtils.java b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/ClassUtils.java index 77afde121f..7cd46ce079 100644 --- a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/ClassUtils.java +++ b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/ClassUtils.java @@ -430,45 +430,6 @@ public class ClassUtils { return null; } - /** - * Checks if one generic declaration (typically a class) is an inner class of another. - * - * <p> - * This method walks up the enclosing class hierarchy of the potential inner class to determine if it's - * nested within the outer class at any level. It's used during generic type resolution to determine if - * type variables from different scopes refer to the same logical type parameter. - * - * <h5 class='section'>Example:</h5> - * <p class='bjava'> - * <jc>// Given these classes:</jc> - * <jk>class</jk> Outer<T> { - * <jk>class</jk> Inner<T> { - * <jc>// The T here could refer to either Outer.T or Inner.T</jc> - * } - * } - * - * <jc>// This method helps determine the relationship:</jc> - * isInnerClass(Outer.<jk>class</jk>, Inner.<jk>class</jk>); <jc>// Returns true</jc> - * isInnerClass(Inner.<jk>class</jk>, Outer.<jk>class</jk>); <jc>// Returns false</jc> - * </p> - * - * @param od - * The potential outer declaration (typically an outer class). - * @param id - * The potential inner declaration (typically an inner class). - * @return - * <jk>true</jk> if <c>id</c> is nested within <c>od</c> at any level, <jk>false</jk> otherwise. - * <br>Returns <jk>false</jk> if either parameter is not a <c>Class</c>. - */ - public static boolean isInnerClass(GenericDeclaration od, GenericDeclaration id) { - if (od instanceof Class<?> oc && id instanceof Class<?> ic) { - while (nn(ic = ic.getEnclosingClass())) - if (ic == oc) - return true; - } - return false; - } - /** * Returns <jk>false</jk> if the specific class is <jk>null</jk> or <c><jk>void</jk>.<jk>class</jk></c> or {@link Void} or has the simple name <js>"Void</js>. * diff --git a/juneau-utest/src/test/java/org/apache/juneau/commons/utils/ClassUtils_Test.java b/juneau-utest/src/test/java/org/apache/juneau/commons/utils/ClassUtils_Test.java index 084f73f382..34512e23d7 100644 --- a/juneau-utest/src/test/java/org/apache/juneau/commons/utils/ClassUtils_Test.java +++ b/juneau-utest/src/test/java/org/apache/juneau/commons/utils/ClassUtils_Test.java @@ -565,63 +565,6 @@ class ClassUtils_Test { assertNull(result); } - //----------------------------------------------------------------------------------------------------------------- - // isInnerClass(GenericDeclaration, GenericDeclaration) tests - //----------------------------------------------------------------------------------------------------------------- - - @Test - public void l01_isInnerClass_true() { - assertTrue(isInnerClass(Map.class, Map.Entry.class)); - } - - @Test - public void l02_isInnerClass_false() { - assertFalse(isInnerClass(Map.Entry.class, Map.class)); - assertFalse(isInnerClass(String.class, Integer.class)); - } - - @Test - public void l03_isInnerClass_sameClass() { - assertFalse(isInnerClass(String.class, String.class)); - } - - @Test - public void l04_isInnerClass_nestedInner() { - class Outer { - class Inner { - class Deep {} - } - } - assertTrue(isInnerClass(Outer.class, Outer.Inner.class)); - assertTrue(isInnerClass(Outer.class, Outer.Inner.Deep.class)); - assertTrue(isInnerClass(Outer.Inner.class, Outer.Inner.Deep.class)); - } - - @Test - public void l05_isInnerClass_notClass() { - // Test line 590: false branch when od or id is not a Class - // When od or id is not a Class, the instanceof check fails and method returns false - Method method = null; - Constructor<?> constructor = null; - try { - method = String.class.getMethod("toString"); - constructor = String.class.getConstructor(); - } catch (NoSuchMethodException e) { - fail("Could not get method or constructor for testing"); - } - - // Test with Method (not a Class) - assertFalse(isInnerClass(String.class, method)); - assertFalse(isInnerClass(method, String.class)); - - // Test with Constructor (not a Class) - assertFalse(isInnerClass(String.class, constructor)); - assertFalse(isInnerClass(constructor, String.class)); - - // Test with both non-Class - assertFalse(isInnerClass(method, constructor)); - } - //----------------------------------------------------------------------------------------------------------------- // getProxyFor(Object) tests //-----------------------------------------------------------------------------------------------------------------
