java.lang.Object
net.luis.utils.util.unsafe.classpath.ClassPathUtils
Utility class for classpath related operations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
The mode which determines if the classes should be included or excluded. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.apache.logging.log4j.Logger
The logger for this class. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Private constructor to prevent instantiation.
This is a static helper class. -
Method Summary
Modifier and TypeMethodDescriptionGets all classes from the classpath.
If an error occurs, the error will be logged and an empty list will be returned.getAnnotatedClasses
(@NotNull Class<? extends Annotation> annotation) Gets all classes from the classpath which are annotated with the given annotation.getAnnotatedClasses
(@Nullable String packageName, @NotNull Class<? extends Annotation> annotation) Gets all classes from the given package which are annotated with the given annotation.getAnnotatedFields
(@NotNull Class<? extends Annotation> annotation) Gets all fields from the classpath which are annotated with the given annotation.getAnnotatedFields
(@Nullable String packageName, @NotNull Class<? extends Annotation> annotation) Gets all fields from the classes in the given package which are annotated with the given annotation.getAnnotatedMethods
(@NotNull Class<? extends Annotation> annotation) Gets all methods from the classpath which are annotated with the given annotation.getAnnotatedMethods
(@Nullable String packageName, @NotNull Class<? extends Annotation> annotation) Gets all methods from the classes in the given package which are annotated with the given annotation.getClasses
(@Nullable String packageName) Gets all classes from the given package.
If the given package name is null, all classes will be returned.getClasses
(@Nullable String packageName, @Nullable ClassPathUtils.Mode mode) Gets all classes from the given package.
The mode determines if the classes should be included or excluded
if the package name of the class starts with the given package name.Gets all classes from the classpath which are related to the project.
Related classes are classes that are in the same package as the caller of this method.
By default, the depth of the package which is used to filter the classes is 3.
-
Field Details
-
LOGGER
private static final org.apache.logging.log4j.Logger LOGGERThe logger for this class.
-
-
Constructor Details
-
ClassPathUtils
private ClassPathUtils()Private constructor to prevent instantiation.
This is a static helper class.
-
-
Method Details
-
getAllClasses
Gets all classes from the classpath.
If an error occurs, the error will be logged and an empty list will be returned.- Returns:
- A list of all classes from the classpath
-
getProjectClasses
Gets all classes from the classpath which are related to the project.
Related classes are classes that are in the same package as the caller of this method.
By default, the depth of the package which is used to filter the classes is 3.
For example, if the caller of this method is in the package "net.luis.utils.util",
all classes in the packages "net.luis.utils" will be returned,
because the depth is 3 which means that the package will be cut after the third dot.
The depth can be changed by using the system property 'unsafe.package.depth'.
If an error occurs, the error will be logged and an empty list will be returned.
- Returns:
- A list of all classes from the classpath which are related to the project
- See Also:
-
getClasses
Gets all classes from the given package.
If the given package name is null, all classes will be returned.- Parameters:
packageName
- The package name in which the classes should be- Returns:
- A list of all classes
-
getClasses
@NotNull public static @NotNull List<Class<?>> getClasses(@Nullable @Nullable String packageName, @Nullable @Nullable ClassPathUtils.Mode mode) Gets all classes from the given package.
The mode determines if the classes should be included or excluded
if the package name of the class starts with the given package name.
If the given package name is null, all classes will be returned.
If the mode is null, the classes will be included.
- Parameters:
packageName
- The package name to filter the classesmode
- Whether the classes should be included or excluded- Returns:
- A list of all classes
-
getAnnotatedClasses
@NotNull public static @NotNull List<Class<?>> getAnnotatedClasses(@NotNull @NotNull Class<? extends Annotation> annotation) Gets all classes from the classpath which are annotated with the given annotation.- Parameters:
annotation
- The annotation which should be present on the classes- Returns:
- A list of all classes
- Throws:
NullPointerException
- If the given annotation is null
-
getAnnotatedClasses
@NotNull public static @NotNull List<Class<?>> getAnnotatedClasses(@Nullable @Nullable String packageName, @NotNull @NotNull Class<? extends Annotation> annotation) Gets all classes from the given package which are annotated with the given annotation.- Parameters:
packageName
- The package name in which the classes should beannotation
- The annotation which should be present on the classes- Returns:
- A list of all classes
- Throws:
NullPointerException
- If the given annotation is null
-
getAnnotatedMethods
@NotNull public static @NotNull List<Method> getAnnotatedMethods(@NotNull @NotNull Class<? extends Annotation> annotation) Gets all methods from the classpath which are annotated with the given annotation.- Parameters:
annotation
- The annotation which should be present on the methods- Returns:
- A list of all methods
- Throws:
NullPointerException
- If the given annotation is null
-
getAnnotatedMethods
@NotNull public static @NotNull List<Method> getAnnotatedMethods(@Nullable @Nullable String packageName, @NotNull @NotNull Class<? extends Annotation> annotation) Gets all methods from the classes in the given package which are annotated with the given annotation.- Parameters:
packageName
- The package name in which the classes should beannotation
- The annotation which should be present on the methods- Returns:
- A list of all methods
- Throws:
NullPointerException
- If the given annotation is null
-
getAnnotatedFields
@NotNull public static @NotNull List<Field> getAnnotatedFields(@NotNull @NotNull Class<? extends Annotation> annotation) Gets all fields from the classpath which are annotated with the given annotation.- Parameters:
annotation
- The annotation which should be present on the fields- Returns:
- A list of all fields
- Throws:
NullPointerException
- If the given annotation is null
-
getAnnotatedFields
@NotNull public static @NotNull List<Field> getAnnotatedFields(@Nullable @Nullable String packageName, @NotNull @NotNull Class<? extends Annotation> annotation) Gets all fields from the classes in the given package which are annotated with the given annotation.- Parameters:
packageName
- The package name in which the classes should beannotation
- The annotation which should be present on the fields- Returns:
- A list of all fields
- Throws:
NullPointerException
- If the given annotation is null
-