Package org.codehaus.groovy.ast

# Interface NodeMetaDataHandler

All Known Implementing Classes:
  `AbstractGinqExpression`, `AnnotatedNode`, `AnnotationConstantExpression`, `AnnotationNode`, `ArgumentListExpression`, `ArrayExpression`, `AssertStatement`, `ASTNode`, `AttributeExpression`, `BinaryExpression`, `BitwiseNegationExpression`, `BlockStatement`, `BooleanExpression`, `BreakStatement`, `BytecodeExpression`, `BytecodeSequence`, `CaseStatement`, `CastExpression`, `CatchStatement`, `ClassExpression`, `ClassNode`, `ClosureExpression`, `ClosureListExpression`, `CompareIdentityExpression`, `CompareToNullExpression`, `CompileUnit`, `ConstantExpression`, `ConstructorCallExpression`, `ConstructorNode`, `ContinueStatement`, `DataSourceExpression`, `DeclarationExpression`, `DecompiledClassNode`, `DoWhileStatement`, `ElvisOperatorExpression`, `EmptyExpression`, `EmptyStatement`, `EnumConstantClassNode`, `Expression`, `ExpressionAsVariableSlot`, `ExpressionStatement`, `ExtensionMethodNode`, `FieldExpression`, `FieldNode`, `FilterExpression`, `ForStatement`, `FromExpression`, `GenericsType`, `GinqExpression`, `GroovyParser.AdditiveExprAltContext`, `GroovyParser.AndExprAltContext`, `GroovyParser.AnnotatedQualifiedClassNameContext`, `GroovyParser.AnnotationContext`, `GroovyParser.AnnotationNameContext`, `GroovyParser.AnnotationsOptContext`, `GroovyParser.AnonymousInnerClassDeclarationContext`, `GroovyParser.ArgumentsContext`, `GroovyParser.ArrayInitializerContext`, `GroovyParser.AssertStatementContext`, `GroovyParser.AssertStmtAltContext`, `GroovyParser.AssignmentExprAltContext`, `GroovyParser.AsyncClosureExprAltContext`, `GroovyParser.AwaitExprAltContext`, `GroovyParser.BlockContext`, `GroovyParser.BlockStatementContext`, `GroovyParser.BlockStatementsContext`, `GroovyParser.BlockStatementsOptContext`, `GroovyParser.BlockStmtAltContext`, `GroovyParser.BooleanLiteralAltContext`, `GroovyParser.BreakStatementContext`, `GroovyParser.BreakStmtAltContext`, `GroovyParser.BuiltInTypeContext`, `GroovyParser.BuiltInTypePrmrAltContext`, `GroovyParser.CastExprAltContext`, `GroovyParser.CastParExpressionContext`, `GroovyParser.CatchClauseContext`, `GroovyParser.CatchTypeContext`, `GroovyParser.ClassBodyContext`, `GroovyParser.ClassBodyDeclarationContext`, `GroovyParser.ClassDeclarationContext`, `GroovyParser.ClassNameContext`, `GroovyParser.ClassOrInterfaceModifierContext`, `GroovyParser.ClassOrInterfaceModifiersContext`, `GroovyParser.ClassOrInterfaceModifiersOptContext`, `GroovyParser.ClosureContext`, `GroovyParser.ClosureOrLambdaExpressionContext`, `GroovyParser.ClosureOrLambdaExpressionPrmrAltContext`, `GroovyParser.CoercionTypeContext`, `GroovyParser.CommandArgumentContext`, `GroovyParser.CommandExprAltContext`, `GroovyParser.CommandExpressionContext`, `GroovyParser.CompactConstructorDeclarationContext`, `GroovyParser.CompilationUnitContext`, `GroovyParser.ConditionalExprAltContext`, `GroovyParser.ConditionalStatementContext`, `GroovyParser.ConditionalStmtAltContext`, `GroovyParser.ContinueStatementContext`, `GroovyParser.ContinueStmtAltContext`, `GroovyParser.CreatedNameContext`, `GroovyParser.CreatorContext`, `GroovyParser.DeferStmtAltContext`, `GroovyParser.Dim0Context`, `GroovyParser.Dim1Context`, `GroovyParser.DoWhileStmtAltContext`, `GroovyParser.DynamicMemberNameContext`, `GroovyParser.ElementValueArrayInitializerContext`, `GroovyParser.ElementValueContext`, `GroovyParser.ElementValuePairContext`, `GroovyParser.ElementValuePairNameContext`, `GroovyParser.ElementValuePairsContext`, `GroovyParser.ElementValuesContext`, `GroovyParser.EmptyStmtAltContext`, `GroovyParser.EnhancedArgumentListElementContext`, `GroovyParser.EnhancedArgumentListInParContext`, `GroovyParser.EnhancedExpressionContext`, `GroovyParser.EnhancedForControlContext`, `GroovyParser.EnhancedStatementExpressionContext`, `GroovyParser.EnumConstantContext`, `GroovyParser.EnumConstantsContext`, `GroovyParser.EqualityExprAltContext`, `GroovyParser.ExclusiveOrExprAltContext`, `GroovyParser.ExpressionContext`, `GroovyParser.ExpressionInParContext`, `GroovyParser.ExpressionListContext`, `GroovyParser.ExpressionListElementContext`, `GroovyParser.ExpressionStmtAltContext`, `GroovyParser.FieldDeclarationContext`, `GroovyParser.FinallyBlockContext`, `GroovyParser.FloatingPointLiteralAltContext`, `GroovyParser.ForControlContext`, `GroovyParser.ForInitContext`, `GroovyParser.FormalParameterContext`, `GroovyParser.FormalParameterListContext`, `GroovyParser.FormalParametersContext`, `GroovyParser.ForStmtAltContext`, `GroovyParser.ForUpdateContext`, `GroovyParser.GroovyParserRuleContext`, `GroovyParser.GstringContext`, `GroovyParser.GstringPathContext`, `GroovyParser.GstringPrmrAltContext`, `GroovyParser.GstringValueContext`, `GroovyParser.IdentifierContext`, `GroovyParser.IdentifierPrmrAltContext`, `GroovyParser.IfElseStatementContext`, `GroovyParser.ImplicationExprAltContext`, `GroovyParser.ImportDeclarationContext`, `GroovyParser.InclusiveOrExprAltContext`, `GroovyParser.IndexPropertyArgsContext`, `GroovyParser.IndexVariableContext`, `GroovyParser.IntegerLiteralAltContext`, `GroovyParser.IntersectionTypeContext`, `GroovyParser.KeyedPairContext`, `GroovyParser.KeywordsContext`, `GroovyParser.LabeledStmtAltContext`, `GroovyParser.LambdaBodyContext`, `GroovyParser.ListContext`, `GroovyParser.ListPrmrAltContext`, `GroovyParser.LiteralContext`, `GroovyParser.LiteralPrmrAltContext`, `GroovyParser.LocalVariableDeclarationContext`, `GroovyParser.LocalVariableDeclarationStmtAltContext`, `GroovyParser.LogicalAndExprAltContext`, `GroovyParser.LogicalOrExprAltContext`, `GroovyParser.LoopStatementContext`, `GroovyParser.LoopStmtAltContext`, `GroovyParser.MapContext`, `GroovyParser.MapEntryContext`, `GroovyParser.MapEntryLabelContext`, `GroovyParser.MapEntryListContext`, `GroovyParser.MapPrmrAltContext`, `GroovyParser.MatchingTypeContext`, `GroovyParser.MemberDeclarationContext`, `GroovyParser.MethodBodyContext`, `GroovyParser.MethodDeclarationContext`, `GroovyParser.MethodNameContext`, `GroovyParser.ModifierContext`, `GroovyParser.ModifiersContext`, `GroovyParser.ModifiersOptContext`, `GroovyParser.MultipleAssignmentExprAltContext`, `GroovyParser.MultiplicativeExprAltContext`, `GroovyParser.NamedPropertyArgsContext`, `GroovyParser.NamePartContext`, `GroovyParser.NewPrmrAltContext`, `GroovyParser.NlsContext`, `GroovyParser.NonWildcardTypeArgumentsContext`, `GroovyParser.NotInstanceofTypeContext`, `GroovyParser.NullLiteralAltContext`, `GroovyParser.OriginalForControlContext`, `GroovyParser.PackageDeclarationContext`, `GroovyParser.ParenPrmrAltContext`, `GroovyParser.ParExpressionContext`, `GroovyParser.PathElementContext`, `GroovyParser.PathExpressionContext`, `GroovyParser.PostfixExprAltContext`, `GroovyParser.PostfixExpressionContext`, `GroovyParser.PowerExprAltContext`, `GroovyParser.PrimaryContext`, `GroovyParser.PrimitiveTypeContext`, `GroovyParser.QualifiedClassNameContext`, `GroovyParser.QualifiedClassNameListContext`, `GroovyParser.QualifiedNameContext`, `GroovyParser.QualifiedNameElementContext`, `GroovyParser.QualifiedNameElementsContext`, `GroovyParser.QualifiedStandardClassNameContext`, `GroovyParser.ReferenceTypeContext`, `GroovyParser.RegexExprAltContext`, `GroovyParser.RelationalExprAltContext`, `GroovyParser.ResourceContext`, `GroovyParser.ResourceListContext`, `GroovyParser.ResourcesContext`, `GroovyParser.ReturnStmtAltContext`, `GroovyParser.ReturnTypeContext`, `GroovyParser.ScriptStatementContext`, `GroovyParser.ScriptStatementsContext`, `GroovyParser.SepContext`, `GroovyParser.ShiftExprAltContext`, `GroovyParser.StandardLambdaExpressionContext`, `GroovyParser.StandardLambdaParametersContext`, `GroovyParser.StatementContext`, `GroovyParser.StatementExpressionContext`, `GroovyParser.StringLiteralAltContext`, `GroovyParser.StringLiteralContext`, `GroovyParser.SuperPrmrAltContext`, `GroovyParser.SwitchBlockStatementExpressionGroupContext`, `GroovyParser.SwitchBlockStatementGroupContext`, `GroovyParser.SwitchExprAltContext`, `GroovyParser.SwitchExpressionContext`, `GroovyParser.SwitchExpressionLabelContext`, `GroovyParser.SwitchLabelContext`, `GroovyParser.SwitchStatementContext`, `GroovyParser.SynchronizedStmtAltContext`, `GroovyParser.ThisFormalParameterContext`, `GroovyParser.ThisPrmrAltContext`, `GroovyParser.ThrowStmtAltContext`, `GroovyParser.TryCatchStatementContext`, `GroovyParser.TryCatchStmtAltContext`, `GroovyParser.TypeArgumentContext`, `GroovyParser.TypeArgumentsContext`, `GroovyParser.TypeArgumentsOrDiamondContext`, `GroovyParser.TypeBoundContext`, `GroovyParser.TypeContext`, `GroovyParser.TypeDeclarationContext`, `GroovyParser.TypeListContext`, `GroovyParser.TypeNamePairContext`, `GroovyParser.TypeNamePairsContext`, `GroovyParser.TypeParameterContext`, `GroovyParser.TypeParametersContext`, `GroovyParser.UnaryAddExprAltContext`, `GroovyParser.UnaryNotExprAltContext`, `GroovyParser.VariableDeclarationContext`, `GroovyParser.VariableDeclaratorContext`, `GroovyParser.VariableDeclaratorIdContext`, `GroovyParser.VariableDeclaratorsContext`, `GroovyParser.VariableInitializerContext`, `GroovyParser.VariableModifierContext`, `GroovyParser.VariableModifiersContext`, `GroovyParser.VariableModifiersOptContext`, `GroovyParser.VariableNamesContext`, `GroovyParser.WhileStmtAltContext`, `GroovyParser.YieldReturnStmtAltContext`, `GroovyParser.YieldStatementContext`, `GroovyParser.YieldStmtAltContext`, `GroupExpression`, `GStringExpression`, `HavingExpression`, `IfStatement`, `ImportNode`, `InnerClassNode`, `InterfaceHelperClassNode`, `IntersectionTypeClassNode`, `JoinExpression`, `LambdaExpression`, `LimitExpression`, `ListExpression`, `ListOfExpressionsExpression`, `MapEntryExpression`, `MapExpression`, `MethodCallExpression`, `MethodNode`, `MethodPointerExpression`, `MethodReferenceExpression`, `MixinNode`, `ModifierNode`, `ModuleNode`, `NamedArgumentListExpression`, `NotExpression`, `OnExpression`, `OrderExpression`, `PackageNode`, `Parameter`, `PostfixExpression`, `PrefixExpression`, `ProcessExpression`, `PropertyExpression`, `PropertyNode`, `RangeExpression`, `RecordComponentNode`, `ReturnStatement`, `SelectExpression`, `SetOperationExpression`, `ShutdownExpression`, `SpreadExpression`, `SpreadMapExpression`, `Statement`, `StaticMethodCallExpression`, `SwitchStatement`, `SynchronizedStatement`, `TemporaryVariableExpression`, `TernaryExpression`, `ThrowStatement`, `TryCatchStatement`, `TupleExpression`, `UnaryMinusExpression`, `UnaryPlusExpression`, `VariableExpression`, `VariableSlotLoader`, `WhereExpression`, `WhileStatement`, `WideningCategories.LowestUpperBoundClassNode`

public interface NodeMetaDataHandler
An interface to mark a node being able to handle metadata.

The default `newMetaDataMap()` returns a `ListHashMap` wrapped in `Collections.synchronizedMap(java.util.Map<K, V>)`, so concurrent compiles sharing an AST node (e.g. built-in annotation `ClassNode`s cached by `ClassHelper`) cannot trip an `ArrayIndexOutOfBoundsException` during the array-to-`HashMap` transition in `ListHashMap.put`. Implementers that store the map in a field should declare it `volatile` so the unsynchronized fast-path read in the default methods sees publish-time writes.

Since:
  3.0.0

- ## Method Summary

  Modifier and Type
  Method
  Description
  `default void`
  `copyNodeMetaData(NodeMetaDataHandler other)`
  Copies all node metadata from the other node to this one
  `Map<?,?>`
  `getMetaDataMap()`
  Returns the underlying metadata map.
  `default Map<?,?>`
  `getNodeMetaData()`
  Returns an unmodifiable snapshot of the current node metadata.
  `default <T> T`
  `getNodeMetaData(Object key)`
  Gets the node metadata.
  `default <T> T`
  `getNodeMetaData(Object key, Function<?,? extends T> valFn)`
  Gets the node metadata.
  `default Map<?,?>`
  `newMetaDataMap()`
  Creates the backing metadata map.
  `default Object`
  `putNodeMetaData(Object key, Object value)`
  Sets the node metadata but allows overwriting values.
  `default void`
  `removeNodeMetaData(Object key)`
  Removes a node metadata entry.
  `void`
  `setMetaDataMap(Map<?,?> metaDataMap)`
  `default void`
  `setNodeMetaData(Object key, Object value)`
  Sets the node metadata.

- ## Method Details

  - ### getNodeMetaData

    default <T> T getNodeMetaData(Object key)
    Gets the node metadata.
    Parameters:
      `key` - the metadata key
    Returns:
      the node metadata value for this key

  - ### getNodeMetaData

    default <T> T getNodeMetaData(Object key, Function<?,? extends T> valFn)
    Gets the node metadata.
    Parameters:
      `key` - the metadata key
      `valFn` - the metadata value supplier
    Returns:
      the node metadata value for this key

  - ### copyNodeMetaData

    default void copyNodeMetaData(NodeMetaDataHandler other)
    Copies all node metadata from the other node to this one
    Parameters:
      `other` - the other node

  - ### setNodeMetaData

    default void setNodeMetaData(Object key, Object value)
    Sets the node metadata.
    Parameters:
      `key` - the metadata key
      `value` - the metadata value
    Throws:
      `GroovyBugError` - if key is null or there is already metadata for key

  - ### putNodeMetaData

    default Object putNodeMetaData(Object key, Object value)
    Sets the node metadata but allows overwriting values.
    Parameters:
      `key` - the metadata key
      `value` - the metadata value
    Returns:
      the old node metadata value for this key
    Throws:
      `GroovyBugError` - if key is null

  - ### removeNodeMetaData

    default void removeNodeMetaData(Object key)
    Removes a node metadata entry.
    Parameters:
      `key` - the metadata key
    Throws:
      `GroovyBugError` - if the key is null

  - ### getNodeMetaData

    default Map<?,?> getNodeMetaData()
    Returns an unmodifiable snapshot of the current node metadata.
    Returns:
      the node metadata. Always not null.

  - ### getMetaDataMap

    Map<?,?> getMetaDataMap()
    Returns the underlying metadata map. The map returned by the default `newMetaDataMap()` is internally synchronized, so individual `get`/`put`/`remove` calls are thread-safe; however, per the `Collections.synchronizedMap(java.util.Map<K, V>)` contract, iteration over the returned map (or any of its `keySet`, `values`, or `entrySet` views) must be done inside a `synchronized (map) { ... }` block to avoid `ConcurrentModificationException`.

  - ### newMetaDataMap

    default Map<?,?> newMetaDataMap()
    Creates the backing metadata map. The default returns a `ListHashMap` wrapped in `Collections.synchronizedMap(java.util.Map<K, V>)` for thread-safe per-entry access; subclasses may override to supply an alternative map (e.g. for different memory/concurrency trade-offs).
    Since:
      5.0.0

  - ### setMetaDataMap

    void setMetaDataMap(Map<?,?> metaDataMap)