Class BadgePolicy

java.lang.Object
com.vaadin.copilot.rewriter.BadgePolicy

public final class BadgePolicy extends Object
What the alignment, gap and padding badges mean, independently of the language the answer is written in.

The counterpart of StylePolicy for the three badge commands, and extracted for the same reason: these decisions are about Vaadin, not about Java. Each badge has two vocabularies — in a Lumo project it writes Lumo utility class names, otherwise CSS values — and which one applies is chosen at runtime by AppThemeUtils.isLumo(). Written once per language that would be two sets of answers, and the second would be the one nobody updates.

Deliberately holds no JavaParser and no PSI. Turning an answer into source text stays with each rewriter: for Lumo that is building the addClassNames(LumoUtility.…) argument, which is where the policy and the syntax genuinely meet.

  • Field Details

    • ALIGNMENT_PROPERTIES

      public static final Set<String> ALIGNMENT_PROPERTIES
      The CSS properties the alignment badge owns, named as the frontend sends them.

      Used to clear what a previous alignment left behind before writing the new one — so the badge cannot accumulate contradictory declarations.

    • ALIGNMENT_PROPERTIES_WITHOUT_LUMO_CLASSES

      public static final Set<String> ALIGNMENT_PROPERTIES_WITHOUT_LUMO_CLASSES
      The two alignment properties with no Lumo utility class.

      They are written as inline styles whichever theme is in use, which is the single place the two branches agree.

  • Method Details

    • gapValueOf

      public static String gapValueOf(String token)
      The CSS value a gap token stands for, as in gap-m → var(--vaadin-gap-m).
      Parameters:
      token - the token the badge sends, or null
      Returns:
      the CSS value, or null when there is no token or the size is not one this knows
    • paddingValueOf

      public static String paddingValueOf(String token)
      The CSS value a padding token stands for, as in pt-l → var(--vaadin-padding-l).
      Parameters:
      token - the token the badge sends, or null
      Returns:
      the CSS value, or null when there is no token or the size is not one this knows
    • isGapProperty

      public static boolean isGapProperty(String property)
      Whether an inline style belongs to the gap badge, and so should be cleared before it writes.
      Parameters:
      property - the CSS property
      Returns:
      true if the gap badge owns it
    • isPaddingProperty

      public static boolean isPaddingProperty(String property)
      Whether an inline style belongs to the padding badge.
      Parameters:
      property - the CSS property
      Returns:
      true if the padding badge owns it
    • lumoFieldsOf

      public static Map<String,String> lumoFieldsOf(String innerClassName)
      The constants of one LumoUtility inner class, by field name.

      Reflection rather than a hard-coded table, so the set cannot drift from the Vaadin version the application is built against.

      Parameters:
      innerClassName - the inner class, as in Gap or Padding.Top
      Returns:
      field name to CSS class name, in no particular order
    • lumoFieldFor

      public static Optional<String> lumoFieldFor(String innerClassName, String cssClassName)
      The field that holds a CSS class name, within one inner class.
      Parameters:
      innerClassName - the inner class to look in
      cssClassName - the class name the badge sent, as in gap-m
      Returns:
      the field name, as in MEDIUM, or empty when that inner class has no such constant
    • lumoVariableFor

      public static String lumoVariableFor(String cssClassName)
      The constant naming a CSS class, searched across every LumoUtility inner class.

      Returns the reference as source text — LumoUtility.Gap.MEDIUM — which is spelled the same in Java and in Kotlin, so it stays policy rather than syntax.

      Parameters:
      cssClassName - the class name to look for
      Returns:
      the reference, or null when no constant holds that value