Extract Function: Do not report "Moving out of scope" warning on nested declarations

This commit is contained in:
Alexey Sedunov
2014-07-04 14:23:52 +04:00
parent 52c107504d
commit 59b33fcba4
6 changed files with 70 additions and 3 deletions
@@ -515,14 +515,19 @@ private fun ExtractionData.inferParametersInfo(
return null
}
private fun ExtractionData.checkDeclarationsMovingOutOfScope(controlFlow: ControlFlow): ErrorMessage? {
private fun ExtractionData.checkDeclarationsMovingOutOfScope(
enclosingDeclaration: JetDeclaration,
controlFlow: ControlFlow
): ErrorMessage? {
val declarationsOutOfScope = HashSet<JetNamedDeclaration>()
if (controlFlow is JumpBasedControlFlow) {
controlFlow.elementToInsertAfterCall.accept(
object: JetTreeVisitorVoid() {
override fun visitSimpleNameExpression(expression: JetSimpleNameExpression) {
val target = expression.getReference()?.resolve()
if (target is JetNamedDeclaration && target.isInsideOf(originalElements)) {
if (target is JetNamedDeclaration
&& target.isInsideOf(originalElements)
&& target.getParentByType(javaClass<JetDeclaration>(), true) == enclosingDeclaration) {
declarationsOutOfScope.add(target)
}
}
@@ -608,7 +613,7 @@ fun ExtractionData.performAnalysis(): AnalysisResult {
)
}
checkDeclarationsMovingOutOfScope(controlFlow)?.let { messages.add(it) }
checkDeclarationsMovingOutOfScope(enclosingDeclaration!!, controlFlow)?.let { messages.add(it) }
val functionNameValidator =
JetNameValidatorImpl(