Package org.codehaus.groovy.ast.stmt

# Class SynchronizedStatement

java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.stmt.Statement
org.codehaus.groovy.ast.stmt.SynchronizedStatement

All Implemented Interfaces:
  `NodeMetaDataHandler`

public class SynchronizedStatement extends Statement
Represents a synchronized statement that provides mutual exclusion for a code block. A synchronized statement acquires a lock on the monitor associated with the control `expression` before executing the code block, ensuring that only one thread can execute the synchronized block at a time for the given monitor object.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SynchronizedStatement(Expression expression, Statement code)`
  Constructs a synchronized statement with the given monitor expression and code block.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Statement`
  `getCode()`
  Returns the statement executed within the synchronized block.
  `Expression`
  `getExpression()`
  Returns the monitor expression whose lock is acquired for synchronization.
  `void`
  `setCode(Statement statement)`
  Sets the statement executed within the synchronized block.
  `void`
  `setExpression(Expression expression)`
  Sets the monitor expression whose lock is acquired for synchronization.
  `void`
  `visit(GroovyCodeVisitor visitor)`
  Accepts a code visitor for AST traversal and transformation.

  ### Methods inherited from class org.codehaus.groovy.ast.stmt.Statement

  `addStatementAnnotation, addStatementLabel, copyStatementLabels, getStatementAnnotations, getStatementLabel, getStatementLabels, isEmpty, setStatementLabel`

  ### Methods inherited from class org.codehaus.groovy.ast.ASTNode

  `copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler

  `copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData`

- ## Constructor Details

  - ### SynchronizedStatement

    public SynchronizedStatement(Expression expression, Statement code)
    Constructs a synchronized statement with the given monitor expression and code block.
    Parameters:
      `expression` - the `Expression` that evaluates to the monitor object to synchronize on
      `code` - the `Statement` to execute under mutual exclusion

- ## Method Details

  - ### getCode

    public Statement getCode()
    Returns the statement executed within the synchronized block.
    Returns:
      the `Statement` executed under mutual exclusion

  - ### setCode

    public void setCode(Statement statement)
    Sets the statement executed within the synchronized block.
    Parameters:
      `statement` - the `Statement` to execute under mutual exclusion

  - ### getExpression

    public Expression getExpression()
    Returns the monitor expression whose lock is acquired for synchronization.
    Returns:
      the monitor `Expression`

  - ### visit

    public void visit(GroovyCodeVisitor visitor)
    Description copied from class: `ASTNode`
    Accepts a code visitor for AST traversal and transformation. Subclasses must implement this method to support visitor pattern-based processing. The visitor pattern enables decoupling of AST structure from processing logic.
    Overrides:
      `visit` in class `ASTNode`
    Parameters:
      `visitor` - the `GroovyCodeVisitor` to process this node

  - ### setExpression

    public void setExpression(Expression expression)
    Sets the monitor expression whose lock is acquired for synchronization.
    Parameters:
      `expression` - the monitor `Expression`