Move logic related to expression occurrence searching to ide-common
This commit is contained in:
committed by
Pavel V. Talanov
parent
bd57096b66
commit
dd11fa9320
@@ -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<KtDeclaration>()
|
||||
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() }
|
||||
}
|
||||
@@ -324,23 +324,6 @@ fun PsiElement.getLineCount(): Int {
|
||||
|
||||
fun PsiElement.isMultiLine(): Boolean = getLineCount() > 1
|
||||
|
||||
fun KtElement.getContextForContainingDeclarationBody(): BindingContext? {
|
||||
val enclosingDeclaration = getStrictParentOfType<KtDeclaration>()
|
||||
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 <T> chooseContainerElement(
|
||||
containers: List<T>,
|
||||
editor: Editor,
|
||||
|
||||
Reference in New Issue
Block a user