void (@NotNull PsiElement element) { if (!(element instanceof PsiReferenceExpression referenceExpression)) { return; } final PsiElement target = referenceExpression.resolve(); if (!(target instanceof PsiVariable variable)) { return; } NullableNotNullManager manager = NullableNotNullManager.getInstance(element.getProject()); final NullabilityAnnotationInfo info = manager.findEffectiveNullabilityInfo(variable); final PsiAnnotation annotation = info == null ? null : info.getAnnotation(); final CommentTracker commentTracker = new CommentTracker(); if (annotation == null) { final PsiStatement referenceStatement = PsiTreeUtil.getParentOfType(referenceExpression, PsiStatement.class); if (referenceStatement == null) { return; } final PsiElement parent = referenceStatement.getParent(); if (!(parent instanceof PsiCodeBlock codeBlock)) { return; } final PsiStatement[] statements = codeBlock.getStatements(); PsiStatement statementToDelete = null; for (PsiStatement statement : statements) { if (statement == referenceStatement) { break; } if (NullCheckedAssignmentPredicate.isNotNullAssertion(statement, variable) || NullCheckedAssignmentPredicate.isIfStatementNullCheck(statement, variable)) { statementToDelete = statement; break; } } if (statementToDelete == null) { return; } commentTracker.delete(statementToDelete); } PsiReplacementUtil.replaceExpressionAndShorten(referenceExpression, "java.util.Objects.requireNonNull(" + commentTracker.text(referenceExpression) + ")", commentTracker); }