private Expression getRetainedWithTarget ( Assignment node , VariableElement var ) { Expression lhs = node . getLeftHandSide ( ) ; if ( ! ( lhs instanceof FieldAccess ) ) { return new ThisExpression ( ElementUtil . getDeclaringClass ( var ) . asType ( ) ) ; } // To avoid duplicating the target expression we must save the result to a local variable. FieldAccess fieldAccess = ( FieldAccess ) lhs ; Expression target = fieldAccess . getExpression ( ) ; VariableElement targetVar = GeneratedVariableElement . newLocalVar ( "__rw$" + rwCount ++ , target . getTypeMirror ( ) , null ) ; TreeUtil . asStatementList ( TreeUtil . getOwningStatement ( lhs ) ) . add ( 0 , new VariableDeclarationStatement ( targetVar , null ) ) ; fieldAccess . setExpression ( new SimpleName ( targetVar ) ) ; CommaExpression commaExpr = new CommaExpression ( new Assignment ( new SimpleName ( targetVar ) , target ) ) ; node . replaceWith ( commaExpr ) ; commaExpr . addExpression ( node ) ; return new SimpleName ( targetVar ) ; }
Gets the target object for a call to the RetainedWith wrapper .