simplify ? extends Object (IDEA-91631; IDEA-91144)

This commit is contained in:
anna
2012-09-18 12:46:54 +02:00
parent 5f51e64449
commit 21a0d8565e
7 changed files with 76 additions and 0 deletions
@@ -258,6 +258,7 @@ public class GenericsUtil {
if (((PsiWildcardType)acceptedBound).isExtends() != wildcardType.isExtends()) return PsiWildcardType.createUnbounded(manager);
return acceptedBound;
}
if (wildcardType.isExtends() && acceptedBound.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) return PsiWildcardType.createUnbounded(manager);
if (acceptedBound.equals(bound)) return wildcardType;
return wildcardType.isExtends()
? PsiWildcardType.createExtends(manager, acceptedBound)
@@ -0,0 +1,12 @@
interface Generic<T> {
SomeGeneric<? extends T> foo();
}
class II implements Generic<Object> {
public SomeGeneric<?> foo() {
<selection>return null; //To change body of implemented methods use File | Settings | File Templates.</selection>
}
}
class SomeGeneric<P> {
}
@@ -0,0 +1,10 @@
interface Generic<T> {
SomeGeneric<? extends T> foo();
}
class II implements Generic<Object> {
<caret>
}
class SomeGeneric<P> {
}
@@ -0,0 +1,24 @@
import java.util.*;
public class IntroduceParameterProducesWarning {
private final List<Generic<?>> elements;
public IntroduceParameterProducesWarning(final ArrayList<Generic<?>> anObject) {
elements = anObject;
}
public static <E> ArrayList<E> newArrayList(E... elements) {
ArrayList<E> list = new ArrayList<E>();
Collections.addAll(list, elements);
return list;
}
private static interface Generic<T>{
}
private static class SomeGeneric implements Generic<String> {
}
private static class SomeOtherGeneric implements Generic<Object> {
}
}
@@ -0,0 +1,24 @@
import java.util.*;
public class IntroduceParameterProducesWarning {
private final List<Generic<?>> elements;
public IntroduceParameterProducesWarning() {
elements = <selection>newArrayList(new SomeGeneric(), new SomeOtherGeneric())</selection>;
}
public static <E> ArrayList<E> newArrayList(E... elements) {
ArrayList<E> list = new ArrayList<E>();
Collections.addAll(list, elements);
return list;
}
private static interface Generic<T>{
}
private static class SomeGeneric implements Generic<String> {
}
private static class SomeOtherGeneric implements Generic<Object> {
}
}
@@ -60,6 +60,7 @@ public class OverrideImplementTest extends LightCodeInsightTestCase {
public void testSubstituteBoundInMethodTypeParam() { doTest(false); }
public void testClone() { doTest(false); }
public void testOnTheLineWithExistingExpression() { doTest(false); }
public void testSimplifyObjectWildcard() { doTest(false); }
public void testImplementExtensionMethods() { doTest8(false, true); }
public void testDoNotImplementExtensionMethods() { doTest8(false, true); }
@@ -313,6 +313,10 @@ public class IntroduceParameterTest extends LightRefactoringTestCase {
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL, true, false, true, false);
}
public void testSimplifiedResultedType() throws Exception {
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL, true, false, true, false);
}
private void doTestThroughHandler() throws Exception {
configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java");
boolean enabled = true;