Class ModelUtils
- java.lang.Object
-
- io.micronaut.annotation.processing.ModelUtils
-
@Internal public class ModelUtils extends java.lang.Object
Provides utility method for working with the annotation processor AST.- Since:
- 1.0
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ModelUtils(javax.lang.model.util.Elements elementUtils, javax.lang.model.util.Types typeUtils)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.lang.model.element.TypeElement
classElementFor(javax.lang.model.element.Element element)
Obtains theTypeElement
for an given element.javax.lang.model.element.ExecutableElement
concreteConstructorFor(javax.lang.model.element.TypeElement classElement, AnnotationUtils annotationUtils)
The constructor inject for the given class element.javax.lang.model.element.ExecutableElement
defaultConstructorFor(javax.lang.model.element.TypeElement classElement)
javax.lang.model.element.ExecutableElement
defaultStaticCreatorFor(javax.lang.model.element.TypeElement classElement, AnnotationUtils annotationUtils)
java.util.Set<javax.lang.model.element.TypeElement>
getAllInterfaces(javax.lang.model.element.TypeElement aClass)
javax.lang.model.util.Types
getTypeUtils()
boolean
isObjectClass(javax.lang.model.element.TypeElement element)
Return whether the given element is the java.lang.Object class.boolean
isPackagePrivate(javax.lang.model.element.Element element)
Returns whether an element is package private.java.util.Optional<javax.lang.model.element.ExecutableElement>
overridingOrHidingMethod(javax.lang.model.element.ExecutableElement overridden, javax.lang.model.element.TypeElement classElement, boolean strict)
Tests if candidate method is overridden from a given class or subclass.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.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.javax.lang.model.element.ExecutableElement
staticCreatorFor(javax.lang.model.element.TypeElement classElement, AnnotationUtils annotationUtils)
The static method or Kotlin companion method to execute to construct the given class element.
-
-
-
Method Detail
-
getTypeUtils
public javax.lang.model.util.Types getTypeUtils()
- Returns:
- The type utilities
-
classElementFor
@Nullable public final javax.lang.model.element.TypeElement classElementFor(javax.lang.model.element.Element element)
Obtains theTypeElement
for an given element.- Parameters:
element
- The element- Returns:
- The
TypeElement
-
concreteConstructorFor
@Nullable public javax.lang.model.element.ExecutableElement concreteConstructorFor(javax.lang.model.element.TypeElement classElement, AnnotationUtils annotationUtils)
The constructor inject for the given class element.- Parameters:
classElement
- The class elementannotationUtils
- The annotation utilities- Returns:
- The constructor
-
staticCreatorFor
@Nullable public javax.lang.model.element.ExecutableElement staticCreatorFor(javax.lang.model.element.TypeElement classElement, AnnotationUtils annotationUtils)
The static method or Kotlin companion method to execute to construct the given class element.- Parameters:
classElement
- The class elementannotationUtils
- The annotation utilities- Returns:
- The creator method
-
defaultConstructorFor
public javax.lang.model.element.ExecutableElement defaultConstructorFor(javax.lang.model.element.TypeElement classElement)
- Parameters:
classElement
- The class element- Returns:
- True if the element has a non private 0 arg constructor
-
defaultStaticCreatorFor
public javax.lang.model.element.ExecutableElement defaultStaticCreatorFor(javax.lang.model.element.TypeElement classElement, AnnotationUtils annotationUtils)
- Parameters:
classElement
- The class elementannotationUtils
- The annotation utils- Returns:
- A static creator with no args, or null
-
isObjectClass
public boolean isObjectClass(javax.lang.model.element.TypeElement element)
Return whether the given element is the java.lang.Object class.- Parameters:
element
- The element- Returns:
- True if it is java.lang.Object
-
isPackagePrivate
public boolean isPackagePrivate(javax.lang.model.element.Element element)
Returns whether an element is package private.- Parameters:
element
- The element- Returns:
- True if it is package provide
-
getAllInterfaces
public java.util.Set<javax.lang.model.element.TypeElement> getAllInterfaces(javax.lang.model.element.TypeElement aClass)
- Parameters:
aClass
- A class- Returns:
- All the interfaces
-
overridingOrHidingMethod
public java.util.Optional<javax.lang.model.element.ExecutableElement> overridingOrHidingMethod(javax.lang.model.element.ExecutableElement overridden, javax.lang.model.element.TypeElement classElement, boolean strict)
Tests if candidate method is overridden from a given class or subclass.- Parameters:
overridden
- the candidate overridden methodclassElement
- the type element that may contain the overriding method, either directly or in a subclassstrict
- Whether to use strict checks for overriding and not include logic to handle method overloading- Returns:
- the overriding method
-
resolveKind
public 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
-
resolveKind
public 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
-
-