Class PythonElementFactory
java.lang.Object
io.micronaut.python.processing.visitor.PythonElementFactory
- All Implemented Interfaces:
ElementFactory<ElementDef, ClassDef, FunctionDef, AttributeDef>
public final class PythonElementFactory
extends Object
implements ElementFactory<ElementDef, ClassDef, FunctionDef, AttributeDef>
Python implementation of
ElementFactory for creating Python AST-based elements.
This factory creates Micronaut elements from Python AST definition objects:
- ClassDef for classes
- FunctionDef for methods and constructors
- AttributeDef for fields and enum constants
- Since:
- 5.2.0
- Author:
- Micronaut Team
-
Constructor Summary
ConstructorsConstructorDescriptionPythonElementFactory(PythonProcessingEnvironment environment) Creates a new PythonElementFactory with the given processing environment. -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull PythonScriptElementcreateScriptElement(@NonNull ScriptDef scriptDef, @NonNull PythonProcessingEnvironment processingEnvironment) Creates a new PythonScriptElement from a ScriptDef using the processing environment.newClassElement(@NonNull ClassDef classDef, @NonNull ElementAnnotationMetadataFactory annotationMetadataFactory) Builds a new class element for the given type.newConstructorElement(@NonNull ClassElement owningClass, @NonNull FunctionDef constructor, @NonNull ElementAnnotationMetadataFactory annotationMetadataFactory) Builds a new constructor element for the given type.newEnumConstantElement(@NonNull ClassElement owningClass, @NonNull AttributeDef enumConstant, @NonNull ElementAnnotationMetadataFactory annotationMetadataFactory) Builds a new enum constant element for the given type.newFieldElement(@NonNull ClassElement owningClass, @NonNull AttributeDef field, @NonNull ElementAnnotationMetadataFactory annotationMetadataFactory) Builds a new field element for the given type.newMethodElement(@NonNull ClassElement owningClass, @NonNull FunctionDef method, @NonNull ElementAnnotationMetadataFactory annotationMetadataFactory) Builds a new method element for the given type.newScriptElement(@NonNull ScriptDef scriptDef, @NonNull ElementAnnotationMetadataFactory annotationMetadataFactory) Creates a new PythonScriptElement from a ScriptDef.newSourceClassElement(@NonNull ClassDef classDef, @NonNull ElementAnnotationMetadataFactory annotationMetadataFactory) Builds a new source class element for the given type.newSourceMethodElement(@NonNull ClassElement owningClass, @NonNull FunctionDef method, @NonNull ElementAnnotationMetadataFactory annotationMetadataFactory) Builds a new source method element for the given method.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ElementFactory
newClassElement
-
Constructor Details
-
PythonElementFactory
Creates a new PythonElementFactory with the given processing environment.- Parameters:
environment- The Python processing environment
-
-
Method Details
-
newClassElement
@NonNull public @NonNull ClassElement newClassElement(@NonNull @NonNull ClassDef classDef, @NonNull @NonNull ElementAnnotationMetadataFactory annotationMetadataFactory) Description copied from interface:ElementFactoryBuilds a new class element for the given type.- Specified by:
newClassElementin interfaceElementFactory<ElementDef, ClassDef, FunctionDef, AttributeDef>- Parameters:
classDef- The typeannotationMetadataFactory- The element annotation metadata factory- Returns:
- The class element
-
newScriptElement
@NonNull public @NonNull PythonScriptElement newScriptElement(@NonNull @NonNull ScriptDef scriptDef, @NonNull @NonNull ElementAnnotationMetadataFactory annotationMetadataFactory) Creates a new PythonScriptElement from a ScriptDef.- Parameters:
scriptDef- The script definitionannotationMetadataFactory- The annotation metadata factory- Returns:
- The Python script element
-
createScriptElement
@NonNull public static @NonNull PythonScriptElement createScriptElement(@NonNull @NonNull ScriptDef scriptDef, @NonNull @NonNull PythonProcessingEnvironment processingEnvironment) Creates a new PythonScriptElement from a ScriptDef using the processing environment.- Parameters:
scriptDef- The script definitionprocessingEnvironment- The processing environment- Returns:
- The Python script element
-
newSourceClassElement
@NonNull public @NonNull ClassElement newSourceClassElement(@NonNull @NonNull ClassDef classDef, @NonNull @NonNull ElementAnnotationMetadataFactory annotationMetadataFactory) Description copied from interface:ElementFactoryBuilds a new source class element for the given type. This method differs fromElementFactory.newClassElement(Object, ElementAnnotationMetadataFactory)in that it should only be called from elements that are known to originate from source code.- Specified by:
newSourceClassElementin interfaceElementFactory<ElementDef, ClassDef, FunctionDef, AttributeDef>- Parameters:
classDef- The typeannotationMetadataFactory- The element annotation metadata factory- Returns:
- The class element
-
newSourceMethodElement
@NonNull public @NonNull MethodElement newSourceMethodElement(@NonNull @NonNull ClassElement owningClass, @NonNull @NonNull FunctionDef method, @NonNull @NonNull ElementAnnotationMetadataFactory annotationMetadataFactory) Description copied from interface:ElementFactoryBuilds a new source method element for the given method. This method differs fromElementFactory.newMethodElement(ClassElement, Object, ElementAnnotationMetadataFactory)in that it should only be called from elements that are known to originate from source code.- Specified by:
newSourceMethodElementin interfaceElementFactory<ElementDef, ClassDef, FunctionDef, AttributeDef>- Parameters:
owningClass- The owning classmethod- The methodannotationMetadataFactory- The element annotation metadata factory- Returns:
- The class element
-
newMethodElement
@NonNull public @NonNull MethodElement newMethodElement(@NonNull @NonNull ClassElement owningClass, @NonNull @NonNull FunctionDef method, @NonNull @NonNull ElementAnnotationMetadataFactory annotationMetadataFactory) Description copied from interface:ElementFactoryBuilds a new method element for the given type.- Specified by:
newMethodElementin interfaceElementFactory<ElementDef, ClassDef, FunctionDef, AttributeDef>- Parameters:
owningClass- The owning classmethod- The methodannotationMetadataFactory- The element annotation metadata factory- Returns:
- The method element
-
newConstructorElement
@NonNull public @NonNull ConstructorElement newConstructorElement(@NonNull @NonNull ClassElement owningClass, @NonNull @NonNull FunctionDef constructor, @NonNull @NonNull ElementAnnotationMetadataFactory annotationMetadataFactory) Description copied from interface:ElementFactoryBuilds a new constructor element for the given type.- Specified by:
newConstructorElementin interfaceElementFactory<ElementDef, ClassDef, FunctionDef, AttributeDef>- Parameters:
owningClass- The owning classconstructor- The constructorannotationMetadataFactory- The element annotation metadata factory- Returns:
- The constructor element
-
newEnumConstantElement
@NonNull public @NonNull EnumConstantElement newEnumConstantElement(@NonNull @NonNull ClassElement owningClass, @NonNull @NonNull AttributeDef enumConstant, @NonNull @NonNull ElementAnnotationMetadataFactory annotationMetadataFactory) Description copied from interface:ElementFactoryBuilds a new enum constant element for the given type.- Specified by:
newEnumConstantElementin interfaceElementFactory<ElementDef, ClassDef, FunctionDef, AttributeDef>- Parameters:
owningClass- The owning classenumConstant- The enum constantannotationMetadataFactory- The element annotation metadata factory- Returns:
- The enum constant element
-
newFieldElement
@NonNull public @NonNull FieldElement newFieldElement(@NonNull @NonNull ClassElement owningClass, @NonNull @NonNull AttributeDef field, @NonNull @NonNull ElementAnnotationMetadataFactory annotationMetadataFactory) Description copied from interface:ElementFactoryBuilds a new field element for the given type.- Specified by:
newFieldElementin interfaceElementFactory<ElementDef, ClassDef, FunctionDef, AttributeDef>- Parameters:
owningClass- The owning classfield- The fieldannotationMetadataFactory- The element annotation metadata factory- Returns:
- The field element
-