mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-57487 Smart completion in cast operator inserts ill-formed type
This commit is contained in:
@@ -30,20 +30,24 @@ class SmartCastProvider extends CompletionProvider<CompletionParameters> {
|
||||
PsiTypeCastExpression.class));
|
||||
|
||||
protected void addCompletions(@NotNull final CompletionParameters parameters, final ProcessingContext context, @NotNull final CompletionResultSet result) {
|
||||
for (final ExpectedTypeInfo type : JavaSmartCompletionContributor.getExpectedTypes(parameters)) {
|
||||
if (type.getType() == PsiType.VOID) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (final ExpectedTypeInfo info : JavaSmartCompletionContributor.getExpectedTypes(parameters)) {
|
||||
final PsiElement originalPosition = parameters.getOriginalPosition();
|
||||
final boolean overwrite = INSIDE_TYPECAST_TYPE.accepts(originalPosition);
|
||||
|
||||
final PsiType defaultType = type.getDefaultType();
|
||||
result.addElement(createSmartCastElement(parameters, overwrite, defaultType));
|
||||
if (defaultType instanceof PsiPrimitiveType) {
|
||||
final PsiType type1 = getCastedExpressionType(originalPosition);
|
||||
if (type1 != null && !(type1 instanceof PsiPrimitiveType)) {
|
||||
final PsiClassType boxedType = ((PsiPrimitiveType)defaultType).getBoxedType(originalPosition);
|
||||
PsiType type = info.getDefaultType();
|
||||
if (type instanceof PsiWildcardType) {
|
||||
type = ((PsiWildcardType)type).getBound();
|
||||
}
|
||||
|
||||
if (type == null || type == PsiType.VOID) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.addElement(createSmartCastElement(parameters, overwrite, type));
|
||||
if (type instanceof PsiPrimitiveType) {
|
||||
final PsiType castedType = getCastedExpressionType(originalPosition);
|
||||
if (castedType != null && !(castedType instanceof PsiPrimitiveType)) {
|
||||
final PsiClassType boxedType = ((PsiPrimitiveType)type).getBoxedType(originalPosition);
|
||||
if (boxedType != null) {
|
||||
result.addElement(createSmartCastElement(parameters, overwrite, boxedType));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
abstract class A<T> {
|
||||
void foo(T x){}
|
||||
void bar(A<? super Throwable> a, Object b){
|
||||
a.foo((Throwable) <caret>b);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
abstract class A<T> {
|
||||
void foo(T x){}
|
||||
void bar(A<? super Throwable> a, Object b){
|
||||
a.foo((<caret>) b);
|
||||
}
|
||||
}
|
||||
+1
@@ -434,6 +434,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
|
||||
public void testCastAutoboxing() throws Throwable { doActionItemTest(); }
|
||||
public void testCastAutoboxing2() throws Throwable { doActionItemTest(); }
|
||||
public void testCastAutoboxing3() throws Throwable { doActionItemTest(); }
|
||||
public void testCastWildcards() throws Throwable { doTest(); }
|
||||
|
||||
public void testNoFieldsInSuperConstructorCall() throws Throwable { doTest(); }
|
||||
public void testNoUninitializedFieldsInConstructor() throws Throwable { doTest(); }
|
||||
|
||||
Reference in New Issue
Block a user