Drop some usages of KotlinBuiltIns.getInstance() in idea module
This commit is contained in:
@@ -934,7 +934,12 @@ public class KotlinBuiltIns {
|
||||
return isAny(getFqName(descriptor));
|
||||
}
|
||||
|
||||
public static boolean isAny(@NotNull JetType type) {
|
||||
return isConstructedFromGivenClassAndNotNullable(type, FQ_NAMES.any);
|
||||
}
|
||||
|
||||
public static boolean isBoolean(@NotNull JetType type) {
|
||||
|
||||
return isConstructedFromGivenClassAndNotNullable(type, FQ_NAMES._boolean);
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -41,6 +41,7 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
@@ -331,7 +332,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
||||
|
||||
//TODO: IMO it's not good that Any is to be added manually
|
||||
if (superClasses.all { it.kind == ClassKind.INTERFACE }) {
|
||||
superClasses += KotlinBuiltIns.getInstance().any
|
||||
superClasses += classDescriptor.builtIns.any
|
||||
}
|
||||
|
||||
if (!isNoQualifierContext()) {
|
||||
|
||||
@@ -421,7 +421,7 @@ class ExpectedInfos(
|
||||
private fun calculateForIf(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||
val ifExpression = (expressionWithType.getParent() as? JetContainerNode)?.getParent() as? JetIfExpression ?: return null
|
||||
return when (expressionWithType) {
|
||||
ifExpression.getCondition() -> listOf(ExpectedInfo(KotlinBuiltIns.getInstance().getBooleanType(), null, Tail.RPARENTH))
|
||||
ifExpression.getCondition() -> listOf(ExpectedInfo(resolutionFacade.moduleDescriptor.builtIns.booleanType, null, Tail.RPARENTH))
|
||||
|
||||
ifExpression.getThen() -> calculate(ifExpression).map { ExpectedInfo(it.filter, it.expectedName, Tail.ELSE) }
|
||||
|
||||
@@ -492,14 +492,14 @@ class ExpectedInfos(
|
||||
return listOf(ExpectedInfo(subjectType, null, null))
|
||||
}
|
||||
else {
|
||||
return listOf(ExpectedInfo(KotlinBuiltIns.getInstance().getBooleanType(), null, null))
|
||||
return listOf(ExpectedInfo(resolutionFacade.moduleDescriptor.builtIns.booleanType, null, null))
|
||||
}
|
||||
}
|
||||
|
||||
private fun calculateForExclOperand(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||
val prefixExpression = expressionWithType.getParent() as? JetPrefixExpression ?: return null
|
||||
if (prefixExpression.getOperationToken() != JetTokens.EXCL) return null
|
||||
return listOf(ExpectedInfo(KotlinBuiltIns.getInstance().getBooleanType(), null, null))
|
||||
return listOf(ExpectedInfo(resolutionFacade.moduleDescriptor.builtIns.booleanType, null, null))
|
||||
}
|
||||
|
||||
private fun calculateForInitializer(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||
@@ -574,7 +574,7 @@ class ExpectedInfos(
|
||||
|
||||
val leftOperandType = binaryExpression.left?.let { bindingContext.getType(it) } ?: return null
|
||||
val scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, expressionWithType)!!
|
||||
val detector = TypesWithContainsDetector(scope, leftOperandType, resolutionFacade.ideService<HeuristicSignatures>())
|
||||
val detector = TypesWithContainsDetector(scope, leftOperandType, resolutionFacade)
|
||||
|
||||
val byTypeFilter = object : ByTypeFilter {
|
||||
override fun matchingSubstitutor(descriptorType: FuzzyType): TypeSubstitutor? {
|
||||
|
||||
+6
-4
@@ -16,10 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.completion.smart
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.idea.completion.HeuristicSignatures
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.resolve.ideService
|
||||
import org.jetbrains.kotlin.idea.util.FuzzyType
|
||||
import org.jetbrains.kotlin.idea.util.nullability
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
@@ -28,16 +29,17 @@ import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.typeUtil.TypeNullability
|
||||
import java.util.HashMap
|
||||
import java.util.*
|
||||
|
||||
class TypesWithContainsDetector(
|
||||
private val scope: JetScope,
|
||||
private val argumentType: JetType,
|
||||
private val heuristicSignatures: HeuristicSignatures
|
||||
private val resolutionFacade: ResolutionFacade
|
||||
) {
|
||||
private val cache = HashMap<FuzzyType, Boolean>()
|
||||
private val containsName = Name.identifier("contains")
|
||||
private val booleanType = KotlinBuiltIns.getInstance().getBooleanType()
|
||||
private val booleanType = resolutionFacade.moduleDescriptor.builtIns.booleanType
|
||||
private val heuristicSignatures = resolutionFacade.ideService<HeuristicSignatures>()
|
||||
|
||||
private val typesWithExtensionContains: Collection<JetType> = scope.getFunctions(containsName, NoLookupLocation.FROM_IDE)
|
||||
.filter { it.getExtensionReceiverParameter() != null && isGoodContainsFunction(it, listOf()) }
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.decapitalizeSmart
|
||||
import java.util.*
|
||||
import java.util.regex.Pattern
|
||||
@@ -134,7 +135,7 @@ public object KotlinNameSuggester {
|
||||
|
||||
private fun MutableCollection<String>.addNamesByType(type: JetType, validator: (String) -> Boolean) {
|
||||
var type = TypeUtils.makeNotNullable(type) // wipe out '?'
|
||||
val builtIns = KotlinBuiltIns.getInstance()
|
||||
val builtIns = type.builtIns
|
||||
val typeChecker = JetTypeChecker.DEFAULT
|
||||
if (ErrorUtils.containsErrorType(type)) return
|
||||
|
||||
@@ -166,7 +167,7 @@ public object KotlinNameSuggester {
|
||||
addName("s", validator)
|
||||
}
|
||||
else if (KotlinBuiltIns.isArray(type) || KotlinBuiltIns.isPrimitiveArray(type)) {
|
||||
val elementType = KotlinBuiltIns.getInstance().getArrayElementType(type)
|
||||
val elementType = builtIns.getArrayElementType(type)
|
||||
if (typeChecker.equalTypes(builtIns.getBooleanType(), elementType)) {
|
||||
addName("booleans", validator)
|
||||
}
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention<Jet
|
||||
private fun messageIsFunction(callExpr: JetCallExpression): Boolean {
|
||||
val resolvedCall = callExpr.getResolvedCall(callExpr.analyze()) ?: return false
|
||||
val valParameters = resolvedCall.getResultingDescriptor().getValueParameters()
|
||||
return valParameters.size() > 1 && valParameters[1].getType() != KotlinBuiltIns.getInstance().getAnyType()
|
||||
return valParameters.size() > 1 && !KotlinBuiltIns.isAny(valParameters[1].type)
|
||||
}
|
||||
|
||||
private fun simplifyConditionIfPossible(ifExpression: JetIfExpression) {
|
||||
|
||||
@@ -50,6 +50,7 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.types.typeUtil.supertypes
|
||||
import java.util.*
|
||||
@@ -112,12 +113,13 @@ public class ConvertFunctionToPropertyIntention : JetSelfTargetingIntention<JetN
|
||||
|
||||
if (callable is JetNamedFunction) {
|
||||
if (callable.getTypeReference() == null) {
|
||||
val type = (callable.resolveToDescriptor() as FunctionDescriptor).getReturnType()
|
||||
val functionDescriptor = callable.resolveToDescriptor() as FunctionDescriptor
|
||||
val type = functionDescriptor.getReturnType()
|
||||
val typeToInsert = when {
|
||||
type == null || type.isError() -> null
|
||||
type.getConstructor().isDenotable() -> type
|
||||
else -> type.supertypes().firstOrNull { it.getConstructor().isDenotable() }
|
||||
} ?: KotlinBuiltIns.getInstance().getNullableAnyType()
|
||||
} ?: functionDescriptor.builtIns.nullableAnyType
|
||||
callable.typeFqNameToAdd = IdeDescriptorRenderers.SOURCE_CODE.renderType(typeToInsert)
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public class ConvertToExpressionBodyIntention : JetSelfTargetingOffsetIndependen
|
||||
if (!declaration.hasDeclaredReturnType() && declaration is JetNamedFunction) {
|
||||
val valueType = value.analyze().getType(value)
|
||||
if (valueType == null || !KotlinBuiltIns.isUnit(valueType)) {
|
||||
declaration.setType(KotlinBuiltIns.getInstance().getUnitType())
|
||||
declaration.setType(KotlinBuiltIns.FQ_NAMES.unit.asString(), shortenReferences = true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ public class SpecifyTypeExplicitlyIntention : JetSelfTargetingIntention<JetCalla
|
||||
val project = declaration.getProject()
|
||||
val expression = createTypeExpressionForTemplate(exprType)
|
||||
|
||||
declaration.setType(KotlinBuiltIns.getInstance().getAnyType())
|
||||
declaration.setType(KotlinBuiltIns.FQ_NAMES.any.asString())
|
||||
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments()
|
||||
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument())
|
||||
|
||||
@@ -34,7 +34,11 @@ import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
fun JetCallableDeclaration.setType(type: JetType, shortenReferences: Boolean = true) {
|
||||
if (type.isError()) return
|
||||
val typeReference = JetPsiFactory(getProject()).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type))
|
||||
setType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type), shortenReferences)
|
||||
}
|
||||
|
||||
fun JetCallableDeclaration.setType(typeString: String, shortenReferences: Boolean = true) {
|
||||
val typeReference = JetPsiFactory(project).createType(typeString)
|
||||
setTypeReference(typeReference)
|
||||
if (shortenReferences) {
|
||||
ShortenReferences.DEFAULT.process(getTypeReference()!!)
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
@@ -57,11 +58,13 @@ public class ChangeFunctionLiteralReturnTypeFix extends JetIntentionAction<JetFu
|
||||
this.type = type;
|
||||
functionLiteralReturnTypeRef = functionLiteralExpression.getFunctionLiteral().getTypeReference();
|
||||
|
||||
BindingContext context = ResolutionUtils.analyzeFully(functionLiteralExpression.getContainingJetFile());
|
||||
AnalysisResult analysisResult = ResolutionUtils.analyzeFullyAndGetResult(functionLiteralExpression.getContainingJetFile());
|
||||
BindingContext context = analysisResult.getBindingContext();
|
||||
JetType functionLiteralType = context.getType(functionLiteralExpression);
|
||||
assert functionLiteralType != null : "Type of function literal not available in binding context";
|
||||
|
||||
ClassDescriptor functionClass = KotlinBuiltIns.getInstance().getFunction(functionLiteralType.getArguments().size() - 1);
|
||||
KotlinBuiltIns builtIns = analysisResult.getModuleDescriptor().getBuiltIns();
|
||||
ClassDescriptor functionClass = builtIns.getFunction(functionLiteralType.getArguments().size() - 1);
|
||||
List<JetType> functionClassTypeParameters = new LinkedList<JetType>();
|
||||
for (TypeProjection typeProjection: functionLiteralType.getArguments()) {
|
||||
functionClassTypeParameters.add(typeProjection.getType());
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
||||
import org.jetbrains.kotlin.idea.JetBundle;
|
||||
@@ -42,6 +43,7 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.dataClassUtils.DataClassUtilsPackage;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.types.ErrorUtils;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
|
||||
@@ -51,6 +53,7 @@ import java.util.List;
|
||||
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH;
|
||||
import static org.jetbrains.kotlin.psi.PsiPackage.JetPsiFactory;
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getBuiltIns;
|
||||
|
||||
public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction> {
|
||||
private final JetType type;
|
||||
@@ -162,10 +165,11 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
|
||||
BindingContext context = ResolutionUtils.analyze(expression);
|
||||
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.LOOP_RANGE_HAS_NEXT_RESOLVED_CALL, expression);
|
||||
if (resolvedCall == null) return null;
|
||||
FunctionDescriptor hasNextDescriptor = resolvedCall.getCandidateDescriptor();
|
||||
JetFunction hasNextFunction = (JetFunction) DescriptorToSourceUtils
|
||||
.descriptorToDeclaration(resolvedCall.getCandidateDescriptor());
|
||||
.descriptorToDeclaration(hasNextDescriptor);
|
||||
if (hasNextFunction != null) {
|
||||
return new ChangeFunctionReturnTypeFix(hasNextFunction, KotlinBuiltIns.getInstance().getBooleanType());
|
||||
return new ChangeFunctionReturnTypeFix(hasNextFunction, getBuiltIns(hasNextDescriptor).getBooleanType());
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
@@ -183,9 +187,10 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
|
||||
BindingContext context = ResolutionUtils.analyze(expression);
|
||||
ResolvedCall<?> resolvedCall = CallUtilPackage.getResolvedCall(expression, context);
|
||||
if (resolvedCall == null) return null;
|
||||
PsiElement compareTo = DescriptorToSourceUtils.descriptorToDeclaration(resolvedCall.getCandidateDescriptor());
|
||||
CallableDescriptor compareToDescriptor = resolvedCall.getCandidateDescriptor();
|
||||
PsiElement compareTo = DescriptorToSourceUtils.descriptorToDeclaration(compareToDescriptor);
|
||||
if (!(compareTo instanceof JetFunction)) return null;
|
||||
return new ChangeFunctionReturnTypeFix((JetFunction) compareTo, KotlinBuiltIns.getInstance().getIntType());
|
||||
return new ChangeFunctionReturnTypeFix((JetFunction) compareTo, getBuiltIns(compareToDescriptor).getIntType());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetValVar;
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
|
||||
@@ -123,7 +124,7 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
|
||||
String name = getNewArgumentName(argument, validator);
|
||||
JetExpression expression = argument.getArgumentExpression();
|
||||
JetType type = expression != null ? bindingContext.getType(expression) : null;
|
||||
type = type != null ? type : KotlinBuiltIns.getInstance().getNullableAnyType();
|
||||
type = type != null ? type : DescriptorUtilsKt.getBuiltIns(functionDescriptor).getNullableAnyType();
|
||||
JetParameterInfo parameterInfo =
|
||||
new JetParameterInfo(functionDescriptor, -1, name, type, null, null, JetValVar.None, null);
|
||||
parameterInfo.setCurrentTypeText(IdeDescriptorRenderers.SOURCE_CODE.renderType(type));
|
||||
|
||||
+2
-4
@@ -34,7 +34,6 @@ import com.intellij.psi.*
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.util.IncorrectOperationException
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.Pseudocode
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.getContainingPseudocode
|
||||
@@ -185,7 +184,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
||||
}
|
||||
|
||||
if (newTypes.isEmpty()) {
|
||||
newTypes.add(EqWrapper(KotlinBuiltIns.getInstance().getAnyType()))
|
||||
newTypes.add(EqWrapper(currentFileModule.builtIns.anyType))
|
||||
}
|
||||
|
||||
newTypes.map { TypeCandidate(it._type, scope) }.reverse()
|
||||
@@ -959,8 +958,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
||||
is JetProperty -> {
|
||||
if (!declaration.hasInitializer() && containingElement is JetBlockExpression) {
|
||||
val defaultValueType = typeCandidates[callableInfo.returnTypeInfo]!!.firstOrNull()?.theType
|
||||
?: KotlinBuiltIns.getInstance().getAnyType()
|
||||
val defaultValue = CodeInsightUtils.defaultInitializer(defaultValueType) ?: "null"
|
||||
val defaultValue = defaultValueType?.let {CodeInsightUtils.defaultInitializer(it) } ?: "null"
|
||||
val initializer = declaration.setInitializer(JetPsiFactory(declaration).createExpression(defaultValue))!!
|
||||
val range = initializer.getTextRange()
|
||||
selectionModel.setSelection(range.getStartOffset(), range.getEndOffset())
|
||||
|
||||
+8
-6
@@ -50,22 +50,22 @@ abstract class TypeInfo(val variance: Variance) {
|
||||
context = builder.currentFileContext,
|
||||
module = builder.currentFileModule,
|
||||
pseudocode = builder.pseudocode
|
||||
).flatMap { it.getPossibleSupertypes(variance) }
|
||||
).flatMap { it.getPossibleSupertypes(variance, builder) }
|
||||
}
|
||||
|
||||
class ByTypeReference(val typeReference: JetTypeReference, variance: Variance): TypeInfo(variance) {
|
||||
override fun getPossibleTypes(builder: CallableBuilder): List<JetType> =
|
||||
builder.currentFileContext[BindingContext.TYPE, typeReference].getPossibleSupertypes(variance)
|
||||
builder.currentFileContext[BindingContext.TYPE, typeReference].getPossibleSupertypes(variance, builder)
|
||||
}
|
||||
|
||||
class ByType(val theType: JetType, variance: Variance): TypeInfo(variance) {
|
||||
override fun getPossibleTypes(builder: CallableBuilder): List<JetType> =
|
||||
theType.getPossibleSupertypes(variance)
|
||||
theType.getPossibleSupertypes(variance, builder)
|
||||
}
|
||||
|
||||
class ByReceiverType(variance: Variance): TypeInfo(variance) {
|
||||
override fun getPossibleTypes(builder: CallableBuilder): List<JetType> =
|
||||
(builder.placement as CallablePlacement.WithReceiver).receiverTypeCandidate.theType.getPossibleSupertypes(variance)
|
||||
(builder.placement as CallablePlacement.WithReceiver).receiverTypeCandidate.theType.getPossibleSupertypes(variance, builder)
|
||||
}
|
||||
|
||||
abstract class DelegatingTypeInfo(val delegate: TypeInfo): TypeInfo(delegate.variance) {
|
||||
@@ -87,8 +87,10 @@ abstract class TypeInfo(val variance: Variance) {
|
||||
open val possibleNamesFromExpression: Array<String> get() = ArrayUtil.EMPTY_STRING_ARRAY
|
||||
abstract fun getPossibleTypes(builder: CallableBuilder): List<JetType>
|
||||
|
||||
protected fun JetType?.getPossibleSupertypes(variance: Variance): List<JetType> {
|
||||
if (this == null || ErrorUtils.containsErrorType(this)) return Collections.singletonList(KotlinBuiltIns.getInstance().getAnyType())
|
||||
protected fun JetType?.getPossibleSupertypes(variance: Variance, callableBuilder: CallableBuilder): List<JetType> {
|
||||
if (this == null || ErrorUtils.containsErrorType(this)) {
|
||||
return Collections.singletonList(callableBuilder.currentFileModule.builtIns.anyType)
|
||||
}
|
||||
val single = Collections.singletonList(this)
|
||||
return when (variance) {
|
||||
Variance.IN_VARIANCE -> single + supertypes()
|
||||
|
||||
+3
-3
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
@@ -38,12 +37,13 @@ import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelectorOrThis
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.Qualifier
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.source.getPsi
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
||||
import java.util.Collections
|
||||
import java.util.*
|
||||
|
||||
sealed class CreateCallableFromCallActionFactory<E : JetExpression>(
|
||||
extensionsEnabled: Boolean = true
|
||||
@@ -180,7 +180,7 @@ sealed class CreateCallableFromCallActionFactory<E : JetExpression>(
|
||||
if ((klass !is JetClass && klass !is PsiClass) || !klass.canRefactor()) return null
|
||||
|
||||
val expectedType = context[BindingContext.EXPECTED_EXPRESSION_TYPE, expression.getQualifiedExpressionForSelectorOrThis()]
|
||||
?: KotlinBuiltIns.getInstance().nullableAnyType
|
||||
?: classDescriptor!!.builtIns.nullableAnyType
|
||||
if (!classDescriptor!!.defaultType.isSubtypeOf(expectedType)) return null
|
||||
|
||||
val parameters = expression.getParameterInfos()
|
||||
|
||||
+2
-1
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.psi.JetClass
|
||||
import org.jetbrains.kotlin.psi.JetConstructorDelegationCall
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
object CreateConstructorFromDelegationCallActionFactory : CreateCallableMemberFromUsageFactory<JetConstructorDelegationCall>() {
|
||||
@@ -57,7 +58,7 @@ object CreateConstructorFromDelegationCallActionFactory : CreateCallableMemberFr
|
||||
}
|
||||
if (!(targetClass.canRefactor() && (targetClass is JetClass || targetClass is PsiClass))) return null
|
||||
|
||||
val anyType = KotlinBuiltIns.getInstance().nullableAnyType
|
||||
val anyType = classDescriptor.builtIns.nullableAnyType
|
||||
val parameters = element.valueArguments.map {
|
||||
ParameterInfo(
|
||||
it.getArgumentExpression()?.let { TypeInfo(it, Variance.IN_VARIANCE) } ?: TypeInfo(anyType, Variance.IN_VARIANCE),
|
||||
|
||||
+2
-1
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.psi.JetClass
|
||||
import org.jetbrains.kotlin.psi.JetDelegatorToSuperCall
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
object CreateConstructorFromDelegatorToSuperCallActionFactory : CreateCallableMemberFromUsageFactory<JetDelegatorToSuperCall>() {
|
||||
@@ -50,7 +51,7 @@ object CreateConstructorFromDelegatorToSuperCallActionFactory : CreateCallableMe
|
||||
val targetClass = DescriptorToSourceUtilsIde.getAnyDeclaration(project, superClassDescriptor) ?: return null
|
||||
if (!(targetClass.canRefactor() && (targetClass is JetClass || targetClass is PsiClass))) return null
|
||||
|
||||
val anyType = KotlinBuiltIns.getInstance().nullableAnyType
|
||||
val anyType = superClassDescriptor.builtIns.nullableAnyType
|
||||
val parameters = element.valueArguments.map {
|
||||
ParameterInfo(
|
||||
it.getArgumentExpression()?.let { TypeInfo(it, Variance.IN_VARIANCE) } ?: TypeInfo(anyType, Variance.IN_VARIANCE),
|
||||
|
||||
+4
-3
@@ -43,10 +43,11 @@ object CreateIteratorFunctionActionFactory : CreateCallableMemberFromUsageFactor
|
||||
val iterableExpr = element.loopRange ?: return null
|
||||
val variableExpr: JetExpression = ((element.loopParameter ?: element.multiParameter) ?: return null) as JetExpression
|
||||
val iterableType = TypeInfo(iterableExpr, Variance.IN_VARIANCE)
|
||||
val returnJetType = KotlinBuiltIns.getInstance().iterator.defaultType
|
||||
|
||||
val analysisResult = file.analyzeFullyAndGetResult()
|
||||
val returnJetTypeParameterTypes = variableExpr.guessTypes(analysisResult.bindingContext, analysisResult.moduleDescriptor)
|
||||
val (bindingContext, moduleDescriptor) = file.analyzeFullyAndGetResult()
|
||||
|
||||
val returnJetType = moduleDescriptor.builtIns.iterator.defaultType
|
||||
val returnJetTypeParameterTypes = variableExpr.guessTypes(bindingContext, moduleDescriptor)
|
||||
if (returnJetTypeParameterTypes.size() != 1) return null
|
||||
|
||||
val returnJetTypeParameterType = TypeProjectionImpl(returnJetTypeParameterTypes[0])
|
||||
|
||||
+2
-2
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.JetProperty
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
object CreatePropertyDelegateAccessorsActionFactory : CreateCallableMemberFromUsageFactory<JetExpression>() {
|
||||
@@ -43,8 +44,6 @@ object CreatePropertyDelegateAccessorsActionFactory : CreateCallableMemberFromUs
|
||||
fun isApplicableForAccessor(accessor: PropertyAccessorDescriptor?): Boolean =
|
||||
accessor != null && context[BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, accessor] == null
|
||||
|
||||
val builtIns = KotlinBuiltIns.getInstance()
|
||||
|
||||
val property = element.getNonStrictParentOfType<JetProperty>() ?: return emptyList()
|
||||
val propertyDescriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, property] as? PropertyDescriptor
|
||||
?: return emptyList()
|
||||
@@ -53,6 +52,7 @@ object CreatePropertyDelegateAccessorsActionFactory : CreateCallableMemberFromUs
|
||||
val propertyType = propertyDescriptor.type
|
||||
|
||||
val accessorReceiverType = TypeInfo(element, Variance.IN_VARIANCE)
|
||||
val builtIns = propertyDescriptor.builtIns
|
||||
val thisRefParam = ParameterInfo(TypeInfo(propertyReceiver?.type ?: builtIns.nullableNothingType, Variance.IN_VARIANCE))
|
||||
val metadataParam = ParameterInfo(TypeInfo(builtIns.propertyMetadata.defaultType, Variance.IN_VARIANCE))
|
||||
|
||||
|
||||
+3
-2
@@ -20,6 +20,7 @@ import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.ParameterInfo
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -58,14 +59,14 @@ public object CreateClassFromCallWithConstructorCalleeActionFactory : CreateClas
|
||||
val typeRef = callee.typeReference ?: return null
|
||||
val userType = typeRef.typeElement as? JetUserType ?: return null
|
||||
|
||||
val context = userType.analyze()
|
||||
val (context, module) = userType.analyzeAndGetResult()
|
||||
|
||||
val qualifier = userType.qualifier?.referenceExpression
|
||||
val qualifierDescriptor = qualifier?.let { context[BindingContext.REFERENCE_TARGET, it] }
|
||||
|
||||
val targetParent = getTargetParentByQualifier(file, qualifier != null, qualifierDescriptor) ?: return null
|
||||
|
||||
val anyType = KotlinBuiltIns.getInstance().nullableAnyType
|
||||
val anyType = module.builtIns.nullableAnyType
|
||||
val valueArguments = element.valueArguments
|
||||
val defaultParamName = if (valueArguments.size() == 1) "value" else null
|
||||
val parameterInfos = valueArguments.map {
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ public object CreateClassFromConstructorCallActionFactory: CreateClassFromUsageF
|
||||
|
||||
val valueArguments = callExpr.valueArguments
|
||||
val defaultParamName = if (inAnnotationEntry && valueArguments.size() == 1) "value" else null
|
||||
val anyType = KotlinBuiltIns.getInstance().nullableAnyType
|
||||
val anyType = moduleDescriptor.builtIns.nullableAnyType
|
||||
val parameterInfos = valueArguments.map {
|
||||
ParameterInfo(
|
||||
it.getArgumentExpression()?.let { TypeInfo(it, Variance.IN_VARIANCE) } ?: TypeInfo(anyType, Variance.IN_VARIANCE),
|
||||
|
||||
+3
-2
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createClass
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult
|
||||
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo
|
||||
import org.jetbrains.kotlin.psi.JetConstructorCalleeExpression
|
||||
@@ -63,13 +64,13 @@ public object CreateClassFromTypeReferenceActionFactory : CreateClassFromUsageFa
|
||||
|
||||
val file = element.containingFile as? JetFile ?: return null
|
||||
|
||||
val context = element.analyze()
|
||||
val (context, module) = element.analyzeAndGetResult()
|
||||
val qualifier = element.qualifier?.referenceExpression
|
||||
val qualifierDescriptor = qualifier?.let { context[BindingContext.REFERENCE_TARGET, it] }
|
||||
|
||||
val targetParent = getTargetParentByQualifier(file, qualifier != null, qualifierDescriptor) ?: return null
|
||||
|
||||
val anyType = KotlinBuiltIns.getInstance().anyType
|
||||
val anyType = module.builtIns.anyType
|
||||
|
||||
return ClassInfo(
|
||||
name = name,
|
||||
|
||||
+2
-1
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetParameterInfo
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
|
||||
public object CreateParameterByNamedArgumentActionFactory: CreateParameterFromUsageFactory<JetValueArgument>() {
|
||||
override fun getElementOfInterest(diagnostic: Diagnostic): JetValueArgument? {
|
||||
@@ -47,7 +48,7 @@ public object CreateParameterByNamedArgumentActionFactory: CreateParameterFromUs
|
||||
val callable = DescriptorToSourceUtilsIde.getAnyDeclaration(callElement.project, functionDescriptor) ?: return null
|
||||
if (!((callable is JetFunction || callable is JetClass) && callable.canRefactor())) return null
|
||||
|
||||
val anyType = KotlinBuiltIns.getInstance().anyType
|
||||
val anyType = functionDescriptor.builtIns.anyType
|
||||
val paramType = argumentExpression?.guessTypes(context, result.moduleDescriptor)?.let {
|
||||
when (it.size()) {
|
||||
0 -> anyType
|
||||
|
||||
+3
-2
@@ -58,12 +58,13 @@ object CreateParameterByRefActionFactory : CreateParameterFromUsageFactory<JetSi
|
||||
): CreateParameterData<JetSimpleNameExpression>? {
|
||||
val result = (diagnostic.psiFile as? JetFile)?.analyzeFullyAndGetResult() ?: return null
|
||||
val context = result.bindingContext
|
||||
val moduleDescriptor = result.moduleDescriptor
|
||||
|
||||
val varExpected = element.getAssignmentByLHS() != null
|
||||
|
||||
val paramType = element.getExpressionForTypeGuess().guessTypes(context, result.moduleDescriptor).let {
|
||||
val paramType = element.getExpressionForTypeGuess().guessTypes(context, moduleDescriptor).let {
|
||||
when (it.size()) {
|
||||
0 -> KotlinBuiltIns.getInstance().anyType
|
||||
0 -> moduleDescriptor.builtIns.anyType
|
||||
1 -> it.first()
|
||||
else -> return null
|
||||
}
|
||||
|
||||
+6
-5
@@ -616,13 +616,14 @@ private fun ExtractionData.inferParametersInfo(
|
||||
resolvedCall: ResolvedCall<*>?,
|
||||
useSmartCastsIfPossible: Boolean
|
||||
): JetType {
|
||||
val builtIns = originalDescriptor.builtIns
|
||||
return when {
|
||||
extractFunctionRef -> {
|
||||
originalDescriptor as FunctionDescriptor
|
||||
KotlinBuiltIns.getInstance().getFunctionType(Annotations.EMPTY,
|
||||
originalDescriptor.getExtensionReceiverParameter()?.getType(),
|
||||
originalDescriptor.getValueParameters().map { it.getType() },
|
||||
originalDescriptor.getReturnType() ?: originalDescriptor.builtIns.defaultReturnType)
|
||||
builtIns.getFunctionType(Annotations.EMPTY,
|
||||
originalDescriptor.getExtensionReceiverParameter()?.getType(),
|
||||
originalDescriptor.getValueParameters().map { it.getType() },
|
||||
originalDescriptor.getReturnType() ?: builtIns.defaultReturnType)
|
||||
}
|
||||
parameterExpression != null ->
|
||||
(if (useSmartCastsIfPossible) bindingContext[BindingContext.SMARTCAST, parameterExpression] else null)
|
||||
@@ -643,7 +644,7 @@ private fun ExtractionData.inferParametersInfo(
|
||||
}
|
||||
receiverToExtract.exists() -> receiverToExtract.getType()
|
||||
else -> null
|
||||
} ?: originalDescriptor.builtIns.defaultParameterType
|
||||
} ?: builtIns.defaultParameterType
|
||||
}
|
||||
|
||||
for (refInfo in getBrokenReferencesInfo(createTemporaryCodeBlock())) {
|
||||
|
||||
+2
-1
@@ -52,6 +52,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getCalleeExpressionIfAny
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.isFlexible
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
import java.util.ArrayList
|
||||
import java.util.Collections
|
||||
import java.util.HashMap
|
||||
@@ -636,7 +637,7 @@ fun ExtractionGeneratorConfiguration.generateDeclaration(
|
||||
}
|
||||
|
||||
if (declaration.getTypeReference() != null) {
|
||||
declaration.getTypeReference()?.debugTypeInfo = KotlinBuiltIns.getInstance().getAnyType()
|
||||
declaration.getTypeReference()?.debugTypeInfo = descriptor.returnType.builtIns.anyType
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.idea.search.declarationsSearch.searchOverriders
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import java.util.Collections
|
||||
|
||||
public class KotlinIntroduceParameterMethodUsageProcessor : IntroduceParameterMethodUsagesProcessor {
|
||||
@@ -70,7 +71,7 @@ public class KotlinIntroduceParameterMethodUsageProcessor : IntroduceParameterMe
|
||||
val defaultValueForCall = (data.getParameterInitializer().getExpression()!! as? PsiExpression)?.let { it.j2k() }
|
||||
changeInfo.addParameter(JetParameterInfo(callableDescriptor = psiMethodDescriptor,
|
||||
name = data.getParameterName(),
|
||||
type = KotlinBuiltIns.getInstance().getAnyType(),
|
||||
type = psiMethodDescriptor.builtIns.anyType,
|
||||
defaultValueForCall = defaultValueForCall))
|
||||
return changeInfo
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.asJava.getRepresentativeLightMethod
|
||||
import org.jetbrains.kotlin.asJava.namedUnwrappedElement
|
||||
import org.jetbrains.kotlin.asJava.toLightClass
|
||||
import org.jetbrains.kotlin.asJava.unwrapped
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.JetLanguage
|
||||
import org.jetbrains.kotlin.idea.codeInsight.shorten.addToShorteningWaitSet
|
||||
@@ -369,8 +368,8 @@ class KotlinPullUpHelper(
|
||||
|
||||
// TODO: Drop after PsiTypes in light elements are properly generated
|
||||
if (member is JetCallableDeclaration && member.typeReference == null) {
|
||||
val returnType = (data.memberDescriptors[member] as CallableDescriptor).returnType ?: KotlinBuiltIns.getInstance().anyType
|
||||
returnType.anonymousObjectSuperTypeOrNull()?.let { member.setType(it, false) }
|
||||
val returnType = (data.memberDescriptors[member] as CallableDescriptor).returnType
|
||||
returnType?.anonymousObjectSuperTypeOrNull()?.let { member.setType(it, false) }
|
||||
}
|
||||
|
||||
val project = member.project
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||
@@ -108,14 +109,15 @@ fun makeAbstract(member: JetCallableDeclaration,
|
||||
member.addModifierWithSpace(JetTokens.ABSTRACT_KEYWORD)
|
||||
}
|
||||
|
||||
val builtIns = originalMemberDescriptor.builtIns
|
||||
if (member.typeReference == null) {
|
||||
var type = originalMemberDescriptor.returnType
|
||||
if (type == null || type.isError) {
|
||||
type = KotlinBuiltIns.getInstance().nullableAnyType
|
||||
type = builtIns.nullableAnyType
|
||||
}
|
||||
else {
|
||||
type = substitutor.substitute(type.anonymousObjectSuperTypeOrNull() ?: type, Variance.INVARIANT)
|
||||
?: KotlinBuiltIns.getInstance().nullableAnyType
|
||||
?: builtIns.nullableAnyType
|
||||
}
|
||||
|
||||
if (member is JetProperty || !type.isUnit()) {
|
||||
|
||||
Reference in New Issue
Block a user