Fix usages of AnalyzerUtil

Sadly contains some changes that hard to merge into appropriate commits introduced after rebasing repeatedly
This commit is contained in:
Pavel V. Talanov
2015-08-06 15:28:32 +03:00
parent 5cc39e3fb2
commit 72710c0318
10 changed files with 69 additions and 35 deletions
@@ -32,20 +32,36 @@ import org.jetbrains.kotlin.types.expressions.JetTypeInfo
jvmOverloads
public fun JetExpression.computeTypeInfoInContext(
scope: JetScope,
contextExpression: JetExpression = this,
trace: BindingTrace = BindingTraceContext(),
dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY,
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE,
isStatement: Boolean = false
): JetTypeInfo {
return getResolutionFacade().frontendService<ExpressionTypingServices>(this).getTypeInfo(scope, this, expectedType, dataFlowInfo, trace)
return contextExpression.getResolutionFacade().frontendService<ExpressionTypingServices>(contextExpression)
.getTypeInfo(scope, this, expectedType, dataFlowInfo, trace, isStatement)
}
jvmOverloads
public fun JetExpression.analyzeInContext(
scope: JetScope,
contextExpression: JetExpression = this,
trace: BindingTrace = BindingTraceContext(),
dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY,
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE,
isStatement: Boolean = false
): BindingContext {
computeTypeInfoInContext(scope, contextExpression, trace, dataFlowInfo, expectedType, isStatement)
return trace.getBindingContext()
}
jvmOverloads
public fun JetExpression.computeTypeInContext(
scope: JetScope,
contextExpression: JetExpression = this,
trace: BindingTrace = BindingTraceContext(),
dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY,
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE
): BindingContext {
computeTypeInfoInContext(scope, trace, dataFlowInfo, expectedType)
return trace.getBindingContext()
): JetType? {
return computeTypeInfoInContext(scope, contextExpression, trace, dataFlowInfo, expectedType).type
}
@@ -33,7 +33,6 @@ import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
import javax.inject.Inject
import kotlin.properties.Delegates
public class CodeFragmentAnalyzer(
private val resolveSession: ResolveSession,
@@ -57,7 +56,8 @@ public class CodeFragmentAnalyzer(
codeFragmentExpression,
TypeUtils.NO_EXPECTED_TYPE,
dataFlowInfo,
trace
trace,
false
)
}
@@ -20,15 +20,15 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.idea.analysis.analyzeInContext
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.idea.analysis.analyzeInContext
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport
import org.jetbrains.kotlin.idea.imports.getImportableTargets
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.idea.util.ShortenReferences.Options
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.psi.*
@@ -339,7 +339,7 @@ public class ShortenReferences(val options: (JetElement) -> Options = { Options.
val scope = bindingContext[BindingContext.RESOLUTION_SCOPE, qualifiedExpression] ?: return false
val selectorCopy = selector.copy() as JetReferenceExpression
val newContext = selectorCopy.analyzeInContext(scope)
val newContext = selectorCopy.analyzeInContext(scope, selector)
val targetsWhenShort = (selectorCopy.getCalleeExpressionIfAny() as JetReferenceExpression).targets(newContext)
val targetsMatch = targetsWhenShort.singleOrNull()?.asString() == target.asString()
@@ -386,7 +386,7 @@ public class ShortenReferences(val options: (JetElement) -> Options = { Options.
val targetBefore = thisExpression.getInstanceReference().targets(bindingContext).singleOrNull() ?: return
val scope = bindingContext[BindingContext.RESOLUTION_SCOPE, thisExpression] ?: return
val newContext = simpleThis.analyzeInContext(scope)
val newContext = simpleThis.analyzeInContext(scope, thisExpression)
val targetAfter = simpleThis.getInstanceReference().targets(newContext).singleOrNull()
if (targetBefore == targetAfter) {
addElementToShorten(thisExpression)