diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java index d2a350e0d918..95a4eca5463a 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java @@ -27,7 +27,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.JavaSdkVersion; -import com.intellij.openapi.projectRoots.JavaSdkVersionUtil; +import com.intellij.openapi.projectRoots.JavaVersionService; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.TextRange; import com.intellij.pom.java.LanguageLevel; @@ -509,7 +509,8 @@ public class GenericsHighlightUtil { final PsiType retErasure2 = TypeConversionUtil.erasure(superMethod.getReturnType()); boolean differentReturnTypeErasure = !Comparing.equal(retErasure1, retErasure2); - if (checkEqualsSuper && JavaSdkVersionUtil.isAtLeast(checkMethod, JavaSdkVersion.JDK_1_7)) { + final boolean atLeast17 = JavaVersionService.getInstance().isAtLeast(checkMethod, JavaSdkVersion.JDK_1_7); + if (checkEqualsSuper && atLeast17) { if (retErasure1 != null && retErasure2 != null) { differentReturnTypeErasure = !TypeConversionUtil.isAssignable(retErasure1, retErasure2); } else { @@ -520,8 +521,17 @@ public class GenericsHighlightUtil { if (differentReturnTypeErasure && !TypeConversionUtil.isVoidType(retErasure1) && !TypeConversionUtil.isVoidType(retErasure2) && - !(checkEqualsSuper && Arrays.equals(superSignature.getParameterTypes(), signatureToCheck.getParameterTypes()))) { - return null; + !(checkEqualsSuper && Arrays.equals(superSignature.getParameterTypes(), signatureToCheck.getParameterTypes())) && + !atLeast17) { + int idx = 0; + final PsiType[] parameterTypes = signatureToCheck.getParameterTypes(); + boolean erasure = parameterTypes.length > 0; + for (PsiType type : superSignature.getParameterTypes()) { + erasure &= Comparing.equal(type, TypeConversionUtil.erasure(parameterTypes[idx])); + idx++; + } + + if (!erasure) return null; } if (!checkEqualsSuper && MethodSignatureUtil.isSubsignature(superSignature, signatureToCheck)) { diff --git a/java/java-impl/src/com/intellij/openapi/projectRoots/JavaVersionServiceImpl.java b/java/java-impl/src/com/intellij/openapi/projectRoots/JavaVersionServiceImpl.java index 366a0b870404..b1bba82602b5 100644 --- a/java/java-impl/src/com/intellij/openapi/projectRoots/JavaVersionServiceImpl.java +++ b/java/java-impl/src/com/intellij/openapi/projectRoots/JavaVersionServiceImpl.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.projectRoots; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.psi.PsiElement; /** @@ -22,8 +23,15 @@ import com.intellij.psi.PsiElement; * Date: 3/28/12 */ public class JavaVersionServiceImpl extends JavaVersionService { + private boolean myTestVersion = false; + + public void setTestVersion(boolean testVersion) { + myTestVersion = testVersion; + } + @Override public boolean isAtLeast(PsiElement element, JavaSdkVersion version) { + if (ApplicationManager.getApplication().isUnitTestMode()) return myTestVersion; return JavaSdkVersionUtil.isAtLeast(element, version); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA66311.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA66311.java new file mode 100644 index 000000000000..d67ac65edd9f --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA66311.java @@ -0,0 +1,21 @@ +import java.util.*; + +class ErasureTest { + public static double[] toArrayDouble(List v) { + return null; + } + + public static double[][] toArrayDouble(List v) { + return null; + } +} + +class ErasureTest1 { + public static double[] toArrayDouble(List v) { + return null; + } + + public static double[][] toArrayDouble(List v) { + return null; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA66311_16.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA66311_16.java new file mode 100644 index 000000000000..db7abdc9fef7 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA66311_16.java @@ -0,0 +1,31 @@ +import java.util.*; + +class ErasureTest { + public static double[] toArrayDouble(List v) { + return null; + } + + public static double[][] toArrayDouble(List v) { + return null; + } +} + +class ErasureTest1 { + public static double[] toArrayDouble(List v) { + return null; + } + + public static double[][] toArrayDouble(List v) { + return null; + } +} + +class ErasureTest2 { + public static double[] toArrayDouble(List v) { + return null; + } + + public static double[] toArrayDouble(List v) { + return null; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java index 7d767cf5c083..4471d00c1e30 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java @@ -4,6 +4,8 @@ import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection; import com.intellij.codeInspection.unusedImport.UnusedImportLocalInspection; import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.openapi.projectRoots.JavaVersionService; +import com.intellij.openapi.projectRoots.JavaVersionServiceImpl; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; import com.intellij.openapi.roots.LanguageLevelProjectExtension; @@ -100,7 +102,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { public void testSOE() throws Exception { doTest(true); } public void testGenericExtendException() throws Exception { doTest(false); } - public void testSameErasureDifferentReturnTypes() throws Exception { doTest(false); } + public void testSameErasureDifferentReturnTypes() throws Exception { doTest17Incompatibility(); } public void testSameErasureDifferentReturnTypesJdk14() throws Exception { doTest(false); } public void testDeepConflictingReturnTypes() throws Exception { doTest(false); } public void testInheritFromTypeParameter() throws Exception { doTest(false); } @@ -116,13 +118,16 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { public void testPrivateInnerClassRef() throws Exception { doTest(false); } public void testWideningCastToTypeParam() throws Exception { doTest(false); } public void testCapturedWildcardAssignments() throws Exception { doTest(false);} - public void testTypeParameterBoundVisibility() throws Exception { doTest(false);} + public void testTypeParameterBoundVisibility() throws Exception { doTest17Incompatibility(); } public void testTypeParameterBoundVisibilityJdk14() throws Exception { doTest(false);} public void testUncheckedWarningsLevel6() throws Exception { doTest(true);} public void testIDEA77991() throws Exception { doTest(false);} public void testIDEA80386() throws Exception { doTest(false);} + public void testIDEA66311() throws Exception { doTest17Incompatibility();} + public void testIDEA66311_16() throws Exception { doTest(false);} + public void testJavaUtilCollections_NoVerify() throws Exception { PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule())); @@ -132,4 +137,15 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { configureFromFileText("Collections.java", text.replaceAll("\r","\n")); doTestConfiguredFile(false, false, null); } + + private void doTest17Incompatibility() throws Exception { + final JavaVersionServiceImpl javaVersionService = (JavaVersionServiceImpl)JavaVersionService.getInstance(); + try { + javaVersionService.setTestVersion(true); + doTest(false); + } + finally { + javaVersionService.setTestVersion(false); + } + } }