Package com.vaadin.copilot.javarewriter
Class JavaModifier.CompilationUnitOperations
java.lang.Object
com.vaadin.copilot.javarewriter.JavaModifier.CompilationUnitOperations
- Enclosing class:
- JavaModifier
A class for performing operations on a CompilationUnit.
-
Constructor Summary
ConstructorsConstructorDescriptionCompilationUnitOperations
(com.github.javaparser.ast.CompilationUnit cu, Class<?> cls) Creates a new operations object for the given CompilationUnit and class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addClassAnnotation
(Class<? extends Annotation> annotation, String value) Adds a specified annotation with a value to the public type in the class represented by the provided Class object.void
addInterface
(Class<?> interfaceClass) Adds an interface to the public type in the class.boolean
hasClassAnnotation
(Class<? extends Annotation> annotationClass) Checks if the class has the given annotation.
-
Constructor Details
-
CompilationUnitOperations
Creates a new operations object for the given CompilationUnit and class.- Parameters:
cu
- The CompilationUnit to operate on.cls
- The class that the CompilationUnit represents.
-
-
Method Details
-
addClassAnnotation
public void addClassAnnotation(Class<? extends Annotation> annotation, String value) throws IOException Adds a specified annotation with a value to the public type in the class represented by the provided Class object. This is primarily used to dynamically modify the source code of a class by adding annotations that may influence its behavior at runtime or during further processing.- Parameters:
annotation
- The annotation class to add to the class.value
- The value to assign to the annotation.- Throws:
IOException
- If an error occurs during file operations or if the class does not contain an application type where the annotation can be added.
-
hasClassAnnotation
Checks if the class has the given annotation.- Parameters:
annotationClass
- The annotation class to check for.- Returns:
- true if the class has the annotation, false otherwise.
-
addInterface
Adds an interface to the public type in the class.- Parameters:
interfaceClass
- The interface class to add to the class.
-