use of org.codehaus.groovy.ast.stmt.Statement in project groovy-core by groovy.
the class ImmutableASTTransformation method createConstructorStatementArrayOrCloneable.
private Statement createConstructorStatementArrayOrCloneable(FieldNode fNode) {
final Expression fieldExpr = varX(fNode);
Expression initExpr = fNode.getInitialValueExpression();
ClassNode fieldType = fNode.getType();
final Expression array = findArg(fNode.getName());
final Statement assignInit;
if (initExpr == null || (initExpr instanceof ConstantExpression && ((ConstantExpression) initExpr).isNullExpression())) {
assignInit = assignS(fieldExpr, ConstantExpression.EMPTY_EXPRESSION);
} else {
assignInit = assignS(fieldExpr, cloneArrayOrCloneableExpr(initExpr, fieldType));
}
return ifElseS(equalsNullX(array), assignInit, assignS(fieldExpr, cloneArrayOrCloneableExpr(array, fieldType)));
}
use of org.codehaus.groovy.ast.stmt.Statement in project groovy-core by groovy.
the class ImmutableASTTransformation method createConstructorStatementCollection.
private Statement createConstructorStatementCollection(FieldNode fNode) {
final Expression fieldExpr = varX(fNode);
ClassNode fieldType = fieldExpr.getType();
Expression initExpr = fNode.getInitialValueExpression();
final Statement assignInit;
if (initExpr == null || (initExpr instanceof ConstantExpression && ((ConstantExpression) initExpr).isNullExpression())) {
assignInit = assignS(fieldExpr, ConstantExpression.EMPTY_EXPRESSION);
} else {
assignInit = assignS(fieldExpr, cloneCollectionExpr(initExpr, fieldType));
}
Expression collection = findArg(fNode.getName());
return ifElseS(equalsNullX(collection), assignInit, ifElseS(isInstanceOfX(collection, CLONEABLE_TYPE), assignS(fieldExpr, cloneCollectionExpr(cloneArrayOrCloneableExpr(collection, fieldType), fieldType)), assignS(fieldExpr, cloneCollectionExpr(collection, fieldType))));
}
use of org.codehaus.groovy.ast.stmt.Statement in project groovy-core by groovy.
the class ImmutableASTTransformation method createConstructorStatementMapSpecial.
private Statement createConstructorStatementMapSpecial(FieldNode fNode) {
final Expression fieldExpr = varX(fNode);
final ClassNode fieldType = fieldExpr.getType();
final Expression initExpr = fNode.getInitialValueExpression();
final Statement assignInit;
if (initExpr == null || (initExpr instanceof ConstantExpression && ((ConstantExpression) initExpr).isNullExpression())) {
assignInit = assignS(fieldExpr, ConstantExpression.EMPTY_EXPRESSION);
} else {
assignInit = assignS(fieldExpr, cloneCollectionExpr(initExpr, fieldType));
}
Expression namedArgs = findArg(fNode.getName());
Expression baseArgs = varX("args");
return ifElseS(equalsNullX(baseArgs), assignInit, ifElseS(equalsNullX(namedArgs), ifElseS(isTrueX(callX(baseArgs, "containsKey", constX(fNode.getName()))), assignS(fieldExpr, namedArgs), assignS(fieldExpr, cloneCollectionExpr(baseArgs, fieldType))), ifElseS(isOneX(callX(baseArgs, "size")), assignS(fieldExpr, cloneCollectionExpr(namedArgs, fieldType)), assignS(fieldExpr, cloneCollectionExpr(baseArgs, fieldType)))));
}
use of org.codehaus.groovy.ast.stmt.Statement in project groovy-core by groovy.
the class JavaAwareResolveVisitor method visitConstructor.
@Override
public void visitConstructor(ConstructorNode node) {
super.visitConstructor(node);
Statement code = node.getCode();
Expression cce = getConstructorCall(code);
if (cce == null)
return;
cce.visit(this);
}
use of org.codehaus.groovy.ast.stmt.Statement in project groovy-core by groovy.
the class LineCheckVisitor method visitConstructorOrMethod.
protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor) {
visitAnnotations(node);
analyseMethodHead(node);
Statement code = node.getCode();
visitClassCodeContainer(code);
}
Aggregations