Class VarScope

java.lang.Object
com.axelor.workflow.expression.VarScope

public final class VarScope extends Object
One frame of a run's variables, and the frame it sits inside. The run, each split branch and each body iteration have a frame.

A read walks up the chain. A write lands in the frame where the name is found, else in the current frame. So vars.total += line.price inside a body accumulates into a total the caller set, while a name first written inside the body goes with the frame.

Each frame tracks the names written in it (dirtyKeys()), so a resuming branch merges only those. Not thread-safe: one walk is one thread.

  • Method Details

    • root

      public static VarScope root()
      The outermost frame: a run's own variables.
    • push

      public VarScope push()
      A frame inside this one, for a branch or an iteration.
    • pop

      public VarScope pop()
      The frame this one sits in.
      Throws:
      IllegalStateException - if this is the run's own frame
    • depth

      public int depth()
      How deep this frame is; the run's own is 0.
    • get

      public Object get(String key)
      The value this chain resolves key to, or null when no frame has it.
    • has

      public boolean has(String key)
      Whether any frame in this chain has key, null-valued or not.
    • put

      public void put(String key, Object value)
      Write key where it is already found, or here when it is found nowhere.
    • putLocal

      public void putLocal(String key, Object value)
      Writes key into this frame, whatever an outer one holds; for seeding a frame, where put(java.lang.String, java.lang.Object) would overwrite an outer name.
    • keys

      public Set<String> keys()
      Every name this chain resolves, outermost first.
    • flatten

      public Map<String,Object> flatten()
      The chain as one map, inner frames shadowing outer ones.
    • outerFlatten

      public Map<String,Object> outerFlatten()
      Everything this frame inherits, without its own -- the other half of ownValues().
    • ownValues

      public Map<String,Object> ownValues()
      This frame's own values, without anything it inherits.
    • dirtyKeys

      public Set<String> dirtyKeys()
      The names written in this frame, which are the ones a merge has to carry.
    • dirtyValues

      public Map<String,Object> dirtyValues()
      Every name written anywhere in this chain, with the value the chain resolves it to. A resuming branch writes back only these, so siblings' writes land in either order.
    • checkpoint

      public VarScope.Checkpoint checkpoint()
    • writtenSince

      public Map<String,Object> writtenSince(VarScope.Checkpoint before)
      Includes explicit assignments of the same value and mutations inside containers.
    • outerDirtyValues

      public Map<String,Object> outerDirtyValues()
      The same, for everything this frame inherits -- the other half of dirtyValues().