From 5347c755c7036b723fc7a51c4aea5af22fd3e198 Mon Sep 17 00:00:00 2001 From: Alexandr Suhinin Date: Wed, 6 May 2020 15:54:38 +0300 Subject: [PATCH] IDEA-CR-62340: move common prefix out of the error message & test expected errors messages GitOrigin-RevId: 218608616889b2021860dc1ec31d5a30b30ebfb6 --- .../newImpl/ExtractMethodAnalyzer.kt | 1 - .../extractMethod/newImpl/MethodExtractor.kt | 4 +++- .../refactoring/ExtractMethodNewTest.java | 19 +++---------------- .../messages/JavaRefactoringBundle.properties | 15 ++++++++------- 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/extractMethod/newImpl/ExtractMethodAnalyzer.kt b/java/java-impl/src/com/intellij/refactoring/extractMethod/newImpl/ExtractMethodAnalyzer.kt index 9a1339ea0290..ccfd29557bb1 100644 --- a/java/java-impl/src/com/intellij/refactoring/extractMethod/newImpl/ExtractMethodAnalyzer.kt +++ b/java/java-impl/src/com/intellij/refactoring/extractMethod/newImpl/ExtractMethodAnalyzer.kt @@ -46,7 +46,6 @@ fun findExtractOptions(elements: List): ExtractOptions { return ExtractMethodHelper.areSemanticallySame(statements) && !haveReferenceToScope(statements, scope) } - //TODO use correct error messages val dataOutput = when { expression != null -> ExpressionOutput(getExpressionType(expression), null, listOf(expression), CodeFragmentAnalyzer.inferNullability(listOf(expression))) variableData is VariableOutput -> when { diff --git a/java/java-impl/src/com/intellij/refactoring/extractMethod/newImpl/MethodExtractor.kt b/java/java-impl/src/com/intellij/refactoring/extractMethod/newImpl/MethodExtractor.kt index ceab2b1bc140..d4cb77a2c114 100644 --- a/java/java-impl/src/com/intellij/refactoring/extractMethod/newImpl/MethodExtractor.kt +++ b/java/java-impl/src/com/intellij/refactoring/extractMethod/newImpl/MethodExtractor.kt @@ -3,6 +3,7 @@ package com.intellij.refactoring.extractMethod.newImpl import com.intellij.codeInsight.highlighting.HighlightManager import com.intellij.ide.util.PropertiesComponent +import com.intellij.java.refactoring.JavaRefactoringBundle import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.command.CommandProcessor import com.intellij.openapi.diagnostic.Logger @@ -56,7 +57,8 @@ class MethodExtractor { } } catch (e: ExtractException) { - CommonRefactoringUtil.showErrorHint(project, editor, e.message!!, refactoringName, HelpID.EXTRACT_METHOD) + val message = JavaRefactoringBundle.message("extract.method.error.prefix") + " " + (e.message ?: "") + CommonRefactoringUtil.showErrorHint(project, editor, message, refactoringName, HelpID.EXTRACT_METHOD) showError(editor, e.problems) } } diff --git a/java/java-tests/testSrc/com/intellij/java/refactoring/ExtractMethodNewTest.java b/java/java-tests/testSrc/com/intellij/java/refactoring/ExtractMethodNewTest.java index 2d4f4e852851..eb4468b43f57 100644 --- a/java/java-tests/testSrc/com/intellij/java/refactoring/ExtractMethodNewTest.java +++ b/java/java-tests/testSrc/com/intellij/java/refactoring/ExtractMethodNewTest.java @@ -484,20 +484,11 @@ public class ExtractMethodNewTest extends LightJavaCodeInsightTestCase { } public void testLocalClass() throws Exception { - try { - doTest(); - fail("Should fail if local class is defined out of the selected block"); - } catch (PrepareFailedException ignore){ - } + doPrepareErrorTest("Local class is defined out of the selected block."); } public void testLocalClassUsage() throws Exception { - try { - doTest(); - fail("Should fail if local class is used out of the selected block"); - } catch (PrepareFailedException ignore) { - - } + doPrepareErrorTest("Local class is used out of the selected block."); } public void testStaticImport() throws Exception { @@ -525,11 +516,7 @@ public class ExtractMethodNewTest extends LightJavaCodeInsightTestCase { } public void testLocalClassDefinedInMethodWhichIsUsedLater() throws Exception { - try { - doTest(); - fail("Should fail if local class is used out of the selected block"); - } catch (PrepareFailedException ignored) { - } + doPrepareErrorTest("Local class is used out of the selected block."); } public void testForceBraces() throws Exception { diff --git a/java/openapi/resources/messages/JavaRefactoringBundle.properties b/java/openapi/resources/messages/JavaRefactoringBundle.properties index c127f741ef11..fe609e26d18b 100644 --- a/java/openapi/resources/messages/JavaRefactoringBundle.properties +++ b/java/openapi/resources/messages/JavaRefactoringBundle.properties @@ -193,13 +193,14 @@ extract.delegate.create.nested.checkbox=Create nested class extract.delegate.generate.accessors.checkbox=Generate accessors extract.delegate.unable.create.warning.message=Unable to create class with the given name extract.method.control.flow.analysis.failed=Code contains syntax errors. Cannot perform necessary analysis. -extract.method.error.class.outside.used=Unable to extract method. Local class is used out of the selected block. -extract.method.error.class.outside.defined=Unable to extract method. Local class is defined out of the selected block. -extract.method.error.many.outputs = Unable to extract method. There are multiple variables to return. -extract.method.error.many.exits = Unable to extract method. There are multiple exit points. -extract.method.error.many.finals = Unable to extract method. There is an assignment to the final field. -extract.method.error.variable.in.expression=Unable to extract method. There is a variable to return inside of the selected expression. -extract.method.error.class.not.found=Unable to extract method. Selected block should be a part of java class. +extract.method.error.prefix=Unable to extract method. +extract.method.error.class.outside.used=Local class is used out of the selected block. +extract.method.error.class.outside.defined=Local class is defined out of the selected block. +extract.method.error.many.outputs=There are multiple variables to return. +extract.method.error.many.exits=There are multiple exit points. +extract.method.error.many.finals=There is an assignment to the final field. +extract.method.error.variable.in.expression=There is a variable to return inside of the selected expression. +extract.method.error.class.not.found=Selected block should be a part of java class. extract.method.object.anonymous.make.varargs.option=Make &varargs extract.method.object.class.name=&Class name: extract.method.object.create.anonymous.class=Create &anonymous class