From f925294d4eab098ba3808a945f23ae4f0d252a6e Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 7 Jul 2010 21:57:13 +0400 Subject: [PATCH] type migration: do not propagate formal types (IDEA-54117; IDEA-54112) --- .../typeMigration/TypeMigrationLabeler.java | 22 +++++++++++-------- .../TypeMigrationStatementProcessor.java | 5 ++++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java b/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java index b1f85817e46b..ebe56e91f786 100644 --- a/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java +++ b/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java @@ -362,15 +362,7 @@ public class TypeMigrationLabeler { type = userDefinedType ? type : TypeEvaluator.substituteType(type, originalType, isContraVariantPosition); if (!userDefinedType) { - if (originalType instanceof PsiClassType) { - final PsiClassType psiClassType = (PsiClassType)originalType; - if (psiClassType.resolve() instanceof PsiTypeParameter) { - return false; - } - for (PsiType paramType : psiClassType.getParameters()) { - if (paramType instanceof PsiClassType && ((PsiClassType)paramType).resolve() instanceof PsiTypeParameter) return false; - } - } + if (typeContainsTypeParameters(originalType)) return false; } if (type instanceof PsiCapturedWildcardType) { @@ -433,6 +425,18 @@ public class TypeMigrationLabeler { } } + static boolean typeContainsTypeParameters(PsiType originalType) { + if (originalType instanceof PsiClassType) { + final PsiClassType psiClassType = (PsiClassType)originalType; + if (psiClassType.resolve() instanceof PsiTypeParameter) { + return true; + } + for (PsiType paramType : psiClassType.getParameters()) { + if (paramType instanceof PsiClassType && ((PsiClassType)paramType).resolve() instanceof PsiTypeParameter) return true; + } + } + return false; + } @Nullable diff --git a/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationStatementProcessor.java b/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationStatementProcessor.java index dc7a470a4363..84c7fe5be7d3 100644 --- a/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationStatementProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationStatementProcessor.java @@ -168,7 +168,10 @@ class TypeMigrationStatementProcessor extends JavaRecursiveElementVisitor { final PsiType valueType = myTypeEvaluator.evaluateType(value); if (returnType != null && valueType != null) { - myLabeler.addMigrationRoot(method, valueType, myStatement, TypeConversionUtil.isAssignable(returnType, valueType), true); + if (!myLabeler.addMigrationRoot(method, valueType, myStatement, TypeConversionUtil.isAssignable(returnType, valueType), true) + && TypeMigrationLabeler.typeContainsTypeParameters(returnType)) { + myLabeler.markFailedConversion(new Pair(returnType, valueType), value); + } } } }