AnnotationContext (UExpression expression) { UElement parent = expression.getUastParent(); PsiModifierListOwner var = null; if (parent instanceof UVariable) { var = ObjectUtils.tryCast(parent.getJavaPsi(), PsiModifierListOwner.class); } else if (parent instanceof UBinaryExpression binOp) { UastBinaryOperator operator = binOp.getOperator(); UExpression rightOperand = binOp.getRightOperand(); if ((operator == UastBinaryOperator.ASSIGN || operator == UastBinaryOperator.PLUS_ASSIGN) && expressionsAreEquivalent(expression, rightOperand)) { UExpression leftOperand = UastUtils.skipParenthesizedExprDown(binOp.getLeftOperand()); UReferenceExpression lValue = ObjectUtils.tryCast(leftOperand, UReferenceExpression.class); if (lValue instanceof UQualifiedReferenceExpression) { lValue = ObjectUtils.tryCast(((UQualifiedReferenceExpression)lValue).getSelector(), UReferenceExpression.class); } if (lValue != null) { var = ObjectUtils.tryCast(lValue.resolve(), PsiModifierListOwner.class); } else { while (leftOperand instanceof UArrayAccessExpression) { leftOperand = ((UArrayAccessExpression)leftOperand).getReceiver(); } if (leftOperand instanceof UResolvable) { var = ObjectUtils.tryCast(((UResolvable)leftOperand).resolve(), PsiModifierListOwner.class); } } if (var != null && var.getLanguage().isKindOf(JavaLanguage.INSTANCE) && var instanceof PsiMethod && PsiTypes.voidType().equals(((PsiMethod)var).getReturnType())) { // If assignment target is Java, it resolves to the setter PsiParameter[] parameters = ((PsiMethod)var).getParameterList().getParameters(); if (parameters.length == 1) { var = parameters[0]; } } } } else if (parent instanceof USwitchClauseExpression) { if (((USwitchClauseExpression)parent).getCaseValues().contains(normalize(expression))) { USwitchExpression switchExpression = UastUtils.getParentOfType(parent, USwitchExpression.class); if (switchExpression != null) { UExpression selector = switchExpression.getExpression(); if (selector instanceof UResolvable) { var = ObjectUtils.tryCast(((UResolvable)selector).resolve(), PsiModifierListOwner.class); } } } } return fromModifierListOwner(var); }