From dd11fa932083f8593c50859c24c5855fba4b95c0 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Mon, 28 Dec 2015 13:43:23 +0300 Subject: [PATCH] Move logic related to expression occurrence searching to ide-common --- .../introduce/ExtractableSubstringInfo.kt | 0 .../idea/refactoring/ktRefactoringUtil.kt | 40 +++++++++++++++++++ .../psi/patternMatching/KotlinPsiRange.kt | 0 .../psi/patternMatching/KotlinPsiUnifier.kt | 0 .../idea/refactoring/jetRefactoringUtil.kt | 17 -------- 5 files changed, 40 insertions(+), 17 deletions(-) rename idea/{ => ide-common}/src/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractableSubstringInfo.kt (100%) create mode 100644 idea/ide-common/src/org/jetbrains/kotlin/idea/refactoring/ktRefactoringUtil.kt rename idea/{ => ide-common}/src/org/jetbrains/kotlin/idea/util/psi/patternMatching/KotlinPsiRange.kt (100%) rename idea/{ => ide-common}/src/org/jetbrains/kotlin/idea/util/psi/patternMatching/KotlinPsiUnifier.kt (100%) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractableSubstringInfo.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractableSubstringInfo.kt similarity index 100% rename from idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractableSubstringInfo.kt rename to idea/ide-common/src/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractableSubstringInfo.kt diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/refactoring/ktRefactoringUtil.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/refactoring/ktRefactoringUtil.kt new file mode 100644 index 00000000000..924afd41e8b --- /dev/null +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/refactoring/ktRefactoringUtil.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.refactoring + +import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType +import org.jetbrains.kotlin.psi.psiUtil.isAncestor +import org.jetbrains.kotlin.resolve.BindingContext + +fun KtElement.getContextForContainingDeclarationBody(): BindingContext? { + val enclosingDeclaration = getStrictParentOfType() + val bodyElement = when (enclosingDeclaration) { + is KtDeclarationWithBody -> enclosingDeclaration.getBodyExpression() + is KtWithExpressionInitializer -> enclosingDeclaration.getInitializer() + is KtDestructuringDeclaration -> enclosingDeclaration.getInitializer() + is KtParameter -> enclosingDeclaration.getDefaultValue() + is KtAnonymousInitializer -> enclosingDeclaration.body + is KtClass -> { + val delegationSpecifierList = enclosingDeclaration.getSuperTypeList() + if (delegationSpecifierList.isAncestor(this)) this else null + } + else -> null + } + return bodyElement?.let { it.analyze() } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/util/psi/patternMatching/KotlinPsiRange.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/psi/patternMatching/KotlinPsiRange.kt similarity index 100% rename from idea/src/org/jetbrains/kotlin/idea/util/psi/patternMatching/KotlinPsiRange.kt rename to idea/ide-common/src/org/jetbrains/kotlin/idea/util/psi/patternMatching/KotlinPsiRange.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/util/psi/patternMatching/KotlinPsiUnifier.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/psi/patternMatching/KotlinPsiUnifier.kt similarity index 100% rename from idea/src/org/jetbrains/kotlin/idea/util/psi/patternMatching/KotlinPsiUnifier.kt rename to idea/ide-common/src/org/jetbrains/kotlin/idea/util/psi/patternMatching/KotlinPsiUnifier.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/jetRefactoringUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/jetRefactoringUtil.kt index d68abcd5fb5..d251daaf146 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/jetRefactoringUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/jetRefactoringUtil.kt @@ -324,23 +324,6 @@ fun PsiElement.getLineCount(): Int { fun PsiElement.isMultiLine(): Boolean = getLineCount() > 1 -fun KtElement.getContextForContainingDeclarationBody(): BindingContext? { - val enclosingDeclaration = getStrictParentOfType() - val bodyElement = when (enclosingDeclaration) { - is KtDeclarationWithBody -> enclosingDeclaration.bodyExpression - is KtWithExpressionInitializer -> enclosingDeclaration.initializer - is KtDestructuringDeclaration -> enclosingDeclaration.initializer - is KtParameter -> enclosingDeclaration.defaultValue - is KtAnonymousInitializer -> enclosingDeclaration.body - is KtClass -> { - val delegationSpecifierList = enclosingDeclaration.getSuperTypeList() - if (delegationSpecifierList.isAncestor(this)) this else null - } - else -> null - } - return bodyElement?.let { it.analyze() } -} - fun chooseContainerElement( containers: List, editor: Editor,