public class ClassUtil extends Object
Modifier and Type | Field and Description |
---|---|
static String |
GET_PREFIX |
static Package |
JAVA_LANG_PACKAGE |
static Map<String,String> |
PREDICATE_PREFIXES |
Constructor and Description |
---|
ClassUtil() |
Modifier and Type | Method and Description |
---|---|
static Set<com.google.common.reflect.TypeToken<?>> |
collectClasses(ClassLoader classLoader,
boolean includePrivateClasses,
String... classOrPackageNames)
Collects all the classes from given classes names or classes belonging to given a package name
(recursively), with control on private classes including.
|
static Set<com.google.common.reflect.TypeToken<?>> |
collectClasses(ClassLoader classLoader,
String... classOrPackageNames)
Collects all the public classes from given classes names or classes belonging to given a package name
(recursively).
|
static Set<com.google.common.reflect.TypeToken<?>> |
collectClasses(String... classOrPackageNames)
Call
collectClasses(ClassLoader, String...) with Thread.currentThread().getContextClassLoader()
|
static List<Field> |
declaredFieldsOf(com.google.common.reflect.TypeToken<?> type) |
static Set<Method> |
declaredGetterMethodsOf(com.google.common.reflect.TypeToken<?> type,
Set<Class<?>> includeAnnotations) |
static List<Field> |
getAllFieldsInHierarchy(com.google.common.reflect.TypeToken<?> clazz)
Retrieves all fields (whatever access levels) in the hierarchy of a class up to Object.class excluded.
|
static String |
getAssertType(com.google.common.reflect.TypeToken<?> type,
String packageName)
Gets the name of the class that will be the "assert".
|
static Class<?> |
getClass(Type type)
Get the underlying class for a valueType, or null if the valueType is a variable valueType.
|
static Set<Class<?>> |
getClassesRelatedTo(Type type) |
static String |
getNegativePredicateFor(String name) |
static String |
getPredicatePrefix(String name) |
static String |
getSimpleNameWithOuterClass(Class<?> clazz)
Gets the simple name of the class but, unlike
Class.getSimpleName() , it includes the name of the outer
class when clazz is an inner class. |
static Set<Method> |
getterMethodsOf(com.google.common.reflect.TypeToken<?> type,
Set<Class<?>> includeAnnotations) |
static String |
getTypeDeclaration(com.google.common.reflect.TypeToken<?> type)
Generates a "type declaration" that could be used in Java code based on the
type . |
static String |
getTypeNameWithoutDots(String typeName)
Gets a type name without any dots in it if they are present -- this is for nested classes
|
static boolean |
inheritsCollectionOrIsIterable(Class<?> returnType) |
static boolean |
isBoolean(com.google.common.reflect.TypeToken<?> type)
Checks if a type is a boolean type
|
static boolean |
isInnerPackageOf(Package child,
Package parent)
Checks if the package,
child is under the package parent . |
static boolean |
isJavaLangType(Type type)
Checks if the type passed is a member of
java.lang or is a "built-in" type (e.g. |
static boolean |
isJavaLangType(com.google.common.reflect.TypeToken<?> type)
Checks if the type passed is a member of
java.lang or is a "built-in" type (e.g. |
static boolean |
isPredicate(Method method) |
static boolean |
isStandardGetter(Method method) |
static boolean |
isValidGetterName(String methodName) |
static boolean |
isValidPredicateName(String name) |
static List<Field> |
nonStaticFieldsOf(com.google.common.reflect.TypeToken<?> clazz) |
static String |
packageNameRegex(String packageName) |
static String |
packageOf(String fullyQualifiedType) |
static String |
propertyNameOf(Field field)
Returns the property name of given field, examples :
|
static String |
propertyNameOf(Method method)
Returns the property name of given getter method, examples :
|
static String |
resolveTypeNameInPackage(Type type,
String currentPackage)
Gets the name of a type without the package if
currentPackage is the same as
type's package . |
static String |
resolveTypeNameInPackage(com.google.common.reflect.TypeToken<?> type,
String currentPackage)
Gets the name of a type without the package if
currentPackage is the same as
type's package . |
static String |
safePackageName(com.google.common.reflect.TypeToken<?> typeToken) |
static Visibility |
visibilityOf(Field field) |
public static final String GET_PREFIX
public static final Package JAVA_LANG_PACKAGE
public static Set<com.google.common.reflect.TypeToken<?>> collectClasses(String... classOrPackageNames)
collectClasses(ClassLoader, String...)
with Thread.currentThread().getContextClassLoader()
classOrPackageNames
- classes or packages to collect.TypeToken
s foundpublic static Set<com.google.common.reflect.TypeToken<?>> collectClasses(ClassLoader classLoader, String... classOrPackageNames)
classLoader
- ClassLoader
used to load classes defines in classOrPackageNamesclassOrPackageNames
- classes names or packages names we want to collect classes from (recursively for
packages)Class
es foundRuntimeException
- if any error occurspublic static Set<com.google.common.reflect.TypeToken<?>> collectClasses(ClassLoader classLoader, boolean includePrivateClasses, String... classOrPackageNames)
classLoader
- ClassLoader
used to load classes defines in classOrPackageNamesincludePrivateClasses
- ClassLoader
used to include private classes when trueclassOrPackageNames
- classes names or packages names we want to collect classes from (recursively for
packages)Class
es foundRuntimeException
- if any error occurspublic static String propertyNameOf(Method method)
getName() -> name
isMostValuablePlayer() -> mostValuablePlayer
method
- getter method to deduce property from.public static String propertyNameOf(Field field)
name -> name isMostValuablePlayer -> mostValuablePlayer
field
- field to deduce property from.public static boolean inheritsCollectionOrIsIterable(Class<?> returnType)
public static boolean isStandardGetter(Method method)
public static boolean isPredicate(Method method)
public static boolean isValidGetterName(String methodName)
public static boolean isValidPredicateName(String name)
public static Set<Method> declaredGetterMethodsOf(com.google.common.reflect.TypeToken<?> type, Set<Class<?>> includeAnnotations)
public static Set<Method> getterMethodsOf(com.google.common.reflect.TypeToken<?> type, Set<Class<?>> includeAnnotations)
public static List<Field> nonStaticFieldsOf(com.google.common.reflect.TypeToken<?> clazz)
public static List<Field> declaredFieldsOf(com.google.common.reflect.TypeToken<?> type)
public static List<Field> getAllFieldsInHierarchy(com.google.common.reflect.TypeToken<?> clazz)
clazz
- the class whose fields should be retrievedpublic static String getSimpleNameWithOuterClass(Class<?> clazz)
Class.getSimpleName()
, it includes the name of the outer
class when clazz
is an inner class.clazz
- the classpublic static Class<?> getClass(Type type)
type
- the valueTypepublic static boolean isInnerPackageOf(Package child, Package parent)
child
is under the package parent
.child
- Child packageparent
- Parent packagenull
.public static boolean isJavaLangType(com.google.common.reflect.TypeToken<?> type)
java.lang
or is a "built-in" type (e.g. primitive or array).type
- type tokenpublic static boolean isJavaLangType(Type type)
java.lang
or is a "built-in" type (e.g. primitive or array).type
- typeisJavaLangType(TypeToken)
public static String getTypeDeclaration(com.google.common.reflect.TypeToken<?> type)
type
.type
- Type to get declaration forpublic static String getAssertType(com.google.common.reflect.TypeToken<?> type, String packageName)
type
- Type being testedpackageName
- package this type will reside inpublic static String resolveTypeNameInPackage(com.google.common.reflect.TypeToken<?> type, String currentPackage)
currentPackage
is the same as
type's package
.type
- Type to importcurrentPackage
- package context for the stringpublic static String resolveTypeNameInPackage(Type type, String currentPackage)
currentPackage
is the same as
type's package
.type
- Type to importcurrentPackage
- package context for the stringpublic static String getTypeNameWithoutDots(String typeName)
typeName
- String name of the type'.'
characterspublic static boolean isBoolean(com.google.common.reflect.TypeToken<?> type)
type
- Type to checkpublic static String safePackageName(com.google.common.reflect.TypeToken<?> typeToken)
public static Visibility visibilityOf(Field field)
Copyright © 2021 AssertJ. All rights reserved.