[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jakarta-commons-dev
Subject:    [GitHub] zmacomber commented on a change in pull request #358: ClassUtils.getBaseClasses(desiredBase
From:       GitBox <git () apache ! org>
Date:       2018-12-28 18:30:41
Message-ID: 154602184103.15882.5481472292471949950.gitbox () gitbox ! apache ! org
[Download RAW message or body]

zmacomber commented on a change in pull request #358: \
                ClassUtils.getBaseClasses(desiredBase, packageName)
URL: https://github.com/apache/commons-lang/pull/358#discussion_r244380396
 
 

 ##########
 File path: src/main/java/org/apache/commons/lang3/ClassUtils.java
 ##########
 @@ -1059,6 +1067,85 @@ public static boolean isInnerClass(final Class<?> cls) {
         return getClass(loader, className, initialize);
     }
 
+    /**
+     * Returns a list of base classes/interfaces underneath the supplied package.
+     * This method only retrieves base classes/interfaces that have child classes \
that can be instantiated +     * via a no-args constructor.
+     * This only retrieves base classes/interfaces directly underneath the supplied \
package. +     *
+     * @param desiredBase the desired base class/interface to retrieve
+     * @param packageName the package name in the standard import format (i.e. \
"java.lang.String") +     * @param classLoader the class loader to use for retrieving \
classes +     * @param <T> The desired base class or interface type to retrieve
+     * @return a list of base classes/interfaces that match the supplied type \
underneath the supplied package +     * @throws IllegalArgumentException if the \
packageName is invalid +     * @throws IOException if an I/O error occurs in getting \
a new directory stream +     * @throws NullPointerException if desiredBase, \
classLoader or url are null +     * @throws URISyntaxException if the generated url \
can't be converted to a URI +     */
+    public static <T> List<T> getBaseClasses(final Class<T> desiredBase, final \
String packageName, ClassLoader classLoader) +            throws \
IllegalArgumentException, IOException, NullPointerException, URISyntaxException  { +
+        Objects.requireNonNull(desiredBase, "desiredBase must not be null");
+
+        if (StringUtils.isBlank(packageName)) {
+            throw new IllegalArgumentException("packageName must not be blank");
+        }
+
+        Objects.requireNonNull(classLoader, "classLoader must not be null");
+
+        URL url = classLoader.getResource(packageName.replaceAll("[.]", "/"));
+        Objects.requireNonNull(url, "supplied package not found");
+
+        Path classesPath = Paths.get(url.toURI());
 
 Review comment:
   @ecki I'm not sure if it will work with jmod or jar files.  I designed the method \
to just work with class directories.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic