Refactor: inline AnalyzerFacadeWithCache#getContextForElement

This commit is contained in:
Pavel V. Talanov
2014-11-20 19:29:09 +03:00
parent 67b2c32253
commit ff3b3c8a6b
60 changed files with 147 additions and 207 deletions
@@ -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 {
@@ -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]
@@ -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);
}
}
@@ -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> {
@@ -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 {
@@ -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
@@ -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()
@@ -33,7 +33,7 @@ import org.jetbrains.jet.lang.psi.JetDeclaration;
import org.jetbrains.jet.lang.psi.JetPackageDirective;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import org.jetbrains.jet.renderer.DescriptorRenderer;
public class JetQuickDocumentationProvider extends AbstractDocumentationProvider {
@@ -67,7 +67,7 @@ public class JetQuickDocumentationProvider extends AbstractDocumentationProvider
if (quickNavigation) {
JetReferenceExpression referenceExpression = PsiTreeUtil.getParentOfType(originalElement, JetReferenceExpression.class, false);
if (referenceExpression != null) {
BindingContext context = AnalyzerFacadeWithCache.getContextForElement(referenceExpression);
BindingContext context = ResolvePackage.analyze(referenceExpression);
DeclarationDescriptor declarationDescriptor = context.get(BindingContext.REFERENCE_TARGET, referenceExpression);
if (declarationDescriptor != null) {
return mixKotlinToJava(declarationDescriptor, element, originalElement);
@@ -82,7 +82,7 @@ public class JetQuickDocumentationProvider extends AbstractDocumentationProvider
}
private static String renderKotlinDeclaration(JetDeclaration declaration, boolean quickNavigation) {
BindingContext context = AnalyzerFacadeWithCache.getContextForElement(declaration);
BindingContext context = ResolvePackage.analyze(declaration);
DeclarationDescriptor declarationDescriptor = context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
assert declarationDescriptor != null;
@@ -26,8 +26,8 @@ import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.plugin.JetBundle;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import org.jetbrains.jet.plugin.codeInsight.CodeInsightUtils;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
public class KotlinSurrounderUtils {
public static String SURROUND_WITH = JetBundle.message("surround.with");
@@ -46,7 +46,7 @@ public class KotlinSurrounderUtils {
@Nullable
public static JetType getExpressionType(JetExpression expression) {
BindingContext expressionBindingContext = AnalyzerFacadeWithCache.getContextForElement(expression);
BindingContext expressionBindingContext = ResolvePackage.analyze(expression);
return expressionBindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
}
@@ -29,9 +29,9 @@ import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import org.jetbrains.jet.plugin.codeInsight.CodeInsightUtils;
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers;
import java.util.ArrayList;
@@ -116,7 +116,7 @@ public class MoveDeclarationsOutHelper {
@NotNull
private static JetType getPropertyType(@NotNull JetProperty property) {
BindingContext expressionBindingContext = AnalyzerFacadeWithCache.getContextForElement(property);
BindingContext expressionBindingContext = ResolvePackage.analyze(property);
VariableDescriptor propertyDescriptor = expressionBindingContext.get(BindingContext.VARIABLE, property);
assert propertyDescriptor != null : "Couldn't resolve property to property descriptor " + property.getText();
@@ -24,7 +24,6 @@ import com.intellij.debugger.actions.MethodSmartStepTarget
import com.intellij.util.containers.OrderedSet
import com.intellij.util.Range
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.asJava.LightClassUtil
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor
import com.intellij.psi.PsiElement
@@ -40,6 +39,7 @@ import com.intellij.psi.PsiDocumentManager
import org.jetbrains.jet.lang.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils
import org.jetbrains.jet.plugin.util.application.runReadAction
import org.jetbrains.jet.plugin.caches.resolve.analyze
public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
@@ -66,7 +66,7 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
if (doc == null) return Collections.emptyList()
val lines = Range<Int>(doc.getLineNumber(elementTextRange.getStartOffset()), doc.getLineNumber(elementTextRange.getEndOffset()))
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(element)
val bindingContext = element.analyze()
val result = OrderedSet<SmartStepTarget>()
// TODO support class initializers, local functions, delegated properties with specified type, setter for properties
@@ -42,7 +42,7 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import javax.swing.*;
@@ -164,7 +164,7 @@ public class KotlinCallHierarchyNodeDescriptor extends HierarchyNodeDescriptor i
elementText = ((JetFile) element).getName();
}
else if (element instanceof JetNamedDeclaration) {
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement((JetElement) element);
BindingContext bindingContext = ResolvePackage.analyze((JetElement) element);
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);
if (descriptor == null) return null;
@@ -27,7 +27,7 @@ import com.intellij.psi.PsiReference;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.asJava.KotlinLightMethod;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import java.util.ArrayList;
import java.util.HashMap;
@@ -84,7 +84,7 @@ public class KotlinCalleeMethodsTreeStructure extends KotlinCallTreeStructure {
final Map<PsiReference, PsiElement> referencesToCalleeElements = new HashMap<PsiReference, PsiElement>();
for (JetElement element : elementsToAnalyze) {
element.accept(
new CalleeReferenceVisitorBase(AnalyzerFacadeWithCache.getContextForElement(element), false) {
new CalleeReferenceVisitorBase(ResolvePackage.analyze(element), false) {
@Override
protected void processDeclaration(JetReferenceExpression reference, PsiElement declaration) {
referencesToCalleeElements.put(reference.getReference(), declaration);
@@ -37,8 +37,8 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.asJava.LightClassUtil;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import org.jetbrains.jet.plugin.hierarchy.HierarchyUtils;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.references.JetReference;
import org.jetbrains.jet.plugin.search.usagesSearch.UsagesSearchPackage;
@@ -68,7 +68,7 @@ public class KotlinCallerMethodsTreeStructure extends KotlinCallTreeStructure {
JetElement codeBlockForLocalDeclaration = getEnclosingElementForLocalDeclaration(element);
if (codeBlockForLocalDeclaration != null) {
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement((JetElement) element);
BindingContext bindingContext = ResolvePackage.analyze((JetElement) element);
final Map<PsiReference, PsiElement> referencesToElements = new HashMap<PsiReference, PsiElement>();
codeBlockForLocalDeclaration.accept(new CalleeReferenceVisitorBase(bindingContext, true) {
@@ -35,8 +35,8 @@ import com.intellij.codeInsight.daemon.GutterIconNavigationHandler
import java.util.ArrayList
import com.intellij.util.Function
import org.jetbrains.jet.lang.psi.JetDeclaration
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.plugin.caches.resolve.analyze
object SuperDeclarationMarkerTooltip: Function<JetDeclaration, String> {
override fun `fun`(jetDeclaration: JetDeclaration?): String? {
@@ -112,7 +112,7 @@ public data class ResolveWithParentsResult(
val overriddenDescriptors: Collection<CallableMemberDescriptor>)
public fun resolveDeclarationWithParents(element: JetDeclaration): ResolveWithParentsResult {
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(element)
val bindingContext = element.analyze()
val descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element)
if (descriptor !is CallableMemberDescriptor) return ResolveWithParentsResult(null, listOf())
@@ -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.psi.JetPsiFactory
import org.jetbrains.jet.lang.psi.JetPrefixExpression
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences
@@ -32,6 +31,7 @@ import org.jetbrains.jet.lang.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.jet.lang.psi.JetBlockExpression
import org.jetbrains.jet.lang.psi.JetThrowExpression
import org.jetbrains.jet.lang.psi.psiUtil.replaced
import org.jetbrains.jet.plugin.caches.resolve.analyze
public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention<JetCallExpression>(
"convert.assert.to.if.with.throw", javaClass()) {
@@ -45,7 +45,7 @@ public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention<Jet
if (argumentSize !in 1..2) return false
if (element.getFunctionLiteralArguments().size == 1 && argumentSize == 1) return false
val context = AnalyzerFacadeWithCache.getContextForElement(element)
val context = element.analyze()
val resolvedCall = element.getResolvedCall(context)
if (resolvedCall == null) return false
@@ -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.psi.JetPsiFactory
import org.jetbrains.jet.lang.psi.JetPrefixExpression
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences
@@ -30,6 +29,7 @@ import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression
import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.plugin.intentions.branchedTransformations.isNullExpression
import org.jetbrains.jet.lang.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.jet.plugin.caches.resolve.analyze
public class ConvertIfWithThrowToAssertIntention :
JetSelfTargetingIntention<JetIfExpression>("convert.if.with.throw.to.assert", javaClass()) {
@@ -48,7 +48,7 @@ public class ConvertIfWithThrowToAssertIntention :
val paramAmount = thrownExpr.getValueArguments().size
if (paramAmount > 1) return false
val context = AnalyzerFacadeWithCache.getContextForElement(thrownExpr)
val context = thenExpr.analyze()
val resolvedCall = thrownExpr.getResolvedCall(context)
if (resolvedCall == null) return false
@@ -7,11 +7,11 @@ import org.jetbrains.jet.lang.psi.JetStringTemplateEntry
import org.jetbrains.jet.lang.psi.JetBinaryExpression
import org.jetbrains.jet.lang.psi.JetStringTemplateEntryWithExpression
import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.resolve.BindingContextUtils
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
import org.jetbrains.jet.lang.psi.JetIfExpression
import org.jetbrains.jet.lang.psi.JetBlockExpression
import org.jetbrains.jet.plugin.caches.resolve.analyze
public class ConvertToConcatenatedStringIntention : JetSelfTargetingIntention<JetStringTemplateExpression>("convert.to.concatenated.string.intention", javaClass()) {
override fun isApplicableTo(element: JetStringTemplateExpression): Boolean {
@@ -62,7 +62,7 @@ public class ConvertToConcatenatedStringIntention : JetSelfTargetingIntention<Je
private fun String.quote(quote: String) = quote + this + quote
private fun JetExpression.isStringExpression(): Boolean {
val context = AnalyzerFacadeWithCache.getContextForElement(this)
val context = this.analyze()
val elementType = BindingContextUtils.getRecordedTypeInfo(this, context)?.getType()
return KotlinBuiltIns.getInstance().isString(elementType)
@@ -18,7 +18,6 @@ package org.jetbrains.jet.plugin.intentions
import org.jetbrains.jet.lang.psi.JetBinaryExpression
import com.intellij.openapi.editor.Editor
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.resolve.BindingContextUtils
import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.lang.psi.JetPsiFactory
@@ -33,13 +32,14 @@ import org.jetbrains.jet.lang.psi.JetPsiUtil
import com.intellij.openapi.util.text.StringUtil
import com.intellij.psi.util.PsiUtilCore
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
import org.jetbrains.jet.plugin.caches.resolve.analyze
public class ConvertToStringTemplateIntention : JetSelfTargetingIntention<JetBinaryExpression>("convert.to.string.template", javaClass()) {
override fun isApplicableTo(element: JetBinaryExpression): Boolean {
if (element.getOperationToken() != JetTokens.PLUS) return false
val context = AnalyzerFacadeWithCache.getContextForElement(element)
val context = element.analyze()
val elementType = BindingContextUtils.getRecordedTypeInfo(element, context)?.getType()
if (!(KotlinBuiltIns.getInstance().isString(elementType))) return false
@@ -80,7 +80,7 @@ public class ConvertToStringTemplateIntention : JetSelfTargetingIntention<JetBin
val expressionText = expression?.getText() ?: ""
return when (expression) {
is JetConstantExpression -> {
val context = AnalyzerFacadeWithCache.getContextForElement(expression)
val context = expression.analyze()
val trace = DelegatingBindingTrace(context, "Trace for evaluating constant")
val constant = ConstantExpressionEvaluator.evaluate(expression, trace, null)
if (constant is IntegerValueTypeConstant) {
@@ -18,13 +18,13 @@ 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.psi.JetPsiFactory
import org.jetbrains.jet.lang.types.ErrorUtils
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences
import org.jetbrains.jet.lang.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.jet.lang.psi.JetTypeArgumentList
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers
import org.jetbrains.jet.plugin.caches.resolve.analyze
public class InsertExplicitTypeArguments : JetSelfTargetingIntention<JetCallExpression>(
"insert.explicit.type.arguments", javaClass()) {
@@ -40,7 +40,7 @@ public class InsertExplicitTypeArguments : JetSelfTargetingIntention<JetCallExpr
val textRange = element.getCalleeExpression()?.getTextRange()
if (textRange == null || !textRange.contains(editor.getCaretModel().getOffset())) return false
val context = AnalyzerFacadeWithCache.getContextForElement(element)
val context = element.analyze()
val resolvedCall = element.getResolvedCall(context)
if (resolvedCall == null) return false
@@ -61,7 +61,7 @@ public class InsertExplicitTypeArguments : JetSelfTargetingIntention<JetCallExpr
class object {
fun createTypeArguments(element: JetCallExpression): JetTypeArgumentList? {
val context = AnalyzerFacadeWithCache.getContextForElement(element)
val context = element.analyze()
val resolvedCall = element.getResolvedCall(context)
if (resolvedCall == null) return null
@@ -18,13 +18,13 @@ package org.jetbrains.jet.plugin.intentions
import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression
import com.intellij.openapi.editor.Editor
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.types.ErrorUtils
import org.jetbrains.jet.lang.psi.JetPsiFactory
import com.intellij.psi.PsiWhiteSpace
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers
import org.jetbrains.jet.plugin.caches.resolve.analyze
public class MakeTypeExplicitInLambdaIntention : JetSelfTargetingIntention<JetFunctionLiteralExpression>(
"make.type.explicit.in.lambda", javaClass()) {
@@ -42,7 +42,7 @@ public class MakeTypeExplicitInLambdaIntention : JetSelfTargetingIntention<JetFu
caretLocation != closeBraceOffset) return false
else if (arrow == null && caretLocation != openBraceOffset + 1 && caretLocation != closeBraceOffset) return false
val context = AnalyzerFacadeWithCache.getContextForElement(element)
val context = element.analyze()
val func = context[BindingContext.FUNCTION, element.getFunctionLiteral()]
if (func == null || ErrorUtils.containsErrorType(func)) return false
@@ -55,7 +55,7 @@ public class MakeTypeExplicitInLambdaIntention : JetSelfTargetingIntention<JetFu
override fun applyTo(element: JetFunctionLiteralExpression, editor: Editor) {
val functionLiteral = element.getFunctionLiteral()
val context = AnalyzerFacadeWithCache.getContextForElement(element)
val context = element.analyze()
val func = context[BindingContext.FUNCTION, functionLiteral]!!
// Step 1: make the parameters types explicit
@@ -26,8 +26,8 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.plugin.JetBundle;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers;
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
@@ -81,6 +81,6 @@ public class ReconstructTypeInCastOrIsAction extends PsiElementBaseIntentionActi
}
private static JetType getReconstructedType(JetTypeReference typeRef) {
return AnalyzerFacadeWithCache.getContextForElement(typeRef).get(BindingContext.TYPE, typeRef);
return ResolvePackage.analyze(typeRef).get(BindingContext.TYPE, typeRef);
}
}
@@ -26,9 +26,7 @@ import com.intellij.usageView.UsageInfo
import org.jetbrains.jet.lang.psi.*
import org.jetbrains.jet.plugin.JetBundle
import com.intellij.psi.codeStyle.CodeStyleManager
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor
import org.jetbrains.jet.lang.resolve.BindingContextUtils
import org.jetbrains.jet.plugin.references.JetReference
import org.jetbrains.jet.lang.descriptors.VariableDescriptor
import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils
@@ -27,12 +27,12 @@ import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression
import org.jetbrains.jet.lang.psi.JetPsiFactory
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.plugin.JetBundle
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor
import org.jetbrains.jet.lang.psi.JetFunctionLiteral
import org.jetbrains.jet.plugin.references.JetReference
import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils
import org.jetbrains.jet.plugin.caches.resolve.analyze
public class ReplaceItWithExplicitFunctionLiteralParamIntention() : PsiElementBaseIntentionAction() {
override fun invoke(project: Project, editor: Editor, element: PsiElement) {
@@ -74,7 +74,7 @@ public class ReplaceItWithExplicitFunctionLiteralParamIntention() : PsiElementBa
return false
}
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(simpleNameExpression)
val bindingContext = simpleNameExpression.analyze()
val reference = simpleNameExpression.getReference() as JetReference?
val simpleNameTarget = reference?.resolveToDescriptors()?.firstOrNull() as? ValueParameterDescriptor?
if (simpleNameTarget == null || bindingContext.get(BindingContext.AUTO_CREATED_IT, simpleNameTarget) != true) {
@@ -23,11 +23,11 @@ import org.jetbrains.jet.plugin.caches.resolve.analyzeFully
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.plugin.JetBundle
import org.jetbrains.jet.lang.psi.JetValueArgument
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.psi.JetPsiUnparsingUtils
import org.jetbrains.jet.lang.psi.JetPsiFactory
import com.intellij.codeInsight.hint.HintManager
import org.jetbrains.jet.lang.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.jet.plugin.caches.resolve.analyze
public open class ReplaceWithInfixFunctionCallIntention : JetSelfTargetingIntention<JetCallExpression>("replace.with.infix.function.call.intention", javaClass()) {
override fun isApplicableTo(element: JetCallExpression): Boolean {
@@ -88,7 +88,7 @@ public open class ReplaceWithInfixFunctionCallIntention : JetSelfTargetingIntent
val operatorText = element.getCalleeExpression()!!.getText()
val valueArguments = element.getValueArgumentList()?.getArguments() ?: listOf<JetValueArgument>()
val functionLiteralArguments = element.getFunctionLiteralArguments()
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(parent)
val bindingContext = parent.analyze()
val receiverType = bindingContext[BindingContext.EXPRESSION_TYPE, receiver]
if (receiverType == null) {
if (bindingContext[BindingContext.QUALIFIER, receiver] != null) {
@@ -21,13 +21,11 @@ import com.intellij.openapi.editor.Editor
import org.jetbrains.jet.lexer.JetTokens
import org.jetbrains.jet.lang.psi.JetPsiFactory
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
import org.jetbrains.jet.plugin.util.psi.patternMatching.JetPsiUnifier
import org.jetbrains.jet.plugin.util.psi.patternMatching.UnificationResult
import org.jetbrains.jet.plugin.util.psi.patternMatching.matches
import org.jetbrains.jet.plugin.caches.resolve.analyze
public class ReplaceWithOperatorAssignIntention : JetSelfTargetingIntention<JetBinaryExpression>("replace.with.operator.assign.intention", javaClass()) {
@@ -44,7 +42,7 @@ public class ReplaceWithOperatorAssignIntention : JetSelfTargetingIntention<JetB
}
fun checkExpressionRepeat(variableExpression: JetSimpleNameExpression, expression: JetBinaryExpression): Boolean {
val context = AnalyzerFacadeWithCache.getContextForElement(expression)
val context = expression.analyze()
val descriptor = context[BindingContext.REFERENCE_TARGET, expression.getOperationReference()]?.getContainingDeclaration()
val isPrimitiveOperation = descriptor is ClassDescriptor && KotlinBuiltIns.getInstance().isPrimitiveType(descriptor.getDefaultType())
@@ -24,11 +24,11 @@ import org.jetbrains.jet.lang.psi.JetParenthesizedExpression
import org.jetbrains.jet.lexer.JetTokens
import org.jetbrains.jet.lang.resolve.CompileTimeConstantUtils
import org.jetbrains.jet.lang.resolve.DelegatingBindingTrace
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import com.intellij.psi.tree.IElementType
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.jet.lang.psi.psiUtil.copied
import org.jetbrains.jet.lang.psi.psiUtil.replaced
import org.jetbrains.jet.plugin.caches.resolve.analyze
public class SimplifyBooleanWithConstantsIntention : JetSelfTargetingIntention<JetBinaryExpression>(
"simplify.boolean.with.constants", javaClass()) {
@@ -128,7 +128,7 @@ public class SimplifyBooleanWithConstantsIntention : JetSelfTargetingIntention<J
}
private fun JetExpression.canBeReducedToBooleanConstant(constant: Boolean?): Boolean {
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(this)
val bindingContext = this.analyze()
val trace = DelegatingBindingTrace(bindingContext, "trace for constant check")
return CompileTimeConstantUtils.canBeReducedToBooleanConstant(this, trace, constant)
}
@@ -22,7 +22,6 @@ import org.jetbrains.jet.lang.psi.JetQualifiedExpression
import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression
import org.jetbrains.jet.plugin.intentions.JetSelfTargetingIntention
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
import org.jetbrains.jet.lang.psi.ValueArgument
import org.jetbrains.jet.plugin.JetBundle
@@ -33,6 +32,7 @@ import org.jetbrains.jet.plugin.util.MaybeError
import org.jetbrains.jet.plugin.util.MaybeValue
import com.intellij.codeInsight.hint.HintManager
import org.jetbrains.jet.lang.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.jet.plugin.caches.resolve.analyze
// Internal because you shouldn't construct this manually. You can end up with an inconsistant CallDescription.
public class CallDescription internal (
@@ -89,7 +89,7 @@ public class CallDescription internal (
public fun JetQualifiedExpression.toCallDescription(): CallDescription? {
val callExpression = getSelectorExpression() as? JetCallExpression ?: return null
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(callExpression)
val bindingContext = callExpression.analyze()
// This should work. Nothing that returns a CallableDescriptor returns null and (out T is T)
val resolvedCall = callExpression.getResolvedCall(bindingContext) ?:
return null
@@ -27,7 +27,6 @@ import com.intellij.openapi.editor.Editor
import org.jetbrains.jet.plugin.refactoring.introduce.introduceVariable.KotlinIntroduceVariableHandler
import org.jetbrains.jet.lang.psi.JetSafeQualifiedExpression
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import com.intellij.psi.PsiElement
import org.jetbrains.jet.plugin.refactoring.inline.KotlinInlineValHandler
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
@@ -44,6 +43,7 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils
import org.jetbrains.jet.lang.psi.JetElement
import org.jetbrains.jet.lang.resolve.bindingContextUtil.isUsedAsStatement
import org.jetbrains.jet.lang.psi.JetProperty
import org.jetbrains.jet.plugin.caches.resolve.analyze
val NULL_PTR_EXCEPTION = "NullPointerException"
val NULL_PTR_EXCEPTION_FQ = "java.lang.NullPointerException"
@@ -73,7 +73,7 @@ fun JetExpression.extractExpressionIfSingle(): JetExpression? {
return innerExpression
}
fun JetExpression.isStatement(): Boolean = isUsedAsStatement(AnalyzerFacadeWithCache.getContextForElement(this))
fun JetExpression.isStatement(): Boolean = isUsedAsStatement(this.analyze())
fun JetBinaryExpression.getNonNullExpression(): JetExpression? = when {
this.getLeft()?.isNullExpression() == false ->
@@ -94,7 +94,7 @@ fun JetThrowExpression.throwsNullPointerExceptionWithNoArguments(): Boolean {
val thrownExpression = this.getThrownExpression()
if (thrownExpression !is JetCallExpression) return false
val context = AnalyzerFacadeWithCache.getContextForElement(this)
val context = this.analyze()
val descriptor = context.get(BindingContext.REFERENCE_TARGET, thrownExpression.getCalleeExpression() as JetSimpleNameExpression)
val declDescriptor = descriptor?.getContainingDeclaration()
if (declDescriptor == null) return false
@@ -169,7 +169,7 @@ fun JetPostfixExpression.inlineBaseExpressionIfApplicableWithPrompt(editor: Edit
}
fun JetExpression.isStableVariable(): Boolean {
val context = AnalyzerFacadeWithCache.getContextForElement(this)
val context = this.analyze()
val descriptor = BindingContextUtils.extractVariableDescriptorIfAny(context, this, false)
return descriptor is VariableDescriptor && DataFlowValueFactory.isStableVariable(descriptor)
}
@@ -25,10 +25,7 @@ import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.PsiWhiteSpace
import java.util.Collections
import com.intellij.util.containers.ContainerUtil
import org.jetbrains.jet.plugin.util.psi.patternMatching.JetPsiUnifier
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.plugin.util.psi.patternMatching.toRange
import org.jetbrains.jet.plugin.util.psi.patternMatching.UnificationResult
import org.jetbrains.jet.plugin.util.psi.patternMatching.matches
public val TRANSFORM_WITHOUT_CHECK: String = "Expression must be checked before applying transformation"
@@ -22,10 +22,9 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
@@ -45,7 +44,7 @@ public class DeclarationUtils {
private static JetType getPropertyTypeIfNeeded(@NotNull JetProperty property) {
if (property.getTypeReference() != null) return null;
JetType type = AnalyzerFacadeWithCache.getContextForElement(property).get(
JetType type = ResolvePackage.analyze(property).get(
BindingContext.EXPRESSION_TYPE, property.getInitializer()
);
return type == null || type.isError() ? null : type;
@@ -32,8 +32,8 @@ import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import org.jetbrains.jet.plugin.codeInsight.ImplementMethodsHandler;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import java.util.HashMap;
import java.util.Map;
@@ -60,7 +60,7 @@ class AnonymousTemplateEditingListener extends TemplateEditingAdapter {
PsiElement name = psiFile.findElementAt(variableRange.getStartOffset());
if (name != null && name.getParent() instanceof JetReferenceExpression) {
JetReferenceExpression ref = (JetReferenceExpression) name.getParent();
DeclarationDescriptor descriptor = AnalyzerFacadeWithCache.getContextForElement(ref).get(BindingContext.REFERENCE_TARGET, ref);
DeclarationDescriptor descriptor = ResolvePackage.analyze(ref).get(BindingContext.REFERENCE_TARGET, ref);
if (descriptor instanceof ClassDescriptor) {
classRef = ref;
classDescriptor = (ClassDescriptor) descriptor;
@@ -40,7 +40,7 @@ import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils;
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.plugin.JetBundle;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import java.util.ArrayList;
import java.util.LinkedHashSet;
@@ -91,7 +91,7 @@ public class JetAnonymousSuperMacro extends Macro {
JetExpression expression = PsiTreeUtil.getParentOfType(psiFile.findElementAt(context.getStartOffset()), JetExpression.class);
if (expression == null) return null;
BindingContext bc = AnalyzerFacadeWithCache.getContextForElement(expression);
BindingContext bc = ResolvePackage.analyze(expression);
JetScope scope = bc.get(BindingContext.RESOLUTION_SCOPE, expression);
if (scope == null) return null;
@@ -2,7 +2,6 @@ package org.jetbrains.jet.plugin.quickfix.createFromUsage.createClass
import org.jetbrains.jet.lang.diagnostics.Diagnostic
import com.intellij.codeInsight.intention.IntentionAction
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.TypeInfo
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.types.Variance
@@ -14,12 +13,11 @@ import org.jetbrains.jet.lang.psi.JetAnnotationEntry
import org.jetbrains.jet.lang.psi.JetUserType
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.jet.lang.psi.JetDelegatorToSuperCall
import org.jetbrains.jet.lang.psi.JetDelegatorToThisCall
import org.jetbrains.jet.lang.psi.JetCallElement
import org.jetbrains.jet.lang.psi.psiUtil.isAncestor
import org.jetbrains.jet.lang.psi.JetConstructorCalleeExpression
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
import java.util.Collections
import org.jetbrains.jet.plugin.caches.resolve.analyze
public object CreateClassFromCallWithConstructorCalleeActionFactory : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
@@ -42,7 +40,7 @@ public object CreateClassFromCallWithConstructorCalleeActionFactory : JetSingleI
val typeRef = callee.getTypeReference() ?: return null
val userType = typeRef.getTypeElement() as? JetUserType ?: return null
val context = AnalyzerFacadeWithCache.getContextForElement(userType)
val context = userType.analyze()
val qualifier = userType.getQualifier()?.getReferenceExpression()
val qualifierDescriptor = qualifier?.let { context[BindingContext.REFERENCE_TARGET, it] }
@@ -12,8 +12,8 @@ import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.TypeInf
import org.jetbrains.jet.lang.types.Variance
import org.jetbrains.jet.lang.psi.JetDelegatorToSuperClass
import org.jetbrains.jet.lang.psi.JetConstructorCalleeExpression
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.utils.addToStdlib.singletonOrEmptyList
import org.jetbrains.jet.plugin.caches.resolve.analyze
public object CreateClassFromTypeReferenceActionFactory: JetIntentionActionsFactory() {
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction> {
@@ -28,7 +28,7 @@ public object CreateClassFromTypeReferenceActionFactory: JetIntentionActionsFact
val traitExpected = typeRefParent is JetDelegatorToSuperClass
val context = AnalyzerFacadeWithCache.getContextForElement(userType)
val context = userType.analyze()
val file = userType.getContainingFile() as? JetFile ?: return Collections.emptyList()
@@ -9,7 +9,6 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
import org.jetbrains.jet.lexer.JetTokens
import org.jetbrains.jet.lang.psi.JetQualifiedExpression
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.resolve.calls.callUtil.getCall
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.jet.lang.resolve.scopes.receivers.Qualifier
@@ -26,6 +25,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.psi.JetTypeReference
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.jet.lang.psi.JetAnnotationEntry
import org.jetbrains.jet.plugin.caches.resolve.analyze
object CreateFunctionOrPropertyFromCallActionFactory : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
@@ -33,22 +33,22 @@ object CreateFunctionOrPropertyFromCallActionFactory : JetSingleIntentionActionF
if (PsiTreeUtil.getParentOfType(diagElement, javaClass<JetTypeReference>(), javaClass<JetAnnotationEntry>()) != null) return null
val callExpr = when (diagnostic.getFactory()) {
in Errors.UNRESOLVED_REFERENCE_DIAGNOSTICS, Errors.EXPRESSION_EXPECTED_PACKAGE_FOUND -> {
val parent = diagElement.getParent()
if (parent is JetCallExpression && parent.getCalleeExpression() == diagElement) parent else diagElement
}
in Errors.UNRESOLVED_REFERENCE_DIAGNOSTICS, Errors.EXPRESSION_EXPECTED_PACKAGE_FOUND -> {
val parent = diagElement.getParent()
if (parent is JetCallExpression && parent.getCalleeExpression() == diagElement) parent else diagElement
}
Errors.NO_VALUE_FOR_PARAMETER,
Errors.TOO_MANY_ARGUMENTS -> diagElement.getParentByType(javaClass<JetCallExpression>())
Errors.NO_VALUE_FOR_PARAMETER,
Errors.TOO_MANY_ARGUMENTS -> diagElement.getParentByType(javaClass<JetCallExpression>())
else -> throw AssertionError("Unexpected diagnostic: ${diagnostic.getFactory()}")
} as? JetExpression ?: return null
else -> throw AssertionError("Unexpected diagnostic: ${diagnostic.getFactory()}")
} as? JetExpression ?: return null
val calleeExpr = when (callExpr) {
is JetCallExpression -> callExpr.getCalleeExpression()
is JetSimpleNameExpression -> callExpr
else -> null
} as? JetSimpleNameExpression ?: return null
is JetCallExpression -> callExpr.getCalleeExpression()
is JetSimpleNameExpression -> callExpr
else -> null
} as? JetSimpleNameExpression ?: return null
if (calleeExpr.getReferencedNameElementType() != JetTokens.IDENTIFIER) return null
@@ -56,7 +56,7 @@ object CreateFunctionOrPropertyFromCallActionFactory : JetSingleIntentionActionF
val fullCallExpr =
if (callParent is JetQualifiedExpression && callParent.getSelectorExpression() == callExpr) callParent else callExpr
val context = AnalyzerFacadeWithCache.getContextForElement(callExpr)
val context = calleeExpr.analyze()
val receiver = callExpr.getCall(context)?.getExplicitReceiver()
val receiverType = when (receiver) {
@@ -8,7 +8,6 @@ import org.jetbrains.jet.lang.types.Variance
import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.ParameterInfo
import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.FunctionInfo
import org.jetbrains.jet.lang.psi.JetProperty
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
@@ -17,11 +16,12 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.CallableInfo
import com.intellij.util.SmartList
import org.jetbrains.jet.lang.descriptors.PropertyAccessorDescriptor
import org.jetbrains.jet.plugin.caches.resolve.analyze
object CreatePropertyDelegateAccessorsActionFactory : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
val expression = diagnostic.getPsiElement() as? JetExpression ?: return null
val context = AnalyzerFacadeWithCache.getContextForElement(expression)
val context = expression.analyze()
[suppress("UNCHECKED_CAST")]
fun isApplicableForAccessor(accessor: PropertyAccessorDescriptor?): Boolean =
@@ -15,8 +15,8 @@ import org.jetbrains.jet.lang.psi.JetOperationExpression
import org.jetbrains.jet.lang.psi.JetUnaryExpression
import org.jetbrains.jet.lang.types.expressions.OperatorConventions
import org.jetbrains.jet.lang.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.types.ErrorUtils
import org.jetbrains.jet.plugin.caches.resolve.analyze
object CreateSetFunctionActionFactory : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
@@ -38,7 +38,7 @@ object CreateSetFunctionActionFactory : JetSingleIntentionActionFactory() {
is JetUnaryExpression -> {
if (assignmentExpr.getOperationToken() !in OperatorConventions.INCREMENT_OPERATIONS) return null
val context = AnalyzerFacadeWithCache.getContextForElement(assignmentExpr)
val context = assignmentExpr.analyze()
val rhsType = assignmentExpr.getResolvedCall(context)?.getResultingDescriptor()?.getReturnType()
TypeInfo(if (rhsType == null || ErrorUtils.containsErrorType(rhsType)) builtIns.getAnyType() else rhsType, Variance.IN_VARIANCE)
}
@@ -33,7 +33,7 @@ import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lexer.JetLexer;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import java.util.ArrayList;
import java.util.regex.Matcher;
@@ -67,7 +67,7 @@ public class JetNameSuggester {
public static @NotNull String[] suggestNames(@NotNull JetExpression expression, @NotNull JetNameValidator validator, @Nullable String defaultName) {
ArrayList<String> result = new ArrayList<String>();
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(expression);
BindingContext bindingContext = ResolvePackage.analyze(expression);
JetType jetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
if (jetType != null) {
addNamesForType(result, jetType, validator);
@@ -25,7 +25,7 @@ import org.jetbrains.jet.lang.psi.JetVisitorVoid;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import java.util.HashSet;
import java.util.Set;
@@ -72,7 +72,7 @@ public class JetNameValidatorImpl extends JetNameValidator {
private boolean checkElement(String name, PsiElement sibling, final Set<JetScope> visitedScopes) {
if (!(sibling instanceof JetElement)) return true;
final BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement((JetElement) sibling);
final BindingContext bindingContext = ResolvePackage.analyze((JetElement) sibling);
final Name identifier = Name.identifier(name);
final Ref<Boolean> result = new Ref<Boolean>(true);
@@ -51,9 +51,9 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lexer.JetModifierKeywordToken;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.plugin.JetBundle;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import org.jetbrains.jet.plugin.codeInsight.CodeInsightUtils;
import org.jetbrains.jet.plugin.codeInsight.DescriptorToDeclarationUtil;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers;
import org.jetbrains.jet.plugin.util.string.StringPackage;
import org.jetbrains.jet.renderer.DescriptorRenderer;
@@ -127,7 +127,7 @@ public class JetRefactoringUtil {
@Nullable Collection<PsiElement> ignore,
@NotNull String actionStringKey
) {
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(declaration);
BindingContext bindingContext = ResolvePackage.analyze(declaration);
CallableDescriptor declarationDescriptor =
(CallableDescriptor)bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
@@ -262,7 +262,7 @@ public class JetRefactoringUtil {
PsiElement originalDeclaration = AsJavaPackage.getUnwrapped(method);
if (originalDeclaration instanceof JetDeclaration) {
JetDeclaration jetDeclaration = (JetDeclaration) originalDeclaration;
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(jetDeclaration);
BindingContext bindingContext = ResolvePackage.analyze(jetDeclaration);
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, jetDeclaration);
if (descriptor != null) return formatFunctionDescriptor(descriptor);
@@ -272,7 +272,7 @@ public class JetRefactoringUtil {
@NotNull
public static String formatClass(@NotNull JetClassOrObject classOrObject) {
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(classOrObject);
BindingContext bindingContext = ResolvePackage.analyze(classOrObject);
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, classOrObject);
if (descriptor instanceof ClassDescriptor) return formatClassDescriptor(descriptor);
@@ -425,7 +425,7 @@ public class JetRefactoringUtil {
}
if (addExpression) {
JetExpression expression = (JetExpression)element;
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(expression);
BindingContext bindingContext = ResolvePackage.analyze(expression);
JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
if (expressionType == null || !KotlinBuiltIns.getInstance().isUnit(expressionType)) {
expressions.add(expression);
@@ -32,10 +32,13 @@ import com.intellij.refactoring.util.CommonRefactoringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import org.jetbrains.jet.plugin.refactoring.JetRefactoringBundle;
import java.util.Collection;
@@ -74,7 +77,7 @@ public class JetChangeSignatureHandler implements ChangeSignatureHandler {
JetElement jetElement = PsiTreeUtil.getParentOfType(element, JetElement.class);
if (jetElement == null) return null;
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(jetElement);
BindingContext bindingContext = ResolvePackage.analyze(jetElement);
DeclarationDescriptor descriptor =
bindingContext.get(BindingContext.REFERENCE_TARGET, (JetSimpleNameExpression) receiverExpr);
@@ -92,7 +95,7 @@ public class JetChangeSignatureHandler implements ChangeSignatureHandler {
@NotNull Project project,
@Nullable Editor editor
) {
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(element);
BindingContext bindingContext = ResolvePackage.analyze(element);
FunctionDescriptor functionDescriptor = findDescriptor(element, project, editor, bindingContext);
if (functionDescriptor == null) {
return;
@@ -41,7 +41,7 @@ import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import org.jetbrains.jet.plugin.refactoring.changeSignature.usages.JetFunctionCallUsage;
import org.jetbrains.jet.plugin.refactoring.changeSignature.usages.JetFunctionDefinitionUsage;
import org.jetbrains.jet.plugin.refactoring.changeSignature.usages.JetParameterUsage;
@@ -129,7 +129,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
JetChangeInfo changeInfo = (JetChangeInfo) info;
PsiElement function = info.getMethod();
PsiElement element = function != null ? function : changeInfo.getContext();
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement((JetElement) element);
BindingContext bindingContext = ResolvePackage.analyze((JetElement) element);
FunctionDescriptor oldDescriptor = changeInfo.getOldDescriptor();
JetScope parametersScope = null;
DeclarationDescriptor containingDeclaration = oldDescriptor != null ? oldDescriptor.getContainingDeclaration() : null;
@@ -22,7 +22,6 @@ import com.intellij.refactoring.changeSignature.ParameterInfo;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetFunction;
import org.jetbrains.jet.lang.psi.JetParameter;
import org.jetbrains.jet.lang.resolve.BindingContext;
@@ -30,7 +29,7 @@ import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import java.util.List;
@@ -91,7 +90,7 @@ public class JetParameterInfo implements ParameterInfo {
String inheritedParamName = inheritedParam.getName();
if (oldParam.getName().equals(inheritedParamName)) {
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(inheritedJetFunction);
BindingContext bindingContext = ResolvePackage.analyze(inheritedJetFunction);
JetScope parametersScope = JetChangeSignatureUsageProcessor.getFunctionBodyScope(inheritedJetFunction, bindingContext);
if (parametersScope != null && parametersScope.getLocalVariable(Name.identifier(name)) == null)
@@ -42,7 +42,6 @@ import org.jetbrains.jet.utils.DFS
import org.jetbrains.jet.utils.DFS.*
import com.intellij.refactoring.util.RefactoringUIUtil
import com.intellij.util.containers.MultiMap
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.diagnostics.Errors
import org.jetbrains.jet.plugin.refactoring.extractFunction.AnalysisResult.Status
import org.jetbrains.jet.plugin.refactoring.extractFunction.AnalysisResult.ErrorMessage
@@ -67,6 +66,7 @@ import org.jetbrains.jet.plugin.refactoring.extractFunction.OutputValueBoxer.AsL
import org.jetbrains.jet.plugin.refactoring.getContextForContainingDeclarationBody
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers
import org.jetbrains.jet.plugin.caches.resolve.findModuleDescriptor
import org.jetbrains.jet.plugin.caches.resolve.analyze
private val DEFAULT_FUNCTION_NAME = "myFun"
private val DEFAULT_RETURN_TYPE = KotlinBuiltIns.getInstance().getUnitType()
@@ -776,7 +776,7 @@ fun ExtractableCodeDescriptor.validate(): ExtractableCodeDescriptorWithConflicts
val result = generateDeclaration(ExtractionGeneratorOptions(inTempFile = true))
val valueParameterList = (result.declaration as? JetNamedFunction)?.getValueParameterList()
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(result.declaration.getGeneratedBlockBody())
val bindingContext = result.declaration.getGeneratedBlockBody().analyze()
for ((originalOffset, resolveResult) in extractionData.refOffsetToDeclaration) {
if (resolveResult.declaration.isInsideOf(extractionData.originalElements)) continue
@@ -62,7 +62,6 @@ import org.jetbrains.jet.plugin.JetLanguage;
import org.jetbrains.jet.plugin.caches.resolve.ResolutionFacade;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers;
import java.util.List;
@@ -231,7 +230,7 @@ public class KotlinInlineValHandler extends InlineActionHandler {
return null;
}
BindingContext context = AnalyzerFacadeWithCache.getContextForElement(initializer);
BindingContext context = ResolvePackage.analyze(initializer);
SimpleFunctionDescriptor fun = context.get(BindingContext.FUNCTION, functionLiteralExpression.getFunctionLiteral());
if (fun == null || ErrorUtils.containsErrorType(fun)) {
return null;
@@ -343,7 +342,7 @@ public class KotlinInlineValHandler extends InlineActionHandler {
@Nullable
private static String getTypeArgumentsStringForCall(@NotNull JetExpression initializer) {
BindingContext context = AnalyzerFacadeWithCache.getContextForElement(initializer);
BindingContext context = ResolvePackage.analyze(initializer);
ResolvedCall<?> call = CallUtilPackage.getResolvedCall(initializer, context);
if (call == null) return null;
@@ -59,7 +59,6 @@ import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
import org.jetbrains.jet.lang.psi.psiUtil.isAncestor
import com.intellij.psi.PsiNamedElement
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
import org.jetbrains.jet.renderer.DescriptorRenderer
import com.intellij.openapi.util.text.StringUtil
@@ -299,7 +298,7 @@ public fun chooseContainerElement<T>(
private fun JetElement.renderDeclaration(): String? {
val name = renderName()
val descriptor = AnalyzerFacadeWithCache.getContextForElement(this)[BindingContext.DECLARATION_TO_DESCRIPTOR, this]
val descriptor = this.analyze()[BindingContext.DECLARATION_TO_DESCRIPTOR, this]
val params = (descriptor as? FunctionDescriptor)?.let { descriptor ->
descriptor.getValueParameters()
.map { DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(it.getType()) }
@@ -21,12 +21,8 @@ import com.intellij.usageView.UsageInfo
import com.intellij.psi.PsiClass
import org.jetbrains.jet.lang.psi.JetQualifiedExpression
import org.jetbrains.jet.lang.psi.psiUtil.getQualifiedElementSelector
import org.jetbrains.jet.lang.psi.JetReferenceExpression
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.psi.JetCallExpression
import org.jetbrains.jet.lang.psi.JetPsiFactory
import java.util.Collections
import java.util.ArrayList
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
import com.intellij.psi.util.PsiTreeUtil
@@ -33,7 +33,6 @@ import com.intellij.usageView.UsageInfo
import com.intellij.refactoring.listeners.RefactoringElementListener
import com.intellij.openapi.editor.Editor
import org.jetbrains.jet.lexer.JetTokens
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.psi.JetClassOrObject
import com.intellij.openapi.ui.Messages
@@ -42,6 +41,7 @@ import org.jetbrains.jet.asJava.namedUnwrappedElement
import org.jetbrains.jet.lang.resolve.OverrideResolver
import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils
import org.jetbrains.jet.plugin.util.application.runReadAction
import org.jetbrains.jet.plugin.caches.resolve.analyze
public class RenameKotlinPropertyProcessor : RenamePsiElementProcessor() {
override fun canProcessElement(element: PsiElement): Boolean = element.namedUnwrappedElement is JetProperty
@@ -170,7 +170,7 @@ public class RenameKotlinPropertyProcessor : RenamePsiElementProcessor() {
private fun findDeepestOverriddenProperty(jetProperty: JetProperty): JetProperty? {
if (jetProperty.getModifierList()?.hasModifier(JetTokens.OVERRIDE_KEYWORD) == true) {
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(jetProperty)
val bindingContext = jetProperty.analyze()
val descriptor = bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, jetProperty]
if (descriptor != null) {
@@ -16,25 +16,21 @@
package org.jetbrains.jet.plugin.refactoring.safeDelete
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiParameter
import com.intellij.psi.PsiReference
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.refactoring.safeDelete.JavaSafeDeleteDelegate
import com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteReferenceSimpleDeleteUsageInfo
import com.intellij.usageView.UsageInfo
import org.jetbrains.jet.asJava.unwrapped
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
import org.jetbrains.jet.lang.psi.*
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.resolve.BindingContextUtils
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.plugin.references.JetReference
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
import org.jetbrains.jet.lang.psi.psiUtil.isAncestor
import org.jetbrains.jet.lang.psi.psiUtil.parameterIndex
import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils
import org.jetbrains.jet.plugin.caches.resolve.analyze
public class KotlinJavaSafeDeleteDelegate : JavaSafeDeleteDelegate {
override fun createUsageInfoForParameter(
@@ -50,7 +46,7 @@ public class KotlinJavaSafeDeleteDelegate : JavaSafeDeleteDelegate {
val calleeExpression = callExpression.getCalleeExpression()
if (!(calleeExpression is JetReferenceExpression && calleeExpression.isAncestor(element))) return
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(element)
val bindingContext = element.analyze()
val descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, calleeExpression)
if (descriptor == null) return
@@ -36,10 +36,13 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.psi.JetElement;
import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.psi.JetProperty;
import org.jetbrains.jet.lang.psi.JetPsiUtil;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.plugin.JetBundle;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import org.jetbrains.jet.plugin.refactoring.JetRefactoringUtil;
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers;
import org.jetbrains.jet.renderer.DescriptorRenderer;
@@ -90,7 +93,7 @@ class KotlinOverridingDialog extends DialogWrapper {
private static String formatElement(PsiElement element) {
element = JetPsiUtil.ascendIfPropertyAccessor(element);
if (element instanceof JetNamedFunction || element instanceof JetProperty) {
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement((JetElement) element);
BindingContext bindingContext = ResolvePackage.analyze((JetElement) element);
DeclarationDescriptor declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);
if (declarationDescriptor instanceof CallableMemberDescriptor) {
@@ -39,12 +39,12 @@ import org.jetbrains.jet.lang.psi.*
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lexer.JetTokens
import org.jetbrains.jet.plugin.JetBundle
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.plugin.refactoring.JetRefactoringUtil
import org.jetbrains.jet.plugin.references.JetReference
import java.util.*
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
import org.jetbrains.jet.lang.psi.psiUtil.deleteElementAndCleanParent
import org.jetbrains.jet.plugin.caches.resolve.analyze
public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
override fun handlesElement(element: PsiElement): Boolean = element.canDeleteElement()
@@ -208,7 +208,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
val modifierList = jetClass.getModifierList()
if (modifierList != null && modifierList.hasModifier(JetTokens.ABSTRACT_KEYWORD)) return null
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(element as JetElement)
val bindingContext = (element as JetElement).analyze()
val declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element)
if (declarationDescriptor !is CallableMemberDescriptor) return null
@@ -17,10 +17,9 @@
package org.jetbrains.jet.plugin.refactoring.safeDelete
import com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteReferenceSimpleDeleteUsageInfo
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
import org.jetbrains.jet.lang.psi.*
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.plugin.caches.resolve.analyze
public class SafeDeleteImportDirectiveUsageInfo(
importDirective: JetImportDirective, declaration: JetDeclaration
@@ -39,7 +38,7 @@ fun JetImportDirective.isSafeToDelete(declaration: JetDeclaration): Boolean {
}
if (importReference != null) {
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(importReference)
val bindingContext = importReference.analyze()
val referenceDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, importReference)
val declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration)
return referenceDescriptor == declarationDescriptor
@@ -43,7 +43,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.plugin.MainFunctionDetector;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import org.jetbrains.jet.plugin.stubindex.JetTopLevelFunctionsFqnNameIndex;
import java.util.*;
@@ -271,7 +271,7 @@ public class JetRunConfiguration extends ModuleBasedConfiguration<RunConfigurati
Collection<JetNamedFunction> mainFunctions = JetTopLevelFunctionsFqnNameIndex.getInstance().get(
mainFunFqName, module.getProject(), module.getModuleRuntimeScope(true));
for (JetNamedFunction function : mainFunctions) {
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(function);
BindingContext bindingContext = ResolvePackage.analyze(function);
MainFunctionDetector mainFunctionDetector = new MainFunctionDetector(bindingContext);
if (mainFunctionDetector.isMain(function)) {
return function;
@@ -17,9 +17,7 @@
package org.jetbrains.jet.completion
import org.jetbrains.jet.plugin.PluginTestCaseBase
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.psi.JetFile
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.psi.JetExpression
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.jet.plugin.completion.renderDataFlowValue
@@ -30,6 +28,7 @@ import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getDataFlowInfo
import org.jetbrains.jet.plugin.caches.resolve.analyze
public abstract class AbstractDataFlowValueRenderingTest: JetLightCodeInsightFixtureTestCase() {
override fun getTestDataPath() : String {
@@ -47,7 +46,7 @@ public abstract class AbstractDataFlowValueRenderingTest: JetLightCodeInsightFix
val jetFile = fixture.getFile() as JetFile
val element = jetFile.findElementAt(fixture.getCaretOffset())
val expression = PsiTreeUtil.getParentOfType(element, javaClass<JetExpression>())!!
val info = AnalyzerFacadeWithCache.getContextForElement(expression).getDataFlowInfo(expression)
val info = expression.analyze().getDataFlowInfo(expression)
val allValues = (info.getCompleteTypeInfo().keySet() + info.getCompleteNullabilityInfo().keySet()).toSet()
val actual = allValues.map { renderDataFlowValue(it) }.filterNotNull().sort().makeString("\n")
@@ -33,7 +33,6 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase;
import org.jetbrains.jet.plugin.PluginTestCaseBase;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import java.io.File;
import java.util.List;
@@ -112,7 +111,7 @@ public abstract class AbstractInsertImportOnPasteTest extends JetLightCodeInsigh
DebugInfoUtil.markDebugAnnotations(file, bindingContext, new DebugInfoUtil.DebugInfoReporter() {
@Override
public void preProcessReference(@NotNull JetReferenceExpression expression) {
AnalyzerFacadeWithCache.getContextForElement(expression);
ResolvePackage.analyze(expression);
}
@Override
@@ -33,7 +33,7 @@ import org.jetbrains.jet.lang.resolve.dataClassUtils.DataClassUtilsPackage;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.plugin.KotlinCodeInsightTestCase;
import org.jetbrains.jet.plugin.PluginTestCaseBase;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
import org.jetbrains.jet.plugin.refactoring.JetRefactoringBundle;
import java.io.File;
@@ -235,7 +235,7 @@ public class JetChangeSignatureTest extends KotlinCodeInsightTestCase {
return true;
}
};
BindingContext context = AnalyzerFacadeWithCache.getContextForElement(method);
BindingContext context = ResolvePackage.analyze(method);
ChangeSignaturePackage
.runChangeSignature(getProject(), changeInfo.getOldDescriptor(), empty, context, method, "test");
@@ -298,7 +298,7 @@ public class JetChangeSignatureTest extends KotlinCodeInsightTestCase {
JetElement element = (JetElement) new JetChangeSignatureHandler().findTargetMember(file, editor);
assertNotNull("Target element is null", element);
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(element);
BindingContext bindingContext = ResolvePackage.analyze(element);
PsiElement context = file.findElementAt(editor.getCaretModel().getOffset());
assertNotNull(context);