Refactor: inline AnalyzerFacadeWithCache#getContextForElement
This commit is contained in:
@@ -21,7 +21,6 @@ import org.jetbrains.jet.lang.psi.JetForExpression
|
||||
import org.jetbrains.jet.lang.psi.JetMultiDeclaration
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByTypeAndBranch
|
||||
import org.jetbrains.jet.lang.psi.JetCallableReferenceExpression
|
||||
@@ -61,8 +60,8 @@ import org.jetbrains.jet.lang.descriptors.ClassKind
|
||||
import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor
|
||||
import com.intellij.psi.PsiPackage
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor
|
||||
import org.jetbrains.jet.plugin.JetBundle
|
||||
import org.jetbrains.jet.plugin.findUsages.UsageTypeEnum.*
|
||||
import org.jetbrains.jet.plugin.caches.resolve.analyze
|
||||
|
||||
public object UsageTypeUtils {
|
||||
public fun getUsageType(element: PsiElement?): UsageTypeEnum? {
|
||||
@@ -74,7 +73,7 @@ public object UsageTypeUtils {
|
||||
val refExpr = element?.getParentByType(javaClass<JetReferenceExpression>())
|
||||
if (refExpr == null) return null
|
||||
|
||||
val context = AnalyzerFacadeWithCache.getContextForElement(refExpr)
|
||||
val context = refExpr.analyze()
|
||||
|
||||
fun getCommonUsageType(): UsageTypeEnum? {
|
||||
return when {
|
||||
|
||||
+3
-3
@@ -27,10 +27,10 @@ import org.jetbrains.jet.lexer.JetTokens
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||
import org.jetbrains.jet.lang.psi.JetElement
|
||||
import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.jet.plugin.caches.resolve.analyze
|
||||
|
||||
public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpression>("operator.to.function", javaClass()) {
|
||||
class object {
|
||||
@@ -57,7 +57,7 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
|
||||
}
|
||||
|
||||
private fun isApplicableCall(element: JetCallExpression): Boolean {
|
||||
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(element)
|
||||
val bindingContext = element.analyze()
|
||||
val resolvedCall = element.getResolvedCall(bindingContext)
|
||||
val descriptor = resolvedCall?.getResultingDescriptor()
|
||||
if (descriptor is FunctionDescriptor && descriptor.getName().asString() == "invoke") {
|
||||
@@ -115,7 +115,7 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
|
||||
return element
|
||||
}
|
||||
|
||||
val context = AnalyzerFacadeWithCache.getContextForElement(element)
|
||||
val context = element.analyze()
|
||||
val functionCandidate = element.getResolvedCall(context)
|
||||
val functionName = functionCandidate?.getCandidateDescriptor()?.getName().toString()
|
||||
val elemType = context[BindingContext.EXPRESSION_TYPE, left]
|
||||
|
||||
+2
-2
@@ -18,7 +18,6 @@ package org.jetbrains.jet.plugin.intentions
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import org.jetbrains.jet.lang.psi.JetCallExpression
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.lang.resolve.calls.util.DelegatingCall
|
||||
import org.jetbrains.jet.lang.types.TypeUtils
|
||||
@@ -36,6 +35,7 @@ import org.jetbrains.jet.lang.psi.psiUtil.getTextWithLocation
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getDataFlowInfo
|
||||
import org.jetbrains.jet.plugin.util.approximateFlexibleTypes
|
||||
import org.jetbrains.jet.plugin.caches.resolve.findModuleDescriptor
|
||||
import org.jetbrains.jet.plugin.caches.resolve.analyze
|
||||
|
||||
public class RemoveExplicitTypeArguments : JetSelfTargetingIntention<JetTypeArgumentList>(
|
||||
"remove.explicit.type.arguments", javaClass()) {
|
||||
@@ -44,7 +44,7 @@ public class RemoveExplicitTypeArguments : JetSelfTargetingIntention<JetTypeArgu
|
||||
val callExpression = element.getParent()
|
||||
if (callExpression !is JetCallExpression) return false
|
||||
|
||||
val context = AnalyzerFacadeWithCache.getContextForElement(callExpression)
|
||||
val context = callExpression.analyze()
|
||||
if (callExpression.getTypeArguments().isEmpty()) return false
|
||||
|
||||
val injector = InjectorForMacros(callExpression.getProject(), callExpression.findModuleDescriptor())
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.jet.plugin.project;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
|
||||
|
||||
public final class AnalyzerFacadeWithCache {
|
||||
|
||||
private AnalyzerFacadeWithCache() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static BindingContext getContextForElement(@NotNull JetElement jetElement) {
|
||||
return ResolvePackage.analyze(jetElement);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -22,11 +22,11 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import org.jetbrains.jet.plugin.JetBundle
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import com.intellij.codeInspection.SuppressIntentionAction
|
||||
import org.jetbrains.jet.plugin.util.JetPsiPrecedences
|
||||
import org.jetbrains.jet.plugin.caches.resolve.analyze
|
||||
|
||||
public class KotlinSuppressIntentionAction(
|
||||
private val suppressAt: JetExpression,
|
||||
@@ -132,7 +132,7 @@ public class KotlinSuppressIntentionAction(
|
||||
private fun suppressAnnotationText(id: String) = "[suppress($id)]"
|
||||
|
||||
private fun findSuppressAnnotation(annotated: JetAnnotated): JetAnnotationEntry? {
|
||||
val context = AnalyzerFacadeWithCache.getContextForElement(annotated)
|
||||
val context = annotated.analyze()
|
||||
for (entry in annotated.getAnnotationEntries()) {
|
||||
val annotationDescriptor = context.get(BindingContext.ANNOTATION, entry)
|
||||
if (annotationDescriptor != null && KotlinBuiltIns.getInstance().isSuppressAnnotation(annotationDescriptor)) {
|
||||
|
||||
@@ -25,12 +25,12 @@ import com.intellij.util.IncorrectOperationException
|
||||
import com.intellij.psi.PsiReference
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
|
||||
import java.util.Collections
|
||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression
|
||||
import org.jetbrains.jet.plugin.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.jet.lang.psi.JetElement
|
||||
import org.jetbrains.jet.utils.keysToMap
|
||||
import org.jetbrains.jet.plugin.caches.resolve.analyze
|
||||
|
||||
public trait JetReference : PsiPolyVariantReference {
|
||||
public fun resolveToDescriptors(): Collection<DeclarationDescriptor>
|
||||
@@ -72,18 +72,15 @@ public abstract class AbstractJetReference<T : JetElement>(element: T)
|
||||
override fun isSoft(): Boolean = false
|
||||
|
||||
private fun resolveToPsiElements(): Collection<PsiElement> {
|
||||
val context = AnalyzerFacadeWithCache.getContextForElement(expression)
|
||||
return resolveToPsiElements(context, getTargetDescriptors(context))
|
||||
return resolveToPsiElements(expression.analyze(), getTargetDescriptors(expression.analyze()))
|
||||
}
|
||||
|
||||
override fun resolveToDescriptors(): Collection<DeclarationDescriptor> {
|
||||
val context = AnalyzerFacadeWithCache.getContextForElement(expression)
|
||||
return getTargetDescriptors(context)
|
||||
return getTargetDescriptors(expression.analyze())
|
||||
}
|
||||
|
||||
override fun resolveMap(): Map<DeclarationDescriptor, Collection<PsiElement>> {
|
||||
val context = AnalyzerFacadeWithCache.getContextForElement(expression)
|
||||
return getTargetDescriptors(context) keysToMap { DescriptorToDeclarationUtil.resolveToPsiElements(expression.getProject(), it) }
|
||||
return getTargetDescriptors(expression.analyze()) keysToMap { DescriptorToDeclarationUtil.resolveToPsiElements(expression.getProject(), it) }
|
||||
}
|
||||
|
||||
private fun resolveToPsiElements(context: BindingContext, targetDescriptors: Collection<DeclarationDescriptor>): Collection<PsiElement> {
|
||||
|
||||
+3
-3
@@ -31,12 +31,12 @@ import org.jetbrains.jet.plugin.refactoring.fqName.getKotlinFqName
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions
|
||||
import org.jetbrains.jet.lexer.JetToken
|
||||
import org.jetbrains.jet.plugin.intentions.OperatorToFunctionIntention
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import com.intellij.util.IncorrectOperationException
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByTypeAndBranch
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.lang.resolve.dataClassUtils.isComponentLike
|
||||
import org.jetbrains.jet.plugin.caches.resolve.analyze
|
||||
|
||||
public class JetSimpleNameReference(
|
||||
jetSimpleNameExpression: JetSimpleNameExpression
|
||||
@@ -78,13 +78,13 @@ public class JetSimpleNameReference(
|
||||
val opExpression =
|
||||
PsiTreeUtil.getParentOfType<JetExpression>(expression, javaClass<JetUnaryExpression>(), javaClass<JetBinaryExpression>())
|
||||
if (elementType is JetToken && OperatorConventions.getNameForOperationSymbol(elementType) != null && opExpression != null) {
|
||||
val oldDescriptor = AnalyzerFacadeWithCache.getContextForElement(expression)[BindingContext.REFERENCE_TARGET, expression]
|
||||
val oldDescriptor = expression.analyze()[BindingContext.REFERENCE_TARGET, expression]
|
||||
val newExpression = OperatorToFunctionIntention.convert(opExpression)
|
||||
newExpression.accept(
|
||||
object: JetTreeVisitorVoid() {
|
||||
override fun visitCallExpression(expression: JetCallExpression) {
|
||||
val callee = expression.getCalleeExpression() as? JetSimpleNameExpression
|
||||
if (callee != null && AnalyzerFacadeWithCache.getContextForElement(callee)[BindingContext.REFERENCE_TARGET, callee] == oldDescriptor) {
|
||||
if (callee != null && callee.analyze()[BindingContext.REFERENCE_TARGET, callee] == oldDescriptor) {
|
||||
nameElement = callee.getReferencedNameElement()
|
||||
}
|
||||
else {
|
||||
|
||||
+2
-2
@@ -33,13 +33,13 @@ import org.jetbrains.jet.asJava.LightClassUtil.PropertyAccessorsPsiMethods
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.*
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.lexer.JetSingleValueToken
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.jet.lexer.JetTokens
|
||||
import org.jetbrains.jet.plugin.references.*
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import org.jetbrains.jet.plugin.caches.resolve.analyze
|
||||
|
||||
val isTargetUsage = (PsiReference::matchesTarget).searchFilter
|
||||
|
||||
@@ -75,7 +75,7 @@ public fun PsiNamedElement.getSpecialNamesToSearch(): List<String> {
|
||||
this is JetParameter -> {
|
||||
if (!hasValOrVarNode()) return Collections.emptyList<String>()
|
||||
|
||||
val context = AnalyzerFacadeWithCache.getContextForElement(this)
|
||||
val context = this.analyze()
|
||||
val paramDescriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, this] as? ValueParameterDescriptor
|
||||
context[BindingContext.DATA_CLASS_COMPONENT_FUNCTION, paramDescriptor]?.let {
|
||||
listOf(it.getName().asString(), JetTokens.LPAR.getValue())
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.jetbrains.jet.lang.descriptors.*
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.*
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
|
||||
import com.intellij.psi.PsiReference
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils
|
||||
import org.jetbrains.jet.codegen.PropertyCodegen
|
||||
@@ -31,12 +30,13 @@ import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.jet.plugin.references.*
|
||||
import org.jetbrains.jet.plugin.findUsages.UsageTypeUtils
|
||||
import org.jetbrains.jet.plugin.findUsages.UsageTypeEnum
|
||||
import org.jetbrains.jet.plugin.caches.resolve.analyze
|
||||
|
||||
val JetDeclaration.descriptor: DeclarationDescriptor?
|
||||
get() = AnalyzerFacadeWithCache.getContextForElement(this).get(BindingContext.DECLARATION_TO_DESCRIPTOR, this)
|
||||
get() = this.analyze().get(BindingContext.DECLARATION_TO_DESCRIPTOR, this)
|
||||
|
||||
val JetParameter.propertyDescriptor: PropertyDescriptor?
|
||||
get() = AnalyzerFacadeWithCache.getContextForElement(this).get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, this)
|
||||
get() = this.analyze().get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, this)
|
||||
|
||||
fun PsiReference.checkUsageVsOriginalDescriptor(
|
||||
target: JetDeclaration,
|
||||
@@ -82,7 +82,7 @@ fun PsiReference.isConstructorUsage(jetClassOrObject: JetClassOrObject): Boolean
|
||||
fun checkKotlinUsage(): Boolean {
|
||||
if (this !is JetElement) return false
|
||||
|
||||
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(this)
|
||||
val bindingContext = this.analyze()
|
||||
|
||||
val descriptor = getCallDescriptor(bindingContext)
|
||||
if (descriptor !is ConstructorDescriptor) return false
|
||||
|
||||
+2
-7
@@ -16,21 +16,16 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.structureView
|
||||
|
||||
import com.intellij.ide.util.treeView.smartTree.TreeElement
|
||||
import com.intellij.ide.util.InheritedMembersNodeProvider
|
||||
import com.intellij.ide.util.treeView.smartTree.TreeElement
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject
|
||||
import com.intellij.psi.NavigatablePsiElement
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.jet.plugin.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor
|
||||
import com.intellij.psi.NavigatablePsiElement
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject
|
||||
import org.jetbrains.jet.plugin.caches.resolve.analyze
|
||||
|
||||
public class KotlinInheritedMembersNodeProvider: InheritedMembersNodeProvider<TreeElement>() {
|
||||
override fun provideNodes(node: TreeElement): Collection<TreeElement> {
|
||||
@@ -42,7 +37,7 @@ public class KotlinInheritedMembersNodeProvider: InheritedMembersNodeProvider<Tr
|
||||
[suppress("USELESS_CAST")] // KT-3996 Workaround
|
||||
val project = (element as NavigatablePsiElement).getProject()
|
||||
|
||||
val context = AnalyzerFacadeWithCache.getContextForElement(element)
|
||||
val context = element.analyze()
|
||||
val descriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, element]
|
||||
|
||||
if (descriptor !is ClassifierDescriptor) return listOf()
|
||||
|
||||
Reference in New Issue
Block a user