PsiElement (@NotNull PsiField field) { Project project = field.getProject(); PsiClass containingClass = field.getContainingClass(); if (containingClass == null) return null; String name = field.getName(); PsiExpression disjunction = tryCast(myFirstComparison.getParent(), PsiPolyadicExpression.class); if (disjunction == null) return null; int startOffset = myFirstComparison.getStartOffsetInParent(); int endOffset = myLastComparison.getStartOffsetInParent() + myLastComparison.getTextLength(); String origText = disjunction.getText(); String fieldReference = PsiResolveHelper.getInstance(project).resolveReferencedVariable(name, disjunction) == field ? name : containingClass.getQualifiedName() + "." + name; String replacementText = origText.substring(0, startOffset) + fieldReference + ".contains(" + myExpression.getText() + ")" + origText.substring(endOffset); PsiExpression replacement = JavaPsiFacade.getElementFactory(project).createExpressionFromText(replacementText, disjunction); if (replacement instanceof PsiMethodCallExpression && disjunction.getParent() instanceof PsiParenthesizedExpression) { disjunction = (PsiExpression)disjunction.getParent(); } return disjunction.replace(replacement); }