Package de.spraener.nxtgen.target
Class CodeTargetContext
java.lang.Object
de.spraener.nxtgen.target.CodeTargetContext
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionCodeTargetContext(Object aspect, ModelElement modelElement) Activate a new ClassTargetContext with the given Information. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static CodeTargetContextRetrieves the current active ClassTargetContext from the ThreadLocal Stack.Returns the aspect of this (currently active) CodeTargetContext.Returns the ModelElement of this (currently active) CodeTargetContext
-
Constructor Details
-
CodeTargetContext
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
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
Returns the aspect of this (currently active) CodeTargetContext.- Returns:
- aspect or null
-
getModelElement
Returns the ModelElement of this (currently active) CodeTargetContext- Returns:
- ModelElement or null
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-