Class FlowComponentQuirks

java.lang.Object
com.vaadin.copilot.javarewriter.FlowComponentQuirks

public final class FlowComponentQuirks extends Object
This class contains hacks related to Flow components and how they work.
  • Field Details

  • Method Details

    • getClassForComponent

      public static String getClassForComponent(CopilotComponent copilotComponent)
      Returns the Java class name for a given HTML tag.
      Parameters:
      copilotComponent - the java Component
      Returns:
      the Java class name
    • getClassHierarchy

      public static List<String> getClassHierarchy(CopilotComponent copilotComponent)
    • isUnsupportedSvgTag

      public static boolean isUnsupportedSvgTag(String tag)
      Returns whether the tag refers to an SVG element that Flow doesn't map to a Java component class.
      Parameters:
      tag - the element tag name
      Returns:
      true if the tag is an SVG element we should skip
    • componentSpecificValueMapping

      public static Object componentSpecificValueMapping(Class<?> componentType, String prop, Object value)
      Rewrites the value of a property for a specific component type.
      Parameters:
      componentType - the component type
      prop - the property name
      value - the property value
      Returns:
      the rewritten value or the original value if no rewriting is needed
    • convertReactPropertyToJavaSetter

      public static String convertReactPropertyToJavaSetter(String property, Class<?> type)
      Converts a React property name to a Java setter method name.

      Used to map React properties to Java setters when the react property API does not match the Java API.

      Parameters:
      property - the property name
      type - the component type
      Returns:
      the Java setter method name or null if no mapping is found
    • getInnerTextProperty

      public static String getInnerTextProperty(Class<?> componentType)
    • isInvertedBoolean

      public static boolean isInvertedBoolean(String property, Class<?> type)
    • childrenGeneratesData

      public static boolean childrenGeneratesData(CopilotComponent parent, CopilotComponent child)
      Returns true if child is not a component but an item that is used in DataProvider.
      Parameters:
      parent - Parent component
      child - Child definition
      Returns:
      true if it is, false otherwise.
    • hasSetItemsProps

      public static boolean hasSetItemsProps(CopilotComponent component)
      Checks the given component has items property and supported.
      Parameters:
      component - component which has tag and props.
      Returns:
      true if component tag is listed in supported list and has items property, false otherwise.
    • hasSetItemsMethod

      public static boolean hasSetItemsMethod(CopilotComponent component)
    • skipProps

      public static boolean skipProps(CopilotComponent component, String propKey)
    • getMethodCallChildren

      public static List<CopilotComponent> getMethodCallChildren(CopilotComponent copilotComponent)
      Returns the list of children of the given CopilotComponent that should be added as method calls
      Parameters:
      copilotComponent - The CopilotComponent
      Returns:
      The list of children to be added as method calls
    • getSetterNameFromComponent

      public static String getSetterNameFromComponent(CopilotComponent child)
      Returns the name of the setter method to be called on the owner object for the given CopilotComponent
      Parameters:
      child - The CopilotComponent
      Returns:
      The name of the setter method
    • getMethodCallExprFromComponent

      public static List<com.github.javaparser.ast.expr.MethodCallExpr> getMethodCallExprFromComponent(com.github.javaparser.ast.CompilationUnit compilationUnit, CopilotComponent child, com.github.javaparser.ast.expr.Expression owner, String dataEntityRecordName)
      Returns the MethodCallExpr to be added to the owner object for the given CopilotComponent
      Parameters:
      child - The CopilotComponent
      owner - The owner object
      dataEntityRecordName - The name of the data entity record
      Returns:
      The MethodCallExpr
    • isGridColumnDefinition

      public static boolean isGridColumnDefinition(CopilotComponent component)
      Returns true when the java component indicates a Grid column definition according to Hilla React template. Grid column components are GridColumn, GridSortColumn and GridTreeColumn. If this component are present for columns defined for a Grid.
      Parameters:
      component - The CopilotComponent
      Returns:
      true if the component is a Grid column component, false otherwise
    • isGridTreeColumnDefinition

      public static boolean isGridTreeColumnDefinition(CopilotComponent component)
      Returns true when the java component indicates a Tree Grid column definition according to Hilla React template. Tree Grid column attribute components is GridTreeColumn.
      Parameters:
      component - The CopilotComponent
      Returns:
      true if the component is a TreeGrid column attribute, false otherwise
    • isGridColumnAttribute

      public static boolean isGridColumnAttribute(CopilotComponent component)
      Returns true when the java component indicates a Grid attribute according to Hilla React template. Grid attribute components so far is GridSelectionColumn.
      Parameters:
      component - The CopilotComponent
      Returns:
      true if the component is a Grid attribute, false otherwise
    • isTabSheetDefinition

      public static boolean isTabSheetDefinition(CopilotComponent component)
    • createSettersForGridConstructor

      public static boolean createSettersForGridConstructor(Constructor<?> constructor, com.github.javaparser.ast.stmt.BlockStmt blockToAdd, String variableName, com.github.javaparser.ast.expr.ObjectCreationExpr objectCreationExpr)
      ConstructorAnalyzer is unable to resolve constructor for the Grid as method names do not start with `set` prefix.
      When a Class type is given to the Grid e.g. Grid(SomeClass.class), configureBeanType is called. This method resolves constructors Grid(SomeClass.class) and Grid(SomeClass.class, boolean autoColumns) and adds the method call to given block
      Parameters:
      constructor - Constructor code of the Grid
      blockToAdd - block to add method call expression into
      variableName - variable as method scope
      objectCreationExpr - creation expression to get argument values
      Returns:
      true if given constructor belongs to Grid and one of Grid(Classinvalid input: '<'?>)/Grid(Classinvalid input: '<'?>,boolean) constructor is used.
    • getPropertySetExpression

      public static com.github.javaparser.ast.expr.Expression getPropertySetExpression(CopilotComponent copilotComponent, String parentSetterName, String setterName, Object value, com.github.javaparser.ast.expr.Expression owner, InsertionPoint insertionPoint)
      Returns the expression to be used to set a property in a CopilotComponent. This method modifies the code adding everything required to set the property like intermediate variables or method calls.
      Parameters:
      copilotComponent - The CopilotComponent
      parentSetterName - The name of the parent setter method
      setterName - The name of the setter method
      value - The value of the property
      owner - The owner object where the property will be set
      insertionPoint - The insertion point where the expression will be added to add more required expressions different to the actual setter if needed
      Returns:
    • isSingleComponentAttachExpression

      public static boolean isSingleComponentAttachExpression(com.github.javaparser.ast.expr.Expression expression)
      Whether this is an attach expression whose arguments describe one component, rather than only the component itself.

      For example, FormLayout.addFormItem(Component, String) attaches a component together with its label. Removing the component must therefore remove the whole call even though the label argument remains.

      Parameters:
      expression - the possible attach expression
      Returns:
      true when removing its component also requires removing the expression
    • isFormLayoutRowAttachExpression

      public static boolean isFormLayoutRowAttachExpression(AttachExpression attachExpression)
      Whether an attach expression creates a row in a FormLayout.
      Parameters:
      attachExpression - the possible attach expression
      Returns:
      true when its arguments are the items of a FormLayout row
    • requiresSeparateMethodInfoPerCall

      public static boolean requiresSeparateMethodInfoPerCall(String className, String methodName)
      Whether each invocation of a child-accepting method needs a separate entry in the drop API dialog.
      Parameters:
      className - declaring class name, simple or fully qualified
      methodName - method name to inspect
      Returns:
      true when method invocations represent distinct containers
    • useReferenceFormRowScopeForAttachedComponent

      public static void useReferenceFormRowScopeForAttachedComponent(AttachExpression attachExpression, ComponentInfo referenceComponent, AddTemplateOptions addTemplateOptions)
      Makes an addFormRow call use the same FormLayout receiver as the reference row when inserting a new row next to an existing one.

      Form rows are implicitly created by FormLayout.addFormRow(...), so the normal attach expression can otherwise inherit an unsuitable scope. This adjustment is only needed for the AddReplace.ADD variant of that API.

      Parameters:
      attachExpression - the expression that attaches the newly created component
      referenceComponent - the existing form row that determines the receiver
      addTemplateOptions - options describing the selected add API