[extract method] IDEA-317499: infer type arguments for class usage parameters ('this')

GitOrigin-RevId: 7e1b558415ac7a7d381287e99bf54ce87eeef6cb
This commit is contained in:
Alexandr Suhinin
2023-04-07 13:13:30 +00:00
committed by intellij-monorepo-bot
parent 26bae9e549
commit 23ff859664
4 changed files with 20 additions and 1 deletions
@@ -228,7 +228,7 @@ object ExtractMethodPipeline {
val name = member.name ?: return null
val type = when (member) {
is PsiField -> member.type
is PsiClass -> PsiTypesUtil.getClassType(member)
is PsiClass -> usages.firstOrNull()?.type ?: PsiTypesUtil.getClassType(member)
else -> return null
}
return InputParameter(usages, StringUtil.decapitalize(name), type)
@@ -0,0 +1,5 @@
public class Test<K> {
public Test<K> test() {
<selection>return this;</selection>
}
}
@@ -0,0 +1,9 @@
public class Test<K> {
public Test<K> test() {
return getkTest(this);
}
private static <K> Test<K> getkTest(Test<K> test) {
return test;
}
}
@@ -504,6 +504,11 @@ class ExtractMethodAndDuplicatesInplaceTest: LightJavaCodeInsightTestCase() {
doTest()
}
fun testPassThisAsParameter(){
JavaRefactoringSettings.getInstance().EXTRACT_STATIC_METHOD_AND_PASS_FIELDS = true
doTest()
}
fun testRefactoringListener(){
templateTest {
configureByFile("$BASE_PATH/${getTestName(false)}.java")