Class ReducerFactory.Context<D,R>

java.lang.Object
eu.bandm.tools.ramus.ogma.ReducerFactory.Context<D,R>
Type Parameters:
D - the type of document identifiers
R - the type of AST results
All Implemented Interfaces:
MessageReceiver<SimpleMessage<D>>, Environment, Consumer<SimpleMessage<D>>
Enclosing class:
ReducerFactory

public class ReducerFactory.Context<D,R> extends Object implements MessageReceiver<SimpleMessage<D>>, Environment
Context server for AST reduction.

The lifetime of objects of this class is controlled by a ReducerFactory. They are both created and evaluated (and rendered unusable) behind the scenes.

  • Method Details

    • getLocation

      public @Opt Location<D> getLocation()
      Returns the input location associated with this context, if available.
      Returns:
      the input location associated with this context, or null if not available.
    • getMessages

      public List<? extends SimpleMessage<D>> getMessages()
      Returns the list of diagnostic messages attached to this context.
      Returns:
      an unmodifiable list of diagnostic messages attached to this context
    • isEvaluated

      public boolean isEvaluated()
      Checks whether this context has already been evaluated.

      A context may only be evaluated once. Further attempts to modify the semantic state, to attach messages or to branch nondeterministically are forbidden, and result in IllegalStateException being thrown.

      Returns:
      true if this context has already been evaluated, false if it may be modified and evaluated
    • receive

      public void receive(SimpleMessage<D> message)
      Receive the given message.
      Specified by:
      receive in interface MessageReceiver<D>
      Parameters:
      message - the message to receive.
      Throws:
      IllegalStateException - if this context has already been evaluated
    • warning

      public void warning(String message, Object... args)
      Appends a warning to the list of diagnostic messages.
      Parameters:
      message - the text of the message
      args - the list of arguments
      Throws:
      IllegalStateException - if this context has already been evaluated
      See Also:
    • warning

      public void warning(@Opt Location<D> location, String message, Object... args)
      Appends a warning to the list of diagnostic messages.
      Parameters:
      location - the message location, or null if not available
      message - the text of the message
      args - the list of arguments
      Throws:
      IllegalStateException - if this context has already been evaluated
      See Also:
    • warning

      public void warning(int level, String message, Object... args)
      Appends a warning to the list of diagnostic messages.
      Parameters:
      level - the message level
      message - the text of the message
      args - the list of arguments
      Throws:
      IllegalStateException - if this context has already been evaluated
      See Also:
    • warning

      public void warning(int level, @Opt Location<D> location, String message, Object... args)
      Appends a warning to the list of diagnostic messages.
      Parameters:
      level - the message level
      location - the message location, or null if not available
      message - the text of the message
      args - the list of arguments
      Throws:
      IllegalStateException - if this context has already been evaluated
      See Also:
    • error

      public void error(String message, Object... args)
      Appends an error to the list of diagnostic messages.
      Parameters:
      message - the text of the message
      args - the list of arguments
      Throws:
      IllegalStateException - if this context has already been evaluated
      See Also:
    • error

      public void error(@Opt Location<D> location, String message, Object... args)
      Appends an error to the list of diagnostic messages.
      Parameters:
      location - the message location, or null if not available
      message - the text of the message
      args - the list of arguments
      Throws:
      IllegalStateException - if this context has already been evaluated
      See Also:
    • hint

      public void hint(String message, Object... args)
      Appends a hint to the list of diagnostic messages.
      Parameters:
      message - the text of the message
      args - the list of arguments
      Throws:
      IllegalStateException - if this context has already been evaluated
      See Also:
    • hint

      public void hint(@Opt Location<D> location, String message, Object... args)
      Appends a hint to the list of diagnostic messages.
      Parameters:
      location - the message location, or null if not available
      message - the text of the message
      args - the list of arguments
      Throws:
      IllegalStateException - if this context has already been evaluated
      See Also:
    • getValue

      public Data getValue()
      Returns the current accumulator value.
      Specified by:
      getValue in interface Environment
      Returns:
      the current accumulator value
    • get

      public Data get(Object key)
      Returns the current value assigned to the given key.
      Specified by:
      get in interface Environment
      Parameters:
      key - the key
      Returns:
      the current value assigned to key, or null if there is no entry for key
    • setValue

      public void setValue(Data value)
      Sets the current accumulator value.
      Parameters:
      value - the new accumulator value
      Throws:
      NullPointerException - if value is null
      IllegalStateException - if this context has already been evaluated
      See Also:
    • put

      public void put(Object key, Data value)
      Sets the current value assigned to the given key.
      Parameters:
      key - the key
      value - the new value to be assigned to key
      Throws:
      NullPointerException - if key or value is null
      IllegalStateException - if this context has already been evaluated
      See Also:
    • push

      public void push()
      Enters a new scope of the semantic state.
      Throws:
      IllegalStateException - if this context has already been evaluated
      See Also:
    • pop

      public void pop()
      Leaves and discards a scope of the semantic state.
      Throws:
      IllegalStateException - if this context has already been evaluated
      See Also:
    • abort

      public <X> X abort() throws ReducerFactory.Abort
      Aborts the current creation of an AST node. All diagnostic messages and semantic state transitions are discarded.

      This method never returns normally. To make the control-flow check of the Java compiler aware of this fact, in a non-void method one may write return abort();.

      Type Parameters:
      X - the fictitious return type
      Returns:
      never
      Throws:
      ReducerFactory.Abort - always
    • fork

      public void fork(ReducerFactory.Constructor0<D,R> other)
      Forks of an alternative nondeterministic branch with a clone of this context.
      Parameters:
      other - a consumer to work on the branch
      Throws:
      NullPointerException - if other is null
      IllegalStateException - if this context has already been evaluated
    • variable

      public <T> VirtualField<T> variable(Reading.Key<T> key)