diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/CallBuilder.kt b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/CallBuilder.kt index 6124ee185b93..e92cde70e2ec 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/CallBuilder.kt +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/CallBuilder.kt @@ -5,16 +5,14 @@ import com.intellij.psi.* import com.intellij.psi.codeStyle.CodeStyleManager import com.intellij.psi.impl.source.resolve.JavaResolveUtil import com.intellij.psi.util.PsiUtil -import com.intellij.refactoring.IntroduceVariableUtil -import com.intellij.refactoring.extractMethod.newImpl.ExtractMethodHelper.canDeclareVarType import com.intellij.refactoring.extractMethod.newImpl.ExtractMethodHelper.createDeclaration -import com.intellij.refactoring.extractMethod.newImpl.ExtractMethodHelper.shouldDeclareVarType import com.intellij.refactoring.extractMethod.newImpl.structures.DataOutput import com.intellij.refactoring.extractMethod.newImpl.structures.DataOutput.* import com.intellij.refactoring.extractMethod.newImpl.structures.ExtractOptions import com.intellij.refactoring.extractMethod.newImpl.structures.FlowOutput import com.intellij.refactoring.extractMethod.newImpl.structures.FlowOutput.* import com.intellij.refactoring.util.RefactoringChangeUtil + class CallBuilder(private val context: PsiElement) { private val factory: PsiElementFactory = PsiElementFactory.getInstance(context.project) @@ -39,14 +37,9 @@ class CallBuilder(private val context: PsiElement) { } val declarationStatement = declaration as? PsiDeclarationStatement val declaredVariable = declarationStatement?.declaredElements?.firstOrNull() as? PsiVariable - if (declaredVariable != null) { - if (dataOutput is VariableOutput) { - val needsFinal = dataOutput.variable.hasModifierProperty(PsiModifier.FINAL) - PsiUtil.setModifierProperty(declaredVariable, PsiModifier.FINAL, needsFinal) - } - if (canDeclareVarType(dataOutput, context) && shouldDeclareVarType(dataOutput)){ - IntroduceVariableUtil.expandDiamondsAndReplaceExplicitTypeWithVar(declaredVariable.typeElement, declaredVariable) - } + if (dataOutput is VariableOutput && declaredVariable != null) { + val needsFinal = dataOutput.variable.hasModifierProperty(PsiModifier.FINAL) + PsiUtil.setModifierProperty(declaredVariable, PsiModifier.FINAL, needsFinal) } return listOfNotNull(declaration) } @@ -115,7 +108,7 @@ class CallBuilder(private val context: PsiElement) { factory.createReferenceExpression(methodClass) } else { - RefactoringChangeUtil.createThisExpression(method.manager, methodClass) + RefactoringChangeUtil.createThisExpression(PsiManager.getInstance(method.project), methodClass) } callElement.methodExpression.qualifierExpression = ref } diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/ExtractMethodHelper.kt b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/ExtractMethodHelper.kt index a444e24f454d..afd7892c1b9b 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/ExtractMethodHelper.kt +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/ExtractMethodHelper.kt @@ -18,7 +18,6 @@ import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.util.PsiUtil import com.intellij.refactoring.IntroduceVariableUtil -import com.intellij.refactoring.JavaRefactoringSettings import com.intellij.refactoring.extractMethod.newImpl.structures.DataOutput import com.intellij.refactoring.extractMethod.newImpl.structures.DataOutput.* import com.intellij.refactoring.extractMethod.newImpl.structures.ExtractOptions @@ -28,23 +27,6 @@ import com.intellij.util.CommonJavaRefactoringUtil object ExtractMethodHelper { - fun canDeclareVarType(dataOutput: DataOutput, context: PsiElement): Boolean { - if (!PsiUtil.isLanguageLevel10OrHigher(context)) { - return false - } - return when (dataOutput) { - ArtificialBooleanOutput -> true - is VariableOutput -> true - is EmptyOutput -> false - is ExpressionOutput -> false - } - } - - fun shouldDeclareVarType(dataOutput: DataOutput): Boolean { - val isInferredType = (dataOutput as? VariableOutput)?.variable?.typeElement?.isInferredType == true - return isInferredType || JavaRefactoringSettings.getInstance().DECLARE_VAR_TYPE - } - fun hasReferencesToScope(scope: List, elements: List): Boolean { val localVariables = scope.asSequence().flatMap { element -> PsiTreeUtil.findChildrenOfType(element, PsiVariable::class.java) }.toSet() return elements.asSequence() diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/MethodExtractor.kt b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/MethodExtractor.kt index a8124c18fbc2..d0e1885ff57b 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/MethodExtractor.kt +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/MethodExtractor.kt @@ -25,10 +25,8 @@ import com.intellij.refactoring.JavaRefactoringSettings import com.intellij.refactoring.RefactoringBundle import com.intellij.refactoring.extractMethod.ExtractMethodDialog import com.intellij.refactoring.extractMethod.ExtractMethodHandler -import com.intellij.refactoring.extractMethod.newImpl.ExtractMethodHelper.canDeclareVarType import com.intellij.refactoring.extractMethod.newImpl.ExtractMethodHelper.guessMethodName import com.intellij.refactoring.extractMethod.newImpl.ExtractMethodHelper.replaceWithMethod -import com.intellij.refactoring.extractMethod.newImpl.ExtractMethodHelper.shouldDeclareVarType import com.intellij.refactoring.extractMethod.newImpl.ExtractMethodPipeline.findAllOptionsToExtract import com.intellij.refactoring.extractMethod.newImpl.ExtractMethodPipeline.selectOptionWithTargetClass import com.intellij.refactoring.extractMethod.newImpl.ExtractMethodPipeline.withFilteredAnnotations @@ -138,14 +136,12 @@ class MethodExtractor { val defaultStatic = with (JavaRefactoringSettings.getInstance()) { if (makeStaticAndPassFields) EXTRACT_STATIC_METHOD_AND_PASS_FIELDS else EXTRACT_STATIC_METHOD } - val dataOutput = options.dataOutput - val hasAnnotation = dataOutput.nullability != Nullability.UNKNOWN && dataOutput.type !is PsiPrimitiveType + val hasAnnotation = options.dataOutput.nullability != Nullability.UNKNOWN && options.dataOutput.type !is PsiPrimitiveType val annotationAvailable = ExtractMethodHelper.isNullabilityAvailable(options) return ExtractMethodPopupProvider( annotateDefault = if (hasAnnotation && annotationAvailable) needsNullabilityAnnotations(options.project) else null, makeStaticDefault = if (showStatic) defaultStatic else null, - staticPassFields = makeStaticAndPassFields, - declareVarTypeDefault = shouldDeclareVarType(dataOutput).takeIf { canDeclareVarType(dataOutput, options.targetClass) } + staticPassFields = makeStaticAndPassFields ) } diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/ExtractMethodPopupProvider.kt b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/ExtractMethodPopupProvider.kt index 5dff0e0598e7..fe11921e2d5f 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/ExtractMethodPopupProvider.kt +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/ExtractMethodPopupProvider.kt @@ -14,7 +14,6 @@ import javax.swing.LayoutFocusTraversalPolicy class ExtractMethodPopupProvider(val annotateDefault: Boolean? = null, val makeStaticDefault: Boolean? = null, - val declareVarTypeDefault: Boolean? = null, val staticPassFields: Boolean = false) { var annotate = annotateDefault @@ -23,11 +22,8 @@ class ExtractMethodPopupProvider(val annotateDefault: Boolean? = null, var makeStatic = makeStaticDefault private set - var declareVarType = declareVarTypeDefault - private set - val isChanged: Boolean - get() = annotate != annotateDefault || makeStatic != makeStaticDefault || declareVarType != declareVarTypeDefault + get() = annotate != annotateDefault || makeStatic != makeStaticDefault private var changeListener: () -> Unit = {} @@ -72,16 +68,6 @@ class ExtractMethodPopupProvider(val annotateDefault: Boolean? = null, } } } - if (declareVarType != null) { - row { - checkBox(JavaRefactoringBundle.message("declare.var.type")) - .selected(declareVarType ?: false) - .onChanged { component -> - declareVarType = component.isSelected - changeListener.invoke() - } - } - } row { link(JavaRefactoringBundle.message("extract.method.link.label.more.options")) { showDialogAction(null) } .gap(RightGap.SMALL) diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceExtractMethodCollector.kt b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceExtractMethodCollector.kt index 8c158d36ad64..36535b209f8c 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceExtractMethodCollector.kt +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceExtractMethodCollector.kt @@ -28,6 +28,5 @@ class InplaceExtractMethodCollector : CounterUsagesCollector() { enum class ExtractMethodSettingChange(val fusName: String) { AnnotateOn("AnnotateOn"), AnnotateOff("AnnotateOff"), MakeStaticOn("MakeStaticOn"), MakeStaticOff("MakeStaticOff"), MakeStaticWithFieldsOn("MakeStaticWithFieldsOn"), - MakeStaticWithFieldsOff("MakeStaticWithFieldsOff"), DeclareVarTypeOn("DeclareVarTypeOn"), - DeclareVarTypeOff("DeclareVarTypeOff") + MakeStaticWithFieldsOff("MakeStaticWithFieldsOff") } \ No newline at end of file diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceExtractUtils.kt b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceExtractUtils.kt index 17a0894566d7..2b08663b1a78 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceExtractUtils.kt +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceExtractUtils.kt @@ -224,15 +224,6 @@ object InplaceExtractUtils { val change = if (popupProvider.annotate == true) ExtractMethodSettingChange.AnnotateOn else ExtractMethodSettingChange.AnnotateOff logSettingsChange(project, change) } - if (popupProvider.declareVarType != popupProvider.declareVarTypeDefault){ - val change = if (popupProvider.declareVarType == true) { - ExtractMethodSettingChange.DeclareVarTypeOn - } - else { - ExtractMethodSettingChange.DeclareVarTypeOff - } - logSettingsChange(project, change) - } if (popupProvider.makeStatic != popupProvider.makeStaticDefault) { val change = when { popupProvider.makeStatic == true && popupProvider.staticPassFields -> ExtractMethodSettingChange.MakeStaticWithFieldsOn diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceMethodExtractor.kt b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceMethodExtractor.kt index 7d248494acf2..f8e4ed35a695 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceMethodExtractor.kt +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/inplace/InplaceMethodExtractor.kt @@ -157,10 +157,6 @@ class InplaceMethodExtractor(private val editor: Editor, if (!popupProvider.staticPassFields && makeStatic != null) { JavaRefactoringSettings.getInstance().EXTRACT_STATIC_METHOD = makeStatic } - val declareVarType = popupProvider.declareVarType - if (declareVarType != null) { - JavaRefactoringSettings.getInstance().DECLARE_VAR_TYPE = declareVarType - } restartInplace() } popupProvider.setShowDialogAction { actionEvent -> restartInDialog(actionEvent == null) } diff --git a/java/java-impl/src/com/intellij/refactoring/JavaRefactoringSettings.java b/java/java-impl/src/com/intellij/refactoring/JavaRefactoringSettings.java index c692fed3f317..f6f8049c62d7 100644 --- a/java/java-impl/src/com/intellij/refactoring/JavaRefactoringSettings.java +++ b/java/java-impl/src/com/intellij/refactoring/JavaRefactoringSettings.java @@ -76,7 +76,6 @@ public class JavaRefactoringSettings implements PersistentStateComponentString s = "42"; - System.out.println(s); - } -} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/extractMethodAndDuplicatesInplace/DeclareVarType_after.java b/java/java-tests/testData/refactoring/extractMethodAndDuplicatesInplace/DeclareVarType_after.java deleted file mode 100644 index 77487e2fc3ea..000000000000 --- a/java/java-tests/testData/refactoring/extractMethodAndDuplicatesInplace/DeclareVarType_after.java +++ /dev/null @@ -1,15 +0,0 @@ -import org.jetbrains.annotations.NotNull; - -class SomeClass { - - public void test(String filePath) { - var s = getString(); - System.out.println(s); - } - - @NotNull - private static String getString() { - String s = "42"; - return s; - } -} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/extractMethodAndDuplicatesInplace/KeepVarKeyword.java b/java/java-tests/testData/refactoring/extractMethodAndDuplicatesInplace/KeepVarKeyword.java deleted file mode 100644 index 3851ac450c87..000000000000 --- a/java/java-tests/testData/refactoring/extractMethodAndDuplicatesInplace/KeepVarKeyword.java +++ /dev/null @@ -1,7 +0,0 @@ -class SomeClass { - - public void test(String filePath) { - var s = "42"; - System.out.println(s); - } -} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/extractMethodAndDuplicatesInplace/KeepVarKeyword_after.java b/java/java-tests/testData/refactoring/extractMethodAndDuplicatesInplace/KeepVarKeyword_after.java deleted file mode 100644 index 3a0b60625706..000000000000 --- a/java/java-tests/testData/refactoring/extractMethodAndDuplicatesInplace/KeepVarKeyword_after.java +++ /dev/null @@ -1,15 +0,0 @@ -import org.jetbrains.annotations.NotNull; - -class SomeClass { - - public void test(String filePath) { - var s = getString(); - System.out.println(s); - } - - @NotNull - private static String getString() { - var s = "42"; - return s; - } -} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/refactoring/ExtractMethodAndDuplicatesInplaceTest.kt b/java/java-tests/testSrc/com/intellij/java/refactoring/ExtractMethodAndDuplicatesInplaceTest.kt index ddc613aafa03..ff10d1ad9f7c 100644 --- a/java/java-tests/testSrc/com/intellij/java/refactoring/ExtractMethodAndDuplicatesInplaceTest.kt +++ b/java/java-tests/testSrc/com/intellij/java/refactoring/ExtractMethodAndDuplicatesInplaceTest.kt @@ -520,15 +520,6 @@ class ExtractMethodAndDuplicatesInplaceTest: LightJavaCodeInsightTestCase() { doTest() } - fun testKeepVarKeyword(){ - doTest() - } - - fun testDeclareVarType(){ - JavaRefactoringSettings.getInstance().DECLARE_VAR_TYPE = true - doTest() - } - fun testRefactoringListener(){ templateTest { configureByFile("$BASE_PATH/${getTestName(false)}.java") @@ -575,13 +566,11 @@ class ExtractMethodAndDuplicatesInplaceTest: LightJavaCodeInsightTestCase() { val settings = JavaRefactoringSettings.getInstance() val defaultStatic = settings.EXTRACT_STATIC_METHOD val defaultPassFields = settings.EXTRACT_STATIC_METHOD_AND_PASS_FIELDS - val defaultDeclareVar = settings.DECLARE_VAR_TYPE val defaultChangeSignature = DuplicatesMethodExtractor.changeSignatureDefault val defaultReplaceDuplicates = DuplicatesMethodExtractor.replaceDuplicatesDefault Disposer.register(testRootDisposable) { settings.EXTRACT_STATIC_METHOD = defaultStatic settings.EXTRACT_STATIC_METHOD_AND_PASS_FIELDS = defaultPassFields - settings.DECLARE_VAR_TYPE = defaultDeclareVar DuplicatesMethodExtractor.changeSignatureDefault = defaultChangeSignature DuplicatesMethodExtractor.replaceDuplicatesDefault = defaultReplaceDuplicates }