Class MergedStyleNode

java.lang.Object
net.sourceforge.plantuml.style.parser.MergedStyleNode

public final class MergedStyleNode extends Object
One node of the canonical, merged style tree: unlike RawStyleRule, there is at most one node per (selector name, *-or-not) pair at a given level, whatever comma lists or repeated declarations produced it in the source file. Building this tree from a RawStyleSheet does exactly two things the raw parse tree deliberately left undone:
  • a comma-separated selector list, e.g. composite,package { title {...} } , is expanded so each alternative gets its own independent node (so a later declaration of package { title {...} } elsewhere only ever affects package, never composite);
  • repeated declarations of the very same selector path with the same *-ness, e.g. two separate top-level mindmapDiagram { ... } blocks, are folded into a single node: properties are overwritten by whichever declaration comes last in the file (the same last-one-wins rule the legacy Style#mergeWith already applies), and children accumulate across every occurrence.
A selector declared once plain and once starred, e.g. .europeStyle { node { FontSize 20 } } alongside .europeStyle * { node { FontColor red } } , is deliberately not folded together the way two identically-starred declarations are: they land in two separate child slots (see getOrCreateChild(net.sourceforge.plantuml.style.parser.RawSelector, boolean)), because * changes what the declaration actually means -- FontSize 20 must stay on the Europe node alone, while FontColor red must cascade to every descendant too. The legacy character-level parser never had to get this right on purpose: its Context#push always allocates a brand new Context per occurrence, so a plain and a starred declaration of the same name were simply never the same object to begin with. Collapsing them into one node here (as an earlier version of this class did, keying a child purely by selector name) would silently let FontSize leak onto England, Germany and Spain along with FontColor -- a real regression, not a hypothetical one. What this tree still does not do: turn a nested path such as sequenceDiagram > participant into the flat, order-independent signature (a set of SName) the legacy
invalid reference
net.sourceforge.plantuml.style.StyleSignature
matches against, or resolve depth(n) into an actual matching rule. Those are later steps; see net.sourceforge.plantuml.style.LegacyStyleFlattener. A property set inside @media (prefers-color-scheme:dark) { ... } is not kept apart from its plain (light) counterpart either: both land in the very same node, folded into one PrioritizedValue carrying both -- see mergeRule(net.sourceforge.plantuml.style.parser.RawStyleRule, net.sourceforge.plantuml.style.AutomaticCounter, boolean).
  • Method Details

    • newTopLevelContainer

      public static MergedStyleNode newTopLevelContainer()
    • mergeRule

      public void mergeRule(RawStyleRule rule, AutomaticCounter counter, boolean dark)
      Merges one raw declaration -- and, recursively, everything nested inside it -- into this node, which stands for its parent selector (the top-level container for a top-level declaration). counter assigns each property value an increasing priority as it is met, exactly like the legacy StyleBuilder (itself an AutomaticCounter) does when loading a .skin file -- so it must be the very same counter for every mergeRule call across one sheet, @media content included, for priorities to be comparable across every declaration in the file. dark says whether rule sits inside an @media block: every property it sets is then wrapped as a dark value instead of a light one, and PrioritizedValue.mergeWith(PrioritizedValue) takes care of folding it together with whatever light value the very same property already has at this node (in file order, either one may come first). This mirrors the legacy parser's own @media handling (net.sourceforge.plantuml.style.parser.StyleParser's scheme field): it does not look at the actual media condition text at all, it only cares that some @-rule switched parsing into "dark" mode.
    • mergeAll

      public void mergeAll(RawStyleSheet raw, AutomaticCounter counter)
      Merges every top-level rule in raw into this node, @media content dispatched to its dark half exactly as the plain case is -- what net.sourceforge.plantuml.style.StyleLoader#parseStyleText calls to fold a whole .skin file, or a hand-written <style>...</style> block, into one throwaway tree, immediately flattened back to legacy net.sourceforge.plantuml.style.Style objects by LegacyStyleFlattener. counter must be the very same one across every call contributing to one logical load (a whole file, or a file followed by its overlays), exactly like a single top-level mergeRule(net.sourceforge.plantuml.style.parser.RawStyleRule, net.sourceforge.plantuml.style.AutomaticCounter, boolean) call requires.
    • getOtherChildKind

      public RawSelector.Kind getOtherChildKind(String canonicalKey)
      Which RawSelector.Kind produced the "other" child stored under this canonical key -- STEREOTYPE, DEPTH or UNKNOWN -- so a later compilation step can tell a stereotype selector from an unrecognized one, which RawSelector.canonicalOtherKey() alone does not always disambiguate.
    • getNamedChildren

      public Map<SName,MergedStyleNode> getNamedChildren()
      Children reached through a plain (non-starred) named selector. See getStarredNamedChildren().
    • getStarredNamedChildren

      public Map<SName,MergedStyleNode> getStarredNamedChildren()
      Children reached through a starred named selector, e.g. the node in europeStyle * { node {...} } . Kept apart from getNamedChildren() rather than merged with it -- see the class javadoc -- so a caller building a child signature must visit both maps and addStar() unconditionally for entries found here.
    • getOtherChildren

      public Map<String,MergedStyleNode> getOtherChildren()
      Children reached through a plain (non-starred) stereotype/depth/unknown selector. See getStarredOtherChildren().
    • getStarredOtherChildren

      public Map<String,MergedStyleNode> getStarredOtherChildren()
      The starred counterpart of getOtherChildren() -- see getStarredNamedChildren().
    • getProperties

      public Map<PName,PrioritizedValue> getProperties()
      Properties declared anywhere for this exact selector, already merged -- light and dark declarations for the same property folded into one PrioritizedValue, per mergeRule(net.sourceforge.plantuml.style.parser.RawStyleRule, net.sourceforge.plantuml.style.AutomaticCounter, boolean).
    • getProperty

      public PrioritizedValue getProperty(PName name)
    • isStar

      public boolean isStar()
    • toString

      public String toString()
      Overrides:
      toString in class Object