Class KotlinModifier
java.lang.Object
com.vaadin.copilot.kotlinrewriter.KotlinModifier
- All Implemented Interfaces:
ClassDeclarationModifier
Edits the header of a Kotlin class: the annotations above it and the types it
implements.
The Kotlin counterpart of JavaModifier, and like every other writer
here it splices text at offsets rather than mutating the tree — so a file
Copilot applies a theme to comes back byte-identical except on the lines the
theme needed.
The two shapes it has to get right, neither of which Java has:
- An annotation goes below any annotation already there and
directly above the
classkeyword, which is not simply the start of the declaration: a KDoc comment is a child of the declaration in Kotlin PSI, so the declaration's own offset is the start of the documentation. - An interface joins a supertype list, which may be absent
(
class App), already present (class App : VerticalLayout()), and which follows the primary constructor and the type parameters rather than the name.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.copilot.rewriter.ClassDeclarationModifier
ClassDeclarationModifier.OperationFunction<T>, ClassDeclarationModifier.Operations -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionmodify(Class<?> cls, ClassDeclarationModifier.OperationFunction<ClassDeclarationModifier.Operations> operations) Applies the operations to the source file declaring the given class.
-
Constructor Details
-
KotlinModifier
public KotlinModifier()
-
-
Method Details
-
modify
public Map<File,String> modify(Class<?> cls, ClassDeclarationModifier.OperationFunction<ClassDeclarationModifier.Operations> operations) throws IOException Description copied from interface:ClassDeclarationModifierApplies the operations to the source file declaring the given class.- Specified by:
modifyin interfaceClassDeclarationModifier- Parameters:
cls- the class to modifyoperations- what to do to it- Returns:
- the file and the source it should be given, which the caller writes. Returning the content rather than writing it is what lets a caller collect several files and write them under one undo label
- Throws:
IOException- if the source cannot be read
-