Class LumoRewriterUtil

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

public class LumoRewriterUtil extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    addClassNameWithArgs(ComponentInfo component, List<com.github.javaparser.ast.expr.Expression> arguments)
    Creates addClassNames(...) statement with given arguments if there is none.
    static void
    addLumoUtilityImport(com.github.javaparser.ast.CompilationUnit compilationUnit)
     
    static void
    addLumoUtilityStylesheetIfNotExists(com.vaadin.flow.server.VaadinContext vaadinContext)
    Check if @StyleSheet("styles.css") exists on main app class -> yes, put @import "lumo/utility.css" at the top Check if @StyleSheet(Lumo.STYLESHEET) exists on main app -> yes, put @StyleSheet(Lumo.UTILITY_STYLESHEET) below it Otherwise Lumo is loaded in custom way, so just create styles.css add it to main app class using @StyleSheet("styles.css") and add @import "lumo/utility.css" inside.
    static com.github.javaparser.ast.expr.Expression
    createAddClassNameExprUsingLumoVariables(com.github.javaparser.ast.expr.Expression owner, Object value, com.github.javaparser.ast.CompilationUnit cu)
    Creates addClassNames call for the given owner using value.
    static List<com.github.javaparser.ast.expr.Expression>
    getLumoMethodArgExpressions(String lumoInnerClassName, List<String> classNames)
    Converts given class names to LumoUtility field access expressions. e.g.
    static List<com.github.javaparser.ast.expr.Expression>
    getLumoMethodArgExpressions(List<String> lumoInnerClassNames, List<String> classNames)
    Converts given class names of given lumo inner class name lists and return all.
    static void
    removeClassNameArgs(ComponentInfo component, String... lumoUtilityClassNames)
    Searches addClassName, addClassNames, setClassName methods for given component and then remove given lumo utility class names. e.g. if self-start is given for removal, LumoUtility.AlignSelf.START and "self-start" are removed from args.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • createAddClassNameExprUsingLumoVariables

      public static com.github.javaparser.ast.expr.Expression createAddClassNameExprUsingLumoVariables(com.github.javaparser.ast.expr.Expression owner, Object value, com.github.javaparser.ast.CompilationUnit cu)
      Creates addClassNames call for the given owner using value. When value is plain string, it searches lumo utility replacements and replaces plain string class names with LumoUtility classes as possible.

      If there is no change, it returns null "gap-m p-m" -> LumoUtility.Gap.MEDIUM, LumoUtility.Padding.MEDIUM
      "foo gap-m" -> "foo", LumoUtility.Gap.MEDIUM
      Parameters:
      owner - owner of the adding class related call.
      value - Class name arg value. If it is not string, returns null.
      cu - Complication unit to add lumo utility import if required
      Returns:
      methodCallExpr that is owner scoped addClassNames. e.g.
      fooBtn.addClassNames(LumoUtility.Position.ABSOLUTE);
    • addClassNameWithArgs

      public static boolean addClassNameWithArgs(ComponentInfo component, List<com.github.javaparser.ast.expr.Expression> arguments)
      Creates addClassNames(...) statement with given arguments if there is none. Adds arguments to existing one.
      Parameters:
      component - the component to add class name
      arguments - class name arguments. Most likely StringLiteral or FieldAccessExpr generated for LumoUtility.
      Returns:
      true if added successfully, false otherwise.
    • removeClassNameArgs

      public static void removeClassNameArgs(ComponentInfo component, String... lumoUtilityClassNames)
      Searches addClassName, addClassNames, setClassName methods for given component and then remove given lumo utility class names. e.g. if self-start is given for removal, LumoUtility.AlignSelf.START and "self-start" are removed from args.
      Parameters:
      component - the component to remove class names
      lumoUtilityClassNames - Utility class names such as "align-items", "gap-m"
    • addLumoUtilityImport

      public static void addLumoUtilityImport(com.github.javaparser.ast.CompilationUnit compilationUnit)
    • getLumoMethodArgExpressions

      public static List<com.github.javaparser.ast.expr.Expression> getLumoMethodArgExpressions(String lumoInnerClassName, List<String> classNames)
      Converts given class names to LumoUtility field access expressions. e.g. items-center becomes AlignItems.CENTER
      Parameters:
      lumoInnerClassName - Inner class name of LumoUtility class. e.g. AlignSelf, AlignItems etc...
      classNames - html class names
      Returns:
      list of expressions.
    • getLumoMethodArgExpressions

      public static List<com.github.javaparser.ast.expr.Expression> getLumoMethodArgExpressions(List<String> lumoInnerClassNames, List<String> classNames)
      Converts given class names of given lumo inner class name lists and return all.
      Parameters:
      lumoInnerClassNames - List of lumo inner class names e.g. Gap, Gap.Row, Gap.Column
      classNames - class names to look up in given lumo classes
      Returns:
      List of expression to add to a method as arguments
    • addLumoUtilityStylesheetIfNotExists

      public static void addLumoUtilityStylesheetIfNotExists(com.vaadin.flow.server.VaadinContext vaadinContext) throws IOException
      Check if @StyleSheet("styles.css") exists on main app class -> yes, put @import "lumo/utility.css" at the top Check if @StyleSheet(Lumo.STYLESHEET) exists on main app -> yes, put @StyleSheet(Lumo.UTILITY_STYLESHEET) below it Otherwise Lumo is loaded in custom way, so just create styles.css add it to main app class using @StyleSheet("styles.css") and add @import "lumo/utility.css" inside. Same as ThemeEditor is doing.
      Parameters:
      VaadinContext - Context to find the main class of Spring Applications
      Throws:
      IOException - is thrown when file operation fails