}
private IfStatement getAutowiringIfStatement(ClassExpression targetClass, VariableExpression fieldExpression, BinaryExpression testTargetAssignment) {
VariableExpression appCtxVar = new VariableExpression("applicationContext", ClassHelper.make(GrailsWebApplicationContext.class));
BooleanExpression applicationContextCheck = new BooleanExpression(
new BinaryExpression(
new BinaryExpression(fieldExpression, GrailsASTUtils.EQUALS_OPERATOR, GrailsASTUtils.NULL_EXPRESSION),
Token.newSymbol("&&",0,0),
new BinaryExpression(appCtxVar, GrailsASTUtils.NOT_EQUALS_OPERATOR, GrailsASTUtils.NULL_EXPRESSION)));
BlockStatement performAutowireBlock = new BlockStatement();
ArgumentListExpression arguments = new ArgumentListExpression();
arguments.addExpression(fieldExpression);
arguments.addExpression(new ConstantExpression(1));
arguments.addExpression(new ConstantExpression(false));
BlockStatement assignFromApplicationContext = new BlockStatement();
ArgumentListExpression argWithClassName = new ArgumentListExpression();
MethodCallExpression getClassNameMethodCall = new MethodCallExpression(targetClass, "getName", new ArgumentListExpression());
argWithClassName.addExpression(getClassNameMethodCall);
assignFromApplicationContext.addStatement(new ExpressionStatement(new BinaryExpression(fieldExpression, ASSIGN, new MethodCallExpression(appCtxVar, "getBean", argWithClassName))));
BlockStatement elseBlock = new BlockStatement();
elseBlock.addStatement(new ExpressionStatement(testTargetAssignment));
performAutowireBlock.addStatement(new IfStatement(new BooleanExpression(new MethodCallExpression(appCtxVar, "containsBean", argWithClassName)), assignFromApplicationContext, elseBlock));
performAutowireBlock.addStatement(new ExpressionStatement(new MethodCallExpression(new PropertyExpression(appCtxVar,"autowireCapableBeanFactory"), "autowireBeanProperties", arguments)));
return new IfStatement(applicationContextCheck, performAutowireBlock, new BlockStatement());
}