Refactor: Move AnalyzerUtil to "idea-analysis" module and rewrite using new api

This commit is contained in:
Pavel V. Talanov
2015-07-30 18:21:44 +03:00
parent 6802973743
commit 5836fd39e4
9 changed files with 24 additions and 42 deletions
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.types.expressions;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.analyzer.AnalyzerPackage;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
@@ -77,7 +76,8 @@ public class ExpressionTypingServices {
@NotNull BindingTrace 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
@@ -14,50 +14,38 @@
* 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.frontend.di.createContainerForMacros
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.caches.resolve.getService
import org.jetbrains.kotlin.psi.JetExpression
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.BindingTraceContext
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.types.ErrorUtils
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
import org.jetbrains.kotlin.types.expressions.JetTypeInfo
jvmOverloads
public fun JetExpression.computeTypeInfoInContext(
scope: JetScope,
trace: BindingTrace = BindingTraceContext(),
dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY,
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE,
module: ModuleDescriptor = scope.getModule(),
isStatement: Boolean = false
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE
): JetTypeInfo {
val expressionTypingServices = createContainerForMacros(getProject(), module).expressionTypingServices
return expressionTypingServices.getTypeInfo(scope, this, expectedType, dataFlowInfo, trace, isStatement)
return getResolutionFacade().getService<ExpressionTypingServices>(this).getTypeInfo(scope, this, expectedType, dataFlowInfo, trace)
}
jvmOverloads
public fun JetExpression.analyzeInContext(
scope: JetScope,
trace: BindingTrace = BindingTraceContext(),
dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY,
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE,
module: ModuleDescriptor = scope.getModule(),
isStatement: Boolean = false
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE
): BindingContext {
computeTypeInfoInContext(scope, trace, dataFlowInfo, expectedType, module, isStatement)
computeTypeInfoInContext(scope, trace, dataFlowInfo, expectedType)
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.PsiElement
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.ClassifierDescriptor
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.util.TextRange
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.core.replaced
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.util.TextRange
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.descriptors.CallableDescriptor
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 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)
}
@@ -21,7 +21,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import com.intellij.psi.PsiElement
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.descriptors.CallableDescriptor
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.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.impl.LocalVariableDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.ResolutionFacade
@@ -43,11 +43,11 @@ import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.analyzer.AnalyzerPackage;
import org.jetbrains.kotlin.asJava.AsJavaPackage;
import org.jetbrains.kotlin.asJava.KotlinLightMethod;
import org.jetbrains.kotlin.descriptors.*;
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.codeInsight.DescriptorToSourceUtilsIde;
import org.jetbrains.kotlin.idea.codeInsight.JetFileReferencesResolver;
@@ -741,14 +741,8 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
JetSimpleNameExpression labelExpr = newExpr.getTargetLabel();
if (labelExpr == null) continue;
BindingContext newContext =
AnalyzerPackage.analyzeInContext(newExpr,
scope,
new BindingTraceContext(),
DataFlowInfo.EMPTY,
TypeUtils.NO_EXPECTED_TYPE,
DescriptorUtils.getContainingModule(scope.getContainingDeclaration()),
false);
BindingContext newContext = AnalysisPackage.analyzeInContext(newExpr, scope);
if (newContext.get(BindingContext.AMBIGUOUS_LABEL_TARGET, labelExpr) != null) {
result.putValue(
originalExpr,
@@ -37,7 +37,7 @@ import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
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.codeInsight.CodeInsightUtils;
import org.jetbrains.kotlin.idea.core.CorePackage;
@@ -136,8 +136,8 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
DataFlowInfo dataFlowInfo = BindingContextUtilPackage.getDataFlowInfo(bindingContext, expression);
ObservableBindingTrace bindingTrace = new ObservableBindingTrace(new BindingTraceContext());
JetType typeNoExpectedType = AnalyzerPackage.computeTypeInfoInContext(
expression, scope, bindingTrace, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE, analysisResult.getModuleDescriptor(), false
JetType typeNoExpectedType = AnalysisPackage.computeTypeInfoInContext(
expression, scope, bindingTrace, dataFlowInfo
).getType();
if (expressionType != null && typeNoExpectedType != null && !JetTypeChecker.DEFAULT.equalTypes(expressionType,
typeNoExpectedType)) {