Interface ClassUtils
-
- All Superinterfaces:
io.microsphere.util.Utils
public interface ClassUtils extends io.microsphere.util.Utils
The utilities class forClass
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
Class
-
-
Method Summary
Static Methods Modifier and Type Method Description static java.lang.String
getClassName(javax.lang.model.type.TypeMirror type)
Gets the fully qualified class name from the givenTypeMirror
.static java.lang.Class
loadClass(java.lang.String className)
Loads the class represented by the given fully qualified class name.static java.lang.Class
loadClass(javax.lang.model.type.TypeMirror type)
Loads the class represented by the givenTypeMirror
.
-
-
-
Method Detail
-
getClassName
static java.lang.String getClassName(javax.lang.model.type.TypeMirror type)
Gets the fully qualified class name from the givenTypeMirror
.This method is useful when working with annotation processors or other compile-time code analysis tools that deal with type information represented as a
TypeMirror
.Example Usage
TypeMirror type = processingEnv.getElementUtils().getTypeElement("com.example.MyClass").asType(); String className = getClassName(type); // returns "com.example.MyClass"
- Parameters:
type
- the type mirror to extract the class name from- Returns:
- the fully qualified class name as a String
-
loadClass
static java.lang.Class loadClass(javax.lang.model.type.TypeMirror type)
Loads the class represented by the givenTypeMirror
.This method derives the fully qualified class name from the type mirror and delegates to the other
loadClass(String)
method for class loading. It is particularly useful in annotation processors or compile-time tools where types are primarily accessed via their mirror representations.Example Usage
TypeMirror type = processingEnv.getElementUtils().getTypeElement("com.example.MyClass").asType(); Class> clazz = ClassUtils.loadClass(type); // loads com.example.MyClass
- Parameters:
type
- the type mirror representing the class to load- Returns:
- the resolved
Class
, ornull
if the class cannot be found
-
loadClass
static java.lang.Class loadClass(java.lang.String className)
Loads the class represented by the given fully qualified class name.This method attempts to resolve the class using the provided class name and the class loader obtained from
ClassUtils
. If the class is not found, an attempt is made to resolve it as a nested or inner class by replacing the last dot (.
) with a dollar sign ($
).Example Usage
Class> clazz = ClassUtils.loadClass("com.example.MyClass"); // If MyClass is an inner class, this may also attempt to load "com.example.My$Class"
- Parameters:
className
- the fully qualified name of the class to load- Returns:
- the resolved
Class
, ornull
if the class cannot be found
-
-