Interface CopilotRewriter<C extends ComponentRef>
- Type Parameters:
C- the component handle this rewriter resolves components to
- All Known Implementing Classes:
JavaRewriter,KotlinRewriter
Implemented by the Java rewriter and, once it exists, the Kotlin one. Only operations whose contract is genuinely language-independent appear here. Anything that trades in parse-tree nodes — attaching a component to a given insertion point, importing a Lit template, the result of a duplicate — stays on the concrete rewriter, because expressing it here would mean inventing a neutral node model that the Kotlin side does not want: it works in text offsets, not nodes.
The component handle is a type parameter rather than ComponentRef
itself, so an implementation can keep taking its own richer handle without
casting on every call. Java has no covariant parameter types, so the
alternative would have been to change every signature in the Java rewriter
and cast internally.
-
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a call on the component, even if the same call is already present.voidaddComment(C component, String comment, CommentType commentType) Adds a comment next to the component.addComponentUsingTemplate(C referenceComponent, Where where, List<CopilotComponent> template, AddTemplateOptions options) Adds components described by a template, as sent when dropping from the palette, pasting, or importing a design.addConstructorParameterToClass(C referenceComponent, String parameterTypeName, String suggestedParameterName, boolean storeAsField) Adds a constructor parameter to the class the component is declared in, for injecting a service.booleanDeletes the component, along with the code that only existed to support it.voidDuplicates a component together with the given children.extractComponent(C component, IdentityHashMap<C, List<C>> componentChildren, String extractedComponentClassNameSuggestion) Extracts a component and its children into a class of their own.getPropertyValue(C component, String property) Reads a property's value from the source.voidmergeAndReplace(List<C> components, CopilotComponent wrapperComponent) Wraps the given components in a new container.voidmoveComponent(C component, C container, C reference, Where where, MoveTemplateOptions options) Moves a component into a container, relative to a reference component.voidremoveCalls(C component, String function) Removes every call to the given method on the component.voidremovePropertySetter(C component, String setter) Removes a property setter call from the component.replaceFunctionCall(C component, String function, Object value) Replaces a constructor argument, when the value maps to one, or the corresponding setter call otherwise.voidreplaceOrAddCall(C component, String function, Object... parameters) Adds a call on the component, replacing an existing call to the same method.voidsetAlignment(C component, AlignmentValues alignmentValues) Sets the component's flexbox alignment properties.voidSets the gap between a layout's children.voidSets a component's padding.voidSets width and height related properties.voidSets an inline style, or the equivalent utility class when the app uses Lumo.
-
Method Details
-
replaceFunctionCall
Replaces a constructor argument, when the value maps to one, or the corresponding setter call otherwise.- Parameters:
component- the component to modifyfunction- the setter namevalue- the new value, ornullto remove the call- Returns:
- the new variable name if the change renamed the variable
-
addCall
Adds a call on the component, even if the same call is already present.- Parameters:
component- the component to modifyfunction- the method to callparameters- the arguments
-
replaceOrAddCall
Adds a call on the component, replacing an existing call to the same method.- Parameters:
component- the component to modifyfunction- the method to callparameters- the arguments
-
removePropertySetter
Removes a property setter call from the component.- Parameters:
component- the component to modifysetter- the setter name
-
removeCalls
Removes every call to the given method on the component.- Parameters:
component- the component to modifyfunction- the method name
-
getPropertyValue
Reads a property's value from the source.- Parameters:
component- the component to readproperty- the property name- Returns:
- a constant value where the source holds one, otherwise a
SourceExpressionfor something that has to be evaluated, ornullif the property is not set
-
setStyle
Sets an inline style, or the equivalent utility class when the app uses Lumo.- Parameters:
component- the component to modifyproperty- the CSS propertyvalue- the CSS value
-
setSizing
Sets width and height related properties.- Parameters:
component- the component to modifychanges- the properties to set, by name
-
setAlignment
Sets the component's flexbox alignment properties.- Parameters:
component- the component to modifyalignmentValues- the alignment to apply
-
setGap
Sets the gap between a layout's children.- Parameters:
component- the layout to modifyall- the gap on both axes, ornullto set them separatelycolumn- the column gaprow- the row gap
-
setPadding
Sets a component's padding.- Parameters:
component- the component to modifyall- the padding on all sides, ornullto set them separatelytop- the top paddingright- the right paddingbottom- the bottom paddingleft- the left padding
-
delete
Deletes the component, along with the code that only existed to support it.- Parameters:
component- the component to delete- Returns:
- true if the component was deleted
-
moveComponent
Moves a component into a container, relative to a reference component.- Parameters:
component- the component to movecontainer- the container to move it intoreference- the sibling to position against, ornullto appendwhere- the position relative to the referenceoptions- the attach method and add-or-replace behaviour
-
duplicate
Duplicates a component together with the given children.- Parameters:
component- the component to duplicatechildren- the children to duplicate with it
-
addComponentUsingTemplate
List<C> addComponentUsingTemplate(C referenceComponent, Where where, List<CopilotComponent> template, AddTemplateOptions options) Adds components described by a template, as sent when dropping from the palette, pasting, or importing a design.- Parameters:
referenceComponent- the component to position againstwhere- the position relative to the referencetemplate- the components to createoptions- how to declare and attach them- Returns:
- the components that were created
-
mergeAndReplace
Wraps the given components in a new container.- Parameters:
components- the components to wrapwrapperComponent- the container to wrap them in
-
extractComponent
String extractComponent(C component, IdentityHashMap<C, List<C>> componentChildren, String extractedComponentClassNameSuggestion) Extracts a component and its children into a class of their own.- Parameters:
component- the component to extractcomponentChildren- the children of each component, keyed by identity because these handles can be records whose equality changes as the source is rewrittenextractedComponentClassNameSuggestion- the suggested class name- Returns:
- the name of the class that was created
-
addConstructorParameterToClass
String addConstructorParameterToClass(C referenceComponent, String parameterTypeName, String suggestedParameterName, boolean storeAsField) Adds a constructor parameter to the class the component is declared in, for injecting a service.- Parameters:
referenceComponent- a component in the target classparameterTypeName- the parameter's typesuggestedParameterName- the suggested parameter namestoreAsField- whether to also store the parameter in a field- Returns:
- the parameter name that was used
-
addComment
Adds a comment next to the component.- Parameters:
component- the component to comment oncomment- the comment textcommentType- whether to write a line or block comment
-