Package io.micronaut.inject.processing
Class JavaModelUtils
java.lang.Object
io.micronaut.inject.processing.JavaModelUtils
Utility methods for Java model handling.
- Since:
- 1.0
- Author:
- graemerocher
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
getClassArrayName
(TypeElement typeElement) Get the array class name for the given type element.static String
getClassname
(TypedElement type) Return the type reference for a class.static String
getClassName
(TypeElement typeElement) Get the class name for the given type element.static String
getClassNameWithoutPackage
(TypeElement typeElement) Get the class name for the given type element without the package.static String
getPackageName
(TypeElement typeElement) static org.objectweb.asm.Type
getTypeReference
(TypedElement type) Return the type reference for a class.static boolean
Checks if passed type is either boolean primitive or wrapper.static boolean
Whether the given element is a class.static boolean
isClassOrInterface
(Element element) Whether the given element is a class or interface.static boolean
Whether the given element is an enum.static boolean
isInterface
(Element element) Whether the given element is an interface.static @io.micronaut.core.annotation.NonNull boolean
Checks if passed type is one of numeric primitives or numeric wrappers.static boolean
isPrimitive
(@NonNull org.objectweb.asm.Type type) Checks if passed type is a primitive.static boolean
Whether the given element is an interface.static boolean
Return whether this is a component of a record.static boolean
Return whether this is a record or a component of a record.static Optional<ElementKind>
resolveKind
(Element element) The Java APT throws an internal exception {code com.sun.tools.javac.code.Symbol$CompletionFailure} if a class is missing from the classpath andElement.getKind()
is called.static Optional<ElementKind>
resolveKind
(Element element, ElementKind expected) The Java APT throws an internal exception {code com.sun.tools.javac.code.Symbol$CompletionFailure} if a class is missing from the classpath andElement.getKind()
is called.
-
Field Details
-
NAME_TO_TYPE_MAP
-
-
Constructor Details
-
JavaModelUtils
public JavaModelUtils()
-
-
Method Details
-
isPrimitive
Checks if passed type is a primitive.- Parameters:
type
- type to check- Returns:
- true if it is
-
isBoolean
Checks if passed type is either boolean primitive or wrapper.- Parameters:
type
- type to check- Returns:
- true if it is
-
isNumeric
@NonNull public static @io.micronaut.core.annotation.NonNull boolean isNumeric(@NonNull @NonNull org.objectweb.asm.Type type) Checks if passed type is one of numeric primitives or numeric wrappers.- Parameters:
type
- type to check- Returns:
- true if it is
-
resolveKind
The Java APT throws an internal exception {code com.sun.tools.javac.code.Symbol$CompletionFailure} if a class is missing from the classpath andElement.getKind()
is called. This method handles exceptions when calling the getKind() method to avoid this scenario and should be used instead ofElement.getKind()
.- Parameters:
element
- The element- Returns:
- The kind if it is resolvable
-
resolveKind
The Java APT throws an internal exception {code com.sun.tools.javac.code.Symbol$CompletionFailure} if a class is missing from the classpath andElement.getKind()
is called. This method handles exceptions when calling the getKind() method to avoid this scenario and should be used instead ofElement.getKind()
.- Parameters:
element
- The elementexpected
- The expected kind- Returns:
- The kind if it is resolvable and matches the expected kind
-
isInterface
Whether the given element is an interface.- Parameters:
element
- The element- Returns:
- True if it is
-
isRecord
Whether the given element is an interface.- Parameters:
element
- The element- Returns:
- True if it is
-
isClass
Whether the given element is a class.- Parameters:
element
- The element- Returns:
- True if it is
-
isEnum
Whether the given element is an enum.- Parameters:
element
- The element- Returns:
- True if it is
-
isClassOrInterface
Whether the given element is a class or interface.- Parameters:
element
- The element- Returns:
- True if it is
-
getClassName
Get the class name for the given type element. HandlesNestingKind
.- Parameters:
typeElement
- The type element- Returns:
- The class name
-
getClassNameWithoutPackage
Get the class name for the given type element without the package. HandlesNestingKind
.- Parameters:
typeElement
- The type element- Returns:
- The class name
-
getPackageName
-
getClassArrayName
Get the array class name for the given type element. HandlesNestingKind
.- Parameters:
typeElement
- The type element- Returns:
- The class name
-
isRecordOrRecordComponent
Return whether this is a record or a component of a record.- Parameters:
e
- The element- Returns:
- True if it is
-
isRecordComponent
Return whether this is a component of a record.- Parameters:
e
- The element- Returns:
- True if it is
-
getTypeReference
Return the type reference for a class.- Parameters:
type
- The type- Returns:
- The
Type
-
getClassname
Return the type reference for a class.- Parameters:
type
- The type- Returns:
- The
Type
-