From 49edae7469afe47d27bc5a6c46825a79322e26f2 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Fri, 11 Jul 2014 13:52:30 +0400 Subject: [PATCH] Extract Function: Do not report "non-denotable type" message on error types --- .../evaluate/extractFunctionForDebuggerUtil.kt | 1 + .../refactoring/JetRefactoringBundle.properties | 1 + .../extractFunction/ExtractionDescriptor.kt | 2 ++ .../extractFunction/extractFunctionUtils.kt | 11 +++++++++-- .../functions/localFunctionParameters.kt.conflicts | 2 +- .../localFunctionParametersWithLambda.kt.conflicts | 2 +- 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/extractFunctionForDebuggerUtil.kt b/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/extractFunctionForDebuggerUtil.kt index 2c5183292e9..745a9c8e795 100644 --- a/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/extractFunctionForDebuggerUtil.kt +++ b/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/extractFunctionForDebuggerUtil.kt @@ -53,6 +53,7 @@ fun getFunctionForExtractedFragment( ErrorMessage.NO_CONTAINER -> "Cannot perform an action at this breakpoint ${breakpointFile.getName()}:${breakpointLine}" ErrorMessage.SUPER_CALL -> "Cannot perform an action for expression with super call" ErrorMessage.DENOTABLE_TYPES -> "Cannot perform an action because following types are unavailable from debugger scope" + ErrorMessage.ERROR_TYPES -> "Cannot perform an action because this code fragment contains erroneous types" ErrorMessage.MULTIPLE_OUTPUT -> "Cannot perform an action because this code fragment changes more than one variable" ErrorMessage.DECLARATIONS_OUT_OF_SCOPE, ErrorMessage.OUTPUT_AND_EXIT_POINT, diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringBundle.properties b/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringBundle.properties index b77fbf79a3e..a4d682dd8e1 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringBundle.properties +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringBundle.properties @@ -18,6 +18,7 @@ declarations.will.move.out.of.scope=Following declarations won't be available ou cannot.extract.super.call=Cannot extract super-call cannot.refactor.expression.should.have.inferred.type=Expression should have inferred type cannot.refactor.synthesized.function=Cannot refactor synthesized function ''{0}'' +error.types.in.generated.function=Cannot generate function with erroneous return type error.wrong.caret.position.function.or.constructor.name=The caret should be positioned at the name of the function or constructor to be refactored. error.cant.refactor.vararg.functions=Can't refactor the function with variable arguments diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/ExtractionDescriptor.kt b/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/ExtractionDescriptor.kt index b52cb631bd3..b8a249ffe78 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/ExtractionDescriptor.kt +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/ExtractionDescriptor.kt @@ -180,6 +180,7 @@ class AnalysisResult ( NO_CONTAINER SUPER_CALL DENOTABLE_TYPES + ERROR_TYPES MULTIPLE_OUTPUT OUTPUT_AND_EXIT_POINT MULTIPLE_EXIT_POINTS @@ -200,6 +201,7 @@ class AnalysisResult ( NO_CONTAINER -> "cannot.refactor.no.container" SUPER_CALL -> "cannot.extract.super.call" DENOTABLE_TYPES -> "parameter.types.are.not.denotable" + ERROR_TYPES -> "error.types.in.generated.function" MULTIPLE_OUTPUT -> "selected.code.fragment.has.multiple.output.values" OUTPUT_AND_EXIT_POINT -> "selected.code.fragment.has.output.values.and.exit.points" MULTIPLE_EXIT_POINTS -> "selected.code.fragment.has.multiple.exit.points" diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/extractFunctionUtils.kt b/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/extractFunctionUtils.kt index ec3e4b2fbb1..c8c371aeef0 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/extractFunctionUtils.kt +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/extractFunctionUtils.kt @@ -210,7 +210,11 @@ private fun ExtractionData.analyzeControlFlow( val typeOfDefaultFlow = defaultExits.getResultType(pseudocode, bindingContext, options) val returnValueType = valuedReturnExits.getResultType(pseudocode, bindingContext, options) - val defaultControlFlow = DefaultControlFlow(if (returnValueType.isMeaningful()) returnValueType else typeOfDefaultFlow, declarationsToCopy) + + val defaultReturnType = if (returnValueType.isMeaningful()) returnValueType else typeOfDefaultFlow + if (defaultReturnType.isError()) return Pair(DefaultControlFlow(DEFAULT_RETURN_TYPE, declarationsToCopy), ErrorMessage.ERROR_TYPES) + + val defaultControlFlow = DefaultControlFlow(defaultReturnType, declarationsToCopy) if (declarationsToReport.isNotEmpty()) { val localVarStr = declarationsToReport.map { it.renderForMessage(bindingContext)!! }.distinct().sort() @@ -357,6 +361,9 @@ private fun JetType.processTypeIfExtractable( typeToCheck.canBeReferencedViaImport() -> extractable + typeToCheck.isError() -> + false + else -> { nonDenotableTypes.add(typeToCheck) false @@ -756,7 +763,7 @@ fun ExtractionDescriptor.getFunctionText( } with(controlFlow.returnType) { - if (isDefault()) builder.noReturnType() else builder.returnType(descriptorRenderer.renderType(this)) + if (isDefault() || isError()) builder.noReturnType() else builder.returnType(descriptorRenderer.renderType(this)) } builder.typeConstraints(typeParameters.flatMap { it.originalConstraints }.map { it.getText()!! }) diff --git a/idea/testData/refactoring/extractFunction/initializers/functions/localFunctionParameters.kt.conflicts b/idea/testData/refactoring/extractFunction/initializers/functions/localFunctionParameters.kt.conflicts index 6ed3da8069a..ecdc4331d76 100644 --- a/idea/testData/refactoring/extractFunction/initializers/functions/localFunctionParameters.kt.conflicts +++ b/idea/testData/refactoring/extractFunction/initializers/functions/localFunctionParameters.kt.conflicts @@ -1 +1 @@ -Cannot extract method since following types are not denotable in the target scope: [ERROR : <ERROR FUNCTION RETURN TYPE>] \ No newline at end of file +Cannot generate function with erroneous return type \ No newline at end of file diff --git a/idea/testData/refactoring/extractFunction/initializers/functions/localFunctionParametersWithLambda.kt.conflicts b/idea/testData/refactoring/extractFunction/initializers/functions/localFunctionParametersWithLambda.kt.conflicts index 6ed3da8069a..ecdc4331d76 100644 --- a/idea/testData/refactoring/extractFunction/initializers/functions/localFunctionParametersWithLambda.kt.conflicts +++ b/idea/testData/refactoring/extractFunction/initializers/functions/localFunctionParametersWithLambda.kt.conflicts @@ -1 +1 @@ -Cannot extract method since following types are not denotable in the target scope: [ERROR : <ERROR FUNCTION RETURN TYPE>] \ No newline at end of file +Cannot generate function with erroneous return type \ No newline at end of file