InvalidComparatorMethodReferenceInspection: fixes according to IDEA-CR-13278
[idea/community.git] / java / java-analysis-impl / src / com / intellij / codeInspection / InvalidComparatorMethodReferenceInspection.java
index ef837a8957c4626a8347a934163ce18c3d46746f..25fa03ecb7345800f639f9952fa101e7a27628b3 100644 (file)
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.FileModificationService;
 import com.intellij.openapi.project.Project;
 import com.intellij.psi.*;
 import com.intellij.psi.codeStyle.JavaCodeStyleManager;
+import com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionBase;
 import org.jetbrains.annotations.Nls;
 import org.jetbrains.annotations.NotNull;
 
@@ -31,7 +32,7 @@ public class InvalidComparatorMethodReferenceInspection extends BaseJavaBatchLoc
       public void visitMethodReferenceExpression(PsiMethodReferenceExpression expression) {
         PsiExpression qualifierExpression = expression.getQualifierExpression();
         PsiElement referenceNameElement = expression.getReferenceNameElement();
-        if (!(qualifierExpression instanceof PsiReference) || referenceNameElement == null) {
+        if (!(qualifierExpression instanceof PsiReferenceExpressionBase) || referenceNameElement == null) {
           return;
         }
         String name = referenceNameElement.getText();
@@ -46,12 +47,16 @@ public class InvalidComparatorMethodReferenceInspection extends BaseJavaBatchLoc
         if (targetType == null) {
           return;
         }
+        String targetClassName = targetType.getQualifiedName();
+        if(targetClassName == null || !targetClassName.equals(CommonClassNames.JAVA_UTIL_COMPARATOR)) {
+          return;
+        }
         PsiElement refType = ((PsiReference)qualifierExpression).resolve();
         if (!(refType instanceof PsiClass)) {
           return;
         }
         String className = ((PsiClass)refType).getQualifiedName();
-        if (className == null || (!className.equals(Integer.class.getName()) && !className.equals(Math.class.getName()))) {
+        if (className == null || (!className.equals(CommonClassNames.JAVA_LANG_INTEGER) && !className.equals(Math.class.getName()))) {
           return;
         }
         //noinspection DialogTitleCapitalization