TopmostQualifierDiff (@Nullable PsiExpression left, @Nullable PsiExpression right) { PsiMethodCallExpression leftCall = tryCast(left, PsiMethodCallExpression.class); PsiMethodCallExpression rightCall = tryCast(right, PsiMethodCallExpression.class); if(leftCall == null || rightCall == null) return null; while(true) { PsiReferenceExpression leftMethodExpression = leftCall.getMethodExpression(); PsiReferenceExpression rightMethodExpression = rightCall.getMethodExpression(); if(tryCast(leftMethodExpression.resolve(), PsiMethod.class) != tryCast(rightMethodExpression.resolve(), PsiMethod.class)) return null; PsiExpression[] leftExpressions = leftCall.getArgumentList().getExpressions(); PsiExpression[] rightExpressions = rightCall.getArgumentList().getExpressions(); int length = leftExpressions.length; if(length != rightExpressions.length) return null; for (int i = 0; i < length; i++) { if(!ourEquivalence.expressionsAreEquivalent(leftExpressions[i], rightExpressions[i])) return null; } PsiExpression leftQualifier = leftMethodExpression.getQualifierExpression(); leftCall = tryCast(leftQualifier, PsiMethodCallExpression.class); PsiExpression rightQualifier = rightMethodExpression.getQualifierExpression(); rightCall = tryCast(rightQualifier, PsiMethodCallExpression.class); if(leftCall == null || rightCall == null) { return new TopmostQualifierDiff(leftQualifier, rightQualifier); } } }