Class CodeTargetContext

java.lang.Object
de.spraener.nxtgen.target.CodeTargetContext
All Implemented Interfaces:
AutoCloseable

public class CodeTargetContext extends Object implements AutoCloseable
Responsibility The CodeTargetContext manages a Stack in a ThreadLocal variable to give access to the current Aspect and ModelElement. With the use of the CodeTargetContext a Snippet can retrieve this information automatically from the ThreadLocal. This makes the writing of ClassTarget-Creators much more readable.

The CodeTargetContext is a Autocloseable and it is intended to be used in a try()-Header. Nesting is possible. A nested ClassTargetContext will push its information on the stack and pop it on close. The last close will empty the ThreadLocal variable.

Access to the CodeTargetContext is possible to the static method getActiveContext

  • Constructor Details

    • CodeTargetContext

      public CodeTargetContext(Object aspect, ModelElement modelElement)
      Activate a new ClassTargetContext with the given Information.
      Parameters:
      aspect - an Aspect describing the purpose.
      modelElement - a ModelElement that the CodeTarget creator is currently working on.
  • Method Details

    • getActiveContext

      public static CodeTargetContext getActiveContext()
      Retrieves the current active ClassTargetContext from the ThreadLocal Stack. It there is no active ClassTargetContext it will return an empty CodeTargetContex.
      Returns:
      the currently active ClassTargetContext or null.
    • getAspect

      public Object getAspect()
      Returns the aspect of this (currently active) CodeTargetContext.
      Returns:
      aspect or null
    • getModelElement

      public ModelElement getModelElement()
      Returns the ModelElement of this (currently active) CodeTargetContext
      Returns:
      ModelElement or null
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable