mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
jdk7 incompatibility: red good code is green: always check signature erasure equals for jdk7 (IDEA-66311)
add checks for param erasure for jdk6
This commit is contained in:
+14
-4
@@ -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)) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import java.util.*;
|
||||
|
||||
class ErasureTest {
|
||||
<error descr="'toArrayDouble(List<? extends Number>)' clashes with 'toArrayDouble(List<double[]>)'; both methods have same erasure">public static double[] toArrayDouble(List<? extends Number> v)</error> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static double[][] toArrayDouble(List<double[]> v) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class ErasureTest1 {
|
||||
<error descr="'toArrayDouble(List<? extends Number>)' clashes with 'toArrayDouble(List)'; both methods have same erasure">public static double[] toArrayDouble(List<? extends Number> v)</error> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static double[][] toArrayDouble(List v) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
import java.util.*;
|
||||
|
||||
class ErasureTest {
|
||||
public static double[] toArrayDouble(List<? extends Number> v) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static double[][] toArrayDouble(List<double[]> v) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class ErasureTest1 {
|
||||
<error descr="'toArrayDouble(List<? extends Number>)' clashes with 'toArrayDouble(List)'; both methods have same erasure">public static double[] toArrayDouble(List<? extends Number> v)</error> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static double[][] toArrayDouble(List v) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class ErasureTest2 {
|
||||
<error descr="'toArrayDouble(List<? extends Number>)' clashes with 'toArrayDouble(List<String>)'; both methods have same erasure">public static double[] toArrayDouble(List<? extends Number> v)</error> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static double[] toArrayDouble(List<String> v) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+18
-2
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user