Refactor: Move AnalyzerUtil to "idea-analysis" module and rewrite using new api
This commit is contained in:
+2
-2
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.types.expressions;
|
|||||||
import com.intellij.psi.tree.IElementType;
|
import com.intellij.psi.tree.IElementType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.analyzer.AnalyzerPackage;
|
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||||
@@ -77,7 +76,8 @@ public class ExpressionTypingServices {
|
|||||||
@NotNull BindingTrace trace
|
@NotNull BindingTrace trace
|
||||||
) {
|
) {
|
||||||
JetType type = getType(scope, expression, expectedType, dataFlowInfo, trace);
|
JetType type = getType(scope, expression, expectedType, dataFlowInfo, trace);
|
||||||
return AnalyzerPackage.safeType(type, expression);
|
|
||||||
|
return type != null ? type : ErrorUtils.createErrorType("Type for " + expression.getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+10
-22
@@ -14,50 +14,38 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.analyzer
|
package org.jetbrains.kotlin.idea.analysis
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||||
import org.jetbrains.kotlin.frontend.di.createContainerForMacros
|
import org.jetbrains.kotlin.idea.caches.resolve.getService
|
||||||
import org.jetbrains.kotlin.psi.JetExpression
|
import org.jetbrains.kotlin.psi.JetExpression
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||||
import org.jetbrains.kotlin.resolve.BindingTraceContext
|
import org.jetbrains.kotlin.resolve.BindingTraceContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||||
import org.jetbrains.kotlin.types.ErrorUtils
|
|
||||||
import org.jetbrains.kotlin.types.JetType
|
import org.jetbrains.kotlin.types.JetType
|
||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
|
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||||
import org.jetbrains.kotlin.types.expressions.JetTypeInfo
|
import org.jetbrains.kotlin.types.expressions.JetTypeInfo
|
||||||
|
|
||||||
|
jvmOverloads
|
||||||
public fun JetExpression.computeTypeInfoInContext(
|
public fun JetExpression.computeTypeInfoInContext(
|
||||||
scope: JetScope,
|
scope: JetScope,
|
||||||
trace: BindingTrace = BindingTraceContext(),
|
trace: BindingTrace = BindingTraceContext(),
|
||||||
dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY,
|
dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY,
|
||||||
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE,
|
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE
|
||||||
module: ModuleDescriptor = scope.getModule(),
|
|
||||||
isStatement: Boolean = false
|
|
||||||
): JetTypeInfo {
|
): JetTypeInfo {
|
||||||
val expressionTypingServices = createContainerForMacros(getProject(), module).expressionTypingServices
|
return getResolutionFacade().getService<ExpressionTypingServices>(this).getTypeInfo(scope, this, expectedType, dataFlowInfo, trace)
|
||||||
return expressionTypingServices.getTypeInfo(scope, this, expectedType, dataFlowInfo, trace, isStatement)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jvmOverloads
|
||||||
public fun JetExpression.analyzeInContext(
|
public fun JetExpression.analyzeInContext(
|
||||||
scope: JetScope,
|
scope: JetScope,
|
||||||
trace: BindingTrace = BindingTraceContext(),
|
trace: BindingTrace = BindingTraceContext(),
|
||||||
dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY,
|
dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY,
|
||||||
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE,
|
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE
|
||||||
module: ModuleDescriptor = scope.getModule(),
|
|
||||||
isStatement: Boolean = false
|
|
||||||
): BindingContext {
|
): BindingContext {
|
||||||
computeTypeInfoInContext(scope, trace, dataFlowInfo, expectedType, module, isStatement)
|
computeTypeInfoInContext(scope, trace, dataFlowInfo, expectedType)
|
||||||
return trace.getBindingContext()
|
return trace.getBindingContext()
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun JetType?.safeType(expression: JetExpression): JetType {
|
|
||||||
if (this != null) return this
|
|
||||||
|
|
||||||
return ErrorUtils.createErrorType("Type for " + expression.getText())
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun JetScope.getModule(): ModuleDescriptor = this.getContainingDeclaration().module
|
|
||||||
@@ -20,7 +20,7 @@ import com.intellij.openapi.util.TextRange
|
|||||||
import com.intellij.psi.PsiDocumentManager
|
import com.intellij.psi.PsiDocumentManager
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.util.PsiTreeUtil
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
import org.jetbrains.kotlin.analyzer.analyzeInContext
|
import org.jetbrains.kotlin.idea.analysis.analyzeInContext
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import com.intellij.codeInsight.template.TemplateBuilderImpl
|
|||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.PsiDocumentManager
|
import com.intellij.psi.PsiDocumentManager
|
||||||
import org.jetbrains.kotlin.analyzer.analyzeInContext
|
import org.jetbrains.kotlin.idea.analysis.analyzeInContext
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.idea.core.replaced
|
import org.jetbrains.kotlin.idea.core.replaced
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.idea.intentions
|
|||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.analyzer.computeTypeInContext
|
import org.jetbrains.kotlin.idea.analysis.analyzeInContext
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
@@ -97,7 +97,7 @@ public class ConvertToExpressionBodyIntention : JetSelfTargetingOffsetIndependen
|
|||||||
|
|
||||||
val declaredType = (declaration.resolveToDescriptor() as? CallableDescriptor)?.getReturnType() ?: return false
|
val declaredType = (declaration.resolveToDescriptor() as? CallableDescriptor)?.getReturnType() ?: return false
|
||||||
val scope = scopeExpression.analyze()[BindingContext.RESOLUTION_SCOPE, scopeExpression] ?: return false
|
val scope = scopeExpression.analyze()[BindingContext.RESOLUTION_SCOPE, scopeExpression] ?: return false
|
||||||
val expressionType = expression.computeTypeInContext(scope)
|
val expressionType = expression.analyzeInContext(scope)
|
||||||
return !expressionType.isError && expressionType.isSubtypeOf(declaredType)
|
return !expressionType.isError && expressionType.isSubtypeOf(declaredType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import com.intellij.openapi.project.Project
|
|||||||
import com.intellij.openapi.util.Key
|
import com.intellij.openapi.util.Key
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import org.jetbrains.kotlin.analyzer.computeTypeInContext
|
import org.jetbrains.kotlin.idea.analysis.analyzeInContext
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.idea.quickfix
|
|||||||
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.util.Key
|
import com.intellij.openapi.util.Key
|
||||||
import org.jetbrains.kotlin.analyzer.analyzeInContext
|
import org.jetbrains.kotlin.idea.analysis.analyzeInContext
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolutionFacade
|
import org.jetbrains.kotlin.idea.caches.resolve.ResolutionFacade
|
||||||
|
|||||||
+3
-9
@@ -43,11 +43,11 @@ import kotlin.Unit;
|
|||||||
import kotlin.jvm.functions.Function1;
|
import kotlin.jvm.functions.Function1;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.analyzer.AnalyzerPackage;
|
|
||||||
import org.jetbrains.kotlin.asJava.AsJavaPackage;
|
import org.jetbrains.kotlin.asJava.AsJavaPackage;
|
||||||
import org.jetbrains.kotlin.asJava.KotlinLightMethod;
|
import org.jetbrains.kotlin.asJava.KotlinLightMethod;
|
||||||
import org.jetbrains.kotlin.descriptors.*;
|
import org.jetbrains.kotlin.descriptors.*;
|
||||||
import org.jetbrains.kotlin.idea.JetFileType;
|
import org.jetbrains.kotlin.idea.JetFileType;
|
||||||
|
import org.jetbrains.kotlin.idea.analysis.AnalysisPackage;
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde;
|
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde;
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.JetFileReferencesResolver;
|
import org.jetbrains.kotlin.idea.codeInsight.JetFileReferencesResolver;
|
||||||
@@ -741,14 +741,8 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
|
|||||||
JetSimpleNameExpression labelExpr = newExpr.getTargetLabel();
|
JetSimpleNameExpression labelExpr = newExpr.getTargetLabel();
|
||||||
if (labelExpr == null) continue;
|
if (labelExpr == null) continue;
|
||||||
|
|
||||||
BindingContext newContext =
|
BindingContext newContext = AnalysisPackage.analyzeInContext(newExpr, scope);
|
||||||
AnalyzerPackage.analyzeInContext(newExpr,
|
|
||||||
scope,
|
|
||||||
new BindingTraceContext(),
|
|
||||||
DataFlowInfo.EMPTY,
|
|
||||||
TypeUtils.NO_EXPECTED_TYPE,
|
|
||||||
DescriptorUtils.getContainingModule(scope.getContainingDeclaration()),
|
|
||||||
false);
|
|
||||||
if (newContext.get(BindingContext.AMBIGUOUS_LABEL_TARGET, labelExpr) != null) {
|
if (newContext.get(BindingContext.AMBIGUOUS_LABEL_TARGET, labelExpr) != null) {
|
||||||
result.putValue(
|
result.putValue(
|
||||||
originalExpr,
|
originalExpr,
|
||||||
|
|||||||
+3
-3
@@ -37,7 +37,7 @@ import kotlin.jvm.functions.Function1;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||||
import org.jetbrains.kotlin.analyzer.AnalyzerPackage;
|
import org.jetbrains.kotlin.idea.analysis.AnalysisPackage;
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils;
|
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils;
|
||||||
import org.jetbrains.kotlin.idea.core.CorePackage;
|
import org.jetbrains.kotlin.idea.core.CorePackage;
|
||||||
@@ -136,8 +136,8 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
|
|||||||
DataFlowInfo dataFlowInfo = BindingContextUtilPackage.getDataFlowInfo(bindingContext, expression);
|
DataFlowInfo dataFlowInfo = BindingContextUtilPackage.getDataFlowInfo(bindingContext, expression);
|
||||||
|
|
||||||
ObservableBindingTrace bindingTrace = new ObservableBindingTrace(new BindingTraceContext());
|
ObservableBindingTrace bindingTrace = new ObservableBindingTrace(new BindingTraceContext());
|
||||||
JetType typeNoExpectedType = AnalyzerPackage.computeTypeInfoInContext(
|
JetType typeNoExpectedType = AnalysisPackage.computeTypeInfoInContext(
|
||||||
expression, scope, bindingTrace, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE, analysisResult.getModuleDescriptor(), false
|
expression, scope, bindingTrace, dataFlowInfo
|
||||||
).getType();
|
).getType();
|
||||||
if (expressionType != null && typeNoExpectedType != null && !JetTypeChecker.DEFAULT.equalTypes(expressionType,
|
if (expressionType != null && typeNoExpectedType != null && !JetTypeChecker.DEFAULT.equalTypes(expressionType,
|
||||||
typeNoExpectedType)) {
|
typeNoExpectedType)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user