Class KotlinPropertyEditor
One place for what set-component-property and can-be-edited
do when the selected component is Kotlin, so the command handler holds a
single dependency on this package rather than on the resolver, the rewriter
and the component handle separately. That handler is close to Sonar's
coupling limit and this change is what keeps it under: the Kotlin path is a
self-contained subject, so it may as well be a class.
It is also the shape the remaining phases want. As more commands gain Kotlin support they gain a method here, rather than another branch and three more imports in a handler that already serves seventeen commands.
-
Constructor Summary
ConstructorsConstructorDescriptionKotlinPropertyEditor(KotlinFileSourceProvider sources, Function<com.vaadin.flow.component.Component, List<ComponentTypeAndSourceLocation>> siblings) -
Method Summary
Modifier and TypeMethodDescriptionDeclines an operation this class does not cover.static booleanhandles(ComponentTypeAndSourceLocation location) Whether this component's source is Kotlin, and so belongs to this class.readProperty(ComponentTypeAndSourceLocation location, String property) Reads what the source states for a property.setProperty(ComponentTypeAndSourceLocation location, String property, Object value) Sets a property, or clears it when the value isnull.
-
Constructor Details
-
KotlinPropertyEditor
public KotlinPropertyEditor(KotlinFileSourceProvider sources, Function<com.vaadin.flow.component.Component, List<ComponentTypeAndSourceLocation>> siblings) - Parameters:
sources- the parsed Kotlin sources for this operation, so that several edits to one file accumulate into a single writesiblings- the selected component's peers under its parent, used to work out which of several same-line creations it is
-
-
Method Details
-
handles
Whether this component's source is Kotlin, and so belongs to this class.Asked of the component's own file rather than of the project, because a project can hold both languages and often does.
- Parameters:
location- the selected component's type and location- Returns:
- true if the property commands should be routed here
-
setProperty
public String setProperty(ComponentTypeAndSourceLocation location, String property, Object value) throws IOException Sets a property, or clears it when the value isnull.The setter's name is resolved by the same reflection the Java path uses, because that is a question about the component's API rather than about the language. Everything after differs: the component is located by offset in a read-only parse tree and the edit is spliced into the text.
- Parameters:
location- the selected component's type and locationproperty- the JavaBean property namevalue- the new value, ornullto remove the set- Returns:
- the variable's new name if the edit renamed it, which it never does —
see
KotlinRewriter.replaceFunctionCall(com.vaadin.copilot.kotlinrewriter.KotlinComponentInfo, java.lang.String, java.lang.Object) - Throws:
IOException- if the source cannot be read
-
readProperty
public Object readProperty(ComponentTypeAndSourceLocation location, String property) throws IOException Reads what the source states for a property.- Parameters:
location- the selected component's type and locationproperty- the JavaBean property name- Returns:
- a
String,BooleanorNumberfor a literal, aSourceExpressionfor anything that has to be evaluated, ornullwhen the source does not set it - Throws:
IOException- if the source cannot be read
-
decline
Declines an operation this class does not cover.- Parameters:
operation- what was asked for, in words a developer will see- Returns:
- the refusal to throw
-