Interface ClassDeclarationModifier
- All Known Implementing Classes:
JavaModifier,KotlinModifier
It exists for one caller, and for one reason. What a theme is — an
@StyleSheet naming the theme's constant, another naming
styles.css, and AppShellConfigurator — is a decision about
Vaadin, not about Java. Written once per language it would become two
decisions, and the second copy would be the one nobody updates when a theme
grows a third annotation. That is the argument
StylePolicy made for styles, applied to
the one other place Copilot writes a class header.
Deliberately not a general Kotlin-source-editing API. It has exactly the three operations applying a theme needs; anything else belongs to whichever feature needs it, with its own tests.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceWork that edits a class header.static interfaceWhat a caller may do to a class header. -
Method Summary
Modifier and TypeMethodDescriptionstatic ClassDeclarationModifierThe modifier for the language a source file is written in.modify(Class<?> cls, ClassDeclarationModifier.OperationFunction<ClassDeclarationModifier.Operations> operations) Applies the operations to the source file declaring the given class.
-
Method Details
-
forFile
The modifier for the language a source file is written in.The interface naming its own implementations is a small inversion, taken deliberately: there are two callers — applying a theme and adding the Lumo utility stylesheet — and a duplicated
if/elseoverSourceLanguageis the thing most likely to answer differently in one place than the other, which is exactly what this interface exists to prevent.- Parameters:
sourceFile- the file declaring the class- Returns:
- the modifier for that language
- Throws:
UnsupportedSourceLanguageException- for a language with no modifier, which is what a Hilla-only project with a TypeScript entry point gets
-
modify
Map<File,String> modify(Class<?> cls, ClassDeclarationModifier.OperationFunction<ClassDeclarationModifier.Operations> operations) throws IOException Applies the operations to the source file declaring the given class.- 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
-