Package org.opentrafficsim.road
Class ClassList
- java.lang.Object
-
- org.opentrafficsim.road.ClassList
-
public final class ClassList extends Object
Build a list of the classes in the project (or under a specific directory/package in the project).
Adapted from http://stackoverflow.com/questions/3923129/get-a-list-of-resources-from-classpath-directory which apparently copied the code from http://forums.devx.com/showthread.php?153784-how-to-list-resources-in-a-package. Original poster stoughto has not visited that forum after 2006.Copyright (c) 2006 by stoughto! TODO replace this by something that is provably free code.
- Version:
- $Revision$, $LastChangedDate$, by $Author$, initial version Apr 8, 2016
- Author:
- Alexander Verbraeck, Peter Knoppers
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Collection<Class<?>>
classList(String packageRoot, boolean excludeInterfaces)
Return a List of all the classes under a package.static Collection<String>
getResources(Pattern pattern)
For all elements of java.class.path get a Collection of resources Pattern pattern = Pattern.compile(".*"); gets all resources.static boolean
hasNonStaticFields(Class<?> c)
Report if a class has non-static fields.static boolean
isAnonymousInnerClass(Class<?> c)
Determine if a class is an anonymous inner class.static void
main(String[] args)
List the resources that match args[0], or a fixed pattern to demonstrate the use of this class.
-
-
-
Method Detail
-
getResources
public static Collection<String> getResources(Pattern pattern)
For all elements of java.class.path get a Collection of resources Pattern pattern = Pattern.compile(".*"); gets all resources.- Parameters:
pattern
- the pattern to match- Returns:
- the resources in the order they are found
-
classList
public static Collection<Class<?>> classList(String packageRoot, boolean excludeInterfaces)
Return a List of all the classes under a package. Test-classes are excluded from the result.- Parameters:
packageRoot
- String package nameexcludeInterfaces
- boolean; if true; interfaces are excluded from the result- Returns:
- Collection<Class<?>>; the classes under the package
-
isAnonymousInnerClass
public static boolean isAnonymousInnerClass(Class<?> c)
Determine if a class is an anonymous inner class.- Parameters:
c
- Class; the class to check- Returns:
- boolean; true if c is an anonymous inner class; false otherwise
-
hasNonStaticFields
public static boolean hasNonStaticFields(Class<?> c)
Report if a class has non-static fields.- Parameters:
c
- Class<?>; the class- Returns:
- boolean; true if the class has non-static fields
-
main
public static void main(String[] args)
List the resources that match args[0], or a fixed pattern to demonstrate the use of this class.- Parameters:
args
- args[0] is the pattern to match, or list all resources matching a built-in pattern if there are no args
-
-