ExtractableExpressionPart (@NotNull PsiExpression expression, @NotNull List<? extends PsiElement> scope, @Nullable ComplexityHolder complexityHolder) { if (expression instanceof PsiReferenceExpression) { return matchVariable((PsiReferenceExpression)expression, scope); } boolean isConstant = PsiUtil.isConstantExpression(expression); if (isConstant) { // Avoid replacement of coincidentally equal expressions containing different constant fields // E.g. don't count as equal values expressions like (Foo.A + 1) and (Bar.B - 2) if (PsiTreeUtil.findChildOfType(expression, PsiJavaCodeReferenceElement.class) == null) { return matchConstant(expression); } } PsiElement parent = PsiUtil.skipParenthesizedExprUp(expression.getParent()); if (parent instanceof PsiExpressionStatement || parent instanceof PsiExpressionList && parent.getParent() instanceof PsiExpressionListStatement) { return null; } if (complexityHolder != null && (isConstant || complexityHolder.isAcceptableExpression(expression))) { return matchExpression(expression); } return null; }