Extract Function: Do not report "non-denotable type" message on error types

This commit is contained in:
Alexey Sedunov
2014-07-11 13:52:30 +04:00
parent f1445ba635
commit 49edae7469
6 changed files with 15 additions and 4 deletions
@@ -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,
@@ -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
@@ -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"
@@ -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()!! })
@@ -1 +1 @@
Cannot extract method since following types are not denotable in the target scope: [ERROR : <ERROR FUNCTION RETURN TYPE>]
Cannot generate function with erroneous return type
@@ -1 +1 @@
Cannot extract method since following types are not denotable in the target scope: [ERROR : <ERROR FUNCTION RETURN TYPE>]
Cannot generate function with erroneous return type