Class KotlinLocalClassNames
The theme editor gives a component a class name of its own so that a CSS rule
can target just that component, and it has to find that class name again
later to show it, change it or take it away. It marks its own statement with
a line comment so that a developer's addClassName("…") is never
mistaken for one of its own:
// <theme-editor-local-classname>
name.addClassName("hello-world-view-text-field-1")
The marker text is passed in rather than declared here, so that this and the
Java implementation cannot drift into writing one marker and looking for
another.
The statement is found the way any other call on a component is —
KotlinPropertyLocator's receiver rules, which know what a name means
where it is written — so a class name set on a component shadowed by a local
is not read as another component's.
-
Constructor Summary
ConstructorsConstructorDescriptionKotlinLocalClassNames(KotlinFileSourceProvider sources, Function<com.vaadin.flow.component.Component, List<ComponentTypeAndSourceLocation>> siblings, String marker) -
Method Summary
Modifier and TypeMethodDescriptionEvery class name the file already states, so that a suggestion does not collide with one.booleanisAccessible(ComponentTypeAndSourceLocation location) Whether this component can be given a class name at all.read(ComponentTypeAndSourceLocation location) booleanremove(ComponentTypeAndSourceLocation location) Takes the class name away, along with the marker that named it.voidset(ComponentTypeAndSourceLocation location, String className) Sets the class name, replacing the one already there.
-
Constructor Details
-
KotlinLocalClassNames
public KotlinLocalClassNames(KotlinFileSourceProvider sources, Function<com.vaadin.flow.component.Component, List<ComponentTypeAndSourceLocation>> siblings, String marker) - Parameters:
sources- the parsed Kotlin sources for this operationsiblings- the selected component's peers under its parent, for resolving which of several same-line creations it ismarker- the comment text the theme editor marks its own statements with
-
-
Method Details
-
read
- Parameters:
location- the selected component- Returns:
- the class name the theme editor gave this component, or
nullwhen it has not given it one - Throws:
IOException- if the source cannot be read
-
set
Sets the class name, replacing the one already there.- Parameters:
location- the selected componentclassName- the class name to set- Throws:
IOException- if the source cannot be read
-
remove
Takes the class name away, along with the marker that named it.- Parameters:
location- the selected component- Returns:
- true if there was one to remove
- Throws:
IOException- if the source cannot be read
-
isAccessible
Whether this component can be given a class name at all.It cannot when Copilot has nowhere to write the statement — an inline
add(Button("x"))has no name to address andKotlinInsertionPointrefuses it. Asked before the theme editor offers the field, so a refusal here is an answer rather than an error.- Parameters:
location- the selected component- Returns:
- true if a class name could be written
-
existingClassNames
Every class name the file already states, so that a suggestion does not collide with one.All of them, not only the theme editor's own: a suggestion that matches a class name the developer wrote would style their component by accident.
- Parameters:
location- the selected component- Returns:
- the class names, in source order
- Throws:
IOException- if the source cannot be read
-