use of org.codehaus.groovy.ast.stmt.SynchronizedStatement in project groovy by apache.
the class AntlrParserPlugin method statement.
// Statements
//-------------------------------------------------------------------------
protected Statement statement(AST node) {
Statement statement = null;
int type = node.getType();
switch(type) {
case SLIST:
case LITERAL_finally:
statement = statementList(node);
break;
case METHOD_CALL:
statement = methodCall(node);
break;
case VARIABLE_DEF:
statement = variableDef(node);
break;
case LABELED_STAT:
return labelledStatement(node);
case LITERAL_assert:
statement = assertStatement(node);
break;
case LITERAL_break:
statement = breakStatement(node);
break;
case LITERAL_continue:
statement = continueStatement(node);
break;
case LITERAL_if:
statement = ifStatement(node);
break;
case LITERAL_for:
statement = forStatement(node);
break;
case LITERAL_return:
statement = returnStatement(node);
break;
case LITERAL_synchronized:
statement = synchronizedStatement(node);
break;
case LITERAL_switch:
statement = switchStatement(node);
break;
case LITERAL_try:
statement = tryStatement(node);
break;
case LITERAL_throw:
statement = throwStatement(node);
break;
case LITERAL_while:
statement = whileStatement(node);
break;
default:
statement = new ExpressionStatement(expression(node));
}
if (statement != null) {
configureAST(statement, node);
}
return statement;
}
use of org.codehaus.groovy.ast.stmt.SynchronizedStatement in project groovy by apache.
the class LazyASTTransformation method addDoubleCheckedLockingBody.
private static void addDoubleCheckedLockingBody(BlockStatement body, FieldNode fieldNode, Expression initExpr) {
final Expression fieldExpr = varX(fieldNode);
final VariableExpression localVar = varX(fieldNode.getName() + "_local");
body.addStatement(declS(localVar, fieldExpr));
body.addStatement(ifElseS(notNullX(localVar), returnS(localVar), new SynchronizedStatement(syncTarget(fieldNode), ifElseS(notNullX(fieldExpr), returnS(fieldExpr), returnS(assignX(fieldExpr, initExpr))))));
}
use of org.codehaus.groovy.ast.stmt.SynchronizedStatement in project groovy by apache.
the class LazyASTTransformation method createSoftGetter.
private static void createSoftGetter(FieldNode fieldNode, Expression initExpr, ClassNode type) {
final BlockStatement body = new BlockStatement();
final Expression fieldExpr = varX(fieldNode);
final Expression resExpr = varX("res", type);
final MethodCallExpression callExpression = callX(fieldExpr, "get");
callExpression.setSafe(true);
body.addStatement(declS(resExpr, callExpression));
final Statement mainIf = ifElseS(notNullX(resExpr), stmt(resExpr), block(assignS(resExpr, initExpr), assignS(fieldExpr, ctorX(SOFT_REF, resExpr)), stmt(resExpr)));
if (fieldNode.isVolatile()) {
body.addStatement(ifElseS(notNullX(resExpr), stmt(resExpr), new SynchronizedStatement(syncTarget(fieldNode), block(assignS(resExpr, callExpression), mainIf))));
} else {
body.addStatement(mainIf);
}
addMethod(fieldNode, body, type);
}
Aggregations