PsiType (UExpression expression) { UElement parent = expression.getUastParent(); while (parent != null) { if (parent instanceof UMethod) { return ((UMethod)parent).getReturnType(); } if (parent instanceof ULambdaExpression) { PsiType lambdaType = ((ULambdaExpression)parent).getBody().getExpressionType(); if (lambdaType != null) return lambdaType; PsiType functionalInterfaceType = ((ULambdaExpression)parent).getFunctionalInterfaceType(); if (functionalInterfaceType != null) { return LambdaUtil.getFunctionalInterfaceReturnType(functionalInterfaceType); } return null; } if (parent instanceof UClass) { return null; } parent = parent.getUastParent(); } return null; }