Package io.micronaut.inject.processing
Class JavaModelUtils
- java.lang.Object
-
- io.micronaut.inject.processing.JavaModelUtils
-
public class JavaModelUtils extends java.lang.ObjectUtility methods for Java model handling.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.Map<java.lang.String,java.lang.String>NAME_TO_TYPE_MAP
-
Constructor Summary
Constructors Constructor Description JavaModelUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringgetClassArrayName(javax.lang.model.element.TypeElement typeElement)Get the array class name for the given type element.static java.lang.StringgetClassname(TypedElement type)Return the type reference for a class.static java.lang.StringgetClassName(javax.lang.model.element.TypeElement typeElement)Get the class name for the given type element.static java.lang.StringgetClassNameWithoutPackage(javax.lang.model.element.TypeElement typeElement)Get the class name for the given type element without the package.static java.lang.StringgetPackageName(javax.lang.model.element.TypeElement typeElement)static org.objectweb.asm.TypegetTypeReference(TypedElement type)Return the type reference for a class.static booleanisClass(javax.lang.model.element.Element element)Whether the given element is a class.static booleanisClassOrInterface(javax.lang.model.element.Element element)Whether the given element is a class or interface.static booleanisEnum(javax.lang.model.element.Element element)Whether the given element is an enum.static booleanisInterface(javax.lang.model.element.Element element)Whether the given element is an interface.static booleanisRecord(javax.lang.model.element.Element element)Whether the given element is an interface.static booleanisRecordComponent(javax.lang.model.element.Element e)Return whether this is a component of a record.static booleanisRecordOrRecordComponent(javax.lang.model.element.Element e)Return whether this is a record or a component of a record.static java.util.Optional<javax.lang.model.element.ElementKind>resolveKind(javax.lang.model.element.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 java.util.Optional<javax.lang.model.element.ElementKind>resolveKind(javax.lang.model.element.Element element, javax.lang.model.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.
-
-
-
Method Detail
-
resolveKind
public static java.util.Optional<javax.lang.model.element.ElementKind> resolveKind(javax.lang.model.element.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. 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
public static java.util.Optional<javax.lang.model.element.ElementKind> resolveKind(javax.lang.model.element.Element element, javax.lang.model.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. 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
public static boolean isInterface(javax.lang.model.element.Element element)
Whether the given element is an interface.- Parameters:
element- The element- Returns:
- True if it is
-
isRecord
public static boolean isRecord(javax.lang.model.element.Element element)
Whether the given element is an interface.- Parameters:
element- The element- Returns:
- True if it is
-
isClass
public static boolean isClass(javax.lang.model.element.Element element)
Whether the given element is a class.- Parameters:
element- The element- Returns:
- True if it is
-
isEnum
public static boolean isEnum(javax.lang.model.element.Element element)
Whether the given element is an enum.- Parameters:
element- The element- Returns:
- True if it is
-
isClassOrInterface
public static boolean isClassOrInterface(javax.lang.model.element.Element element)
Whether the given element is a class or interface.- Parameters:
element- The element- Returns:
- True if it is
-
getClassName
public static java.lang.String getClassName(javax.lang.model.element.TypeElement typeElement)
Get the class name for the given type element. HandlesNestingKind.- Parameters:
typeElement- The type element- Returns:
- The class name
-
getClassNameWithoutPackage
public static java.lang.String getClassNameWithoutPackage(javax.lang.model.element.TypeElement typeElement)
Get the class name for the given type element without the package. HandlesNestingKind.- Parameters:
typeElement- The type element- Returns:
- The class name
-
getPackageName
public static java.lang.String getPackageName(javax.lang.model.element.TypeElement typeElement)
-
getClassArrayName
public static java.lang.String getClassArrayName(javax.lang.model.element.TypeElement typeElement)
Get the array class name for the given type element. HandlesNestingKind.- Parameters:
typeElement- The type element- Returns:
- The class name
-
isRecordOrRecordComponent
public static boolean isRecordOrRecordComponent(javax.lang.model.element.Element e)
Return whether this is a record or a component of a record.- Parameters:
e- The element- Returns:
- True if it is
-
isRecordComponent
public static boolean isRecordComponent(javax.lang.model.element.Element e)
Return whether this is a component of a record.- Parameters:
e- The element- Returns:
- True if it is
-
getTypeReference
public static org.objectweb.asm.Type getTypeReference(TypedElement type)
Return the type reference for a class.- Parameters:
type- The type- Returns:
- The
Type
-
getClassname
public static java.lang.String getClassname(TypedElement type)
Return the type reference for a class.- Parameters:
type- The type- Returns:
- The
Type
-
-