@ Nullable public static ExpressionTree getReceiver ( ExpressionTree expressionTree ) { if ( expressionTree instanceof MethodInvocationTree ) { ExpressionTree methodSelect = ( ( MethodInvocationTree ) expressionTree ) . getMethodSelect ( ) ; if ( methodSelect instanceof IdentifierTree ) { return null ; } return getReceiver ( methodSelect ) ; } else if ( expressionTree instanceof MemberSelectTree ) { return ( ( MemberSelectTree ) expressionTree ) . getExpression ( ) ; } else if ( expressionTree instanceof MemberReferenceTree ) { return ( ( MemberReferenceTree ) expressionTree ) . getQualifierExpression ( ) ; } else { throw new IllegalStateException ( String . format ( "Expected expression '%s' to be a method invocation or field access, but was %s" , expressionTree , expressionTree . getKind ( ) ) ) ; } }
Returns the receiver of an expression .