Class KotlinComponentInfo

java.lang.Object
com.vaadin.copilot.kotlinrewriter.KotlinComponentInfo
All Implemented Interfaces:
ComponentRef

public final class KotlinComponentInfo extends Object implements ComponentRef
A component resolved to its place in a Kotlin source file.

The Kotlin counterpart of ComponentInfo, and deliberately much smaller: it holds the four things an edit needs — the constructor call, the declaration it is assigned to, the region to search for configuration, and the name the component goes by — and nothing that would have to be kept in step with the parse tree afterwards.

Reading and writing need exactly the same resolution, so this is produced once by KotlinComponentInfoFinder and used by both. Before this existed the reader resolved the component inline, which meant a writer would have had to repeat the occurrence and scope rules and could have disagreed with the panel about which component it was editing.

Public because it appears in KotlinRewriter's signatures, but every accessor that returns a parse-tree node is package private, so the rule that no Kt* type escapes this package still holds by compilation rather than by convention.

  • Method Details

    • type

      public Class<? extends com.vaadin.flow.component.Component> type()
      Specified by:
      type in interface ComponentRef
      Returns:
      the component's runtime type, taken from the live instance rather than parsed from source
    • isReturnValue

      public boolean isReturnValue()
      Always false: a Kotlin component returned from a method rather than attached where it is created is not resolved at all yet, so no instance of this can represent one.
      Specified by:
      isReturnValue in interface ComponentRef
      Returns:
      true if the component is returned from a method rather than attached where it is created
    • typeWithGenerics

      public String typeWithGenerics()
      The type as it should be written in source, with any generic arguments the source itself states.

      Kotlin usually states them on the constructor call — Grid<Person>() — rather than on the declaration, because the declaration's type is normally inferred. An explicit declaration type wins where there is one, since that is what the developer wrote down.

      Specified by:
      typeWithGenerics in interface ComponentRef
      Returns:
      the type name
    • variableName

      public String variableName()
      The name the source addresses this component by.
      Returns:
      the name, or null when the component has no name of its own — an inline add(Button()), or the view itself, whose properties are set with no receiver at all
    • isRoute

      public boolean isRoute()
      Returns:
      true if the component is the view itself, constructed by the framework rather than by this source