Interface Env

All Superinterfaces:
Serializable
All Known Subinterfaces:
DepthTrackingEnv
All Known Implementing Classes:
BlockScopeEnv, CaseEnv, FunctionCallEnv, ProxyEnv, TryBlockEnv

public interface Env extends Serializable
Represents an environment in which Block is evaluated. In the Harvard architecture terms, Block is instruction and Env is data.

This interface is not to be implemented outside this library.

See cps-model.md

Author:
Kohsuke Kawaguchi
  • Method Details

    • declareVariable

      void declareVariable(@NonNull Class type, @NonNull String name)
      Defines a local variable in the current environment. This method is called when a variable declaration is encountered.
      Parameters:
      type - Type of the local variable. Object when unknown/implicit (e.g. "def x")
      name - Name of the local variable.
      See Also:
    • getLocalVariable

      Object getLocalVariable(@NonNull String name)
      Obtains the current value of a local variable in the current environment.
      Parameters:
      name - Name of the local variable.
      See Also:
    • setLocalVariable

      void setLocalVariable(@NonNull String name, Object value)
      Sets the local variable to a new value.
      Parameters:
      name - Name of the local variable.
      value - New value
      See Also:
    • getLocalVariableType

      @CheckForNull Class getLocalVariableType(@NonNull String name)
    • closureOwner

      Object closureOwner()
      Closure instance or 'this' object that surrounds the currently executing code.

      If a new closure instantiation is encountered, this is the object that becomes the owner of that closure.

      Dynamic property access inside closures are also resolved against this instance.

    • getReturnAddress

      Continuation getReturnAddress()
      Where should the return statement return to?
    • getBreakAddress

      Continuation getBreakAddress(String label)
      If we see a break statement, where should we go?
      Parameters:
      label - Specifies the loop to break from. null for nearest loop.
      Returns:
      For semantically correct Groovy code, the return value is never null, because not having the matching label is a compile-time error.
    • getContinueAddress

      Continuation getContinueAddress(String label)
      If we see a continue statement, where should we go?
      Parameters:
      label - Specifies the loop to repeat. null for nearest loop.
      Returns:
      For semantically correct Groovy code, the return value is never null, because not having the matching label is a compile-time error.
    • getExceptionHandler

      Continuation getExceptionHandler(Class<? extends Throwable> type)
      Finds the exception handler that catches a Throwable instance of this type.
      Returns:
      never null. Even if there's no user-specified exception handler, the default 'unhandled exception handler' must be returned.
    • buildStackTraceElements

      void buildStackTraceElements(List<StackTraceElement> stack, int depth)
      Builds the current call stack information for Throwable.getStackTrace().
      Parameters:
      depth - Maximum depth of stack trace to obtain.
    • getInvoker

      Invoker getInvoker()
      Invoker is typically scoped at the whole execution.
      Returns:
      never null