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
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
ConstructorsConstructorDescriptionSynchronizedStatement(Expression expression, Statement code) Constructs a synchronized statement with the given monitor expression and code block. -
Method Summary
Modifier and TypeMethodDescriptiongetCode()Returns the statement executed within the synchronized block.Returns the monitor expression whose lock is acquired for synchronization.voidSets the statement executed within the synchronized block.voidsetExpression(Expression expression) Sets the monitor expression whose lock is acquired for synchronization.voidvisit(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, setStatementLabelMethods inherited from class org.codehaus.groovy.ast.ASTNode
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePositionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler
copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData
-
Constructor Details
-
SynchronizedStatement
Constructs a synchronized statement with the given monitor expression and code block.- Parameters:
expression- theExpressionthat evaluates to the monitor object to synchronize oncode- theStatementto execute under mutual exclusion
-
-
Method Details
-
getCode
Returns the statement executed within the synchronized block.- Returns:
- the
Statementexecuted under mutual exclusion
-
setCode
Sets the statement executed within the synchronized block.- Parameters:
statement- theStatementto execute under mutual exclusion
-
getExpression
Returns the monitor expression whose lock is acquired for synchronization.- Returns:
- the monitor
Expression
-
visit
Description copied from class:ASTNodeAccepts 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:
visitin classASTNode- Parameters:
visitor- theGroovyCodeVisitorto process this node
-
setExpression
Sets the monitor expression whose lock is acquired for synchronization.- Parameters:
expression- the monitorExpression
-