Class JavaStyleRewriter

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

public class JavaStyleRewriter extends Object
Writes and reads inline styles in Java source.

The decisions this makes — which Style call sets a property, what a property is called, what an enum constant means as CSS — live in StylePolicy, so that the Kotlin rewriter reaches the same answers rather than restating them. What is left here is the JavaParser work: finding the calls, chaining a new one on, splicing a value in.

  • Constructor Details

    • JavaStyleRewriter

      public JavaStyleRewriter()
  • Method Details

    • getStyles

      public static List<StylePolicy.StyleInfo> getStyles(ComponentInfo componentInfo)
      Gets the (active) styles of a component.
      Parameters:
      componentInfo - the component to get the styles of
      Returns:
      the styles, as a list of style names and values
    • getStylesWithMethodCalls

      public static Map<StylePolicy.StyleInfo,com.github.javaparser.ast.expr.MethodCallExpr> getStylesWithMethodCalls(ComponentInfo componentInfo)
    • setStyle

      public static void setStyle(ComponentInfo componentInfo, String dashSeparatedProperty, String value)
      /** Sets the given inline style on the given component, replacing an existing style property if present. An exception will be thrown when value is null.
      Parameters:
      componentInfo - the component to set the style on
      dashSeparatedProperty - the style property to set
      value - the style value to set or null to remove the style
    • setStyle

      public static StylePolicy.StylingResult setStyle(ComponentInfo componentInfo, String dashSeparatedProperty, String value, boolean allowNullValue)
      Sets the given inline style on the given component, replacing an existing style property if present.
      Parameters:
      componentInfo - the component to set the style on
      dashSeparatedProperty - the style property to set
      value - the style value to set or null to remove the style
      allowNullValue - allowing value of a style to be null. Throws exception when disallowed.
    • setSizing

      public static void setSizing(ComponentInfo componentInfo, Map<String,String> changes)
      Handles calls of the given component and adjust them based on the given properties.
      Parameters:
      componentInfo - Component to update
      changes - Changed properties for the sizing. Keys are camelCased, values might be string or null. e.g. flexGrow -> "1", maxHeight -> null