mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-17 15:51:23 +00:00
Compare commits
54 Commits
get-script
...
M15
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc5108a102 | ||
|
|
7a5ccf3050 | ||
|
|
b11dd521c8 | ||
|
|
8561d9117b | ||
|
|
ea354b11cc | ||
|
|
ef511afc06 | ||
|
|
b9ca33356c | ||
|
|
6500a73a6c | ||
|
|
15c45adfcb | ||
|
|
46d16567ee | ||
|
|
12c1689b1b | ||
|
|
3b695ac60b | ||
|
|
4c57f16477 | ||
|
|
5a63e5a3bf | ||
|
|
c5c05affc2 | ||
|
|
4c898c901a | ||
|
|
e171a1269e | ||
|
|
3690b926f6 | ||
|
|
a01ade9add | ||
|
|
58684cc8e6 | ||
|
|
d33a656ea3 | ||
|
|
809efe2a71 | ||
|
|
f397e1b30c | ||
|
|
60e27d7178 | ||
|
|
c62743a9ba | ||
|
|
2e40d21cf6 | ||
|
|
6c687b4029 | ||
|
|
9defb70e2b | ||
|
|
d998e0d5b8 | ||
|
|
93eb4d1b70 | ||
|
|
5c7c9d24f4 | ||
|
|
7c1cf80ebb | ||
|
|
71a6c5e0b2 | ||
|
|
8f5e2d0d65 | ||
|
|
47be5904df | ||
|
|
845607902e | ||
|
|
3aff0f1107 | ||
|
|
5857a02841 | ||
|
|
541001fdb1 | ||
|
|
b389f1947d | ||
|
|
dfe854796b | ||
|
|
3cab96599f | ||
|
|
b53d935e83 | ||
|
|
5e3884718b | ||
|
|
1d97c742b7 | ||
|
|
a185f07ff5 | ||
|
|
8fb533f44b | ||
|
|
a186b5ee0d | ||
|
|
d20daf9766 | ||
|
|
20b1cfee0f | ||
|
|
eceae7ccda | ||
|
|
d70a7c1b66 | ||
|
|
22bce2e129 | ||
|
|
fcc0143ae1 |
1
.idea/inspectionProfiles/idea_default.xml
generated
1
.idea/inspectionProfiles/idea_default.xml
generated
@@ -408,7 +408,6 @@
|
||||
<inspection_tool class="UnnecessaryUnboxing" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="UseOfPropertiesAsHashtable" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="UtilityClassWithPublicConstructor" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="VolatileLongOrDoubleField" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="WaitNotInLoop" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="WaitNotInSynchronizedContext" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="WaitWhileHoldingTwoLocks" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.resolve.calls.callResolverUtil.CallResolverUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
||||
|
||||
@@ -141,7 +141,7 @@ public class CodegenUtil {
|
||||
|
||||
@NotNull
|
||||
public static ClassDescriptor getSuperClassByDelegationSpecifier(@NotNull KtDelegationSpecifier specifier, @NotNull BindingContext bindingContext) {
|
||||
KtType superType = bindingContext.get(BindingContext.TYPE, specifier.getTypeReference());
|
||||
KotlinType superType = bindingContext.get(BindingContext.TYPE, specifier.getTypeReference());
|
||||
assert superType != null : "superType should not be null: " + specifier.getText();
|
||||
|
||||
ClassDescriptor superClassDescriptor = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor();
|
||||
@@ -164,13 +164,13 @@ public class CodegenUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean rawTypeMatches(KtType type, ClassifierDescriptor classifier) {
|
||||
private static boolean rawTypeMatches(KotlinType type, ClassifierDescriptor classifier) {
|
||||
return type.getConstructor().equals(classifier.getTypeConstructor());
|
||||
}
|
||||
|
||||
public static boolean isEnumValueOfMethod(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
List<ValueParameterDescriptor> methodTypeParameters = functionDescriptor.getValueParameters();
|
||||
KtType nullableString = TypeUtils.makeNullable(DescriptorUtilsKt.getBuiltIns(functionDescriptor).getStringType());
|
||||
KotlinType nullableString = TypeUtils.makeNullable(DescriptorUtilsKt.getBuiltIns(functionDescriptor).getStringType());
|
||||
return DescriptorUtils.ENUM_VALUE_OF.equals(functionDescriptor.getName())
|
||||
&& methodTypeParameters.size() == 1
|
||||
&& KotlinTypeChecker.DEFAULT.isSubtypeOf(methodTypeParameters.get(0).getType(), nullableString);
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.MemberComparator
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.isDynamic
|
||||
import org.jetbrains.kotlin.utils.keysToMapExceptNulls
|
||||
import java.util.Comparator
|
||||
@@ -38,7 +38,7 @@ public object CodegenUtilKt {
|
||||
public fun getDelegates(
|
||||
descriptor: ClassDescriptor,
|
||||
toTrait: ClassDescriptor,
|
||||
delegateExpressionType: KtType? = null
|
||||
delegateExpressionType: KotlinType? = null
|
||||
): Map<CallableMemberDescriptor, CallableDescriptor> {
|
||||
if (delegateExpressionType?.isDynamic() ?: false) return mapOf();
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtSuperExpression
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
public class AccessorForConstructorDescriptor(
|
||||
private val calleeDescriptor: ConstructorDescriptor,
|
||||
@@ -35,7 +35,7 @@ public class AccessorForConstructorDescriptor(
|
||||
|
||||
override fun isPrimary(): Boolean = false
|
||||
|
||||
override fun getReturnType(): KtType = super.getReturnType()!!
|
||||
override fun getReturnType(): KotlinType = super.getReturnType()!!
|
||||
|
||||
override fun getSuperCallExpression(): KtSuperExpression? = superCallExpression
|
||||
|
||||
|
||||
@@ -20,13 +20,13 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
public class AccessorForPropertyBackingFieldInOuterClass extends AccessorForPropertyDescriptor {
|
||||
public AccessorForPropertyBackingFieldInOuterClass(
|
||||
@NotNull PropertyDescriptor property,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@Nullable KtType delegationType,
|
||||
@Nullable KotlinType delegationType,
|
||||
@NotNull String nameSuffix
|
||||
) {
|
||||
super(property, delegationType != null ? delegationType : property.getType(), null, null, containingDeclaration, null, nameSuffix);
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.KtSuperExpression;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -48,8 +48,8 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implem
|
||||
|
||||
protected AccessorForPropertyDescriptor(
|
||||
@NotNull PropertyDescriptor original,
|
||||
@NotNull KtType propertyType,
|
||||
@Nullable KtType receiverType,
|
||||
@NotNull KotlinType propertyType,
|
||||
@Nullable KotlinType receiverType,
|
||||
@Nullable ReceiverParameterDescriptor dispatchReceiverParameter,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@Nullable KtSuperExpression superCallExpression,
|
||||
|
||||
@@ -157,7 +157,7 @@ public abstract class AnnotationCodegen {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void generateNullabilityAnnotation(@Nullable KtType type, @NotNull Set<String> annotationDescriptorsAlreadyPresent) {
|
||||
private void generateNullabilityAnnotation(@Nullable KotlinType type, @NotNull Set<String> annotationDescriptorsAlreadyPresent) {
|
||||
if (type == null) return;
|
||||
|
||||
if (isBareTypeParameterWithNullableUpperBound(type)) {
|
||||
@@ -253,12 +253,12 @@ public abstract class AnnotationCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isBareTypeParameterWithNullableUpperBound(@NotNull KtType type) {
|
||||
private static boolean isBareTypeParameterWithNullableUpperBound(@NotNull KotlinType type) {
|
||||
ClassifierDescriptor classifier = type.getConstructor().getDeclarationDescriptor();
|
||||
return !type.isMarkedNullable() && classifier instanceof TypeParameterDescriptor && TypeUtils.hasNullableSuperType(type);
|
||||
}
|
||||
|
||||
public void generateAnnotationDefaultValue(@NotNull ConstantValue<?> value, @NotNull KtType expectedType) {
|
||||
public void generateAnnotationDefaultValue(@NotNull ConstantValue<?> value, @NotNull KotlinType expectedType) {
|
||||
AnnotationVisitor visitor = visitAnnotation(null, false); // Parameters are unimportant
|
||||
genCompileTimeValue(null, value, visitor);
|
||||
visitor.visitEnd();
|
||||
@@ -418,7 +418,7 @@ public abstract class AnnotationCodegen {
|
||||
for (ConstantValue<?> value : values) {
|
||||
if (value instanceof EnumValue) {
|
||||
ClassDescriptor enumEntry = ((EnumValue) value).getValue();
|
||||
KtType classObjectType = DescriptorUtilsKt.getClassObjectType(enumEntry);
|
||||
KotlinType classObjectType = DescriptorUtilsKt.getClassObjectType(enumEntry);
|
||||
if (classObjectType != null) {
|
||||
if ("java/lang/annotation/ElementType".equals(typeMapper.mapType(classObjectType).getInternalName())) {
|
||||
result.add(ElementType.valueOf(enumEntry.getName().asString()));
|
||||
@@ -446,7 +446,7 @@ public abstract class AnnotationCodegen {
|
||||
ConstantValue<?> compileTimeConstant = valueArguments.iterator().next();
|
||||
if (compileTimeConstant instanceof EnumValue) {
|
||||
ClassDescriptor enumEntry = ((EnumValue) compileTimeConstant).getValue();
|
||||
KtType classObjectType = DescriptorUtilsKt.getClassObjectType(enumEntry);
|
||||
KotlinType classObjectType = DescriptorUtilsKt.getClassObjectType(enumEntry);
|
||||
if (classObjectType != null) {
|
||||
if ("java/lang/annotation/RetentionPolicy".equals(typeMapper.mapType(classObjectType).getInternalName())) {
|
||||
return RetentionPolicy.valueOf(enumEntry.getName().asString());
|
||||
|
||||
@@ -52,7 +52,7 @@ import org.jetbrains.kotlin.serialization.DescriptorSerializer;
|
||||
import org.jetbrains.kotlin.serialization.jvm.BitEncoding;
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor;
|
||||
import org.jetbrains.kotlin.types.FlexibleTypesKt;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.org.objectweb.asm.*;
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
|
||||
import org.jetbrains.org.objectweb.asm.commons.Method;
|
||||
@@ -432,7 +432,7 @@ public class AsmUtil {
|
||||
allFields.add(Pair.create(CAPTURED_THIS_FIELD, typeMapper.mapType(captureThis)));
|
||||
}
|
||||
|
||||
KtType captureReceiverType = closure.getCaptureReceiverType();
|
||||
KotlinType captureReceiverType = closure.getCaptureReceiverType();
|
||||
if (captureReceiverType != null) {
|
||||
allFields.add(Pair.create(CAPTURED_RECEIVER_FIELD, typeMapper.mapType(captureReceiverType)));
|
||||
}
|
||||
@@ -638,7 +638,7 @@ public class AsmUtil {
|
||||
@NotNull CallableDescriptor parameter,
|
||||
@NotNull String name
|
||||
) {
|
||||
KtType type = parameter.getReturnType();
|
||||
KotlinType type = parameter.getReturnType();
|
||||
if (type == null || isNullableType(type)) return;
|
||||
|
||||
int index = frameMap.getIndex(parameter);
|
||||
@@ -672,7 +672,7 @@ public class AsmUtil {
|
||||
|
||||
if (!isDeclaredInJava(descriptor)) return false;
|
||||
|
||||
KtType type = descriptor.getReturnType();
|
||||
KotlinType type = descriptor.getReturnType();
|
||||
if (type == null || isNullableType(FlexibleTypesKt.lowerIfFlexible(type))) return false;
|
||||
|
||||
Type asmType = state.getTypeMapper().mapReturnType(descriptor);
|
||||
|
||||
@@ -334,7 +334,7 @@ public class ClassFileFactory implements OutputFileCollection {
|
||||
public abstract String asText(ClassBuilderFactory factory);
|
||||
}
|
||||
|
||||
public void removeInlinedClasses(Set<String> classNamesToRemove) {
|
||||
public void removeClasses(Set<String> classNamesToRemove) {
|
||||
for (String classInternalName : classNamesToRemove) {
|
||||
generators.remove(classInternalName + ".class");
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt;
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope;
|
||||
import org.jetbrains.kotlin.serialization.DescriptorSerializer;
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions;
|
||||
import org.jetbrains.kotlin.utils.FunctionsKt;
|
||||
import org.jetbrains.org.objectweb.asm.AnnotationVisitor;
|
||||
@@ -70,8 +70,8 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
|
||||
private final FunctionDescriptor funDescriptor;
|
||||
private final ClassDescriptor classDescriptor;
|
||||
private final SamType samType;
|
||||
private final KtType superClassType;
|
||||
private final List<KtType> superInterfaceTypes;
|
||||
private final KotlinType superClassType;
|
||||
private final List<KotlinType> superInterfaceTypes;
|
||||
private final FunctionDescriptor functionReferenceTarget;
|
||||
private final FunctionGenerationStrategy strategy;
|
||||
private final CalculatedClosure closure;
|
||||
@@ -100,10 +100,10 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
|
||||
this.strategy = strategy;
|
||||
|
||||
if (samType == null) {
|
||||
this.superInterfaceTypes = new ArrayList<KtType>();
|
||||
this.superInterfaceTypes = new ArrayList<KotlinType>();
|
||||
|
||||
KtType superClassType = null;
|
||||
for (KtType supertype : classDescriptor.getTypeConstructor().getSupertypes()) {
|
||||
KotlinType superClassType = null;
|
||||
for (KotlinType supertype : classDescriptor.getTypeConstructor().getSupertypes()) {
|
||||
ClassifierDescriptor classifier = supertype.getConstructor().getDeclarationDescriptor();
|
||||
if (DescriptorUtils.isInterface(classifier)) {
|
||||
superInterfaceTypes.add(supertype);
|
||||
@@ -141,7 +141,7 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
|
||||
sw.writeSuperclassEnd();
|
||||
String[] superInterfaceAsmTypes = new String[superInterfaceTypes.size()];
|
||||
for (int i = 0; i < superInterfaceTypes.size(); i++) {
|
||||
KtType superInterfaceType = superInterfaceTypes.get(i);
|
||||
KotlinType superInterfaceType = superInterfaceTypes.get(i);
|
||||
sw.writeInterface();
|
||||
superInterfaceAsmTypes[i] = typeMapper.mapSupertype(superInterfaceType, sw).getInternalName();
|
||||
sw.writeInterfaceEnd();
|
||||
@@ -428,7 +428,7 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
|
||||
Type type = typeMapper.mapType(captureThis);
|
||||
args.add(FieldInfo.createForHiddenField(ownerType, type, CAPTURED_THIS_FIELD));
|
||||
}
|
||||
KtType captureReceiverType = closure.getCaptureReceiverType();
|
||||
KotlinType captureReceiverType = closure.getCaptureReceiverType();
|
||||
if (captureReceiverType != null) {
|
||||
args.add(FieldInfo.createForHiddenField(ownerType, typeMapper.mapType(captureReceiverType), CAPTURED_RECEIVER_FIELD));
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ class CollectionStubMethodGenerator(
|
||||
return ourSuperCollectionClasses.filter { klass -> klass.readOnlyClass !in redundantClasses }
|
||||
}
|
||||
|
||||
private fun Collection<KtType>.classes(): Collection<ClassDescriptor> =
|
||||
private fun Collection<KotlinType>.classes(): Collection<ClassDescriptor> =
|
||||
this.map { it.getConstructor().getDeclarationDescriptor() as ClassDescriptor }
|
||||
|
||||
private fun findFakeOverridesForMethodsFromMutableCollection(
|
||||
@@ -213,7 +213,7 @@ class CollectionStubMethodGenerator(
|
||||
return result
|
||||
}
|
||||
|
||||
private fun Collection<KtType>.findMostSpecificTypeForClass(klass: ClassDescriptor): KtType {
|
||||
private fun Collection<KotlinType>.findMostSpecificTypeForClass(klass: ClassDescriptor): KotlinType {
|
||||
val types = this.filter { it.getConstructor().getDeclarationDescriptor() == klass }
|
||||
if (types.isEmpty()) error("No supertype of $klass in $this")
|
||||
if (types.size() == 1) return types.first()
|
||||
@@ -239,8 +239,8 @@ class CollectionStubMethodGenerator(
|
||||
return this.getOverriddenDescriptors().firstOrNull { it.getContainingDeclaration() == classDescriptor }
|
||||
}
|
||||
|
||||
private fun newType(classDescriptor: ClassDescriptor, typeArguments: List<TypeProjection>): KtType {
|
||||
return KtTypeImpl.create(Annotations.EMPTY, classDescriptor, false, typeArguments)
|
||||
private fun newType(classDescriptor: ClassDescriptor, typeArguments: List<TypeProjection>): KotlinType {
|
||||
return KotlinTypeImpl.create(Annotations.EMPTY, classDescriptor, false, typeArguments)
|
||||
}
|
||||
|
||||
private fun FunctionDescriptor.signature(): JvmMethodSignature = typeMapper.mapSignature(this)
|
||||
|
||||
@@ -80,7 +80,7 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.*;
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeProjection;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
||||
@@ -225,7 +225,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
}
|
||||
|
||||
private static void addReifiedParametersFromSignature(@NotNull MemberCodegen member, @NotNull ClassDescriptor descriptor) {
|
||||
for (KtType type : descriptor.getTypeConstructor().getSupertypes()) {
|
||||
for (KotlinType type : descriptor.getTypeConstructor().getSupertypes()) {
|
||||
for (TypeProjection supertypeArgument : type.getArguments()) {
|
||||
TypeParameterDescriptor parameterDescriptor = TypeUtils.getTypeParameterDescriptorOrNull(supertypeArgument.getType());
|
||||
if (parameterDescriptor != null && parameterDescriptor.isReified()) {
|
||||
@@ -377,18 +377,18 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Type asmType(@NotNull KtType type) {
|
||||
private Type asmType(@NotNull KotlinType type) {
|
||||
return typeMapper.mapType(type);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Type expressionType(@Nullable KtExpression expression) {
|
||||
KtType type = expressionJetType(expression);
|
||||
KotlinType type = expressionJetType(expression);
|
||||
return type == null ? Type.VOID_TYPE : asmType(type);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public KtType expressionJetType(@Nullable KtExpression expression) {
|
||||
public KotlinType expressionJetType(@Nullable KtExpression expression) {
|
||||
return expression != null ? bindingContext.getType(expression) : null;
|
||||
}
|
||||
|
||||
@@ -543,7 +543,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
|
||||
KtExpression loopRange = forExpression.getLoopRange();
|
||||
assert loopRange != null;
|
||||
KtType loopRangeType = bindingContext.getType(loopRange);
|
||||
KotlinType loopRangeType = bindingContext.getType(loopRange);
|
||||
assert loopRangeType != null;
|
||||
Type asmLoopRangeType = asmType(loopRangeType);
|
||||
if (asmLoopRangeType.getSort() == Type.ARRAY) {
|
||||
@@ -604,7 +604,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
private final Label bodyEnd = new Label();
|
||||
private final List<Runnable> leaveVariableTasks = Lists.newArrayList();
|
||||
|
||||
protected final KtType elementType;
|
||||
protected final KotlinType elementType;
|
||||
protected final Type asmElementType;
|
||||
|
||||
protected int loopParameterVar;
|
||||
@@ -616,7 +616,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private KtType getElementType(KtForExpression forExpression) {
|
||||
private KotlinType getElementType(KtForExpression forExpression) {
|
||||
KtExpression loopRange = forExpression.getLoopRange();
|
||||
assert loopRange != null;
|
||||
ResolvedCall<FunctionDescriptor> nextCall = getNotNull(bindingContext,
|
||||
@@ -765,7 +765,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
LOOP_RANGE_ITERATOR_RESOLVED_CALL, loopRange,
|
||||
"No .iterator() function " + DiagnosticUtils.atLocation(loopRange));
|
||||
|
||||
KtType iteratorType = iteratorCall.getResultingDescriptor().getReturnType();
|
||||
KotlinType iteratorType = iteratorCall.getResultingDescriptor().getReturnType();
|
||||
assert iteratorType != null;
|
||||
this.asmTypeForIterator = asmType(iteratorType);
|
||||
|
||||
@@ -802,7 +802,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
result.put(result.type, v);
|
||||
|
||||
FunctionDescriptor hasNext = hasNextCall.getResultingDescriptor();
|
||||
KtType type = hasNext.getReturnType();
|
||||
KotlinType type = hasNext.getReturnType();
|
||||
assert type != null && KotlinTypeChecker.DEFAULT.isSubtypeOf(type, DescriptorUtilsKt.getBuiltIns(hasNext).getBooleanType());
|
||||
|
||||
Type asmType = asmType(type);
|
||||
@@ -827,7 +827,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
private class ForInArrayLoopGenerator extends AbstractForLoopGenerator {
|
||||
private int indexVar;
|
||||
private int arrayVar;
|
||||
private final KtType loopRangeType;
|
||||
private final KotlinType loopRangeType;
|
||||
|
||||
private ForInArrayLoopGenerator(@NotNull KtForExpression forExpression) {
|
||||
super(forExpression);
|
||||
@@ -1042,7 +1042,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
|
||||
@Override
|
||||
protected void storeRangeStartAndEnd() {
|
||||
KtType loopRangeType = bindingContext.getType(forExpression.getLoopRange());
|
||||
KotlinType loopRangeType = bindingContext.getType(forExpression.getLoopRange());
|
||||
assert loopRangeType != null;
|
||||
Type asmLoopRangeType = asmType(loopRangeType);
|
||||
gen(forExpression.getLoopRange(), asmLoopRangeType);
|
||||
@@ -1074,7 +1074,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
|
||||
incrementVar = createLoopTempVariable(asmElementType);
|
||||
|
||||
KtType loopRangeType = bindingContext.getType(forExpression.getLoopRange());
|
||||
KotlinType loopRangeType = bindingContext.getType(forExpression.getLoopRange());
|
||||
assert loopRangeType != null;
|
||||
Type asmLoopRangeType = asmType(loopRangeType);
|
||||
|
||||
@@ -1308,7 +1308,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
if (compileTimeValue == null) {
|
||||
return null;
|
||||
}
|
||||
KtType expectedType = bindingContext.getType(expression);
|
||||
KotlinType expectedType = bindingContext.getType(expression);
|
||||
return compileTimeValue.toConstantValue(expectedType);
|
||||
}
|
||||
|
||||
@@ -1515,7 +1515,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
}
|
||||
}
|
||||
|
||||
KtType captureReceiver = closure.getCaptureReceiverType();
|
||||
KotlinType captureReceiver = closure.getCaptureReceiverType();
|
||||
if (captureReceiver != null) {
|
||||
Type asmType = typeMapper.mapType(captureReceiver);
|
||||
StackValue.Local capturedReceiver = StackValue.local(AsmUtil.getReceiverIndex(context, context.getContextDescriptor()), asmType);
|
||||
@@ -1998,7 +1998,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
Collection<ExpressionCodegenExtension> codegenExtensions = ExpressionCodegenExtension.Companion.getInstances(state.getProject());
|
||||
if (!codegenExtensions.isEmpty() && resolvedCall != null) {
|
||||
ExpressionCodegenExtension.Context context = new ExpressionCodegenExtension.Context(typeMapper, v);
|
||||
KtType returnType = propertyDescriptor.getReturnType();
|
||||
KotlinType returnType = propertyDescriptor.getReturnType();
|
||||
for (ExpressionCodegenExtension extension : codegenExtensions) {
|
||||
if (returnType != null) {
|
||||
StackValue value = extension.applyProperty(receiver, resolvedCall, context);
|
||||
@@ -2103,7 +2103,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
private StackValue stackValueForLocal(DeclarationDescriptor descriptor, int index) {
|
||||
if (descriptor instanceof VariableDescriptor) {
|
||||
Type sharedVarType = typeMapper.getSharedVarType(descriptor);
|
||||
KtType outType = ((VariableDescriptor) descriptor).getType();
|
||||
KotlinType outType = ((VariableDescriptor) descriptor).getType();
|
||||
if (sharedVarType != null) {
|
||||
return StackValue.shared(index, asmType(outType));
|
||||
}
|
||||
@@ -2126,7 +2126,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static KtType getPropertyDelegateType(@NotNull PropertyDescriptor descriptor, @NotNull BindingContext bindingContext) {
|
||||
private static KotlinType getPropertyDelegateType(@NotNull PropertyDescriptor descriptor, @NotNull BindingContext bindingContext) {
|
||||
PropertyGetterDescriptor getter = descriptor.getGetter();
|
||||
if (getter != null) {
|
||||
Call call = bindingContext.get(DELEGATED_PROPERTY_CALL, getter);
|
||||
@@ -2164,7 +2164,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
boolean isSuper = superExpression != null;
|
||||
boolean isExtensionProperty = propertyDescriptor.getExtensionReceiverParameter() != null;
|
||||
|
||||
KtType delegateType = getPropertyDelegateType(propertyDescriptor, bindingContext);
|
||||
KotlinType delegateType = getPropertyDelegateType(propertyDescriptor, bindingContext);
|
||||
boolean isDelegatedProperty = delegateType != null;
|
||||
|
||||
CallableMethod callableGetter = null;
|
||||
@@ -2504,13 +2504,13 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
|
||||
@NotNull
|
||||
private CallGenerator getOrCreateCallGenerator(@NotNull ResolvedCall<?> resolvedCall) {
|
||||
Map<TypeParameterDescriptor, KtType> typeArguments = resolvedCall.getTypeArguments();
|
||||
Map<TypeParameterDescriptor, KotlinType> typeArguments = resolvedCall.getTypeArguments();
|
||||
ReifiedTypeParameterMappings mappings = new ReifiedTypeParameterMappings();
|
||||
for (Map.Entry<TypeParameterDescriptor, KtType> entry : typeArguments.entrySet()) {
|
||||
for (Map.Entry<TypeParameterDescriptor, KotlinType> entry : typeArguments.entrySet()) {
|
||||
TypeParameterDescriptor key = entry.getKey();
|
||||
if (!key.isReified()) continue;
|
||||
|
||||
KtType type = entry.getValue();
|
||||
KotlinType type = entry.getValue();
|
||||
TypeParameterDescriptor parameterDescriptor = TypeUtils.getTypeParameterDescriptorOrNull(type);
|
||||
if (parameterDescriptor == null) {
|
||||
// type is not generic
|
||||
@@ -2667,7 +2667,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
}
|
||||
|
||||
|
||||
public void genVarargs(@NotNull VarargValueArgument valueArgument, @NotNull KtType outType) {
|
||||
public void genVarargs(@NotNull VarargValueArgument valueArgument, @NotNull KotlinType outType) {
|
||||
Type type = asmType(outType);
|
||||
assert type.getSort() == Type.ARRAY;
|
||||
Type elementType = correctElementType(type);
|
||||
@@ -2761,7 +2761,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
|
||||
@Override
|
||||
public StackValue visitClassLiteralExpression(@NotNull KtClassLiteralExpression expression, StackValue data) {
|
||||
KtType type = bindingContext.getType(expression);
|
||||
KotlinType type = bindingContext.getType(expression);
|
||||
assert type != null;
|
||||
|
||||
assert state.getReflectionTypes().getKClass().getTypeConstructor().equals(type.getConstructor())
|
||||
@@ -2813,7 +2813,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static StackValue generateClassLiteralReference(@NotNull final JetTypeMapper typeMapper, @NotNull final KtType type) {
|
||||
public static StackValue generateClassLiteralReference(@NotNull final JetTypeMapper typeMapper, @NotNull final KotlinType type) {
|
||||
return StackValue.operation(K_CLASS_TYPE, new Function1<InstructionAdapter, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(InstructionAdapter v) {
|
||||
@@ -3312,7 +3312,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
KtExpression initializer = multiDeclaration.getInitializer();
|
||||
if (initializer == null) return StackValue.none();
|
||||
|
||||
KtType initializerType = bindingContext.getType(initializer);
|
||||
KotlinType initializerType = bindingContext.getType(initializer);
|
||||
assert initializerType != null;
|
||||
|
||||
Type initializerAsmType = asmType(initializerType);
|
||||
@@ -3427,7 +3427,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
});
|
||||
}
|
||||
|
||||
public StackValue generateNewArray(@NotNull KtCallExpression expression, @NotNull final KtType arrayType) {
|
||||
public StackValue generateNewArray(@NotNull KtCallExpression expression, @NotNull final KotlinType arrayType) {
|
||||
assert expression.getValueArguments().size() == 1 : "Size argument expected";
|
||||
|
||||
final KtExpression sizeExpression = expression.getValueArguments().get(0).getArgumentExpression();
|
||||
@@ -3443,9 +3443,9 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
});
|
||||
}
|
||||
|
||||
public void newArrayInstruction(@NotNull KtType arrayType) {
|
||||
public void newArrayInstruction(@NotNull KotlinType arrayType) {
|
||||
if (KotlinBuiltIns.isArray(arrayType)) {
|
||||
KtType elementJetType = arrayType.getArguments().get(0).getType();
|
||||
KotlinType elementJetType = arrayType.getArguments().get(0).getType();
|
||||
putReifierMarkerIfTypeIsReifiedParameter(
|
||||
elementJetType,
|
||||
ReifiedTypeInliner.NEW_ARRAY_MARKER_METHOD_NAME
|
||||
@@ -3461,7 +3461,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
@Override
|
||||
public StackValue visitArrayAccessExpression(@NotNull KtArrayAccessExpression expression, StackValue receiver) {
|
||||
KtExpression array = expression.getArrayExpression();
|
||||
KtType type = array != null ? bindingContext.getType(array) : null;
|
||||
KotlinType type = array != null ? bindingContext.getType(array) : null;
|
||||
Type arrayType = expressionType(array);
|
||||
List<KtExpression> indices = expression.getIndexExpressions();
|
||||
FunctionDescriptor operationDescriptor = (FunctionDescriptor) bindingContext.get(REFERENCE_TARGET, expression);
|
||||
@@ -3472,7 +3472,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
assert type != null;
|
||||
Type elementType;
|
||||
if (KotlinBuiltIns.isArray(type)) {
|
||||
KtType jetElementType = type.getArguments().get(0).getType();
|
||||
KotlinType jetElementType = type.getArguments().get(0).getType();
|
||||
elementType = boxType(asmType(jetElementType));
|
||||
}
|
||||
else {
|
||||
@@ -3564,7 +3564,7 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
(or blocks).
|
||||
*/
|
||||
|
||||
KtType jetType = bindingContext.getType(expression);
|
||||
KotlinType jetType = bindingContext.getType(expression);
|
||||
assert jetType != null;
|
||||
final Type expectedAsmType = isStatement ? Type.VOID_TYPE : asmType(jetType);
|
||||
|
||||
@@ -3706,7 +3706,7 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
KtExpression left = expression.getLeft();
|
||||
final IElementType opToken = expression.getOperationReference().getReferencedNameElementType();
|
||||
|
||||
final KtType rightType = bindingContext.get(TYPE, expression.getRight());
|
||||
final KotlinType rightType = bindingContext.get(TYPE, expression.getRight());
|
||||
assert rightType != null;
|
||||
|
||||
final StackValue value = genQualified(receiver, left);
|
||||
@@ -3756,7 +3756,7 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
if (expressionToMatch != null) {
|
||||
Type subjectType = expressionToMatch.type;
|
||||
markStartLineNumber(patternExpression);
|
||||
KtType condJetType = bindingContext.getType(patternExpression);
|
||||
KotlinType condJetType = bindingContext.getType(patternExpression);
|
||||
Type condType;
|
||||
if (isNumberPrimitive(subjectType) || subjectType.getSort() == Type.BOOLEAN) {
|
||||
assert condJetType != null;
|
||||
@@ -3777,13 +3777,13 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
}
|
||||
|
||||
private StackValue generateIsCheck(StackValue expressionToMatch, KtTypeReference typeReference, boolean negated) {
|
||||
KtType jetType = bindingContext.get(TYPE, typeReference);
|
||||
KotlinType jetType = bindingContext.get(TYPE, typeReference);
|
||||
markStartLineNumber(typeReference);
|
||||
StackValue value = generateInstanceOf(expressionToMatch, jetType, false);
|
||||
return negated ? StackValue.not(value) : value;
|
||||
}
|
||||
|
||||
private StackValue generateInstanceOf(final StackValue expressionToGen, final KtType jetType, final boolean leaveExpressionOnStack) {
|
||||
private StackValue generateInstanceOf(final StackValue expressionToGen, final KotlinType jetType, final boolean leaveExpressionOnStack) {
|
||||
return StackValue.operation(Type.BOOLEAN_TYPE, new Function1<InstructionAdapter, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(InstructionAdapter v) {
|
||||
@@ -3812,14 +3812,14 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
});
|
||||
}
|
||||
|
||||
private void generateInstanceOfInstruction(@NotNull KtType jetType) {
|
||||
private void generateInstanceOfInstruction(@NotNull KotlinType jetType) {
|
||||
Type type = boxType(asmType(jetType));
|
||||
putReifierMarkerIfTypeIsReifiedParameter(jetType, ReifiedTypeInliner.INSTANCEOF_MARKER_METHOD_NAME);
|
||||
TypeIntrinsics.instanceOf(v, jetType, type);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private StackValue generateCheckCastInstruction(@NotNull KtType jetType, boolean safeAs) {
|
||||
private StackValue generateCheckCastInstruction(@NotNull KotlinType jetType, boolean safeAs) {
|
||||
Type type = boxType(asmType(jetType));
|
||||
putReifierMarkerIfTypeIsReifiedParameter(jetType,
|
||||
safeAs ? ReifiedTypeInliner.SAFE_CHECKCAST_MARKER_METHOD_NAME
|
||||
@@ -3828,7 +3828,7 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
return StackValue.onStack(type);
|
||||
}
|
||||
|
||||
public void putReifierMarkerIfTypeIsReifiedParameter(@NotNull KtType type, @NotNull String markerMethodName) {
|
||||
public void putReifierMarkerIfTypeIsReifiedParameter(@NotNull KotlinType type, @NotNull String markerMethodName) {
|
||||
TypeParameterDescriptor typeParameterDescriptor = TypeUtils.getTypeParameterDescriptorOrNull(type);
|
||||
if (typeParameterDescriptor != null && typeParameterDescriptor.isReified()) {
|
||||
if (typeParameterDescriptor.getContainingDeclaration() != context.getContextDescriptor()) {
|
||||
@@ -3962,7 +3962,7 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
if (rangeExpression instanceof KtBinaryExpression) {
|
||||
KtBinaryExpression binaryExpression = (KtBinaryExpression) rangeExpression;
|
||||
if (binaryExpression.getOperationReference().getReferencedNameElementType() == KtTokens.RANGE) {
|
||||
KtType jetType = bindingContext.getType(rangeExpression);
|
||||
KotlinType jetType = bindingContext.getType(rangeExpression);
|
||||
assert jetType != null;
|
||||
DeclarationDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor();
|
||||
return DescriptorUtilsKt.getBuiltIns(descriptor).getIntegralRanges().contains(descriptor);
|
||||
|
||||
@@ -17,21 +17,19 @@
|
||||
package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.CompanionObjectMapping;
|
||||
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isNonCompanionObject;
|
||||
|
||||
public class FieldInfo {
|
||||
|
||||
@NotNull
|
||||
public static FieldInfo createForCompanionSingleton(@NotNull ClassDescriptor companionObject, @NotNull JetTypeMapper typeMapper) {
|
||||
ClassDescriptor ownerDescriptor = DescriptorUtils.getParentOfType(companionObject, ClassDescriptor.class);
|
||||
assert ownerDescriptor != null : "Owner not found for class: " + companionObject;
|
||||
Type ownerType = typeMapper.mapType(ownerDescriptor);
|
||||
return new FieldInfo(ownerType, typeMapper.mapType(companionObject), companionObject.getName().asString(), true);
|
||||
}
|
||||
private static final CompanionObjectMapping COMPANION_OBJECT_MAPPING = new CompanionObjectMapping(JvmPlatform.INSTANCE.getBuiltIns());
|
||||
|
||||
@NotNull
|
||||
public static FieldInfo createForSingleton(@NotNull ClassDescriptor classDescriptor, @NotNull JetTypeMapper typeMapper) {
|
||||
@@ -43,6 +41,24 @@ public class FieldInfo {
|
||||
if (!classDescriptor.getKind().isSingleton()) {
|
||||
throw new UnsupportedOperationException("Can't create singleton field for class: " + classDescriptor);
|
||||
}
|
||||
|
||||
if (isNonCompanionObject(classDescriptor) || COMPANION_OBJECT_MAPPING.hasMappingToObject(classDescriptor)) {
|
||||
return createSingletonViaInstance(classDescriptor, typeMapper, oldSingleton);
|
||||
}
|
||||
else {
|
||||
ClassDescriptor ownerDescriptor = DescriptorUtils.getParentOfType(classDescriptor, ClassDescriptor.class);
|
||||
assert ownerDescriptor != null : "Owner not found for class: " + classDescriptor;
|
||||
Type ownerType = typeMapper.mapType(ownerDescriptor);
|
||||
return new FieldInfo(ownerType, typeMapper.mapType(classDescriptor), classDescriptor.getName().asString(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static FieldInfo createSingletonViaInstance(
|
||||
@NotNull ClassDescriptor classDescriptor,
|
||||
@NotNull JetTypeMapper typeMapper,
|
||||
boolean oldSingleton
|
||||
) {
|
||||
Type type = typeMapper.mapType(classDescriptor);
|
||||
return new FieldInfo(type, type, oldSingleton ? JvmAbi.DEPRECATED_INSTANCE_FIELD : JvmAbi.INSTANCE_FIELD, true);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.org.objectweb.asm.*;
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
|
||||
import org.jetbrains.org.objectweb.asm.commons.Method;
|
||||
@@ -887,7 +887,7 @@ public class FunctionCodegen {
|
||||
|
||||
iv.load(1, OBJECT_TYPE);
|
||||
|
||||
KtType jetType = descriptor.getValueParameters().get(0).getType();
|
||||
KotlinType jetType = descriptor.getValueParameters().get(0).getType();
|
||||
|
||||
// TODO: reuse logic from ExpressionCodegen
|
||||
if (jetType.isMarkedNullable()) {
|
||||
|
||||
@@ -66,7 +66,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver;
|
||||
import org.jetbrains.kotlin.serialization.DescriptorSerializer;
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
||||
import org.jetbrains.org.objectweb.asm.*;
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
|
||||
@@ -91,7 +91,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
private static final String ENUM_VALUES_FIELD_NAME = "$VALUES";
|
||||
private Type superClassAsmType;
|
||||
@Nullable // null means java/lang/Object
|
||||
private KtType superClassType;
|
||||
private KotlinType superClassType;
|
||||
private final Type classAsmType;
|
||||
private final boolean isLocal;
|
||||
|
||||
@@ -316,7 +316,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
LinkedHashSet<String> superInterfaces = new LinkedHashSet<String>();
|
||||
Set<String> kotlinMarkerInterfaces = new LinkedHashSet<String>();
|
||||
|
||||
for (KtType supertype : descriptor.getTypeConstructor().getSupertypes()) {
|
||||
for (KotlinType supertype : descriptor.getTypeConstructor().getSupertypes()) {
|
||||
if (isJvmInterface(supertype.getConstructor().getDeclarationDescriptor())) {
|
||||
sw.writeInterface();
|
||||
Type jvmInterfaceType = typeMapper.mapSupertype(supertype, sw);
|
||||
@@ -352,7 +352,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
return;
|
||||
}
|
||||
|
||||
for (KtType supertype : descriptor.getTypeConstructor().getSupertypes()) {
|
||||
for (KotlinType supertype : descriptor.getTypeConstructor().getSupertypes()) {
|
||||
ClassifierDescriptor superClass = supertype.getConstructor().getDeclarationDescriptor();
|
||||
if (superClass != null && !isJvmInterface(superClass)) {
|
||||
superClassAsmType = typeMapper.mapClass(superClass);
|
||||
@@ -421,11 +421,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
continue;
|
||||
}
|
||||
|
||||
KtType returnType = function.getReturnType();
|
||||
KotlinType returnType = function.getReturnType();
|
||||
assert returnType != null : function.toString();
|
||||
KtType paramType = function.getValueParameters().get(0).getType();
|
||||
KotlinType paramType = function.getValueParameters().get(0).getType();
|
||||
if (KotlinBuiltIns.isArray(returnType) && KotlinBuiltIns.isArray(paramType)) {
|
||||
KtType elementType = function.getTypeParameters().get(0).getDefaultType();
|
||||
KotlinType elementType = function.getTypeParameters().get(0).getDefaultType();
|
||||
if (KotlinTypeChecker.DEFAULT.equalTypes(elementType, DescriptorUtilsKt.getBuiltIns(descriptor).getArrayElementType(returnType))
|
||||
&& KotlinTypeChecker.DEFAULT.equalTypes(elementType, DescriptorUtilsKt
|
||||
.getBuiltIns(descriptor).getArrayElementType(paramType))) {
|
||||
@@ -738,7 +738,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
iv.getfield(classAsmType.getInternalName(), CAPTURED_THIS_FIELD, type.getDescriptor());
|
||||
}
|
||||
|
||||
KtType captureReceiver = closure.getCaptureReceiverType();
|
||||
KotlinType captureReceiver = closure.getCaptureReceiverType();
|
||||
if (captureReceiver != null) {
|
||||
iv.load(0, classAsmType);
|
||||
Type type = typeMapper.mapType(captureReceiver);
|
||||
@@ -835,9 +835,12 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
private void generateFieldForSingleton() {
|
||||
if (isEnumEntry(descriptor)) return;
|
||||
|
||||
if (isObject(descriptor)) {
|
||||
StackValue.Field field = StackValue.singleton(descriptor, typeMapper);
|
||||
v.newField(JvmDeclarationOriginKt.OtherOrigin(myClass), ACC_PUBLIC | ACC_STATIC | ACC_FINAL, field.name, field.type.getDescriptor(), null, null);
|
||||
boolean isCompanionObject = isCompanionObject(descriptor);
|
||||
if (isNonCompanionObject(descriptor) || isCompanionObject) {
|
||||
StackValue.Field field = StackValue.singletonViaInstance(descriptor, typeMapper);
|
||||
v.newField(JvmDeclarationOriginKt.OtherOrigin(myClass),
|
||||
ACC_PUBLIC | ACC_STATIC | ACC_FINAL | (isCompanionObject ? ACC_DEPRECATED : 0),
|
||||
field.name, field.type.getDescriptor(), null, null);
|
||||
|
||||
if (isNonCompanionObject(descriptor)) {
|
||||
StackValue.Field oldField = StackValue.oldSingleton(descriptor, typeMapper);
|
||||
@@ -845,18 +848,12 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
if (state.getClassBuilderMode() != ClassBuilderMode.FULL) return;
|
||||
|
||||
// Invoke the object constructor but ignore the result because INSTANCE$ will be initialized in the first line of <init>
|
||||
InstructionAdapter v = createOrGetClInitCodegen().v;
|
||||
markLineNumberForSyntheticFunction(element, v);
|
||||
v.anew(classAsmType);
|
||||
v.invokespecial(classAsmType.getInternalName(), "<init>", "()V", false);
|
||||
if (isCompanionObjectWithBackingFieldsInOuter(descriptor)) {
|
||||
//We should load containing class to initialize companion fields
|
||||
StackValue companion = StackValue.singletonForCompanion(descriptor, typeMapper);
|
||||
companion.put(companion.type, v);
|
||||
AsmUtil.pop(v, companion.type);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -868,7 +865,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
KtObjectDeclaration companionObject = CollectionsKt.firstOrNull(((KtClass) myClass).getCompanionObjects());
|
||||
assert companionObject != null : "Companion object not found: " + myClass.getText();
|
||||
|
||||
StackValue.Field field = StackValue.singletonForCompanion(companionObjectDescriptor, typeMapper);
|
||||
StackValue.Field field = StackValue.singleton(companionObjectDescriptor, typeMapper);
|
||||
v.newField(JvmDeclarationOriginKt.OtherOrigin(companionObject), ACC_PUBLIC | ACC_STATIC | ACC_FINAL, field.name, field.type.getDescriptor(), null, null);
|
||||
|
||||
if (state.getClassBuilderMode() != ClassBuilderMode.FULL) return;
|
||||
@@ -927,8 +924,13 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
private void generateCompanionObjectInitializer(@NotNull ClassDescriptor companionObject) {
|
||||
ExpressionCodegen codegen = createOrGetClInitCodegen();
|
||||
StackValue.singletonForCompanion(companionObject, typeMapper)
|
||||
.store(StackValue.singleton(companionObject, typeMapper), codegen.v, true);
|
||||
//TODO: uncomment when DEPRECATED INSTANCE is removed
|
||||
//FunctionDescriptor constructor = (FunctionDescriptor) context.accessibleDescriptor(
|
||||
// CollectionsKt.single(companionObject.getConstructors()), /* superCallExpression = */ null
|
||||
//);
|
||||
//generateMethodCallTo(constructor, null, codegen.v);
|
||||
//StackValue instance = StackValue.onStack(typeMapper.mapClass(companionObject));
|
||||
StackValue.singleton(companionObject, typeMapper).store(StackValue.singletonViaInstance(companionObject, typeMapper), codegen.v, true);
|
||||
}
|
||||
|
||||
private void generatePrimaryConstructor(final DelegationFieldsInfo delegationFieldsInfo) {
|
||||
@@ -998,7 +1000,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
getDelegationConstructorCall(bindingContext, constructorDescriptor));
|
||||
|
||||
if (isObject(descriptor)) {
|
||||
StackValue.singleton(descriptor, typeMapper).store(StackValue.LOCAL_0, iv);
|
||||
StackValue.singletonViaInstance(descriptor, typeMapper).store(StackValue.LOCAL_0, iv);
|
||||
if (isNonCompanionObject(descriptor)) {
|
||||
StackValue.oldSingleton(descriptor, typeMapper).store(StackValue.LOCAL_0, iv);
|
||||
}
|
||||
@@ -1150,7 +1152,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
result.addField((KtDelegatorByExpressionSpecifier) specifier, propertyDescriptor);
|
||||
}
|
||||
else {
|
||||
KtType expressionType = expression != null ? bindingContext.getType(expression) : null;
|
||||
KotlinType expressionType = expression != null ? bindingContext.getType(expression) : null;
|
||||
Type asmType =
|
||||
expressionType != null ? typeMapper.mapType(expressionType) : typeMapper.mapType(getSuperClass(specifier));
|
||||
result.addField((KtDelegatorByExpressionSpecifier) specifier, asmType, "$delegate_" + n);
|
||||
@@ -1610,7 +1612,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
DelegationFieldsInfo.Field field = delegationFieldsInfo.getInfo((KtDelegatorByExpressionSpecifier) specifier);
|
||||
generateDelegateField(field);
|
||||
KtExpression delegateExpression = ((KtDelegatorByExpressionSpecifier) specifier).getDelegateExpression();
|
||||
KtType delegateExpressionType = delegateExpression != null ? bindingContext.getType(delegateExpression) : null;
|
||||
KotlinType delegateExpressionType = delegateExpression != null ? bindingContext.getType(delegateExpression) : null;
|
||||
generateDelegates(getSuperClass(specifier), delegateExpressionType, field);
|
||||
}
|
||||
}
|
||||
@@ -1623,7 +1625,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
fieldInfo.name, fieldInfo.type.getDescriptor(), /*TODO*/null, null);
|
||||
}
|
||||
|
||||
protected void generateDelegates(ClassDescriptor toTrait, KtType delegateExpressionType, DelegationFieldsInfo.Field field) {
|
||||
protected void generateDelegates(ClassDescriptor toTrait, KotlinType delegateExpressionType, DelegationFieldsInfo.Field field) {
|
||||
for (Map.Entry<CallableMemberDescriptor, CallableDescriptor> entry : CodegenUtilKt.getDelegates(descriptor, toTrait, delegateExpressionType).entrySet()) {
|
||||
CallableMemberDescriptor callableMemberDescriptor = entry.getKey();
|
||||
CallableDescriptor delegateTo = entry.getValue();
|
||||
|
||||
@@ -32,11 +32,14 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.DelegationToTraitImpl
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.org.objectweb.asm.AnnotationVisitor
|
||||
import org.jetbrains.org.objectweb.asm.FieldVisitor
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.ACC_FINAL
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.ACC_PUBLIC
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.ACC_STATIC
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.V1_6
|
||||
import java.util.*
|
||||
|
||||
@@ -46,11 +49,13 @@ public class InterfaceImplBodyCodegen(
|
||||
v: ClassBuilder,
|
||||
state: GenerationState,
|
||||
parentCodegen: MemberCodegen<*>?
|
||||
) : ClassBodyCodegen(aClass, context, v, state, parentCodegen) {
|
||||
) : ClassBodyCodegen(aClass, context, InterfaceImplBodyCodegen.InterfaceImplClassBuilder(v), state, parentCodegen) {
|
||||
private var isAnythingGenerated: Boolean = false
|
||||
get() = (v as InterfaceImplClassBuilder).isAnythingGenerated
|
||||
|
||||
override fun generateDeclaration() {
|
||||
v.defineClass(
|
||||
myClass, V1_6, ACC_PUBLIC or ACC_FINAL or ACC_STATIC,
|
||||
myClass, V1_6, ACC_PUBLIC or ACC_FINAL,
|
||||
typeMapper.mapDefaultImpls(descriptor).internalName,
|
||||
null, "java/lang/Object", ArrayUtil.EMPTY_STRING_ARRAY
|
||||
)
|
||||
@@ -58,6 +63,7 @@ public class InterfaceImplBodyCodegen(
|
||||
}
|
||||
|
||||
override fun classForInnerClassRecord(): ClassDescriptor? {
|
||||
if (!isAnythingGenerated) return null
|
||||
if (DescriptorUtils.isLocal(descriptor)) return null
|
||||
val classDescriptorImpl = ClassDescriptorImpl(
|
||||
descriptor, Name.identifier(JvmAbi.DEFAULT_IMPLS_CLASS_NAME),
|
||||
@@ -145,9 +151,44 @@ public class InterfaceImplBodyCodegen(
|
||||
}
|
||||
|
||||
override fun generateKotlinAnnotation() {
|
||||
(v as InterfaceImplClassBuilder).stopCounting()
|
||||
|
||||
val av = v.newAnnotation(AsmUtil.asmDescByFqNameWithoutInnerClasses(KOTLIN_INTERFACE_DEFAULT_IMPLS), true)
|
||||
av.visit(JvmAnnotationNames.VERSION_FIELD_NAME, JvmAbi.VERSION.toArray())
|
||||
av.visitEnd()
|
||||
AsmUtil.writeKotlinSyntheticClassAnnotation(v, state)
|
||||
}
|
||||
|
||||
override fun done() {
|
||||
super.done()
|
||||
if (!isAnythingGenerated) {
|
||||
state.factory.removeClasses(setOf(typeMapper.mapDefaultImpls(descriptor).internalName))
|
||||
}
|
||||
}
|
||||
|
||||
private class InterfaceImplClassBuilder(private val v: ClassBuilder) : DelegatingClassBuilder() {
|
||||
private var shouldCount: Boolean = true
|
||||
var isAnythingGenerated: Boolean = false
|
||||
private set
|
||||
|
||||
fun stopCounting() {
|
||||
shouldCount = false
|
||||
}
|
||||
|
||||
override fun getDelegate() = v
|
||||
|
||||
override fun newMethod(
|
||||
origin: JvmDeclarationOrigin,
|
||||
access: Int,
|
||||
name: String,
|
||||
desc: String,
|
||||
signature: String?,
|
||||
exceptions: Array<out String>?
|
||||
): MethodVisitor {
|
||||
if (shouldCount) {
|
||||
isAnythingGenerated = true
|
||||
}
|
||||
return super.newMethod(origin, access, name, desc, signature, exceptions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.org.objectweb.asm.AnnotationVisitor;
|
||||
|
||||
import java.io.File;
|
||||
@@ -64,7 +64,7 @@ public class JvmCodegenUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isJvmInterface(KtType type) {
|
||||
public static boolean isJvmInterface(KotlinType type) {
|
||||
return isJvmInterface(type.getConstructor().getDeclarationDescriptor());
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.resolve.TargetPlatformKt;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform;
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils;
|
||||
|
||||
import java.util.*;
|
||||
@@ -72,11 +72,11 @@ public class JvmRuntimeTypes {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<KtType> getSupertypesForClosure(@NotNull FunctionDescriptor descriptor) {
|
||||
public Collection<KotlinType> getSupertypesForClosure(@NotNull FunctionDescriptor descriptor) {
|
||||
ReceiverParameterDescriptor receiverParameter = descriptor.getExtensionReceiverParameter();
|
||||
|
||||
//noinspection ConstantConditions
|
||||
KtType functionType = DescriptorUtilsKt.getBuiltIns(descriptor).getFunctionType(
|
||||
KotlinType functionType = DescriptorUtilsKt.getBuiltIns(descriptor).getFunctionType(
|
||||
Annotations.Companion.getEMPTY(),
|
||||
receiverParameter == null ? null : receiverParameter.getType(),
|
||||
ExpressionTypingUtils.getValueParametersTypes(descriptor.getValueParameters()),
|
||||
@@ -87,15 +87,15 @@ public class JvmRuntimeTypes {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<KtType> getSupertypesForFunctionReference(@NotNull FunctionDescriptor descriptor) {
|
||||
public Collection<KotlinType> getSupertypesForFunctionReference(@NotNull FunctionDescriptor descriptor) {
|
||||
ReceiverParameterDescriptor extensionReceiver = descriptor.getExtensionReceiverParameter();
|
||||
ReceiverParameterDescriptor dispatchReceiver = descriptor.getDispatchReceiverParameter();
|
||||
|
||||
KtType receiverType =
|
||||
KotlinType receiverType =
|
||||
extensionReceiver != null ? extensionReceiver.getType() : dispatchReceiver != null ? dispatchReceiver.getType() : null;
|
||||
|
||||
//noinspection ConstantConditions
|
||||
KtType functionType = DescriptorUtilsKt.getBuiltIns(descriptor).getFunctionType(
|
||||
KotlinType functionType = DescriptorUtilsKt.getBuiltIns(descriptor).getFunctionType(
|
||||
Annotations.Companion.getEMPTY(),
|
||||
receiverType,
|
||||
ExpressionTypingUtils.getValueParametersTypes(descriptor.getValueParameters()),
|
||||
@@ -106,7 +106,7 @@ public class JvmRuntimeTypes {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public KtType getSupertypeForPropertyReference(@NotNull PropertyDescriptor descriptor) {
|
||||
public KotlinType getSupertypeForPropertyReference(@NotNull PropertyDescriptor descriptor) {
|
||||
int arity = (descriptor.getExtensionReceiverParameter() != null ? 1 : 0) +
|
||||
(descriptor.getDispatchReceiverParameter() != null ? 1 : 0);
|
||||
return (descriptor.isVar() ? mutablePropertyReferences : propertyReferences).get(arity).getDefaultType();
|
||||
|
||||
@@ -51,7 +51,7 @@ import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.kotlin.storage.NotNullLazyValue;
|
||||
import org.jetbrains.kotlin.types.ErrorUtils;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.org.objectweb.asm.Label;
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
@@ -66,8 +66,7 @@ import static org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.SYN
|
||||
import static org.jetbrains.kotlin.resolve.BindingContext.VARIABLE;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isCompanionObject;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isTopLevelDeclaration;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.PROPERTY_METADATA_TYPE;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.*;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin.NO_ORIGIN;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt.Synthetic;
|
||||
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
|
||||
@@ -413,7 +412,7 @@ public abstract class MemberCodegen<T extends KtElement/* TODO: & JetDeclaration
|
||||
if (initializerValue == null) return state.getClassBuilderMode() != ClassBuilderMode.LIGHT_CLASSES;
|
||||
|
||||
//TODO: OPTIMIZATION: don't initialize static final fields
|
||||
KtType jetType = getPropertyOrDelegateType(property, propertyDescriptor);
|
||||
KotlinType jetType = getPropertyOrDelegateType(property, propertyDescriptor);
|
||||
Type type = typeMapper.mapType(jetType);
|
||||
return !skipDefaultValue(propertyDescriptor, initializerValue.getValue(), type);
|
||||
}
|
||||
@@ -432,10 +431,10 @@ public abstract class MemberCodegen<T extends KtElement/* TODO: & JetDeclaration
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private KtType getPropertyOrDelegateType(@NotNull KtProperty property, @NotNull PropertyDescriptor descriptor) {
|
||||
private KotlinType getPropertyOrDelegateType(@NotNull KtProperty property, @NotNull PropertyDescriptor descriptor) {
|
||||
KtExpression delegateExpression = property.getDelegateExpression();
|
||||
if (delegateExpression != null) {
|
||||
KtType delegateType = bindingContext.getType(delegateExpression);
|
||||
KotlinType delegateType = bindingContext.getType(delegateExpression);
|
||||
assert delegateType != null : "Type of delegate expression should be recorded";
|
||||
return delegateType;
|
||||
}
|
||||
@@ -509,18 +508,41 @@ public abstract class MemberCodegen<T extends KtElement/* TODO: & JetDeclaration
|
||||
iv.newarray(PROPERTY_METADATA_TYPE);
|
||||
|
||||
for (int i = 0, size = delegatedProperties.size(); i < size; i++) {
|
||||
VariableDescriptor property = BindingContextUtils.getNotNull(bindingContext, VARIABLE, delegatedProperties.get(i));
|
||||
PropertyDescriptor property =
|
||||
(PropertyDescriptor) BindingContextUtils.getNotNull(bindingContext, VARIABLE, delegatedProperties.get(i));
|
||||
|
||||
iv.dup();
|
||||
iv.iconst(i);
|
||||
|
||||
ReceiverParameterDescriptor dispatchReceiver = property.getDispatchReceiverParameter();
|
||||
StackValue value;
|
||||
// TODO: remove this option and always generate PropertyReferenceNImpl creation
|
||||
if ("true".equalsIgnoreCase(System.getProperty("kotlin.jvm.optimize.delegated.properties"))) {
|
||||
int receiverCount = (property.getDispatchReceiverParameter() != null ? 1 : 0) +
|
||||
(property.getExtensionReceiverParameter() != null ? 1 : 0);
|
||||
Type implType = property.isVar() ? MUTABLE_PROPERTY_REFERENCE_IMPL[receiverCount] : PROPERTY_REFERENCE_IMPL[receiverCount];
|
||||
iv.anew(implType);
|
||||
iv.dup();
|
||||
// TODO: generate the container once and save to a local field instead
|
||||
ClosureCodegen.generateCallableReferenceDeclarationContainer(iv, property, state);
|
||||
iv.aconst(property.getName().asString());
|
||||
iv.aconst(PropertyReferenceCodegen.getPropertyReferenceSignature(property, state));
|
||||
iv.invokespecial(
|
||||
implType.getInternalName(), "<init>",
|
||||
Type.getMethodDescriptor(Type.VOID_TYPE, K_DECLARATION_CONTAINER_TYPE, JAVA_STRING_TYPE, JAVA_STRING_TYPE), false
|
||||
);
|
||||
value = StackValue.onStack(implType);
|
||||
Method wrapper = PropertyReferenceCodegen.getWrapperMethodForPropertyReference(property, receiverCount);
|
||||
iv.invokestatic(REFLECTION, wrapper.getName(), wrapper.getDescriptor(), false);
|
||||
}
|
||||
else {
|
||||
ReceiverParameterDescriptor dispatchReceiver = property.getDispatchReceiverParameter();
|
||||
|
||||
//noinspection ConstantConditions
|
||||
StackValue value = createOrGetClInitCodegen().generatePropertyReference(
|
||||
delegatedProperties.get(i).getDelegate(), property, property,
|
||||
dispatchReceiver != null ? new TransientReceiver(dispatchReceiver.getType()) : ReceiverValue.NO_RECEIVER
|
||||
);
|
||||
//noinspection ConstantConditions
|
||||
value = createOrGetClInitCodegen().generatePropertyReference(
|
||||
delegatedProperties.get(i).getDelegate(), property, property,
|
||||
dispatchReceiver != null ? new TransientReceiver(dispatchReceiver.getType()) : ReceiverValue.NO_RECEIVER
|
||||
);
|
||||
}
|
||||
|
||||
value.put(PROPERTY_METADATA_TYPE, iv);
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorImpl;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope;
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeConstructor;
|
||||
import org.jetbrains.kotlin.types.TypeConstructorImpl;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
@@ -41,7 +41,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
private Visibility visibility;
|
||||
private TypeConstructor typeConstructor;
|
||||
private List<TypeParameterDescriptor> typeParameters;
|
||||
private final Collection<KtType> supertypes = new ArrayList<KtType>();
|
||||
private final Collection<KotlinType> supertypes = new ArrayList<KotlinType>();
|
||||
|
||||
public MutableClassDescriptor(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@@ -116,7 +116,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
return typeConstructor;
|
||||
}
|
||||
|
||||
public void addSupertype(@NotNull KtType supertype) {
|
||||
public void addSupertype(@NotNull KotlinType supertype) {
|
||||
assert !supertype.isError() : "Error types must be filtered out in DescriptorResolver";
|
||||
if (TypeUtils.getClassDescriptor(supertype) != null) {
|
||||
// See the Errors.SUPERTYPE_NOT_A_CLASS_OR_INTERFACE
|
||||
|
||||
@@ -44,7 +44,7 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor;
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.kotlin.types.ErrorUtils;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.org.objectweb.asm.FieldVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes;
|
||||
@@ -275,7 +275,7 @@ public class PropertyCodegen {
|
||||
KtNamedDeclaration element,
|
||||
PropertyDescriptor propertyDescriptor,
|
||||
boolean isDelegate,
|
||||
KtType jetType,
|
||||
KotlinType jetType,
|
||||
Object defaultValue,
|
||||
Annotations annotations
|
||||
) {
|
||||
@@ -362,7 +362,7 @@ public class PropertyCodegen {
|
||||
|
||||
private void generatePropertyDelegateAccess(KtProperty p, PropertyDescriptor propertyDescriptor, Annotations annotations) {
|
||||
KtExpression delegateExpression = p.getDelegateExpression();
|
||||
KtType delegateType = delegateExpression != null ? bindingContext.getType(p.getDelegateExpression()) : null;
|
||||
KotlinType delegateType = delegateExpression != null ? bindingContext.getType(p.getDelegateExpression()) : null;
|
||||
if (delegateType == null) {
|
||||
// If delegate expression is unresolved reference
|
||||
delegateType = ErrorUtils.createErrorType("Delegate type");
|
||||
|
||||
@@ -35,10 +35,7 @@ import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ScriptReceiver
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.ACC_FINAL
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.ACC_PUBLIC
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.ACC_SUPER
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.V1_6
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.*
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||
import org.jetbrains.org.objectweb.asm.commons.Method
|
||||
@@ -74,24 +71,7 @@ public class PropertyReferenceCodegen(
|
||||
private val superAsmType = typeMapper.mapClass(classDescriptor.getSuperClassNotAny().sure { "No super class for $classDescriptor" })
|
||||
|
||||
// e.g. mutableProperty0(Lkotlin/jvm/internal/MutablePropertyReference0;)Lkotlin/reflect/KMutableProperty0;
|
||||
private val wrapperMethod: Method
|
||||
|
||||
init {
|
||||
wrapperMethod = when (receiverCount) {
|
||||
2 -> when {
|
||||
target.isVar -> method("mutableProperty2", K_MUTABLE_PROPERTY2_TYPE, MUTABLE_PROPERTY_REFERENCE2)
|
||||
else -> method("property2", K_PROPERTY2_TYPE, PROPERTY_REFERENCE2)
|
||||
}
|
||||
1 -> when {
|
||||
target.isVar -> method("mutableProperty1", K_MUTABLE_PROPERTY1_TYPE, MUTABLE_PROPERTY_REFERENCE1)
|
||||
else -> method("property1", K_PROPERTY1_TYPE, PROPERTY_REFERENCE1)
|
||||
}
|
||||
else -> when {
|
||||
target.isVar -> method("mutableProperty0", K_MUTABLE_PROPERTY0_TYPE, MUTABLE_PROPERTY_REFERENCE0)
|
||||
else -> method("property0", K_PROPERTY0_TYPE, PROPERTY_REFERENCE0)
|
||||
}
|
||||
}
|
||||
}
|
||||
private val wrapperMethod = getWrapperMethodForPropertyReference(target, receiverCount)
|
||||
|
||||
override fun generateDeclaration() {
|
||||
v.defineClass(
|
||||
@@ -127,16 +107,7 @@ public class PropertyReferenceCodegen(
|
||||
}
|
||||
|
||||
generateMethod("property reference getSignature", ACC_PUBLIC, method("getSignature", JAVA_STRING_TYPE)) {
|
||||
target as PropertyDescriptor
|
||||
|
||||
val getter = target.getGetter() ?: run {
|
||||
val defaultGetter = DescriptorFactory.createDefaultGetter(target, Annotations.EMPTY)
|
||||
defaultGetter.initialize(target.getType())
|
||||
defaultGetter
|
||||
}
|
||||
|
||||
val method = typeMapper.mapSignature(getter).getAsmMethod()
|
||||
aconst(method.getName() + method.getDescriptor())
|
||||
aconst(getPropertyReferenceSignature(target as PropertyDescriptor, state))
|
||||
}
|
||||
|
||||
generateAccessors()
|
||||
@@ -207,4 +178,35 @@ public class PropertyReferenceCodegen(
|
||||
StackValue.operation(wrapperMethod.getReturnType()) { iv ->
|
||||
iv.getstatic(asmType.getInternalName(), JvmAbi.INSTANCE_FIELD, wrapperMethod.getReturnType().getDescriptor())
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun getPropertyReferenceSignature(property: PropertyDescriptor, state: GenerationState): String {
|
||||
val getter =
|
||||
property.getter ?: DescriptorFactory.createDefaultGetter(property, Annotations.EMPTY).apply {
|
||||
initialize(property.type)
|
||||
}
|
||||
|
||||
val method = state.typeMapper.mapSignature(getter).asmMethod
|
||||
return method.name + method.descriptor
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getWrapperMethodForPropertyReference(property: VariableDescriptor, receiverCount: Int): Method {
|
||||
return when (receiverCount) {
|
||||
2 -> when {
|
||||
property.isVar -> method("mutableProperty2", K_MUTABLE_PROPERTY2_TYPE, MUTABLE_PROPERTY_REFERENCE2)
|
||||
else -> method("property2", K_PROPERTY2_TYPE, PROPERTY_REFERENCE2)
|
||||
}
|
||||
1 -> when {
|
||||
property.isVar -> method("mutableProperty1", K_MUTABLE_PROPERTY1_TYPE, MUTABLE_PROPERTY_REFERENCE1)
|
||||
else -> method("property1", K_PROPERTY1_TYPE, PROPERTY_REFERENCE1)
|
||||
}
|
||||
else -> when {
|
||||
property.isVar -> method("mutableProperty0", K_MUTABLE_PROPERTY0_TYPE, MUTABLE_PROPERTY_REFERENCE0)
|
||||
else -> method("property0", K_PROPERTY0_TYPE, PROPERTY_REFERENCE0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.name.FqNameUnsafe;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -53,11 +53,11 @@ public class RangeCodegenUtil {
|
||||
|
||||
private RangeCodegenUtil() {}
|
||||
|
||||
public static boolean isRange(KtType rangeType) {
|
||||
public static boolean isRange(KotlinType rangeType) {
|
||||
return !rangeType.isMarkedNullable() && getPrimitiveRangeElementType(rangeType) != null;
|
||||
}
|
||||
|
||||
public static boolean isProgression(KtType rangeType) {
|
||||
public static boolean isProgression(KotlinType rangeType) {
|
||||
return !rangeType.isMarkedNullable() && getPrimitiveProgressionElementType(rangeType) != null;
|
||||
}
|
||||
|
||||
@@ -92,18 +92,18 @@ public class RangeCodegenUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PrimitiveType getPrimitiveRangeElementType(KtType rangeType) {
|
||||
private static PrimitiveType getPrimitiveRangeElementType(KotlinType rangeType) {
|
||||
return getPrimitiveRangeOrProgressionElementType(rangeType, RANGE_TO_ELEMENT_TYPE);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PrimitiveType getPrimitiveProgressionElementType(KtType rangeType) {
|
||||
private static PrimitiveType getPrimitiveProgressionElementType(KotlinType rangeType) {
|
||||
return getPrimitiveRangeOrProgressionElementType(rangeType, PROGRESSION_TO_ELEMENT_TYPE);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PrimitiveType getPrimitiveRangeOrProgressionElementType(
|
||||
@NotNull KtType rangeOrProgression,
|
||||
@NotNull KotlinType rangeOrProgression,
|
||||
@NotNull ImmutableMap<FqName, PrimitiveType> map
|
||||
) {
|
||||
ClassifierDescriptor declarationDescriptor = rangeOrProgression.getConstructor().getDeclarationDescriptor();
|
||||
|
||||
@@ -21,22 +21,22 @@ import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor;
|
||||
import org.jetbrains.kotlin.load.java.sam.SingleAbstractMethodUtils;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
public class SamType {
|
||||
public static SamType create(@NotNull KtType originalType) {
|
||||
public static SamType create(@NotNull KotlinType originalType) {
|
||||
if (!SingleAbstractMethodUtils.isSamType(originalType)) return null;
|
||||
return new SamType(originalType);
|
||||
}
|
||||
|
||||
private final KtType type;
|
||||
private final KotlinType type;
|
||||
|
||||
private SamType(@NotNull KtType type) {
|
||||
private SamType(@NotNull KotlinType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public KtType getType() {
|
||||
public KotlinType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class SamType {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public KtType getKotlinFunctionType() {
|
||||
public KotlinType getKotlinFunctionType() {
|
||||
//noinspection ConstantConditions
|
||||
return getJavaClassDescriptor().getFunctionTypeForSamInterface();
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions;
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
@@ -64,7 +64,7 @@ public class SamWrapperCodegen {
|
||||
Type asmType = asmTypeByFqNameWithoutInnerClasses(fqName);
|
||||
|
||||
// e.g. (T, T) -> Int
|
||||
KtType functionType = samType.getKotlinFunctionType();
|
||||
KotlinType functionType = samType.getKotlinFunctionType();
|
||||
|
||||
ClassDescriptor classDescriptor = new ClassDescriptorImpl(
|
||||
samType.getJavaClassDescriptor().getContainingDeclaration(),
|
||||
@@ -140,7 +140,7 @@ public class SamWrapperCodegen {
|
||||
Type functionType,
|
||||
ClassBuilder cv,
|
||||
SimpleFunctionDescriptor erasedInterfaceFunction,
|
||||
KtType functionJetType
|
||||
KotlinType functionJetType
|
||||
) {
|
||||
// using root context to avoid creating ClassDescriptor and everything else
|
||||
FunctionCodegen codegen = new FunctionCodegen(state.getRootContext().intoClass(
|
||||
|
||||
@@ -17,13 +17,14 @@
|
||||
package org.jetbrains.kotlin.codegen
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.org.objectweb.asm.FieldVisitor
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor
|
||||
import com.intellij.util.containers.LinkedMultiMap
|
||||
import com.intellij.util.containers.MultiMap
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ConflictingJvmDeclarationsData
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.MemberKind
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.MemberKind
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.RawSignature
|
||||
import org.jetbrains.org.objectweb.asm.FieldVisitor
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor
|
||||
|
||||
public abstract class SignatureCollectingClassBuilderFactory(
|
||||
delegate: ClassBuilderFactory
|
||||
@@ -47,7 +48,7 @@ public abstract class SignatureCollectingClassBuilderFactory(
|
||||
|
||||
private var classInternalName: String? = null
|
||||
|
||||
private val signatures = MultiMap<RawSignature, JvmDeclarationOrigin>()
|
||||
private val signatures = LinkedMultiMap<RawSignature, JvmDeclarationOrigin>()
|
||||
|
||||
override fun defineClass(origin: PsiElement?, version: Int, access: Int, name: String, signature: String?, superName: String, interfaces: Array<out String>) {
|
||||
classInternalName = name
|
||||
|
||||
@@ -578,8 +578,8 @@ public abstract class StackValue {
|
||||
return field(FieldInfo.createForSingleton(classDescriptor, typeMapper));
|
||||
}
|
||||
|
||||
public static Field singletonForCompanion(ClassDescriptor companionObject, JetTypeMapper typeMapper) {
|
||||
return field(FieldInfo.createForCompanionSingleton(companionObject, typeMapper));
|
||||
public static Field singletonViaInstance(ClassDescriptor classDescriptor, JetTypeMapper typeMapper) {
|
||||
return field(FieldInfo.createSingletonViaInstance(classDescriptor, typeMapper, false));
|
||||
}
|
||||
|
||||
public static Field oldSingleton(ClassDescriptor classDescriptor, JetTypeMapper typeMapper) {
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.codegen.context.EnclosedValueDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
|
||||
import java.util.List;
|
||||
@@ -33,7 +33,7 @@ public interface CalculatedClosure {
|
||||
ClassDescriptor getCaptureThis();
|
||||
|
||||
@Nullable
|
||||
KtType getCaptureReceiverType();
|
||||
KotlinType getCaptureReceiverType();
|
||||
|
||||
@NotNull
|
||||
Map<DeclarationDescriptor, EnclosedValueDescriptor> getCaptureVariables();
|
||||
|
||||
@@ -51,7 +51,7 @@ import org.jetbrains.kotlin.resolve.constants.EnumValue;
|
||||
import org.jetbrains.kotlin.resolve.constants.NullValue;
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope;
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
|
||||
import java.util.*;
|
||||
@@ -90,7 +90,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
|
||||
private ClassDescriptor recordClassForCallable(
|
||||
@NotNull KtElement element,
|
||||
@NotNull CallableDescriptor callableDescriptor,
|
||||
@NotNull Collection<KtType> supertypes,
|
||||
@NotNull Collection<KotlinType> supertypes,
|
||||
@NotNull String name
|
||||
) {
|
||||
String simpleName = name.substring(name.lastIndexOf('/') + 1);
|
||||
@@ -275,7 +275,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
|
||||
if (functionDescriptor == null) return;
|
||||
|
||||
String name = inventAnonymousClassName();
|
||||
Collection<KtType> supertypes = runtimeTypes.getSupertypesForClosure(functionDescriptor);
|
||||
Collection<KotlinType> supertypes = runtimeTypes.getSupertypesForClosure(functionDescriptor);
|
||||
ClassDescriptor classDescriptor = recordClassForCallable(functionLiteral, functionDescriptor, supertypes, name);
|
||||
recordClosure(classDescriptor, name);
|
||||
|
||||
@@ -293,7 +293,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
|
||||
CallableDescriptor target = referencedFunction.getResultingDescriptor();
|
||||
|
||||
CallableDescriptor callableDescriptor;
|
||||
Collection<KtType> supertypes;
|
||||
Collection<KotlinType> supertypes;
|
||||
|
||||
if (target instanceof FunctionDescriptor) {
|
||||
callableDescriptor = bindingContext.get(FUNCTION, expression);
|
||||
@@ -345,7 +345,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
|
||||
if (delegate != null && descriptor instanceof PropertyDescriptor) {
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
|
||||
String name = inventAnonymousClassName();
|
||||
KtType supertype = runtimeTypes.getSupertypeForPropertyReference(propertyDescriptor);
|
||||
KotlinType supertype = runtimeTypes.getSupertypeForPropertyReference(propertyDescriptor);
|
||||
ClassDescriptor classDescriptor = recordClassForCallable(delegate, propertyDescriptor, Collections.singleton(supertype), name);
|
||||
recordClosure(classDescriptor, name);
|
||||
}
|
||||
@@ -368,7 +368,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
|
||||
}
|
||||
else {
|
||||
String name = inventAnonymousClassName();
|
||||
Collection<KtType> supertypes = runtimeTypes.getSupertypesForClosure(functionDescriptor);
|
||||
Collection<KotlinType> supertypes = runtimeTypes.getSupertypesForClosure(functionDescriptor);
|
||||
ClassDescriptor classDescriptor = recordClassForCallable(function, functionDescriptor, supertypes, name);
|
||||
recordClosure(classDescriptor, name);
|
||||
|
||||
@@ -530,7 +530,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
|
||||
int fieldNumber = mappings.size();
|
||||
|
||||
assert expression.getSubjectExpression() != null : "subject expression should be not null in a valid when by enums";
|
||||
KtType type = bindingContext.getType(expression.getSubjectExpression());
|
||||
KotlinType type = bindingContext.getType(expression.getSubjectExpression());
|
||||
assert type != null : "should not be null in a valid when by enums";
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) type.getConstructor().getDeclarationDescriptor();
|
||||
assert classDescriptor != null : "because it's enum";
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.codegen.context.EnclosedValueDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
|
||||
import java.util.*;
|
||||
@@ -71,7 +71,7 @@ public final class MutableClosure implements CalculatedClosure {
|
||||
}
|
||||
|
||||
@Override
|
||||
public KtType getCaptureReceiverType() {
|
||||
public KotlinType getCaptureReceiverType() {
|
||||
if (captureReceiver) {
|
||||
ReceiverParameterDescriptor parameter = getEnclosingReceiverDescriptor();
|
||||
assert parameter != null : "Receiver parameter should exist in " + enclosingFunWithReceiverDescriptor;
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.kotlin.storage.NullableLazyValue;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
|
||||
import java.util.*;
|
||||
@@ -282,7 +282,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
public <D extends CallableMemberDescriptor> D getAccessor(
|
||||
@NotNull D possiblySubstitutedDescriptor,
|
||||
boolean isForBackingFieldInOuterClass,
|
||||
@Nullable KtType delegateType,
|
||||
@Nullable KotlinType delegateType,
|
||||
@Nullable KtSuperExpression superCallExpression
|
||||
) {
|
||||
if (accessors == null) {
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
|
||||
import static org.jetbrains.kotlin.codegen.AsmUtil.CAPTURED_RECEIVER_FIELD;
|
||||
@@ -139,7 +139,7 @@ public interface LocalLookup {
|
||||
return null;
|
||||
}
|
||||
|
||||
KtType receiverType = closure.getEnclosingReceiverDescriptor().getType();
|
||||
KotlinType receiverType = closure.getEnclosingReceiverDescriptor().getType();
|
||||
Type type = state.getTypeMapper().mapType(receiverType);
|
||||
StackValue.StackValueWithSimpleReceiver innerValue = StackValue.field(type, classType, CAPTURED_RECEIVER_FIELD, false,
|
||||
StackValue.LOCAL_0, d);
|
||||
|
||||
@@ -170,7 +170,7 @@ public class InlineCodegen extends CallGenerator {
|
||||
|
||||
codegen.propagateChildReifiedTypeParametersUsages(result.getReifiedTypeParametersUsages());
|
||||
|
||||
state.getFactory().removeInlinedClasses(result.getClassesToRemove());
|
||||
state.getFactory().removeClasses(result.getClassesToRemove());
|
||||
|
||||
codegen.markLineNumberAfterInlineIfNeeded();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.codegen.context.MethodContext
|
||||
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods
|
||||
import org.jetbrains.kotlin.codegen.intrinsics.TypeIntrinsics
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
@@ -159,14 +159,14 @@ public class ReifiedTypeInliner(private val parametersMapping: ReifiedTypeParame
|
||||
private fun processNewArray(insn: MethodInsnNode, parameter: Type) =
|
||||
processNextTypeInsn(insn, parameter, Opcodes.ANEWARRAY)
|
||||
|
||||
private fun processCheckcast(insn: MethodInsnNode, instructions: InsnList, jetType: KtType, asmType: Type, safe: Boolean) =
|
||||
private fun processCheckcast(insn: MethodInsnNode, instructions: InsnList, jetType: KotlinType, asmType: Type, safe: Boolean) =
|
||||
rewriteNextTypeInsn(insn, Opcodes.CHECKCAST) { instanceofInsn: AbstractInsnNode ->
|
||||
if (instanceofInsn !is TypeInsnNode) return false
|
||||
TypeIntrinsics.checkcast(instanceofInsn, instructions, jetType, asmType, safe)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun processInstanceof(insn: MethodInsnNode, instructions: InsnList, jetType: KtType, asmType: Type) =
|
||||
private fun processInstanceof(insn: MethodInsnNode, instructions: InsnList, jetType: KotlinType, asmType: Type) =
|
||||
rewriteNextTypeInsn(insn, Opcodes.INSTANCEOF) { instanceofInsn: AbstractInsnNode ->
|
||||
if (instanceofInsn !is TypeInsnNode) return false
|
||||
TypeIntrinsics.instanceOf(instanceofInsn, instructions, jetType, asmType)
|
||||
@@ -213,7 +213,7 @@ public class ReifiedTypeInliner(private val parametersMapping: ReifiedTypeParame
|
||||
public class ReifiedTypeParameterMappings() {
|
||||
private val mappingsByName = hashMapOf<String, ReifiedTypeParameterMapping>()
|
||||
|
||||
public fun addParameterMappingToType(name: String, type: KtType, asmType: Type, signature: String) {
|
||||
public fun addParameterMappingToType(name: String, type: KotlinType, asmType: Type, signature: String) {
|
||||
mappingsByName[name] = ReifiedTypeParameterMapping(name, type, asmType, newName = null, signature = signature)
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ public class ReifiedTypeParameterMappings() {
|
||||
}
|
||||
|
||||
public class ReifiedTypeParameterMapping(
|
||||
val name: String, val type: KtType?, val asmType: Type?, val newName: String?, val signature: String?
|
||||
val name: String, val type: KotlinType?, val asmType: Type?, val newName: String?, val signature: String?
|
||||
)
|
||||
|
||||
public class ReifiedTypeParametersUsages {
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.psi.KtClassLiteralExpression
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||
|
||||
@@ -57,7 +57,7 @@ public class KClassJavaProperty : IntrinsicPropertyGetter() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun isReifiedTypeParameter(type: KtType): Boolean {
|
||||
private fun isReifiedTypeParameter(type: KotlinType): Boolean {
|
||||
val typeDescriptor = type.constructor.declarationDescriptor
|
||||
return typeDescriptor is TypeParameterDescriptor && typeDescriptor.isReified
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.kotlin.codegen.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.org.objectweb.asm.tree.*
|
||||
import kotlin.text.Regex
|
||||
|
||||
public object TypeIntrinsics {
|
||||
public @JvmStatic fun instanceOf(v: InstructionAdapter, jetType: KtType, boxedAsmType: Type) {
|
||||
public @JvmStatic fun instanceOf(v: InstructionAdapter, jetType: KotlinType, boxedAsmType: Type) {
|
||||
val functionTypeArity = getFunctionTypeArity(jetType)
|
||||
if (functionTypeArity >= 0) {
|
||||
v.iconst(functionTypeArity)
|
||||
@@ -57,7 +57,7 @@ public object TypeIntrinsics {
|
||||
LdcInsnNode(Integer(value))
|
||||
}
|
||||
|
||||
public @JvmStatic fun instanceOf(instanceofInsn: TypeInsnNode, instructions: InsnList, jetType: KtType, asmType: Type) {
|
||||
public @JvmStatic fun instanceOf(instanceofInsn: TypeInsnNode, instructions: InsnList, jetType: KotlinType, asmType: Type) {
|
||||
val functionTypeArity = getFunctionTypeArity(jetType)
|
||||
if (functionTypeArity >= 0) {
|
||||
instructions.insertBefore(instanceofInsn, iconstNode(functionTypeArity))
|
||||
@@ -78,7 +78,7 @@ public object TypeIntrinsics {
|
||||
instanceofInsn.desc = asmType.internalName
|
||||
}
|
||||
|
||||
public @JvmStatic fun checkcast(v: InstructionAdapter, jetType: KtType, asmType: Type, safe: Boolean) {
|
||||
public @JvmStatic fun checkcast(v: InstructionAdapter, jetType: KotlinType, asmType: Type, safe: Boolean) {
|
||||
if (safe) {
|
||||
v.checkcast(asmType)
|
||||
return
|
||||
@@ -106,7 +106,7 @@ public object TypeIntrinsics {
|
||||
v.checkcast(asmType)
|
||||
}
|
||||
|
||||
public @JvmStatic fun checkcast(checkcastInsn: TypeInsnNode, instructions: InsnList, jetType: KtType, asmType: Type, safe: Boolean) {
|
||||
public @JvmStatic fun checkcast(checkcastInsn: TypeInsnNode, instructions: InsnList, jetType: KotlinType, asmType: Type, safe: Boolean) {
|
||||
if (safe) {
|
||||
checkcastInsn.desc = asmType.internalName
|
||||
return
|
||||
@@ -159,7 +159,7 @@ public object TypeIntrinsics {
|
||||
private val IS_MUTABLE_COLLECTION_METHOD_DESCRIPTOR =
|
||||
Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getObjectType("java/lang/Object"))
|
||||
|
||||
private fun getClassFqName(jetType: KtType): String? {
|
||||
private fun getClassFqName(jetType: KotlinType): String? {
|
||||
val classDescriptor = TypeUtils.getClassDescriptor(jetType) ?: return null
|
||||
return DescriptorUtils.getFqName(classDescriptor).asString()
|
||||
}
|
||||
@@ -169,7 +169,7 @@ public object TypeIntrinsics {
|
||||
/**
|
||||
* @return function type arity (non-negative), or -1 if the given type is not a function type
|
||||
*/
|
||||
private fun getFunctionTypeArity(jetType: KtType): Int {
|
||||
private fun getFunctionTypeArity(jetType: KotlinType): Int {
|
||||
val classFqName = getClassFqName(jetType) ?: return -1
|
||||
val match = KOTLIN_FUNCTION_INTERFACE_REGEX.match(classFqName) ?: return -1
|
||||
return Integer.valueOf(match.groups[1]!!.value)
|
||||
@@ -182,7 +182,7 @@ public object TypeIntrinsics {
|
||||
invokestatic(INTRINSICS_CLASS, methodName, methodDescriptor, false)
|
||||
}
|
||||
|
||||
private fun getIsMutableCollectionMethodName(jetType: KtType): String? =
|
||||
private fun getIsMutableCollectionMethodName(jetType: KotlinType): String? =
|
||||
IS_MUTABLE_COLLECTION_METHOD_NAME[getClassFqName(jetType)]
|
||||
|
||||
private val CHECKCAST_METHOD_NAME = hashMapOf(
|
||||
@@ -196,7 +196,7 @@ public object TypeIntrinsics {
|
||||
"kotlin.MutableMap.MutableEntry" to "asMutableMapEntry"
|
||||
)
|
||||
|
||||
private fun getAsMutableCollectionMethodName(jetType: KtType): String? {
|
||||
private fun getAsMutableCollectionMethodName(jetType: KotlinType): String? {
|
||||
val classDescriptor = TypeUtils.getClassDescriptor(jetType) ?: return null
|
||||
val classFqName = DescriptorUtils.getFqName(classDescriptor).asString()
|
||||
return CHECKCAST_METHOD_NAME[classFqName]
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil
|
||||
import org.jetbrains.kotlin.codegen.optimization.common.MethodAnalyzer
|
||||
import org.jetbrains.kotlin.codegen.optimization.common.OptimizationBasicInterpreter
|
||||
import org.jetbrains.kotlin.codegen.pseudoInsns.PseudoInsn
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.JumpInsnNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||
@@ -73,6 +74,10 @@ public class FixStackAnalyzer(
|
||||
executeBeforeInlineCallMarker(insn)
|
||||
InlineCodegenUtil.isAfterInlineMarker(insn) ->
|
||||
executeAfterInlineCallMarker(insn)
|
||||
InlineCodegenUtil.isMarkedReturn(insn) -> {
|
||||
// KT-9644: might throw "Incompatible return type" on non-local return, in fact we don't care.
|
||||
if (insn.opcode == Opcodes.RETURN) return
|
||||
}
|
||||
}
|
||||
|
||||
super.execute(insn, interpreter)
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.serialization.SerializerExtension;
|
||||
import org.jetbrains.kotlin.serialization.StringTable;
|
||||
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf;
|
||||
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBufUtil;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
import org.jetbrains.org.objectweb.asm.commons.Method;
|
||||
|
||||
@@ -70,7 +70,7 @@ public class JvmSerializerExtension extends SerializerExtension {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeType(@NotNull KtType type, @NotNull ProtoBuf.Type.Builder proto) {
|
||||
public void serializeType(@NotNull KotlinType type, @NotNull ProtoBuf.Type.Builder proto) {
|
||||
// TODO: don't store type annotations in our binary metadata on Java 8, use *TypeAnnotations attributes instead
|
||||
for (AnnotationDescriptor annotation : type.getAnnotations()) {
|
||||
proto.addExtension(JvmProtoBuf.typeAnnotation, annotationSerializer.serializeAnnotation(annotation));
|
||||
@@ -200,7 +200,7 @@ public class JvmSerializerExtension extends SerializerExtension {
|
||||
|
||||
sb.append(")");
|
||||
|
||||
KtType returnType = descriptor.getReturnType();
|
||||
KotlinType returnType = descriptor.getReturnType();
|
||||
String returnTypeDesc = returnType == null ? "V" : mapTypeDefault(returnType);
|
||||
if (returnTypeDesc == null) return true;
|
||||
sb.append(returnTypeDesc);
|
||||
@@ -213,7 +213,7 @@ public class JvmSerializerExtension extends SerializerExtension {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String mapTypeDefault(@NotNull KtType type) {
|
||||
private String mapTypeDefault(@NotNull KotlinType type) {
|
||||
ClassifierDescriptor classifier = type.getConstructor().getDeclarationDescriptor();
|
||||
if (!(classifier instanceof ClassDescriptor)) return null;
|
||||
ClassId classId = classId((ClassDescriptor) classifier);
|
||||
|
||||
@@ -70,9 +70,6 @@ class BuilderFactoryForDuplicateSignatureDiagnostics(
|
||||
for (origin in data.signatureOrigins) {
|
||||
var element = origin.element
|
||||
|
||||
// TODO Remove this code after dropping package facades
|
||||
if (element is KtNamedFunction && mainFunctionDetector.isMain(element) && !element.isInsideJvmMultifileClassFile()) return
|
||||
|
||||
if (element == null || origin.originKind in EXTERNAL_SOURCES_KINDS) {
|
||||
element = data.classOrigin.element
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ public class JetTypeMapper {
|
||||
|
||||
@NotNull
|
||||
private Type mapReturnType(@NotNull CallableDescriptor descriptor, @Nullable BothSignatureWriter sw) {
|
||||
KtType returnType = descriptor.getReturnType();
|
||||
KotlinType returnType = descriptor.getReturnType();
|
||||
assert returnType != null : "Function has no return type: " + descriptor;
|
||||
|
||||
if (descriptor instanceof ConstructorDescriptor) {
|
||||
@@ -370,17 +370,17 @@ public class JetTypeMapper {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Type mapType(@NotNull KtType jetType, @NotNull JetTypeMapperMode mode) {
|
||||
private Type mapType(@NotNull KotlinType jetType, @NotNull JetTypeMapperMode mode) {
|
||||
return mapType(jetType, null, mode);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Type mapSupertype(@NotNull KtType jetType, @Nullable BothSignatureWriter signatureVisitor) {
|
||||
public Type mapSupertype(@NotNull KotlinType jetType, @Nullable BothSignatureWriter signatureVisitor) {
|
||||
return mapType(jetType, signatureVisitor, JetTypeMapperMode.SUPER_TYPE);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Type mapTypeParameter(@NotNull KtType jetType, @Nullable BothSignatureWriter signatureVisitor) {
|
||||
public Type mapTypeParameter(@NotNull KotlinType jetType, @Nullable BothSignatureWriter signatureVisitor) {
|
||||
return mapType(jetType, signatureVisitor, JetTypeMapperMode.TYPE_PARAMETER);
|
||||
}
|
||||
|
||||
@@ -390,7 +390,7 @@ public class JetTypeMapper {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Type mapType(@NotNull KtType jetType) {
|
||||
public Type mapType(@NotNull KotlinType jetType) {
|
||||
return mapType(jetType, null, JetTypeMapperMode.VALUE);
|
||||
}
|
||||
|
||||
@@ -415,13 +415,13 @@ public class JetTypeMapper {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Type mapType(@NotNull KtType jetType, @Nullable BothSignatureWriter signatureVisitor, @NotNull JetTypeMapperMode mode) {
|
||||
private Type mapType(@NotNull KotlinType jetType, @Nullable BothSignatureWriter signatureVisitor, @NotNull JetTypeMapperMode mode) {
|
||||
return mapType(jetType, signatureVisitor, mode, Variance.INVARIANT);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Type mapType(
|
||||
@NotNull KtType jetType,
|
||||
@NotNull KotlinType jetType,
|
||||
@Nullable BothSignatureWriter signatureVisitor,
|
||||
@NotNull JetTypeMapperMode kind,
|
||||
@NotNull Variance howThisTypeIsUsed
|
||||
@@ -450,7 +450,7 @@ public class JetTypeMapper {
|
||||
TypeConstructor constructor = jetType.getConstructor();
|
||||
DeclarationDescriptor descriptor = constructor.getDeclarationDescriptor();
|
||||
if (constructor instanceof IntersectionTypeConstructor) {
|
||||
jetType = CommonSupertypes.commonSupertype(new ArrayList<KtType>(constructor.getSupertypes()));
|
||||
jetType = CommonSupertypes.commonSupertype(new ArrayList<KotlinType>(constructor.getSupertypes()));
|
||||
}
|
||||
|
||||
if (descriptor == null) {
|
||||
@@ -473,7 +473,7 @@ public class JetTypeMapper {
|
||||
throw new UnsupportedOperationException("arrays must have one type argument");
|
||||
}
|
||||
TypeProjection memberProjection = jetType.getArguments().get(0);
|
||||
KtType memberType = memberProjection.getType();
|
||||
KotlinType memberType = memberProjection.getType();
|
||||
|
||||
Type arrayElementType;
|
||||
if (memberProjection.getProjectionKind() == Variance.IN_VARIANCE) {
|
||||
@@ -520,7 +520,7 @@ public class JetTypeMapper {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Type mapBuiltinType(@NotNull KtType type) {
|
||||
private static Type mapBuiltinType(@NotNull KotlinType type) {
|
||||
DeclarationDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
|
||||
if (!(descriptor instanceof ClassDescriptor)) return null;
|
||||
|
||||
@@ -583,7 +583,7 @@ public class JetTypeMapper {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String generateErrorMessageForErrorType(@NotNull KtType type, @NotNull DeclarationDescriptor descriptor) {
|
||||
private static String generateErrorMessageForErrorType(@NotNull KotlinType type, @NotNull DeclarationDescriptor descriptor) {
|
||||
PsiElement declarationElement = DescriptorToSourceUtils.descriptorToDeclaration(descriptor);
|
||||
|
||||
if (declarationElement == null) {
|
||||
@@ -616,7 +616,7 @@ public class JetTypeMapper {
|
||||
private void writeGenericType(
|
||||
BothSignatureWriter signatureVisitor,
|
||||
Type asmType,
|
||||
KtType jetType,
|
||||
KotlinType jetType,
|
||||
Variance howThisTypeIsUsed,
|
||||
boolean projectionsAllowed
|
||||
) {
|
||||
@@ -653,7 +653,7 @@ public class JetTypeMapper {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasNothingInArguments(KtType jetType) {
|
||||
private static boolean hasNothingInArguments(KotlinType jetType) {
|
||||
boolean hasNothingInArguments = CollectionsKt.any(jetType.getArguments(), new Function1<TypeProjection, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(TypeProjection projection) {
|
||||
@@ -691,7 +691,7 @@ public class JetTypeMapper {
|
||||
}
|
||||
|
||||
private Type mapKnownAsmType(
|
||||
KtType jetType,
|
||||
KotlinType jetType,
|
||||
Type asmType,
|
||||
@Nullable BothSignatureWriter signatureVisitor,
|
||||
@NotNull Variance howThisTypeIsUsed
|
||||
@@ -700,7 +700,7 @@ public class JetTypeMapper {
|
||||
}
|
||||
|
||||
private Type mapKnownAsmType(
|
||||
KtType jetType,
|
||||
KotlinType jetType,
|
||||
Type asmType,
|
||||
@Nullable BothSignatureWriter signatureVisitor,
|
||||
@NotNull Variance howThisTypeIsUsed,
|
||||
@@ -1092,7 +1092,7 @@ public class JetTypeMapper {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String mapFieldSignature(@NotNull KtType backingFieldType) {
|
||||
public String mapFieldSignature(@NotNull KotlinType backingFieldType) {
|
||||
BothSignatureWriter sw = new BothSignatureWriter(BothSignatureWriter.Mode.TYPE);
|
||||
mapType(backingFieldType, sw, JetTypeMapperMode.VALUE);
|
||||
return sw.makeJavaGenericSignature();
|
||||
@@ -1143,7 +1143,7 @@ public class JetTypeMapper {
|
||||
{
|
||||
sw.writeClassBound();
|
||||
|
||||
for (KtType jetType : typeParameterDescriptor.getUpperBounds()) {
|
||||
for (KotlinType jetType : typeParameterDescriptor.getUpperBounds()) {
|
||||
if (jetType.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor) {
|
||||
if (!isJvmInterface(jetType)) {
|
||||
mapType(jetType, sw, JetTypeMapperMode.TYPE_PARAMETER);
|
||||
@@ -1159,7 +1159,7 @@ public class JetTypeMapper {
|
||||
}
|
||||
sw.writeClassBoundEnd();
|
||||
|
||||
for (KtType jetType : typeParameterDescriptor.getUpperBounds()) {
|
||||
for (KotlinType jetType : typeParameterDescriptor.getUpperBounds()) {
|
||||
ClassifierDescriptor classifier = jetType.getConstructor().getDeclarationDescriptor();
|
||||
if (classifier instanceof ClassDescriptor) {
|
||||
if (isJvmInterface(jetType)) {
|
||||
@@ -1179,11 +1179,11 @@ public class JetTypeMapper {
|
||||
}
|
||||
}
|
||||
|
||||
private void writeParameter(@NotNull BothSignatureWriter sw, @NotNull KtType type) {
|
||||
private void writeParameter(@NotNull BothSignatureWriter sw, @NotNull KotlinType type) {
|
||||
writeParameter(sw, JvmMethodParameterKind.VALUE, type);
|
||||
}
|
||||
|
||||
private void writeParameter(@NotNull BothSignatureWriter sw, @NotNull JvmMethodParameterKind kind, @NotNull KtType type) {
|
||||
private void writeParameter(@NotNull BothSignatureWriter sw, @NotNull JvmMethodParameterKind kind, @NotNull KotlinType type) {
|
||||
sw.writeParameterType(kind);
|
||||
mapType(type, sw, JetTypeMapperMode.VALUE);
|
||||
sw.writeParameterTypeEnd();
|
||||
@@ -1203,7 +1203,7 @@ public class JetTypeMapper {
|
||||
writeParameter(sw, JvmMethodParameterKind.OUTER, captureThis.getDefaultType());
|
||||
}
|
||||
|
||||
KtType captureReceiverType = closure != null ? closure.getCaptureReceiverType() : null;
|
||||
KotlinType captureReceiverType = closure != null ? closure.getCaptureReceiverType() : null;
|
||||
if (captureReceiverType != null) {
|
||||
writeParameter(sw, JvmMethodParameterKind.RECEIVER, captureReceiverType);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.psi.KtWhenExpression;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
||||
import org.jetbrains.kotlin.resolve.constants.NullValue;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
import org.jetbrains.org.objectweb.asm.Label;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
@@ -131,7 +131,7 @@ abstract public class SwitchCodegen {
|
||||
|
||||
protected void generateNullCheckIfNeeded() {
|
||||
assert expression.getSubjectExpression() != null : "subject expression can't be null";
|
||||
KtType subjectJetType = bindingContext.getType(expression.getSubjectExpression());
|
||||
KotlinType subjectJetType = bindingContext.getType(expression.getSubjectExpression());
|
||||
|
||||
assert subjectJetType != null : "subject type can't be null (i.e. void)";
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.resolve.constants.NullValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.serialization.*
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
public class BuiltInsSerializerExtension : SerializerExtension() {
|
||||
private val stringTable = StringTableImpl()
|
||||
@@ -75,7 +75,7 @@ public class BuiltInsSerializerExtension : SerializerExtension() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun serializeType(type: KtType, proto: ProtoBuf.Type.Builder) {
|
||||
override fun serializeType(type: KotlinType, proto: ProtoBuf.Type.Builder) {
|
||||
for (annotation in type.annotations) {
|
||||
proto.addExtension(BuiltInsProtoBuf.typeAnnotation, annotationSerializer.serializeAnnotation(annotation))
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ public class CLIConfigurationKeys {
|
||||
CompilerConfigurationKey.create("message collector");
|
||||
public static final CompilerConfigurationKey<List<CompilerPlugin>> COMPILER_PLUGINS =
|
||||
CompilerConfigurationKey.create("compiler plugins");
|
||||
public static final CompilerConfigurationKey<Boolean> REPORT_PERF =
|
||||
CompilerConfigurationKey.create("enable perf");
|
||||
|
||||
private CLIConfigurationKeys() {
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ public open class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
|
||||
val configuration = CompilerConfiguration()
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageSeverityCollector)
|
||||
configuration.put(CLIConfigurationKeys.REPORT_PERF, arguments.reportPerf)
|
||||
|
||||
if (IncrementalCompilation.isEnabled()) {
|
||||
val incrementalCompilationComponents = services.get(javaClass<IncrementalCompilationComponents>())
|
||||
@@ -246,8 +247,10 @@ public open class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
}
|
||||
|
||||
public fun reportPerf(configuration: CompilerConfiguration, message: String) {
|
||||
val collector = configuration[CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY]!!
|
||||
collector.report(CompilerMessageSeverity.INFO, "PERF: " + message, CompilerMessageLocation.NO_LOCATION)
|
||||
if (configuration[CLIConfigurationKeys.REPORT_PERF] == true) {
|
||||
val collector = configuration[CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY]!!
|
||||
collector.report(CompilerMessageSeverity.INFO, "PERF: " + message, CompilerMessageLocation.NO_LOCATION)
|
||||
}
|
||||
}
|
||||
|
||||
fun reportGCTime(configuration: CompilerConfiguration) {
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.AnalyzerScriptParameter;
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -35,7 +35,7 @@ public class CommandLineScriptUtils {
|
||||
|
||||
public static List<AnalyzerScriptParameter> scriptParameters() {
|
||||
KotlinBuiltIns builtIns = JvmPlatform.INSTANCE$.getBuiltIns();
|
||||
KtType arrayOfStrings = builtIns.getArrayType(INVARIANT, builtIns.getStringType());
|
||||
KotlinType arrayOfStrings = builtIns.getArrayType(INVARIANT, builtIns.getStringType());
|
||||
AnalyzerScriptParameter argsParameter = new AnalyzerScriptParameter(ARGS_NAME, arrayOfStrings);
|
||||
return Collections.singletonList(argsParameter);
|
||||
}
|
||||
|
||||
@@ -370,7 +370,6 @@ public class KotlinCoreEnvironment private constructor(
|
||||
with (projectEnvironment.getProject()) {
|
||||
registerService(javaClass<JetScriptDefinitionProvider>(), JetScriptDefinitionProvider())
|
||||
registerService(javaClass<KotlinJavaPsiFacade>(), KotlinJavaPsiFacade(this))
|
||||
registerService(javaClass<KotlinLightClassForFacade.PackageFacadeStubCache>(), KotlinLightClassForFacade.PackageFacadeStubCache(this))
|
||||
registerService(javaClass<KotlinLightClassForFacade.FacadeStubCache>(), KotlinLightClassForFacade.FacadeStubCache(this))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ import org.jetbrains.kotlin.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.kotlin.resolve.lazy.data.JetClassLikeInfo;
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.*;
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
|
||||
@@ -356,7 +356,7 @@ public class ReplInterpreter {
|
||||
|
||||
earlierLines.add(new EarlierLine(line, scriptDescriptor, scriptClass, scriptInstance, scriptClassType));
|
||||
|
||||
KtType returnType = scriptDescriptor.getScriptCodeDescriptor().getReturnType();
|
||||
KotlinType returnType = scriptDescriptor.getScriptCodeDescriptor().getReturnType();
|
||||
return LineResult.successful(rv, returnType != null && KotlinBuiltIns.isUnit(returnType));
|
||||
}
|
||||
catch (Throwable e) {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.fileClasses
|
||||
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.resolve.calls.context.CallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.upperIfFlexible
|
||||
@@ -36,20 +36,20 @@ public class RuntimeAssertionInfo(public val needNotNullAssertion: Boolean, publ
|
||||
public interface DataFlowExtras {
|
||||
class OnlyMessage(message: String) : DataFlowExtras {
|
||||
override val canBeNull: Boolean get() = true
|
||||
override val possibleTypes: Set<KtType> get() = setOf()
|
||||
override val possibleTypes: Set<KotlinType> get() = setOf()
|
||||
override val presentableText: String = message
|
||||
}
|
||||
|
||||
val canBeNull: Boolean
|
||||
val possibleTypes: Set<KtType>
|
||||
val possibleTypes: Set<KotlinType>
|
||||
val presentableText: String
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
public fun create(
|
||||
expectedType: KtType,
|
||||
expressionType: KtType,
|
||||
expectedType: KotlinType,
|
||||
expressionType: KotlinType,
|
||||
dataFlowExtras: DataFlowExtras
|
||||
): RuntimeAssertionInfo? {
|
||||
fun assertNotNull(): Boolean {
|
||||
@@ -78,13 +78,13 @@ public class RuntimeAssertionInfo(public val needNotNullAssertion: Boolean, publ
|
||||
null
|
||||
}
|
||||
|
||||
private fun KtType.hasEnhancedNullability()
|
||||
private fun KotlinType.hasEnhancedNullability()
|
||||
= getAnnotations().findAnnotation(JvmAnnotationNames.ENHANCED_NULLABILITY_ANNOTATION) != null
|
||||
}
|
||||
}
|
||||
|
||||
public object RuntimeAssertionsTypeChecker : AdditionalTypeChecker {
|
||||
override fun checkType(expression: KtExpression, expressionType: KtType, expressionTypeWithSmartCast: KtType, c: ResolutionContext<*>) {
|
||||
override fun checkType(expression: KtExpression, expressionType: KotlinType, expressionTypeWithSmartCast: KotlinType, c: ResolutionContext<*>) {
|
||||
if (TypeUtils.noExpectedType(c.expectedType)) return
|
||||
|
||||
val assertionInfo = RuntimeAssertionInfo.create(
|
||||
@@ -93,7 +93,7 @@ public object RuntimeAssertionsTypeChecker : AdditionalTypeChecker {
|
||||
object : RuntimeAssertionInfo.DataFlowExtras {
|
||||
override val canBeNull: Boolean
|
||||
get() = c.dataFlowInfo.getNullability(dataFlowValue).canBeNull()
|
||||
override val possibleTypes: Set<KtType>
|
||||
override val possibleTypes: Set<KotlinType>
|
||||
get() = c.dataFlowInfo.getPossibleTypes(dataFlowValue)
|
||||
override val presentableText: String
|
||||
get() = StringUtil.trimMiddle(expression.getText(), 50)
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolverKt;
|
||||
import org.jetbrains.kotlin.resolve.jvm.kotlinSignature.AlternativeFieldSignatureData;
|
||||
import org.jetbrains.kotlin.resolve.jvm.kotlinSignature.AlternativeMethodSignatureData;
|
||||
import org.jetbrains.kotlin.resolve.jvm.kotlinSignature.SignaturesPropagationData;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -55,8 +55,8 @@ public class TraceBasedExternalSignatureResolver implements ExternalSignatureRes
|
||||
public PropagatedMethodSignature resolvePropagatedSignature(
|
||||
@NotNull JavaMethod method,
|
||||
@NotNull ClassDescriptor owner,
|
||||
@NotNull KtType returnType,
|
||||
@Nullable KtType receiverType,
|
||||
@NotNull KotlinType returnType,
|
||||
@Nullable KotlinType receiverType,
|
||||
@NotNull List<ValueParameterDescriptor> valueParameters,
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters
|
||||
) {
|
||||
@@ -72,8 +72,8 @@ public class TraceBasedExternalSignatureResolver implements ExternalSignatureRes
|
||||
public AlternativeMethodSignature resolveAlternativeMethodSignature(
|
||||
@NotNull JavaMember methodOrConstructor,
|
||||
boolean hasSuperMethods,
|
||||
@Nullable KtType returnType,
|
||||
@Nullable KtType receiverType,
|
||||
@Nullable KotlinType returnType,
|
||||
@Nullable KotlinType receiverType,
|
||||
@NotNull List<ValueParameterDescriptor> valueParameters,
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
boolean hasStableParameterNames
|
||||
@@ -102,7 +102,7 @@ public class TraceBasedExternalSignatureResolver implements ExternalSignatureRes
|
||||
@NotNull
|
||||
public AlternativeFieldSignature resolveAlternativeFieldSignature(
|
||||
@NotNull JavaField field,
|
||||
@NotNull KtType returnType,
|
||||
@NotNull KotlinType returnType,
|
||||
boolean isVar
|
||||
) {
|
||||
AlternativeFieldSignatureData data = new AlternativeFieldSignatureData(field, returnType, project, isVar);
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl;
|
||||
import org.jetbrains.kotlin.resolve.ExternalOverridabilityCondition;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
|
||||
@@ -57,7 +57,7 @@ public class SamAdapterOverridabilityCondition implements ExternalOverridability
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean differentClasses(@NotNull KtType type1, @NotNull KtType type2) {
|
||||
private static boolean differentClasses(@NotNull KotlinType type1, @NotNull KotlinType type2) {
|
||||
DeclarationDescriptor declarationDescriptor1 = type1.getConstructor().getDeclarationDescriptor();
|
||||
if (declarationDescriptor1 == null) return true; // No class, classes are not equal
|
||||
DeclarationDescriptor declarationDescriptor2 = type2.getConstructor().getDeclarationDescriptor();
|
||||
@@ -100,7 +100,7 @@ public class SamAdapterOverridabilityCondition implements ExternalOverridability
|
||||
@Nullable
|
||||
private static SamAdapterInfo getNearestDeclarationOrSynthesized(
|
||||
@NotNull SimpleFunctionDescriptor samAdapter,
|
||||
@NotNull KtType ownerType
|
||||
@NotNull KotlinType ownerType
|
||||
) {
|
||||
if (samAdapter.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
||||
return new SamAdapterInfo(samAdapter, ownerType);
|
||||
@@ -109,7 +109,7 @@ public class SamAdapterOverridabilityCondition implements ExternalOverridability
|
||||
for (CallableMemberDescriptor overridden : samAdapter.getOverriddenDescriptors()) {
|
||||
ClassDescriptor containingClass = (ClassDescriptor) overridden.getContainingDeclaration();
|
||||
|
||||
for (KtType immediateSupertype : TypeUtils.getImmediateSupertypes(ownerType)) {
|
||||
for (KotlinType immediateSupertype : TypeUtils.getImmediateSupertypes(ownerType)) {
|
||||
if (containingClass != immediateSupertype.getConstructor().getDeclarationDescriptor()) {
|
||||
continue;
|
||||
}
|
||||
@@ -126,9 +126,9 @@ public class SamAdapterOverridabilityCondition implements ExternalOverridability
|
||||
|
||||
private static class SamAdapterInfo {
|
||||
private final SimpleFunctionDescriptor samAdapter;
|
||||
private final KtType ownerType;
|
||||
private final KotlinType ownerType;
|
||||
|
||||
private SamAdapterInfo(@NotNull SimpleFunctionDescriptor samAdapter, @NotNull KtType ownerType) {
|
||||
private SamAdapterInfo(@NotNull SimpleFunctionDescriptor samAdapter, @NotNull KotlinType ownerType) {
|
||||
this.samAdapter = samAdapter;
|
||||
this.ownerType = ownerType;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.load.java.descriptors.*
|
||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaMethod
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.load.java.sources.JavaSourceElement
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||
@@ -51,7 +51,7 @@ public object SamConversionResolverImpl : SamConversionResolver {
|
||||
override fun resolveFunctionTypeIfSamInterface(
|
||||
classDescriptor: JavaClassDescriptor,
|
||||
resolveMethod: (JavaMethod) -> FunctionDescriptor
|
||||
): KtType? {
|
||||
): KotlinType? {
|
||||
val jClass = (classDescriptor.getSource() as? JavaSourceElement)?.javaElement as? JavaClass ?: return null
|
||||
val samInterfaceMethod = SingleAbstractMethodUtils.getSamInterfaceMethod(jClass) ?: return null
|
||||
val abstractMethod = if (jClass.getFqName() == samInterfaceMethod.getContainingClass().getFqName()) {
|
||||
@@ -63,7 +63,7 @@ public object SamConversionResolverImpl : SamConversionResolver {
|
||||
return SingleAbstractMethodUtils.getFunctionTypeForAbstractMethod(abstractMethod)
|
||||
}
|
||||
|
||||
private fun findFunctionWithMostSpecificReturnType(supertypes: Set<KtType>): SimpleFunctionDescriptor {
|
||||
private fun findFunctionWithMostSpecificReturnType(supertypes: Set<KotlinType>): SimpleFunctionDescriptor {
|
||||
val candidates = ArrayList<SimpleFunctionDescriptor>(supertypes.size())
|
||||
for (supertype in supertypes) {
|
||||
val abstractMembers = SingleAbstractMethodUtils.getAbstractMembers(supertype)
|
||||
|
||||
@@ -43,7 +43,7 @@ public class SingleAbstractMethodUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<CallableMemberDescriptor> getAbstractMembers(@NotNull KtType type) {
|
||||
public static List<CallableMemberDescriptor> getAbstractMembers(@NotNull KotlinType type) {
|
||||
List<CallableMemberDescriptor> abstractMembers = new ArrayList<CallableMemberDescriptor>();
|
||||
for (DeclarationDescriptor member : type.getMemberScope().getAllDescriptors()) {
|
||||
if (member instanceof CallableMemberDescriptor && ((CallableMemberDescriptor) member).getModality() == Modality.ABSTRACT) {
|
||||
@@ -53,7 +53,7 @@ public class SingleAbstractMethodUtils {
|
||||
return abstractMembers;
|
||||
}
|
||||
|
||||
private static KtType fixProjections(@NotNull KtType functionType) {
|
||||
private static KotlinType fixProjections(@NotNull KotlinType functionType) {
|
||||
//removes redundant projection kinds and detects conflicts
|
||||
|
||||
List<TypeParameterDescriptor> typeParameters = functionType.getConstructor().getParameters();
|
||||
@@ -76,7 +76,7 @@ public class SingleAbstractMethodUtils {
|
||||
}
|
||||
ClassifierDescriptor classifier = functionType.getConstructor().getDeclarationDescriptor();
|
||||
assert classifier instanceof ClassDescriptor : "Not class: " + classifier;
|
||||
return KtTypeImpl.create(
|
||||
return KotlinTypeImpl.create(
|
||||
functionType.getAnnotations(),
|
||||
functionType.getConstructor(),
|
||||
functionType.isMarkedNullable(),
|
||||
@@ -86,21 +86,21 @@ public class SingleAbstractMethodUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static KtType getFunctionTypeForSamType(@NotNull KtType samType) {
|
||||
public static KotlinType getFunctionTypeForSamType(@NotNull KotlinType samType) {
|
||||
// e.g. samType == Comparator<String>?
|
||||
|
||||
ClassifierDescriptor classifier = samType.getConstructor().getDeclarationDescriptor();
|
||||
if (classifier instanceof JavaClassDescriptor) {
|
||||
// Function2<T, T, Int>
|
||||
KtType functionTypeDefault = ((JavaClassDescriptor) classifier).getFunctionTypeForSamInterface();
|
||||
KotlinType functionTypeDefault = ((JavaClassDescriptor) classifier).getFunctionTypeForSamInterface();
|
||||
|
||||
if (functionTypeDefault != null) {
|
||||
// Function2<String, String, Int>?
|
||||
KtType substitute = TypeSubstitutor.create(samType).substitute(functionTypeDefault, Variance.INVARIANT);
|
||||
KotlinType substitute = TypeSubstitutor.create(samType).substitute(functionTypeDefault, Variance.INVARIANT);
|
||||
|
||||
if (substitute == null) return null;
|
||||
|
||||
KtType type = fixProjections(substitute);
|
||||
KotlinType type = fixProjections(substitute);
|
||||
if (type == null) return null;
|
||||
|
||||
if (JavaDescriptorResolverKt.getPLATFORM_TYPES() && FlexibleTypesKt.isNullabilityFlexible(samType)) {
|
||||
@@ -114,11 +114,11 @@ public class SingleAbstractMethodUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static KtType getFunctionTypeForAbstractMethod(@NotNull FunctionDescriptor function) {
|
||||
KtType returnType = function.getReturnType();
|
||||
public static KotlinType getFunctionTypeForAbstractMethod(@NotNull FunctionDescriptor function) {
|
||||
KotlinType returnType = function.getReturnType();
|
||||
assert returnType != null : "function is not initialized: " + function;
|
||||
List<ValueParameterDescriptor> valueParameters = function.getValueParameters();
|
||||
List<KtType> parameterTypes = new ArrayList<KtType>(valueParameters.size());
|
||||
List<KotlinType> parameterTypes = new ArrayList<KotlinType>(valueParameters.size());
|
||||
for (ValueParameterDescriptor parameter : valueParameters) {
|
||||
parameterTypes.add(parameter.getType());
|
||||
}
|
||||
@@ -151,9 +151,9 @@ public class SingleAbstractMethodUtils {
|
||||
|
||||
TypeParameters typeParameters = recreateAndInitializeTypeParameters(samInterface.getTypeConstructor().getParameters(), result);
|
||||
|
||||
KtType parameterTypeUnsubstituted = getFunctionTypeForSamType(samInterface.getDefaultType());
|
||||
KotlinType parameterTypeUnsubstituted = getFunctionTypeForSamType(samInterface.getDefaultType());
|
||||
assert parameterTypeUnsubstituted != null : "couldn't get function type for SAM type " + samInterface.getDefaultType();
|
||||
KtType parameterType = typeParameters.substitutor.substitute(parameterTypeUnsubstituted, Variance.IN_VARIANCE);
|
||||
KotlinType parameterType = typeParameters.substitutor.substitute(parameterTypeUnsubstituted, Variance.IN_VARIANCE);
|
||||
assert parameterType != null : "couldn't substitute type: " + parameterTypeUnsubstituted +
|
||||
", substitutor = " + typeParameters.substitutor;
|
||||
ValueParameterDescriptor parameter = new ValueParameterDescriptorImpl(
|
||||
@@ -163,7 +163,7 @@ public class SingleAbstractMethodUtils {
|
||||
/* isNoinline = */ false,
|
||||
null, SourceElement.NO_SOURCE);
|
||||
|
||||
KtType returnType = typeParameters.substitutor.substitute(samInterface.getDefaultType(), Variance.OUT_VARIANCE);
|
||||
KotlinType returnType = typeParameters.substitutor.substitute(samInterface.getDefaultType(), Variance.OUT_VARIANCE);
|
||||
assert returnType != null : "couldn't substitute type: " + samInterface.getDefaultType() +
|
||||
", substitutor = " + typeParameters.substitutor;
|
||||
|
||||
@@ -180,7 +180,7 @@ public class SingleAbstractMethodUtils {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isSamType(@NotNull KtType type) {
|
||||
public static boolean isSamType(@NotNull KotlinType type) {
|
||||
return getFunctionTypeForSamType(type) != null;
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ public class SingleAbstractMethodUtils {
|
||||
public void initialize(
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
@NotNull List<ValueParameterDescriptor> valueParameters,
|
||||
@NotNull KtType returnType
|
||||
@NotNull KotlinType returnType
|
||||
) {
|
||||
result.initialize(
|
||||
null,
|
||||
@@ -224,7 +224,7 @@ public class SingleAbstractMethodUtils {
|
||||
public void initialize(
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
@NotNull List<ValueParameterDescriptor> valueParameters,
|
||||
@NotNull KtType returnType
|
||||
@NotNull KotlinType returnType
|
||||
) {
|
||||
result.initialize(typeParameters, valueParameters, original.getVisibility());
|
||||
result.setReturnType(returnType);
|
||||
@@ -240,11 +240,11 @@ public class SingleAbstractMethodUtils {
|
||||
) {
|
||||
TypeParameters typeParameters = recreateAndInitializeTypeParameters(original.getTypeParameters(), adapter);
|
||||
|
||||
KtType returnTypeUnsubstituted = original.getReturnType();
|
||||
KotlinType returnTypeUnsubstituted = original.getReturnType();
|
||||
assert returnTypeUnsubstituted != null : "Creating SAM adapter for not initialized original: " + original;
|
||||
|
||||
TypeSubstitutor substitutor = typeParameters.substitutor;
|
||||
KtType returnType = substitutor.substitute(returnTypeUnsubstituted, Variance.INVARIANT);
|
||||
KotlinType returnType = substitutor.substitute(returnTypeUnsubstituted, Variance.INVARIANT);
|
||||
assert returnType != null : "couldn't substitute type: " + returnTypeUnsubstituted +
|
||||
", substitutor = " + substitutor;
|
||||
|
||||
@@ -264,10 +264,10 @@ public class SingleAbstractMethodUtils {
|
||||
List<ValueParameterDescriptor> originalValueParameters = original.getValueParameters();
|
||||
List<ValueParameterDescriptor> valueParameters = new ArrayList<ValueParameterDescriptor>(originalValueParameters.size());
|
||||
for (ValueParameterDescriptor originalParam : originalValueParameters) {
|
||||
KtType originalType = originalParam.getType();
|
||||
KtType functionType = getFunctionTypeForSamType(originalType);
|
||||
KtType newTypeUnsubstituted = functionType != null ? functionType : originalType;
|
||||
KtType newType = substitutor.substitute(newTypeUnsubstituted, Variance.IN_VARIANCE);
|
||||
KotlinType originalType = originalParam.getType();
|
||||
KotlinType functionType = getFunctionTypeForSamType(originalType);
|
||||
KotlinType newTypeUnsubstituted = functionType != null ? functionType : originalType;
|
||||
KotlinType newType = substitutor.substitute(newTypeUnsubstituted, Variance.IN_VARIANCE);
|
||||
assert newType != null : "couldn't substitute type: " + newTypeUnsubstituted + ", substitutor = " + substitutor;
|
||||
|
||||
ValueParameterDescriptor newParam = new ValueParameterDescriptorImpl(
|
||||
@@ -295,8 +295,8 @@ public class SingleAbstractMethodUtils {
|
||||
TypeParameterDescriptor traitTypeParameter = mapEntry.getKey();
|
||||
TypeParameterDescriptorImpl funTypeParameter = mapEntry.getValue();
|
||||
|
||||
for (KtType upperBound : traitTypeParameter.getUpperBounds()) {
|
||||
KtType upperBoundSubstituted = typeParametersSubstitutor.substitute(upperBound, Variance.INVARIANT);
|
||||
for (KotlinType upperBound : traitTypeParameter.getUpperBounds()) {
|
||||
KotlinType upperBoundSubstituted = typeParametersSubstitutor.substitute(upperBound, Variance.INVARIANT);
|
||||
assert upperBoundSubstituted != null : "couldn't substitute type: " + upperBound + ", substitutor = " + typeParametersSubstitutor;
|
||||
funTypeParameter.addUpperBound(upperBoundSubstituted);
|
||||
}
|
||||
@@ -345,7 +345,7 @@ public class SingleAbstractMethodUtils {
|
||||
public abstract void initialize(
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
@NotNull List<ValueParameterDescriptor> valueParameters,
|
||||
@NotNull KtType returnType
|
||||
@NotNull KotlinType returnType
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import java.lang.annotation.Target
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
import org.jetbrains.kotlin.psi.KtScript
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
import java.util.*
|
||||
|
||||
@@ -44,7 +45,7 @@ public object PackagePartClassUtils {
|
||||
private @JvmStatic fun capitalizeAsJavaClassName(str: String): String =
|
||||
// NB use Locale.ENGLISH so that build is locale-independent.
|
||||
// See Javadoc on java.lang.String.toUpperCase() for more details.
|
||||
if (Character.isJavaIdentifierStart(str.charAt(0)))
|
||||
if (Character.isJavaIdentifierStart(str[0]))
|
||||
str.substring(0, 1).toUpperCase(Locale.ENGLISH) + str.substring(1)
|
||||
else
|
||||
"_$str"
|
||||
@@ -81,7 +82,11 @@ public object PackagePartClassUtils {
|
||||
|
||||
@JvmStatic
|
||||
public fun fileHasTopLevelCallables(file: KtFile): Boolean =
|
||||
file.declarations.any { it is KtProperty || it is KtNamedFunction }
|
||||
file.declarations.any {
|
||||
it is KtProperty ||
|
||||
it is KtNamedFunction ||
|
||||
it is KtScript
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
public fun getFilePartShortName(fileName: String): String =
|
||||
|
||||
@@ -42,6 +42,17 @@ public class AsmTypes {
|
||||
public static final Type MUTABLE_PROPERTY_REFERENCE1 = Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference1");
|
||||
public static final Type MUTABLE_PROPERTY_REFERENCE2 = Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference2");
|
||||
|
||||
public static final Type[] PROPERTY_REFERENCE_IMPL = {
|
||||
Type.getObjectType("kotlin/jvm/internal/PropertyReference0Impl"),
|
||||
Type.getObjectType("kotlin/jvm/internal/PropertyReference1Impl"),
|
||||
Type.getObjectType("kotlin/jvm/internal/PropertyReference2Impl")
|
||||
};
|
||||
public static final Type[] MUTABLE_PROPERTY_REFERENCE_IMPL = {
|
||||
Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference0Impl"),
|
||||
Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference1Impl"),
|
||||
Type.getObjectType("kotlin/jvm/internal/MutablePropertyReference2Impl")
|
||||
};
|
||||
|
||||
public static final Type K_CLASS_TYPE = reflect("KClass");
|
||||
public static final Type K_CLASS_ARRAY_TYPE = Type.getObjectType("[" + K_CLASS_TYPE.getDescriptor());
|
||||
public static final Type K_DECLARATION_CONTAINER_TYPE = reflect("KDeclarationContainer");
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
import org.jetbrains.kotlin.types.KtTypeImpl
|
||||
import org.jetbrains.kotlin.types.KotlinTypeImpl
|
||||
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
||||
|
||||
public class JavaClassOnCompanionChecker : CallChecker {
|
||||
@@ -42,7 +42,7 @@ public class JavaClassOnCompanionChecker : CallChecker {
|
||||
if (companionObject.isCompanionObject) {
|
||||
val containingClass = companionObject.containingDeclaration as ClassDescriptor
|
||||
val javaLangClass = actualType.constructor.declarationDescriptor as? ClassDescriptor ?: return
|
||||
val expectedType = KtTypeImpl.create(
|
||||
val expectedType = KotlinTypeImpl.create(
|
||||
Annotations.EMPTY, javaLangClass, actualType.isMarkedNullable,
|
||||
listOf(TypeProjectionImpl(containingClass.defaultType))
|
||||
)
|
||||
|
||||
@@ -36,14 +36,14 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.expressions.SenselessComparisonChecker
|
||||
import org.jetbrains.kotlin.types.flexibility
|
||||
import org.jetbrains.kotlin.types.isFlexible
|
||||
|
||||
public class JavaNullabilityWarningsChecker : AdditionalTypeChecker {
|
||||
private fun KtType.mayBeNull(): ErrorsJvm.NullabilityInformationSource? {
|
||||
private fun KotlinType.mayBeNull(): ErrorsJvm.NullabilityInformationSource? {
|
||||
if (!isError() && !isFlexible() && TypeUtils.isNullableType(this)) return ErrorsJvm.NullabilityInformationSource.KOTLIN
|
||||
|
||||
if (isFlexible() && TypeUtils.isNullableType(flexibility().lowerBound)) return ErrorsJvm.NullabilityInformationSource.KOTLIN
|
||||
@@ -52,7 +52,7 @@ public class JavaNullabilityWarningsChecker : AdditionalTypeChecker {
|
||||
return null
|
||||
}
|
||||
|
||||
private fun KtType.mustNotBeNull(): ErrorsJvm.NullabilityInformationSource? {
|
||||
private fun KotlinType.mustNotBeNull(): ErrorsJvm.NullabilityInformationSource? {
|
||||
if (!isError() && !isFlexible() && !TypeUtils.isNullableType(this)) return ErrorsJvm.NullabilityInformationSource.KOTLIN
|
||||
|
||||
if (isFlexible() && !TypeUtils.isNullableType(flexibility().upperBound)) return ErrorsJvm.NullabilityInformationSource.KOTLIN
|
||||
@@ -62,8 +62,8 @@ public class JavaNullabilityWarningsChecker : AdditionalTypeChecker {
|
||||
}
|
||||
|
||||
private fun doCheckType(
|
||||
expressionType: KtType,
|
||||
expectedType: KtType,
|
||||
expressionType: KotlinType,
|
||||
expectedType: KotlinType,
|
||||
dataFlowValue: DataFlowValue,
|
||||
dataFlowInfo: DataFlowInfo,
|
||||
reportWarning: (expectedMustNotBeNull: ErrorsJvm.NullabilityInformationSource, actualMayBeNull: ErrorsJvm.NullabilityInformationSource) -> Unit
|
||||
@@ -85,7 +85,7 @@ public class JavaNullabilityWarningsChecker : AdditionalTypeChecker {
|
||||
}
|
||||
}
|
||||
|
||||
override fun checkType(expression: KtExpression, expressionType: KtType, expressionTypeWithSmartCast: KtType, c: ResolutionContext<*>) {
|
||||
override fun checkType(expression: KtExpression, expressionType: KotlinType, expressionTypeWithSmartCast: KotlinType, c: ResolutionContext<*>) {
|
||||
doCheckType(
|
||||
expressionType,
|
||||
c.expectedType,
|
||||
|
||||
@@ -30,12 +30,12 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.classId
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getAnnotationRetention
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isRepeatableAnnotation
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
|
||||
public object RepeatableAnnotationChecker: AdditionalAnnotationChecker {
|
||||
override fun checkEntries(entries: List<KtAnnotationEntry>, actualTargets: List<KotlinTarget>, trace: BindingTrace) {
|
||||
val entryTypesWithAnnotations = hashMapOf<KtType, MutableList<AnnotationUseSiteTarget?>>()
|
||||
val entryTypesWithAnnotations = hashMapOf<KotlinType, MutableList<AnnotationUseSiteTarget?>>()
|
||||
|
||||
for (entry in entries) {
|
||||
val descriptor = trace.get(BindingContext.ANNOTATION, entry) ?: continue
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi.KtAnnotationEntry;
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration;
|
||||
import org.jetbrains.kotlin.psi.KtElement;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
import static org.jetbrains.kotlin.diagnostics.PositioningStrategies.*;
|
||||
import static org.jetbrains.kotlin.diagnostics.Severity.ERROR;
|
||||
@@ -74,8 +74,8 @@ public interface ErrorsJvm {
|
||||
|
||||
DiagnosticFactory0<KtElement> NO_REFLECTION_IN_CLASS_PATH = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
DiagnosticFactory2<KtElement, KtType, KtType> JAVA_CLASS_ON_COMPANION = DiagnosticFactory2.create(WARNING);
|
||||
DiagnosticFactory2<KtExpression, KtType, KtType> JAVA_TYPE_MISMATCH = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory2<KtElement, KotlinType, KotlinType> JAVA_CLASS_ON_COMPANION = DiagnosticFactory2.create(WARNING);
|
||||
DiagnosticFactory2<KtExpression, KotlinType, KotlinType> JAVA_TYPE_MISMATCH = DiagnosticFactory2.create(ERROR);
|
||||
|
||||
DiagnosticFactory2<PsiElement, String, String> DUPLICATE_CLASS_NAMES = DiagnosticFactory2.create(ERROR);
|
||||
|
||||
|
||||
@@ -24,16 +24,16 @@ import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaField;
|
||||
import org.jetbrains.kotlin.psi.KtProperty;
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactoryKt;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class AlternativeFieldSignatureData extends ElementAlternativeSignatureData {
|
||||
private KtType altReturnType;
|
||||
private KotlinType altReturnType;
|
||||
|
||||
public AlternativeFieldSignatureData(
|
||||
@NotNull JavaField field,
|
||||
@NotNull KtType originalReturnType,
|
||||
@NotNull KotlinType originalReturnType,
|
||||
@NotNull Project project,
|
||||
boolean isVar
|
||||
) {
|
||||
@@ -59,7 +59,7 @@ public class AlternativeFieldSignatureData extends ElementAlternativeSignatureDa
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public KtType getReturnType() {
|
||||
public KotlinType getReturnType() {
|
||||
checkForErrors();
|
||||
return altReturnType;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolverKt;
|
||||
import org.jetbrains.kotlin.resolve.jvm.JavaResolverUtils;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
import org.jetbrains.kotlin.types.Variance;
|
||||
@@ -52,17 +52,17 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
||||
private final KtNamedFunction altFunDeclaration;
|
||||
|
||||
private List<ValueParameterDescriptor> altValueParameters;
|
||||
private KtType altReturnType;
|
||||
private KotlinType altReturnType;
|
||||
private List<TypeParameterDescriptor> altTypeParameters;
|
||||
|
||||
private Map<TypeParameterDescriptor, TypeParameterDescriptorImpl> originalToAltTypeParameters;
|
||||
|
||||
public AlternativeMethodSignatureData(
|
||||
@NotNull JavaMember methodOrConstructor,
|
||||
@Nullable KtType receiverType,
|
||||
@Nullable KotlinType receiverType,
|
||||
@NotNull Project project,
|
||||
@NotNull List<ValueParameterDescriptor> valueParameters,
|
||||
@Nullable KtType originalReturnType,
|
||||
@Nullable KotlinType originalReturnType,
|
||||
@NotNull List<TypeParameterDescriptor> methodTypeParameters,
|
||||
boolean hasSuperMethods
|
||||
) {
|
||||
@@ -119,7 +119,7 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
||||
private void checkParameterAndReturnTypesForOverridingMethods(
|
||||
@NotNull List<ValueParameterDescriptor> valueParameters,
|
||||
@NotNull List<TypeParameterDescriptor> methodTypeParameters,
|
||||
@Nullable KtType returnType
|
||||
@Nullable KotlinType returnType
|
||||
) {
|
||||
if (JavaDescriptorResolverKt.getPLATFORM_TYPES()) return;
|
||||
TypeSubstitutor substitutor = JavaResolverUtils.createSubstitutorForTypeParameters(originalToAltTypeParameters);
|
||||
@@ -128,7 +128,7 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
||||
int index = parameter.getIndex();
|
||||
ValueParameterDescriptor altParameter = altValueParameters.get(index);
|
||||
|
||||
KtType substituted = substitutor.substitute(parameter.getType(), Variance.INVARIANT);
|
||||
KotlinType substituted = substitutor.substitute(parameter.getType(), Variance.INVARIANT);
|
||||
assert substituted != null;
|
||||
|
||||
if (!TypeUtils.equalTypes(substituted, altParameter.getType())) {
|
||||
@@ -143,7 +143,7 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
||||
for (TypeParameterDescriptor parameter : methodTypeParameters) {
|
||||
int index = parameter.getIndex();
|
||||
|
||||
KtType substituted = substitutor.substitute(parameter.getUpperBoundsAsType(), Variance.INVARIANT);
|
||||
KotlinType substituted = substitutor.substitute(parameter.getUpperBoundsAsType(), Variance.INVARIANT);
|
||||
assert substituted != null;
|
||||
|
||||
if (!TypeUtils.equalTypes(substituted, altTypeParameters.get(index).getUpperBoundsAsType())) {
|
||||
@@ -154,7 +154,7 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
||||
}
|
||||
|
||||
if (returnType != null) {
|
||||
KtType substitutedReturnType = substitutor.substitute(returnType, Variance.INVARIANT);
|
||||
KotlinType substitutedReturnType = substitutor.substitute(returnType, Variance.INVARIANT);
|
||||
assert substitutedReturnType != null;
|
||||
|
||||
if (!KotlinTypeChecker.DEFAULT.isSubtypeOf(altReturnType, substitutedReturnType)) {
|
||||
@@ -171,7 +171,7 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public KtType getReturnType() {
|
||||
public KotlinType getReturnType() {
|
||||
checkForErrors();
|
||||
return altReturnType;
|
||||
}
|
||||
@@ -197,10 +197,10 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
||||
KtTypeElement alternativeTypeElement = annotationValueParameter.getTypeReference().getTypeElement();
|
||||
assert alternativeTypeElement != null;
|
||||
|
||||
KtType alternativeType;
|
||||
KtType alternativeVarargElementType;
|
||||
KotlinType alternativeType;
|
||||
KotlinType alternativeVarargElementType;
|
||||
|
||||
KtType originalParamVarargElementType = originalParameterDescriptor.getVarargElementType();
|
||||
KotlinType originalParamVarargElementType = originalParameterDescriptor.getVarargElementType();
|
||||
if (originalParamVarargElementType == null) {
|
||||
if (annotationValueParameter.isVarArg()) {
|
||||
throw new AlternativeSignatureMismatchException("Parameter in method signature is not vararg, but in alternative signature it is vararg");
|
||||
@@ -253,7 +253,7 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
||||
TypeParameterDescriptorImpl altParamDescriptor = originalToAltTypeParameters.get(originalTypeParamDescriptor);
|
||||
KtTypeParameter altTypeParameter = altFunDeclaration.getTypeParameters().get(i);
|
||||
|
||||
Set<KtType> originalUpperBounds = originalTypeParamDescriptor.getUpperBounds();
|
||||
Set<KotlinType> originalUpperBounds = originalTypeParamDescriptor.getUpperBounds();
|
||||
List<KtTypeReference> altUpperBounds = getUpperBounds(altFunDeclaration, altTypeParameter);
|
||||
if (altUpperBounds.size() != originalUpperBounds.size()) {
|
||||
if (altUpperBounds.isEmpty()
|
||||
@@ -274,7 +274,7 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
||||
}
|
||||
else {
|
||||
int upperBoundIndex = 0;
|
||||
for (KtType upperBound : originalUpperBounds) {
|
||||
for (KotlinType upperBound : originalUpperBounds) {
|
||||
|
||||
KtTypeElement altTypeElement = altUpperBounds.get(upperBoundIndex).getTypeElement();
|
||||
assert altTypeElement != null;
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi.KtTypeElement;
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -86,8 +86,8 @@ public abstract class ElementAlternativeSignatureData {
|
||||
}
|
||||
}
|
||||
|
||||
protected static KtType computeReturnType(
|
||||
@NotNull KtType originalType,
|
||||
protected static KotlinType computeReturnType(
|
||||
@NotNull KotlinType originalType,
|
||||
@Nullable KtTypeReference altReturnTypeReference,
|
||||
@NotNull Map<TypeParameterDescriptor, TypeParameterDescriptorImpl> originalToAltTypeParameters) {
|
||||
if (altReturnTypeReference == null) {
|
||||
|
||||
@@ -25,8 +25,8 @@ import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KtTypeImpl;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.KotlinTypeImpl;
|
||||
import org.jetbrains.kotlin.types.TypeProjectionImpl;
|
||||
import org.jetbrains.kotlin.types.Variance;
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
||||
@@ -41,7 +41,7 @@ class PropagationHeuristics {
|
||||
// Checks for case when method returning Super[] is overridden with method returning Sub[]
|
||||
static void checkArrayInReturnType(
|
||||
@NotNull SignaturesPropagationData data,
|
||||
@NotNull KtType type,
|
||||
@NotNull KotlinType type,
|
||||
@NotNull List<SignaturesPropagationData.TypeAndVariance> typesFromSuper
|
||||
) {
|
||||
List<SignaturesPropagationData.TypeAndVariance> arrayTypesFromSuper = ContainerUtil
|
||||
@@ -55,14 +55,14 @@ class PropagationHeuristics {
|
||||
assert type.getArguments().size() == 1;
|
||||
if (type.getArguments().get(0).getProjectionKind() == Variance.INVARIANT) {
|
||||
for (SignaturesPropagationData.TypeAndVariance typeAndVariance : arrayTypesFromSuper) {
|
||||
KtType arrayTypeFromSuper = typeAndVariance.type;
|
||||
KotlinType arrayTypeFromSuper = typeAndVariance.type;
|
||||
assert arrayTypeFromSuper.getArguments().size() == 1;
|
||||
KtType elementTypeInSuper = arrayTypeFromSuper.getArguments().get(0).getType();
|
||||
KtType elementType = type.getArguments().get(0).getType();
|
||||
KotlinType elementTypeInSuper = arrayTypeFromSuper.getArguments().get(0).getType();
|
||||
KotlinType elementType = type.getArguments().get(0).getType();
|
||||
|
||||
if (KotlinTypeChecker.DEFAULT.isSubtypeOf(elementType, elementTypeInSuper)
|
||||
&& !KotlinTypeChecker.DEFAULT.equalTypes(elementType, elementTypeInSuper)) {
|
||||
KtTypeImpl betterTypeInSuper = KtTypeImpl.create(
|
||||
KotlinTypeImpl betterTypeInSuper = KotlinTypeImpl.create(
|
||||
arrayTypeFromSuper.getAnnotations(),
|
||||
arrayTypeFromSuper.getConstructor(),
|
||||
arrayTypeFromSuper.isMarkedNullable(),
|
||||
|
||||
@@ -66,7 +66,7 @@ public class SignaturesPropagationData {
|
||||
private final List<TypeParameterDescriptor> modifiedTypeParameters;
|
||||
private final ValueParameters modifiedValueParameters;
|
||||
|
||||
private final KtType modifiedReturnType;
|
||||
private final KotlinType modifiedReturnType;
|
||||
private final List<String> signatureErrors = Lists.newArrayList();
|
||||
private final List<FunctionDescriptor> superFunctions;
|
||||
private final Map<TypeParameterDescriptor, TypeParameterDescriptorImpl> autoTypeParameterToModified;
|
||||
@@ -74,8 +74,8 @@ public class SignaturesPropagationData {
|
||||
|
||||
public SignaturesPropagationData(
|
||||
@NotNull ClassDescriptor containingClass,
|
||||
@NotNull KtType autoReturnType, // type built by JavaTypeTransformer from Java signature and @NotNull annotations
|
||||
@Nullable KtType receiverType,
|
||||
@NotNull KotlinType autoReturnType, // type built by JavaTypeTransformer from Java signature and @NotNull annotations
|
||||
@Nullable KotlinType receiverType,
|
||||
@NotNull List<ValueParameterDescriptor> autoValueParameters, // descriptors built by parameters resolver
|
||||
@NotNull List<TypeParameterDescriptor> autoTypeParameters, // descriptors built by signature resolver
|
||||
@NotNull JavaMethod method
|
||||
@@ -97,8 +97,8 @@ public class SignaturesPropagationData {
|
||||
@NotNull
|
||||
private static JavaMethodDescriptor createAutoMethodDescriptor(
|
||||
@NotNull ClassDescriptor containingClass,
|
||||
@NotNull JavaMethod method, KtType autoReturnType,
|
||||
@Nullable KtType receiverType,
|
||||
@NotNull JavaMethod method, KotlinType autoReturnType,
|
||||
@Nullable KotlinType receiverType,
|
||||
@NotNull List<ValueParameterDescriptor> autoValueParameters,
|
||||
@NotNull List<TypeParameterDescriptor> autoTypeParameters
|
||||
) {
|
||||
@@ -125,7 +125,7 @@ public class SignaturesPropagationData {
|
||||
return modifiedTypeParameters;
|
||||
}
|
||||
|
||||
public KtType getModifiedReceiverType() {
|
||||
public KotlinType getModifiedReceiverType() {
|
||||
return modifiedValueParameters.receiverType;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ public class SignaturesPropagationData {
|
||||
return modifiedValueParameters.hasStableParameterNames;
|
||||
}
|
||||
|
||||
public KtType getModifiedReturnType() {
|
||||
public KotlinType getModifiedReturnType() {
|
||||
return modifiedReturnType;
|
||||
}
|
||||
|
||||
@@ -153,8 +153,8 @@ public class SignaturesPropagationData {
|
||||
signatureErrors.add(error);
|
||||
}
|
||||
|
||||
private KtType modifyReturnTypeAccordingToSuperMethods(
|
||||
@NotNull KtType autoType // type built by JavaTypeTransformer
|
||||
private KotlinType modifyReturnTypeAccordingToSuperMethods(
|
||||
@NotNull KotlinType autoType // type built by JavaTypeTransformer
|
||||
) {
|
||||
if (JavaDescriptorResolverKt.getPLATFORM_TYPES()) return autoType;
|
||||
|
||||
@@ -179,24 +179,24 @@ public class SignaturesPropagationData {
|
||||
int index = autoParameter.getIndex();
|
||||
TypeParameterDescriptorImpl modifiedTypeParameter = autoTypeParameterToModified.get(autoParameter);
|
||||
|
||||
List<Iterator<KtType>> upperBoundFromSuperFunctionsIterators = Lists.newArrayList();
|
||||
List<Iterator<KotlinType>> upperBoundFromSuperFunctionsIterators = Lists.newArrayList();
|
||||
for (FunctionDescriptor superFunction : superFunctions) {
|
||||
upperBoundFromSuperFunctionsIterators.add(superFunction.getTypeParameters().get(index).getUpperBounds().iterator());
|
||||
}
|
||||
|
||||
for (KtType autoUpperBound : autoParameter.getUpperBounds()) {
|
||||
for (KotlinType autoUpperBound : autoParameter.getUpperBounds()) {
|
||||
List<TypeAndVariance> upperBoundsFromSuperFunctions = Lists.newArrayList();
|
||||
|
||||
for (Iterator<KtType> iterator : upperBoundFromSuperFunctionsIterators) {
|
||||
for (Iterator<KotlinType> iterator : upperBoundFromSuperFunctionsIterators) {
|
||||
assert iterator.hasNext();
|
||||
upperBoundsFromSuperFunctions.add(new TypeAndVariance(iterator.next(), INVARIANT));
|
||||
}
|
||||
|
||||
KtType modifiedUpperBound = modifyTypeAccordingToSuperMethods(autoUpperBound, upperBoundsFromSuperFunctions, UPPER_BOUND);
|
||||
KotlinType modifiedUpperBound = modifyTypeAccordingToSuperMethods(autoUpperBound, upperBoundsFromSuperFunctions, UPPER_BOUND);
|
||||
modifiedTypeParameter.addUpperBound(modifiedUpperBound);
|
||||
}
|
||||
|
||||
for (Iterator<KtType> iterator : upperBoundFromSuperFunctionsIterators) {
|
||||
for (Iterator<KotlinType> iterator : upperBoundFromSuperFunctionsIterators) {
|
||||
assert !iterator.hasNext();
|
||||
}
|
||||
|
||||
@@ -208,14 +208,14 @@ public class SignaturesPropagationData {
|
||||
}
|
||||
|
||||
private ValueParameters modifyValueParametersAccordingToSuperMethods(
|
||||
@Nullable KtType receiverType,
|
||||
@Nullable KotlinType receiverType,
|
||||
@NotNull List<ValueParameterDescriptor> parameters // descriptors built by parameters resolver
|
||||
) {
|
||||
assert receiverType == null : "Parameters before propagation have receiver type," +
|
||||
" but propagation should be disabled for functions compiled from Kotlin in class: " +
|
||||
DescriptorUtils.getFqName(containingClass);
|
||||
|
||||
KtType resultReceiverType = null;
|
||||
KotlinType resultReceiverType = null;
|
||||
List<ValueParameterDescriptor> resultParameters = new ArrayList<ValueParameterDescriptor>(parameters.size());
|
||||
|
||||
boolean shouldBeExtension = checkIfShouldBeExtension();
|
||||
@@ -239,9 +239,9 @@ public class SignaturesPropagationData {
|
||||
|
||||
VarargCheckResult varargCheckResult = checkVarargInSuperFunctions(originalParam);
|
||||
|
||||
KtType altType = modifyTypeAccordingToSuperMethods(varargCheckResult.parameterType,
|
||||
convertToTypeVarianceList(typesFromSuperMethods),
|
||||
MEMBER_SIGNATURE_CONTRAVARIANT);
|
||||
KotlinType altType = modifyTypeAccordingToSuperMethods(varargCheckResult.parameterType,
|
||||
convertToTypeVarianceList(typesFromSuperMethods),
|
||||
MEMBER_SIGNATURE_CONTRAVARIANT);
|
||||
|
||||
if (shouldBeExtension && originalIndex == 0) {
|
||||
resultReceiverType = altType;
|
||||
@@ -304,7 +304,7 @@ public class SignaturesPropagationData {
|
||||
// TODO: Add propagation for other kotlin descriptors (KT-3621)
|
||||
Name name = method.getName();
|
||||
JvmMethodSignature autoSignature = SIGNATURE_MAPPER.mapToJvmMethodSignature(autoMethodDescriptor);
|
||||
for (KtType supertype : containingClass.getTypeConstructor().getSupertypes()) {
|
||||
for (KotlinType supertype : containingClass.getTypeConstructor().getSupertypes()) {
|
||||
Collection<FunctionDescriptor> superFunctionCandidates = supertype.getMemberScope().getFunctions(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS);
|
||||
for (FunctionDescriptor candidate : superFunctionCandidates) {
|
||||
JvmMethodSignature candidateSignature = SIGNATURE_MAPPER.mapToJvmMethodSignature(candidate);
|
||||
@@ -365,8 +365,8 @@ public class SignaturesPropagationData {
|
||||
}
|
||||
}
|
||||
|
||||
KtType originalVarargElementType = originalParam.getVarargElementType();
|
||||
KtType originalType = originalParam.getType();
|
||||
KotlinType originalVarargElementType = originalParam.getVarargElementType();
|
||||
KotlinType originalType = originalParam.getType();
|
||||
|
||||
if (someSupersVararg && someSupersNotVararg) {
|
||||
reportError("Incompatible super methods: some have vararg parameter, some have not");
|
||||
@@ -389,8 +389,8 @@ public class SignaturesPropagationData {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private KtType modifyTypeAccordingToSuperMethods(
|
||||
@NotNull KtType autoType,
|
||||
private KotlinType modifyTypeAccordingToSuperMethods(
|
||||
@NotNull KotlinType autoType,
|
||||
@NotNull List<TypeAndVariance> typesFromSuper,
|
||||
@NotNull TypeUsage howThisTypeIsUsed
|
||||
) {
|
||||
@@ -409,11 +409,11 @@ public class SignaturesPropagationData {
|
||||
resultScope = autoType.getMemberScope();
|
||||
}
|
||||
|
||||
KtType type = KtTypeImpl.create(autoType.getAnnotations(),
|
||||
resultClassifier.getTypeConstructor(),
|
||||
resultNullable,
|
||||
resultArguments,
|
||||
resultScope);
|
||||
KotlinType type = KotlinTypeImpl.create(autoType.getAnnotations(),
|
||||
resultClassifier.getTypeConstructor(),
|
||||
resultNullable,
|
||||
resultArguments,
|
||||
resultScope);
|
||||
|
||||
PropagationHeuristics.checkArrayInReturnType(this, type, typesFromSuper);
|
||||
return type;
|
||||
@@ -421,7 +421,7 @@ public class SignaturesPropagationData {
|
||||
|
||||
@NotNull
|
||||
private List<TypeProjection> getTypeArgsOfType(
|
||||
@NotNull KtType autoType,
|
||||
@NotNull KotlinType autoType,
|
||||
@NotNull ClassifierDescriptor classifier,
|
||||
@NotNull List<TypeAndVariance> typesFromSuper
|
||||
) {
|
||||
@@ -444,11 +444,11 @@ public class SignaturesPropagationData {
|
||||
for (TypeParameterDescriptor parameter : classifier.getTypeConstructor().getParameters()) {
|
||||
TypeProjection argument = autoArguments.get(parameter.getIndex());
|
||||
|
||||
KtType argumentType = argument.getType();
|
||||
KotlinType argumentType = argument.getType();
|
||||
List<TypeProjectionAndVariance> projectionsFromSuper = typeArgumentsFromSuper.get(parameter.getIndex());
|
||||
List<TypeAndVariance> argTypesFromSuper = getTypes(projectionsFromSuper);
|
||||
|
||||
KtType type = modifyTypeAccordingToSuperMethods(argumentType, argTypesFromSuper, TYPE_ARGUMENT);
|
||||
KotlinType type = modifyTypeAccordingToSuperMethods(argumentType, argTypesFromSuper, TYPE_ARGUMENT);
|
||||
Variance projectionKind = calculateArgumentProjectionKindFromSuper(argument, projectionsFromSuper);
|
||||
|
||||
resultArguments.add(new TypeProjectionImpl(projectionKind, type));
|
||||
@@ -567,7 +567,7 @@ public class SignaturesPropagationData {
|
||||
}
|
||||
|
||||
private boolean typeMustBeNullable(
|
||||
@NotNull KtType autoType,
|
||||
@NotNull KotlinType autoType,
|
||||
@NotNull List<TypeAndVariance> typesFromSuper,
|
||||
@NotNull TypeUsage howThisTypeIsUsed
|
||||
) {
|
||||
@@ -611,7 +611,7 @@ public class SignaturesPropagationData {
|
||||
|
||||
@NotNull
|
||||
private ClassifierDescriptor modifyTypeClassifier(
|
||||
@NotNull KtType autoType,
|
||||
@NotNull KotlinType autoType,
|
||||
@NotNull List<TypeAndVariance> typesFromSuper
|
||||
) {
|
||||
ClassifierDescriptor classifier = autoType.getConstructor().getDeclarationDescriptor();
|
||||
@@ -666,15 +666,15 @@ public class SignaturesPropagationData {
|
||||
return fixed != null ? fixed : classifier;
|
||||
}
|
||||
|
||||
private static boolean isArrayType(@NotNull KtType type) {
|
||||
private static boolean isArrayType(@NotNull KotlinType type) {
|
||||
return KotlinBuiltIns.isArray(type) || KotlinBuiltIns.isPrimitiveArray(type);
|
||||
}
|
||||
|
||||
private static class VarargCheckResult {
|
||||
public final KtType parameterType;
|
||||
public final KotlinType parameterType;
|
||||
public final boolean isVararg;
|
||||
|
||||
public VarargCheckResult(KtType parameterType, boolean isVararg) {
|
||||
public VarargCheckResult(KotlinType parameterType, boolean isVararg) {
|
||||
this.parameterType = parameterType;
|
||||
this.isVararg = isVararg;
|
||||
}
|
||||
@@ -695,10 +695,10 @@ public class SignaturesPropagationData {
|
||||
}
|
||||
|
||||
static class TypeAndVariance {
|
||||
public final KtType type;
|
||||
public final KotlinType type;
|
||||
public final Variance varianceOfPosition;
|
||||
|
||||
public TypeAndVariance(KtType type, Variance varianceOfPosition) {
|
||||
public TypeAndVariance(KotlinType type, Variance varianceOfPosition) {
|
||||
this.type = type;
|
||||
this.varianceOfPosition = varianceOfPosition;
|
||||
}
|
||||
@@ -709,22 +709,22 @@ public class SignaturesPropagationData {
|
||||
}
|
||||
|
||||
private static class TypeAndName {
|
||||
public final KtType type;
|
||||
public final KotlinType type;
|
||||
public final Name name;
|
||||
|
||||
public TypeAndName(KtType type, Name name) {
|
||||
public TypeAndName(KotlinType type, Name name) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ValueParameters {
|
||||
private final KtType receiverType;
|
||||
private final KotlinType receiverType;
|
||||
private final List<ValueParameterDescriptor> descriptors;
|
||||
private final boolean hasStableParameterNames;
|
||||
|
||||
public ValueParameters(
|
||||
@Nullable KtType receiverType,
|
||||
@Nullable KotlinType receiverType,
|
||||
@NotNull List<ValueParameterDescriptor> descriptors,
|
||||
boolean hasStableParameterNames
|
||||
) {
|
||||
|
||||
@@ -42,16 +42,16 @@ import java.util.*;
|
||||
import static org.jetbrains.kotlin.load.java.components.TypeUsage.TYPE_ARGUMENT;
|
||||
import static org.jetbrains.kotlin.types.Variance.INVARIANT;
|
||||
|
||||
public class TypeTransformingVisitor extends KtVisitor<KtType, Void> {
|
||||
public class TypeTransformingVisitor extends KtVisitor<KotlinType, Void> {
|
||||
private static boolean strictMode = false;
|
||||
|
||||
private final KtType originalType;
|
||||
private final KotlinType originalType;
|
||||
private final Map<TypeParameterDescriptor, TypeParameterDescriptorImpl> originalToAltTypeParameters;
|
||||
|
||||
private final TypeUsage typeUsage;
|
||||
|
||||
private TypeTransformingVisitor(
|
||||
KtType originalType,
|
||||
KotlinType originalType,
|
||||
Map<TypeParameterDescriptor, TypeParameterDescriptorImpl> originalToAltTypeParameters,
|
||||
TypeUsage typeUsage
|
||||
) {
|
||||
@@ -61,19 +61,19 @@ public class TypeTransformingVisitor extends KtVisitor<KtType, Void> {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static KtType computeType(
|
||||
public static KotlinType computeType(
|
||||
@NotNull KtTypeElement alternativeTypeElement,
|
||||
@NotNull KtType originalType,
|
||||
@NotNull KotlinType originalType,
|
||||
@NotNull Map<TypeParameterDescriptor, TypeParameterDescriptorImpl> originalToAltTypeParameters,
|
||||
@NotNull TypeUsage typeUsage
|
||||
) {
|
||||
KtType computedType = alternativeTypeElement.accept(new TypeTransformingVisitor(originalType, originalToAltTypeParameters, typeUsage), null);
|
||||
KotlinType computedType = alternativeTypeElement.accept(new TypeTransformingVisitor(originalType, originalToAltTypeParameters, typeUsage), null);
|
||||
assert (computedType != null);
|
||||
return computedType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KtType visitNullableType(@NotNull KtNullableType nullableType, Void aVoid) {
|
||||
public KotlinType visitNullableType(@NotNull KtNullableType nullableType, Void aVoid) {
|
||||
if (!TypeUtils.isNullableType(originalType) && typeUsage != TYPE_ARGUMENT) {
|
||||
throw new AlternativeSignatureMismatchException("Auto type '%s' is not-null, while type in alternative signature is nullable: '%s'",
|
||||
DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(originalType), nullableType.getText());
|
||||
@@ -84,7 +84,7 @@ public class TypeTransformingVisitor extends KtVisitor<KtType, Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public KtType visitFunctionType(@NotNull KtFunctionType type, Void data) {
|
||||
public KotlinType visitFunctionType(@NotNull KtFunctionType type, Void data) {
|
||||
KotlinBuiltIns builtIns = JvmPlatform.INSTANCE$.getBuiltIns();
|
||||
return visitCommonType(type.getReceiverTypeReference() == null
|
||||
? builtIns.getFunction(type.getParameters().size())
|
||||
@@ -92,7 +92,7 @@ public class TypeTransformingVisitor extends KtVisitor<KtType, Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public KtType visitUserType(@NotNull KtUserType type, Void data) {
|
||||
public KotlinType visitUserType(@NotNull KtUserType type, Void data) {
|
||||
KtUserType qualifier = type.getQualifier();
|
||||
|
||||
//noinspection ConstantConditions
|
||||
@@ -102,12 +102,12 @@ public class TypeTransformingVisitor extends KtVisitor<KtType, Void> {
|
||||
return visitCommonType(longName, type);
|
||||
}
|
||||
|
||||
private KtType visitCommonType(@NotNull ClassDescriptor classDescriptor, @NotNull KtTypeElement type) {
|
||||
private KotlinType visitCommonType(@NotNull ClassDescriptor classDescriptor, @NotNull KtTypeElement type) {
|
||||
return visitCommonType(DescriptorUtils.getFqNameSafe(classDescriptor).asString(), type);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private KtType visitCommonType(@NotNull String qualifiedName, @NotNull KtTypeElement type) {
|
||||
private KotlinType visitCommonType(@NotNull String qualifiedName, @NotNull KtTypeElement type) {
|
||||
if (originalType.isError()) {
|
||||
return originalType;
|
||||
}
|
||||
@@ -159,7 +159,7 @@ public class TypeTransformingVisitor extends KtVisitor<KtType, Void> {
|
||||
throw new AssertionError("Unexpected class of type constructor classifier "
|
||||
+ (typeConstructorClassifier == null ? "null" : typeConstructorClassifier.getClass().getName()));
|
||||
}
|
||||
return KtTypeImpl.create(originalType.getAnnotations(), typeConstructor, false, altArguments, memberScope);
|
||||
return KotlinTypeImpl.create(originalType.getAnnotations(), typeConstructor, false, altArguments, memberScope);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -183,7 +183,7 @@ public class TypeTransformingVisitor extends KtVisitor<KtType, Void> {
|
||||
assert argumentAlternativeTypeElement != null;
|
||||
|
||||
TypeParameterDescriptor parameter = typeConstructor.getParameters().get(i);
|
||||
KtType alternativeArgumentType = computeType(argumentAlternativeTypeElement, originalArgument.getType(), originalToAltTypeParameters, TYPE_ARGUMENT);
|
||||
KotlinType alternativeArgumentType = computeType(argumentAlternativeTypeElement, originalArgument.getType(), originalToAltTypeParameters, TYPE_ARGUMENT);
|
||||
Variance projectionKind = originalArgument.getProjectionKind();
|
||||
Variance altProjectionKind;
|
||||
if (type instanceof KtUserType) {
|
||||
@@ -234,7 +234,7 @@ public class TypeTransformingVisitor extends KtVisitor<KtType, Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public KtType visitSelfType(@NotNull KtSelfType type, Void data) {
|
||||
public KotlinType visitSelfType(@NotNull KtSelfType type, Void data) {
|
||||
throw new UnsupportedOperationException("Self-types are not supported yet");
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,8 @@ public object JavaGenericVarianceViolationTypeChecker : AdditionalTypeChecker {
|
||||
// JavaClass.fillWithDefaultObjects(x) // using `x` after this call may lead to CCE
|
||||
override fun checkType(
|
||||
expression: KtExpression,
|
||||
expressionType: KtType,
|
||||
expressionTypeWithSmartCast: KtType,
|
||||
expressionType: KotlinType,
|
||||
expressionTypeWithSmartCast: KotlinType,
|
||||
c: ResolutionContext<*>
|
||||
) {
|
||||
val expectedType = c.expectedType
|
||||
|
||||
@@ -130,7 +130,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager) : KtScopeImpl
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KtType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
|
||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
|
||||
//TODO: use location parameter!
|
||||
|
||||
var result: SmartList<PropertyDescriptor>? = null
|
||||
@@ -162,7 +162,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager) : KtScopeImpl
|
||||
return result
|
||||
}
|
||||
|
||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KtType>): Collection<PropertyDescriptor> {
|
||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> {
|
||||
val result = ArrayList<PropertyDescriptor>()
|
||||
val processedTypes = HashSet<TypeConstructor>()
|
||||
receiverTypes.forEach { result.collectSyntheticProperties(it.constructor, processedTypes) }
|
||||
@@ -253,7 +253,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager) : KtScopeImpl
|
||||
private set
|
||||
|
||||
companion object {
|
||||
fun create(ownerClass: ClassDescriptor, getMethod: FunctionDescriptor, setMethod: FunctionDescriptor?, name: Name, type: KtType): MyPropertyDescriptor {
|
||||
fun create(ownerClass: ClassDescriptor, getMethod: FunctionDescriptor, setMethod: FunctionDescriptor?, name: Name, type: KotlinType): MyPropertyDescriptor {
|
||||
val visibility = syntheticExtensionVisibility(getMethod)
|
||||
val descriptor = MyPropertyDescriptor(DescriptorUtils.getContainingModule(ownerClass),
|
||||
null,
|
||||
|
||||
@@ -52,7 +52,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : KtScope by KtSc
|
||||
return MyFunctionDescriptor.create(enhancedFunction)
|
||||
}
|
||||
|
||||
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KtType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
|
||||
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
|
||||
var result: SmartList<FunctionDescriptor>? = null
|
||||
for (type in receiverTypes) {
|
||||
for (function in type.memberScope.getFunctions(name, location)) {
|
||||
@@ -72,7 +72,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : KtScope by KtSc
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KtType>): Collection<FunctionDescriptor> {
|
||||
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> {
|
||||
return receiverTypes.flatMapTo(LinkedHashSet<FunctionDescriptor>()) { type ->
|
||||
type.memberScope.getDescriptors(DescriptorKindFilter.FUNCTIONS)
|
||||
.filterIsInstance<FunctionDescriptor>()
|
||||
@@ -156,8 +156,8 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : KtScope by KtSc
|
||||
copyOverrides: Boolean,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
newValueParameterDescriptors: MutableList<ValueParameterDescriptor>,
|
||||
newExtensionReceiverParameterType: KtType?,
|
||||
newReturnType: KtType
|
||||
newExtensionReceiverParameterType: KotlinType?,
|
||||
newReturnType: KotlinType
|
||||
): FunctionDescriptor? {
|
||||
val descriptor = super<SimpleFunctionDescriptorImpl>.doSubstitute(
|
||||
originalSubstitutor, newOwner, newModality, newVisibility,
|
||||
|
||||
@@ -56,7 +56,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
||||
|
||||
import java.util.*;
|
||||
@@ -109,7 +109,7 @@ public class JetControlFlowProcessor {
|
||||
CallableDescriptor subroutineDescriptor = (CallableDescriptor) trace.get(BindingContext.DECLARATION_TO_DESCRIPTOR, subroutine);
|
||||
if (subroutineDescriptor == null) return;
|
||||
|
||||
KtType returnType = subroutineDescriptor.getReturnType();
|
||||
KotlinType returnType = subroutineDescriptor.getReturnType();
|
||||
if (returnType != null && KotlinBuiltIns.isUnit(returnType) && subroutineDescriptor instanceof AnonymousFunctionDescriptor) return;
|
||||
|
||||
PseudoValue returnValue = builder.getBoundValue(bodyExpression);
|
||||
@@ -199,7 +199,7 @@ public class JetControlFlowProcessor {
|
||||
return;
|
||||
}
|
||||
|
||||
KtType type = trace.getBindingContext().getType(expression);
|
||||
KotlinType type = trace.getBindingContext().getType(expression);
|
||||
if (type != null && KotlinBuiltIns.isNothing(type)) {
|
||||
builder.jumpToError(expression);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.calls.resolvedCallUtil.ResolvedCallUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils;
|
||||
|
||||
import java.util.*;
|
||||
@@ -129,7 +129,7 @@ public class JetFlowInformationProvider {
|
||||
markWhenWithoutElse();
|
||||
}
|
||||
|
||||
public void checkFunction(@Nullable KtType expectedReturnType) {
|
||||
public void checkFunction(@Nullable KotlinType expectedReturnType) {
|
||||
UnreachableCode unreachableCode = collectUnreachableCode();
|
||||
reportUnreachableCode(unreachableCode);
|
||||
|
||||
@@ -208,7 +208,7 @@ public class JetFlowInformationProvider {
|
||||
|
||||
CallableDescriptor functionDescriptor =
|
||||
(CallableDescriptor) trace.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, localDeclaration);
|
||||
KtType expectedType = functionDescriptor != null ? functionDescriptor.getReturnType() : null;
|
||||
KotlinType expectedType = functionDescriptor != null ? functionDescriptor.getReturnType() : null;
|
||||
|
||||
JetFlowInformationProvider providerForLocalDeclaration =
|
||||
new JetFlowInformationProvider(localDeclaration, trace, localDeclarationInstruction.getBody());
|
||||
@@ -218,7 +218,7 @@ public class JetFlowInformationProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public void checkDefiniteReturn(final @NotNull KtType expectedReturnType, @NotNull final UnreachableCode unreachableCode) {
|
||||
public void checkDefiniteReturn(final @NotNull KotlinType expectedReturnType, @NotNull final UnreachableCode unreachableCode) {
|
||||
assert subroutine instanceof KtDeclarationWithBody;
|
||||
KtDeclarationWithBody function = (KtDeclarationWithBody) subroutine;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.resolve.CompileTimeConstantUtils;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.BindingContextUtilsKt;
|
||||
import org.jetbrains.kotlin.types.FlexibleTypesKt;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -41,7 +41,7 @@ public final class WhenChecker {
|
||||
}
|
||||
|
||||
public static boolean mustHaveElse(@NotNull KtWhenExpression expression, @NotNull BindingTrace trace) {
|
||||
KtType expectedType = trace.get(BindingContext.EXPECTED_EXPRESSION_TYPE, expression);
|
||||
KotlinType expectedType = trace.get(BindingContext.EXPECTED_EXPRESSION_TYPE, expression);
|
||||
boolean isUnit = expectedType != null && KotlinBuiltIns.isUnit(expectedType);
|
||||
// Some "statements" are actually expressions returned from lambdas, their expected types are non-null
|
||||
boolean isStatement = BindingContextUtilsKt.isUsedAsStatement(expression, trace.getBindingContext()) && expectedType == null;
|
||||
@@ -54,7 +54,7 @@ public final class WhenChecker {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ClassDescriptor getClassDescriptorOfTypeIfEnum(@Nullable KtType type) {
|
||||
public static ClassDescriptor getClassDescriptorOfTypeIfEnum(@Nullable KotlinType type) {
|
||||
if (type == null) return null;
|
||||
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(type);
|
||||
if (classDescriptor == null) return null;
|
||||
@@ -64,7 +64,7 @@ public final class WhenChecker {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static KtType whenSubjectType(@NotNull KtWhenExpression expression, @NotNull BindingContext context) {
|
||||
private static KotlinType whenSubjectType(@NotNull KtWhenExpression expression, @NotNull BindingContext context) {
|
||||
KtExpression subjectExpression = expression.getSubjectExpression();
|
||||
return subjectExpression == null ? null : context.getType(subjectExpression);
|
||||
}
|
||||
@@ -136,7 +136,7 @@ public final class WhenChecker {
|
||||
*/
|
||||
private static boolean isNullableTypeWithoutPossibleSmartCast(
|
||||
@Nullable KtExpression expression,
|
||||
@NotNull KtType type,
|
||||
@NotNull KotlinType type,
|
||||
@NotNull BindingContext context
|
||||
) {
|
||||
if (expression == null) return false; // Normally should not happen
|
||||
@@ -152,7 +152,7 @@ public final class WhenChecker {
|
||||
}
|
||||
|
||||
public static boolean isWhenExhaustive(@NotNull KtWhenExpression expression, @NotNull BindingTrace trace) {
|
||||
KtType type = whenSubjectType(expression, trace.getBindingContext());
|
||||
KotlinType type = whenSubjectType(expression, trace.getBindingContext());
|
||||
if (type == null) return false;
|
||||
ClassDescriptor enumClassDescriptor = getClassDescriptorOfTypeIfEnum(type);
|
||||
|
||||
@@ -196,7 +196,7 @@ public final class WhenChecker {
|
||||
ClassDescriptor checkedDescriptor = null;
|
||||
if (condition instanceof KtWhenConditionIsPattern) {
|
||||
KtWhenConditionIsPattern conditionIsPattern = (KtWhenConditionIsPattern) condition;
|
||||
KtType checkedType = trace.get(BindingContext.TYPE, conditionIsPattern.getTypeReference());
|
||||
KotlinType checkedType = trace.get(BindingContext.TYPE, conditionIsPattern.getTypeReference());
|
||||
if (checkedType != null) {
|
||||
checkedDescriptor = TypeUtils.getClassDescriptor(checkedType);
|
||||
}
|
||||
@@ -243,7 +243,7 @@ public final class WhenChecker {
|
||||
if (condition instanceof KtWhenConditionWithExpression) {
|
||||
KtWhenConditionWithExpression conditionWithExpression = (KtWhenConditionWithExpression) condition;
|
||||
if (conditionWithExpression.getExpression() != null) {
|
||||
KtType type = trace.getBindingContext().getType(conditionWithExpression.getExpression());
|
||||
KotlinType type = trace.getBindingContext().getType(conditionWithExpression.getExpression());
|
||||
if (type != null && KotlinBuiltIns.isNothingOrNullableNothing(type)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -476,7 +476,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
@NotNull Map<PseudoValue, ReceiverValue> receiverValues,
|
||||
@NotNull Map<PseudoValue, ValueParameterDescriptor> arguments
|
||||
) {
|
||||
KtType returnType = resolvedCall.getResultingDescriptor().getReturnType();
|
||||
KotlinType returnType = resolvedCall.getResultingDescriptor().getReturnType();
|
||||
CallInstruction instruction = new CallInstruction(
|
||||
valueElement,
|
||||
getCurrentScope(),
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.resolve.BindingContextUtils;
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.calls.resolvedCallUtil.ResolvedCallUtilKt;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.util.slicedMap.ReadOnlySlice;
|
||||
import org.jetbrains.kotlin.util.slicedMap.WritableSlice;
|
||||
|
||||
@@ -72,12 +72,12 @@ public class PseudocodeUtil {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public KtType getType(@NotNull KtExpression expression) {
|
||||
public KotlinType getType(@NotNull KtExpression expression) {
|
||||
return bindingContext.getType(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordType(@NotNull KtExpression expression, @Nullable KtType type) {
|
||||
public void recordType(@NotNull KtExpression expression, @Nullable KotlinType type) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,39 +19,39 @@ package org.jetbrains.kotlin.cfg.pseudocode
|
||||
import com.intellij.util.SmartFMap
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
|
||||
public interface TypePredicate: (KtType) -> Boolean {
|
||||
override fun invoke(typeToCheck: KtType): Boolean
|
||||
public interface TypePredicate: (KotlinType) -> Boolean {
|
||||
override fun invoke(typeToCheck: KotlinType): Boolean
|
||||
}
|
||||
|
||||
public data class SingleType(val targetType: KtType): TypePredicate {
|
||||
override fun invoke(typeToCheck: KtType): Boolean = KotlinTypeChecker.DEFAULT.equalTypes(typeToCheck, targetType)
|
||||
public data class SingleType(val targetType: KotlinType): TypePredicate {
|
||||
override fun invoke(typeToCheck: KotlinType): Boolean = KotlinTypeChecker.DEFAULT.equalTypes(typeToCheck, targetType)
|
||||
override fun toString(): String = targetType.render()
|
||||
}
|
||||
|
||||
public data class AllSubtypes(val upperBound: KtType): TypePredicate {
|
||||
override fun invoke(typeToCheck: KtType): Boolean = KotlinTypeChecker.DEFAULT.isSubtypeOf(typeToCheck, upperBound)
|
||||
public data class AllSubtypes(val upperBound: KotlinType): TypePredicate {
|
||||
override fun invoke(typeToCheck: KotlinType): Boolean = KotlinTypeChecker.DEFAULT.isSubtypeOf(typeToCheck, upperBound)
|
||||
|
||||
override fun toString(): String = "{<: ${upperBound.render()}}"
|
||||
}
|
||||
|
||||
public data class ForAllTypes(val typeSets: List<TypePredicate>): TypePredicate {
|
||||
override fun invoke(typeToCheck: KtType): Boolean = typeSets.all { it(typeToCheck) }
|
||||
override fun invoke(typeToCheck: KotlinType): Boolean = typeSets.all { it(typeToCheck) }
|
||||
|
||||
override fun toString(): String = "AND{${typeSets.joinToString(", ")}}"
|
||||
}
|
||||
|
||||
public data class ForSomeType(val typeSets: List<TypePredicate>): TypePredicate {
|
||||
override fun invoke(typeToCheck: KtType): Boolean = typeSets.any { it(typeToCheck) }
|
||||
override fun invoke(typeToCheck: KotlinType): Boolean = typeSets.any { it(typeToCheck) }
|
||||
|
||||
override fun toString(): String = "OR{${typeSets.joinToString(", ")}}"
|
||||
}
|
||||
|
||||
public object AllTypes : TypePredicate {
|
||||
override fun invoke(typeToCheck: KtType): Boolean = true
|
||||
override fun invoke(typeToCheck: KotlinType): Boolean = true
|
||||
|
||||
override fun toString(): String = "*"
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public fun or(predicates: Collection<TypePredicate>): TypePredicate? =
|
||||
else -> ForSomeType(predicates.toList())
|
||||
}
|
||||
|
||||
fun KtType.getSubtypesPredicate(): TypePredicate {
|
||||
fun KotlinType.getSubtypesPredicate(): TypePredicate {
|
||||
return when {
|
||||
KotlinBuiltIns.isAnyOrNullableAny(this) && isMarkedNullable() -> AllTypes
|
||||
TypeUtils.canHaveSubtypes(KotlinTypeChecker.DEFAULT, this) -> AllSubtypes(this)
|
||||
@@ -80,7 +80,7 @@ fun KtType.getSubtypesPredicate(): TypePredicate {
|
||||
}
|
||||
|
||||
|
||||
private fun KtType.render(): String = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(this)
|
||||
private fun KotlinType.render(): String = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(this)
|
||||
|
||||
public fun <T> TypePredicate.expectedTypeFor(keys: Iterable<T>): Map<T, TypePredicate> =
|
||||
keys.fold(SmartFMap.emptyMap<T, TypePredicate>()) { map, key -> map.plus(key, this) }
|
||||
|
||||
@@ -46,7 +46,7 @@ import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import java.util.*
|
||||
|
||||
@@ -77,7 +77,7 @@ public fun getExpectedTypePredicate(
|
||||
val pseudocode = value.createdAt?.owner ?: return AllTypes
|
||||
val typePredicates = LinkedHashSet<TypePredicate?>()
|
||||
|
||||
fun addSubtypesOf(jetType: KtType?) = typePredicates.add(jetType?.getSubtypesPredicate())
|
||||
fun addSubtypesOf(jetType: KotlinType?) = typePredicates.add(jetType?.getSubtypesPredicate())
|
||||
|
||||
fun addByExplicitReceiver(resolvedCall: ResolvedCall<*>?) {
|
||||
val receiverValue = (resolvedCall ?: return).getExplicitReceiverValue()
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.DynamicCallsKt;
|
||||
import org.jetbrains.kotlin.types.ErrorUtils;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.util.slicedMap.WritableSlice;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -196,7 +196,7 @@ public class DebugInfoUtil {
|
||||
// if 'foo' in 'foo[i]' is unresolved it means 'foo[i]' is unresolved (otherwise 'foo[i]' is marked as 'missing unresolved')
|
||||
markedWithError = true;
|
||||
}
|
||||
KtType expressionType = bindingContext.getType(expression);
|
||||
KotlinType expressionType = bindingContext.getType(expression);
|
||||
DiagnosticFactory<?> factory = markedWithErrorElements.get(expression);
|
||||
if (declarationDescriptor != null &&
|
||||
(ErrorUtils.isError(declarationDescriptor) || ErrorUtils.containsErrorType(expressionType))) {
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor;
|
||||
|
||||
public class LocalVariableDescriptor extends VariableDescriptorWithInitializerImpl {
|
||||
@@ -29,7 +29,7 @@ public class LocalVariableDescriptor extends VariableDescriptorWithInitializerIm
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull Annotations annotations,
|
||||
@NotNull Name name,
|
||||
@Nullable KtType type,
|
||||
@Nullable KotlinType type,
|
||||
boolean mutable,
|
||||
@NotNull SourceElement source
|
||||
) {
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.InferenceErrorData;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.varianceChecker.VarianceChecker.VarianceConflictDiagnosticData;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
@@ -91,7 +91,7 @@ public interface Errors {
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DiagnosticFactory0<KtTypeProjection> PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT = DiagnosticFactory0.create(ERROR, VARIANCE_IN_PROJECTION);
|
||||
DiagnosticFactory2<KtTypeReference, KtType, KtType> UPPER_BOUND_VIOLATED = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory2<KtTypeReference, KotlinType, KotlinType> UPPER_BOUND_VIOLATED = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory0<KtNullableType> REDUNDANT_NULLABLE = DiagnosticFactory0.create(WARNING, NULLABLE_TYPE);
|
||||
DiagnosticFactory1<KtElement, Integer> WRONG_NUMBER_OF_TYPE_ARGUMENTS = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory2<KtTypeReference, Integer, String> NO_TYPE_ARGUMENTS_ON_RHS = DiagnosticFactory2.create(ERROR);
|
||||
@@ -148,7 +148,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<PsiElement> CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> CONST_VAL_WITH_GETTER = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> CONST_VAL_WITH_DELEGATE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, KtType> TYPE_CANT_BE_USED_FOR_CONST_VAL = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, KotlinType> TYPE_CANT_BE_USED_FOR_CONST_VAL = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> CONST_VAL_WITHOUT_INITIALIZER = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtExpression> CONST_VAL_WITH_NON_CONST_INITIALIZER = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
@@ -180,7 +180,7 @@ public interface Errors {
|
||||
|
||||
DiagnosticFactory0<KtTypeReference> MANY_CLASSES_IN_SUPERTYPE_LIST = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtTypeReference> SUPERTYPE_APPEARS_TWICE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory3<KtDelegationSpecifierList, TypeParameterDescriptor, ClassDescriptor, Collection<KtType>>
|
||||
DiagnosticFactory3<KtDelegationSpecifierList, TypeParameterDescriptor, ClassDescriptor, Collection<KotlinType>>
|
||||
INCONSISTENT_TYPE_PARAMETER_VALUES = DiagnosticFactory3.create(ERROR);
|
||||
|
||||
|
||||
@@ -251,7 +251,7 @@ public interface Errors {
|
||||
|
||||
// Type parameter declarations
|
||||
|
||||
DiagnosticFactory1<KtTypeReference, KtType> FINAL_UPPER_BOUND = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory1<KtTypeReference, KotlinType> FINAL_UPPER_BOUND = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory0<KtTypeReference> DYNAMIC_UPPER_BOUND = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory1<KtNamedDeclaration, TypeParameterDescriptor> CONFLICTING_UPPER_BOUNDS =
|
||||
@@ -320,7 +320,7 @@ public interface Errors {
|
||||
DiagnosticFactory2.create(ERROR, DECLARATION_NAME);
|
||||
|
||||
|
||||
DiagnosticFactory1<KtNamedDeclaration, Collection<KtType>> AMBIGUOUS_ANONYMOUS_TYPE_INFERRED =
|
||||
DiagnosticFactory1<KtNamedDeclaration, Collection<KotlinType>> AMBIGUOUS_ANONYMOUS_TYPE_INFERRED =
|
||||
DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE);
|
||||
|
||||
// Property-specific
|
||||
@@ -332,7 +332,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<PsiElement> GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> PRIVATE_SETTER_ON_NON_PRIVATE_LATE_INIT_VAR = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> ACCESSOR_VISIBILITY_FOR_ABSTRACT_PROPERTY = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory2<KtTypeReference, KtType, KtType> WRONG_GETTER_RETURN_TYPE = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory2<KtTypeReference, KotlinType, KotlinType> WRONG_GETTER_RETURN_TYPE = DiagnosticFactory2.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<KtModifierListOwner>
|
||||
ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS = DiagnosticFactory0.create(ERROR, ABSTRACT_MODIFIER);
|
||||
@@ -368,7 +368,7 @@ public interface Errors {
|
||||
|
||||
DiagnosticFactory0<KtExpression> SETTER_PARAMETER_WITH_DEFAULT_VALUE = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory2<KtTypeReference, KtType, KtType> WRONG_SETTER_PARAMETER_TYPE = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory2<KtTypeReference, KotlinType, KotlinType> WRONG_SETTER_PARAMETER_TYPE = DiagnosticFactory2.create(ERROR);
|
||||
|
||||
// Function-specific
|
||||
|
||||
@@ -450,7 +450,7 @@ public interface Errors {
|
||||
|
||||
DiagnosticFactory1<KtElement, ValueParameterDescriptor> NO_VALUE_FOR_PARAMETER = DiagnosticFactory1.create(ERROR, VALUE_ARGUMENTS);
|
||||
|
||||
DiagnosticFactory1<KtExpression, KtType> MISSING_RECEIVER = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, KotlinType> MISSING_RECEIVER = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory0<KtExpression> NO_RECEIVER_ALLOWED = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
// Call resolution
|
||||
@@ -459,7 +459,7 @@ public interface Errors {
|
||||
|
||||
DiagnosticFactory0<PsiElement> SAFE_CALL_IN_QUALIFIER = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory2<KtExpression, KtExpression, KtType> FUNCTION_EXPECTED = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory2<KtExpression, KtExpression, KotlinType> FUNCTION_EXPECTED = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory2<KtExpression, KtExpression, Boolean> FUNCTION_CALL_EXPECTED = DiagnosticFactory2.create(ERROR, CALL_EXPRESSION);
|
||||
|
||||
DiagnosticFactory0<PsiElement> NON_TAIL_RECURSIVE_CALL = DiagnosticFactory0.create(WARNING, CALL_EXPRESSION);
|
||||
@@ -476,7 +476,7 @@ public interface Errors {
|
||||
DiagnosticFactory1<PsiElement, KtExpression> INVOKE_EXTENSION_ON_NOT_EXTENSION_FUNCTION = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
DiagnosticFactory1<PsiElement, TypeParameterDescriptor> TYPE_PARAMETER_AS_REIFIED = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, KtType> REIFIED_TYPE_FORBIDDEN_SUBSTITUTION = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, KotlinType> REIFIED_TYPE_FORBIDDEN_SUBSTITUTION = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
// Type inference
|
||||
|
||||
@@ -489,7 +489,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<PsiElement> TYPE_INFERENCE_INCORPORATION_ERROR = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, TypeParameterDescriptor> TYPE_INFERENCE_ONLY_INPUT_TYPES = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, InferenceErrorData> TYPE_INFERENCE_UPPER_BOUND_VIOLATED = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory2<KtElement, KtType, KtType> TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory2<KtElement, KotlinType, KotlinType> TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH = DiagnosticFactory2.create(ERROR);
|
||||
|
||||
// Reflection
|
||||
|
||||
@@ -504,9 +504,9 @@ public interface Errors {
|
||||
// Multi-declarations
|
||||
|
||||
DiagnosticFactory0<KtMultiDeclaration> INITIALIZER_REQUIRED_FOR_MULTIDECLARATION = DiagnosticFactory0.create(ERROR, DEFAULT);
|
||||
DiagnosticFactory2<KtExpression, Name, KtType> COMPONENT_FUNCTION_MISSING = DiagnosticFactory2.create(ERROR, DEFAULT);
|
||||
DiagnosticFactory2<KtExpression, Name, KotlinType> COMPONENT_FUNCTION_MISSING = DiagnosticFactory2.create(ERROR, DEFAULT);
|
||||
DiagnosticFactory2<KtExpression, Name, Collection<? extends ResolvedCall<?>>> COMPONENT_FUNCTION_AMBIGUITY = DiagnosticFactory2.create(ERROR, DEFAULT);
|
||||
DiagnosticFactory3<KtExpression, Name, KtType, KtType> COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH = DiagnosticFactory3.create(ERROR, DEFAULT);
|
||||
DiagnosticFactory3<KtExpression, Name, KotlinType, KotlinType> COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH = DiagnosticFactory3.create(ERROR, DEFAULT);
|
||||
|
||||
// Super calls
|
||||
|
||||
@@ -533,30 +533,30 @@ public interface Errors {
|
||||
ASSIGN_OPERATOR_AMBIGUITY = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<KtSimpleNameExpression> EQUALS_MISSING = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory3<KtBinaryExpression, KtSimpleNameExpression, KtType, KtType> EQUALITY_NOT_APPLICABLE =
|
||||
DiagnosticFactory3<KtBinaryExpression, KtSimpleNameExpression, KotlinType, KotlinType> EQUALITY_NOT_APPLICABLE =
|
||||
DiagnosticFactory3.create(ERROR);
|
||||
|
||||
|
||||
DiagnosticFactory1<KtExpression, KtType> HAS_NEXT_MISSING = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, KtType> HAS_NEXT_FUNCTION_AMBIGUITY = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, KtType> HAS_NEXT_FUNCTION_NONE_APPLICABLE = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, KtType> HAS_NEXT_FUNCTION_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, KotlinType> HAS_NEXT_MISSING = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, KotlinType> HAS_NEXT_FUNCTION_AMBIGUITY = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, KotlinType> HAS_NEXT_FUNCTION_NONE_APPLICABLE = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, KotlinType> HAS_NEXT_FUNCTION_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
DiagnosticFactory1<KtExpression, KtType> NEXT_AMBIGUITY = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, KtType> NEXT_MISSING = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, KtType> NEXT_NONE_APPLICABLE = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, KotlinType> NEXT_AMBIGUITY = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, KotlinType> NEXT_MISSING = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, KotlinType> NEXT_NONE_APPLICABLE = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<KtExpression> ITERATOR_MISSING = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, Collection<? extends ResolvedCall<?>>> ITERATOR_AMBIGUITY = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
DiagnosticFactory2<KtExpression, String, KtType> DELEGATE_SPECIAL_FUNCTION_MISSING = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory3<PsiElement, FunctionDescriptor, KtType, String> DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION = DiagnosticFactory3.create(WARNING);
|
||||
DiagnosticFactory2<KtExpression, String, KotlinType> DELEGATE_SPECIAL_FUNCTION_MISSING = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory3<PsiElement, FunctionDescriptor, KotlinType, String> DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION = DiagnosticFactory3.create(WARNING);
|
||||
DiagnosticFactory2<KtExpression, String, Collection<? extends ResolvedCall<?>>> DELEGATE_SPECIAL_FUNCTION_AMBIGUITY = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory2<KtExpression, String, Collection<? extends ResolvedCall<?>>> DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory3<KtExpression, String, KtType, KtType> DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH = DiagnosticFactory3.create(ERROR);
|
||||
DiagnosticFactory3<KtExpression, String, KotlinType, KotlinType> DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH = DiagnosticFactory3.create(ERROR);
|
||||
DiagnosticFactory2<KtExpression, String, Collection<? extends ResolvedCall<?>>> DELEGATE_PD_METHOD_NONE_APPLICABLE = DiagnosticFactory2.create(WARNING);
|
||||
|
||||
DiagnosticFactory1<KtSimpleNameExpression, KtType> COMPARE_TO_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtSimpleNameExpression, KotlinType> COMPARE_TO_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<PsiElement> UNDERSCORE_IS_RESERVED = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, String> INVALID_CHARACTERS = DiagnosticFactory1.create(ERROR);
|
||||
@@ -614,14 +614,14 @@ public interface Errors {
|
||||
|
||||
// Nullability
|
||||
|
||||
DiagnosticFactory1<PsiElement, KtType> UNSAFE_CALL = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, KotlinType> UNSAFE_CALL = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory3<KtExpression, String, String, String> UNSAFE_INFIX_CALL = DiagnosticFactory3.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, KtType> UNNECESSARY_SAFE_CALL = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory1<PsiElement, KotlinType> UNNECESSARY_SAFE_CALL = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory0<PsiElement> UNEXPECTED_SAFE_CALL = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, KtType> UNNECESSARY_NOT_NULL_ASSERTION = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory1<PsiElement, KotlinType> UNNECESSARY_NOT_NULL_ASSERTION = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory0<PsiElement> NOT_NULL_ASSERTION_ON_FUNCTION_LITERAL = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
DiagnosticFactory1<KtBinaryExpression, KtType> USELESS_ELVIS = DiagnosticFactory1.create(WARNING, PositioningStrategies.USELESS_ELVIS);
|
||||
DiagnosticFactory1<KtBinaryExpression, KotlinType> USELESS_ELVIS = DiagnosticFactory1.create(WARNING, PositioningStrategies.USELESS_ELVIS);
|
||||
DiagnosticFactory0<PsiElement> USELESS_ELVIS_ON_FUNCTION_LITERAL = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
// Compile-time values
|
||||
@@ -631,27 +631,27 @@ public interface Errors {
|
||||
DiagnosticFactory0<KtConstantExpression> WRONG_LONG_SUFFIX = DiagnosticFactory0.create(ERROR, LONG_LITERAL_SUFFIX);
|
||||
DiagnosticFactory0<KtConstantExpression> INT_LITERAL_OUT_OF_RANGE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtConstantExpression> FLOAT_LITERAL_OUT_OF_RANGE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory2<KtConstantExpression, String, KtType> CONSTANT_EXPECTED_TYPE_MISMATCH = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory2<KtConstantExpression, String, KotlinType> CONSTANT_EXPECTED_TYPE_MISMATCH = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory0<KtConstantExpression> INCORRECT_CHARACTER_LITERAL = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtConstantExpression> EMPTY_CHARACTER_LITERAL = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<KtConstantExpression, KtConstantExpression> TOO_MANY_CHARACTERS_IN_CHARACTER_LITERAL = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtElement, KtElement> ILLEGAL_ESCAPE = DiagnosticFactory1.create(ERROR, CUT_CHAR_QUOTES);
|
||||
DiagnosticFactory1<KtConstantExpression, KtType> NULL_FOR_NONNULL_TYPE = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtConstantExpression, KotlinType> NULL_FOR_NONNULL_TYPE = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory0<KtEscapeStringTemplateEntry> ILLEGAL_ESCAPE_SEQUENCE = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
// Casts and is-checks
|
||||
|
||||
DiagnosticFactory1<KtElement, KtType> CANNOT_CHECK_FOR_ERASED = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory2<KtBinaryExpressionWithTypeRHS, KtType, KtType> UNCHECKED_CAST = DiagnosticFactory2.create(WARNING);
|
||||
DiagnosticFactory1<KtElement, KotlinType> CANNOT_CHECK_FOR_ERASED = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory2<KtBinaryExpressionWithTypeRHS, KotlinType, KotlinType> UNCHECKED_CAST = DiagnosticFactory2.create(WARNING);
|
||||
|
||||
DiagnosticFactory0<KtBinaryExpressionWithTypeRHS> USELESS_CAST = DiagnosticFactory0.create(WARNING, AS_TYPE);
|
||||
DiagnosticFactory0<KtSimpleNameExpression> CAST_NEVER_SUCCEEDS = DiagnosticFactory0.create(WARNING);
|
||||
DiagnosticFactory0<KtTypeReference> DYNAMIC_NOT_ALLOWED = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtTypeReference> IS_ENUM_ENTRY = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory1<KtExpression, KtType> IMPLICIT_CAST_TO_UNIT_OR_ANY = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory1<KtExpression, KotlinType> IMPLICIT_CAST_TO_UNIT_OR_ANY = DiagnosticFactory1.create(WARNING);
|
||||
|
||||
DiagnosticFactory2<KtExpression, KtType, String> SMARTCAST_IMPOSSIBLE = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory2<KtExpression, KotlinType, String> SMARTCAST_IMPOSSIBLE = DiagnosticFactory2.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<KtNullableType> USELESS_NULLABLE_CHECK = DiagnosticFactory0.create(WARNING, NULLABLE_TYPE);
|
||||
|
||||
@@ -684,20 +684,20 @@ public interface Errors {
|
||||
|
||||
// Type mismatch
|
||||
|
||||
DiagnosticFactory2<KtExpression, KtType, KtType> TYPE_MISMATCH = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, KtType> RETURN_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, KtType> EXPECTED_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtBinaryExpression, KtType> ASSIGNMENT_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory2<KtTypeReference, KtType, KtType> TYPE_MISMATCH_IN_FOR_LOOP = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory1<KtElement, KtType> TYPE_MISMATCH_IN_CONDITION = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory3<KtExpression, String, KtType, KtType> RESULT_TYPE_MISMATCH = DiagnosticFactory3.create(ERROR);
|
||||
DiagnosticFactory2<KtExpression, KotlinType, KotlinType> TYPE_MISMATCH = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, KotlinType> RETURN_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, KotlinType> EXPECTED_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtBinaryExpression, KotlinType> ASSIGNMENT_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory2<KtTypeReference, KotlinType, KotlinType> TYPE_MISMATCH_IN_FOR_LOOP = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory1<KtElement, KotlinType> TYPE_MISMATCH_IN_CONDITION = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory3<KtExpression, String, KotlinType, KotlinType> RESULT_TYPE_MISMATCH = DiagnosticFactory3.create(ERROR);
|
||||
DiagnosticFactory0<KtWhenConditionInRange> TYPE_MISMATCH_IN_RANGE = DiagnosticFactory0.create(ERROR, WHEN_CONDITION_IN_RANGE);
|
||||
|
||||
DiagnosticFactory1<KtParameter, KtType> EXPECTED_PARAMETER_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory2<KtFunction, Integer, List<KtType>> EXPECTED_PARAMETERS_NUMBER_MISMATCH =
|
||||
DiagnosticFactory1<KtParameter, KotlinType> EXPECTED_PARAMETER_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory2<KtFunction, Integer, List<KotlinType>> EXPECTED_PARAMETERS_NUMBER_MISMATCH =
|
||||
DiagnosticFactory2.create(ERROR, FUNCTION_PARAMETERS);
|
||||
|
||||
DiagnosticFactory2<KtElement, KtType, KtType> INCOMPATIBLE_TYPES = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory2<KtElement, KotlinType, KotlinType> INCOMPATIBLE_TYPES = DiagnosticFactory2.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<PsiElement> IMPLICIT_NOTHING_RETURN_TYPE = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.renderer.DescriptorRendererOptions;
|
||||
import org.jetbrains.kotlin.renderer.MultiRenderer;
|
||||
import org.jetbrains.kotlin.renderer.Renderer;
|
||||
import org.jetbrains.kotlin.resolve.varianceChecker.VarianceChecker.VarianceConflictDiagnosticData;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.util.MappedExtensionProvider;
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions;
|
||||
|
||||
@@ -565,10 +565,10 @@ public class DefaultErrorMessages {
|
||||
|
||||
MAP.put(FUNCTION_EXPECTED, "Expression ''{0}''{1} cannot be invoked as a function. " +
|
||||
"The function '" + OperatorNameConventions.INVOKE.asString() + "()' is not found",
|
||||
ELEMENT_TEXT, new Renderer<KtType>() {
|
||||
ELEMENT_TEXT, new Renderer<KotlinType>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull KtType type) {
|
||||
public String render(@NotNull KotlinType type) {
|
||||
if (type.isError()) return "";
|
||||
return " of type '" + RENDER_TYPE.render(type) + "'";
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.Constrain
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.RECEIVER_POSITION
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.VALUE_PARAMETER_POSITION
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
@@ -93,7 +93,7 @@ public object Renderers {
|
||||
|
||||
public val RENDER_CLASS_OR_OBJECT_NAME: Renderer<ClassDescriptor> = Renderer { it.renderKindWithName() }
|
||||
|
||||
public val RENDER_TYPE: Renderer<KtType> = Renderer { DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(it) }
|
||||
public val RENDER_TYPE: Renderer<KotlinType> = Renderer { DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(it) }
|
||||
|
||||
public val RENDER_POSITION_VARIANCE: Renderer<Variance> = Renderer {
|
||||
variance: Variance ->
|
||||
@@ -179,7 +179,7 @@ public object Renderers {
|
||||
val receiverType = DescriptorUtils.getReceiverParameterType(substitutedDescriptor.getExtensionReceiverParameter())
|
||||
|
||||
val errorPositions = Sets.newHashSet<ConstraintPosition>()
|
||||
val parameterTypes = Lists.newArrayList<KtType>()
|
||||
val parameterTypes = Lists.newArrayList<KotlinType>()
|
||||
for (valueParameterDescriptor in substitutedDescriptor.getValueParameters()) {
|
||||
parameterTypes.add(valueParameterDescriptor.getType())
|
||||
if (valueParameterDescriptor.getIndex() >= inferenceErrorData.valueArgumentsTypes.size()) continue
|
||||
@@ -279,7 +279,7 @@ public object Renderers {
|
||||
.table(newTable()
|
||||
.descriptor(inferenceErrorData.descriptor))
|
||||
|
||||
var violatedUpperBound: KtType? = null
|
||||
var violatedUpperBound: KotlinType? = null
|
||||
for (upperBound in typeParameterDescriptor.getUpperBounds()) {
|
||||
val upperBoundWithSubstitutedInferredTypes = systemWithoutWeakConstraints.getResultingSubstitutor().substitute(upperBound, Variance.INVARIANT)
|
||||
if (upperBoundWithSubstitutedInferredTypes != null
|
||||
@@ -356,9 +356,9 @@ public object Renderers {
|
||||
}.toString()
|
||||
}
|
||||
|
||||
private fun renderTypes(types: Collection<KtType>) = StringUtil.join(types, { RENDER_TYPE.render(it) }, ", ")
|
||||
private fun renderTypes(types: Collection<KotlinType>) = StringUtil.join(types, { RENDER_TYPE.render(it) }, ", ")
|
||||
|
||||
public val RENDER_COLLECTION_OF_TYPES: Renderer<Collection<KtType>> = Renderer { renderTypes(it) }
|
||||
public val RENDER_COLLECTION_OF_TYPES: Renderer<Collection<KotlinType>> = Renderer { renderTypes(it) }
|
||||
|
||||
private fun renderConstraintSystem(constraintSystem: ConstraintSystem, renderTypeBounds: Renderer<TypeBounds>): String {
|
||||
val typeVariables = constraintSystem.getTypeVariables()
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.TextR
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.renderer.Renderer;
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPosition;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -50,11 +50,11 @@ public class TabledDescriptorRenderer {
|
||||
}
|
||||
|
||||
public static class FunctionArgumentsRow implements TableRow {
|
||||
public final KtType receiverType;
|
||||
public final List<KtType> argumentTypes;
|
||||
public final KotlinType receiverType;
|
||||
public final List<KotlinType> argumentTypes;
|
||||
public final Predicate<ConstraintPosition> isErrorPosition;
|
||||
|
||||
public FunctionArgumentsRow(KtType receiverType, List<KtType> argumentTypes, Predicate<ConstraintPosition> isErrorPosition) {
|
||||
public FunctionArgumentsRow(KotlinType receiverType, List<KotlinType> argumentTypes, Predicate<ConstraintPosition> isErrorPosition) {
|
||||
this.receiverType = receiverType;
|
||||
this.argumentTypes = argumentTypes;
|
||||
this.isErrorPosition = isErrorPosition;
|
||||
@@ -68,13 +68,13 @@ public class TabledDescriptorRenderer {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TableRenderer functionArgumentTypeList(@Nullable KtType receiverType, @NotNull List<KtType> argumentTypes) {
|
||||
public TableRenderer functionArgumentTypeList(@Nullable KotlinType receiverType, @NotNull List<KotlinType> argumentTypes) {
|
||||
|
||||
return functionArgumentTypeList(receiverType, argumentTypes, Predicates.<ConstraintPosition>alwaysFalse());
|
||||
}
|
||||
|
||||
public TableRenderer functionArgumentTypeList(@Nullable KtType receiverType,
|
||||
@NotNull List<KtType> argumentTypes,
|
||||
public TableRenderer functionArgumentTypeList(@Nullable KotlinType receiverType,
|
||||
@NotNull List<KotlinType> argumentTypes,
|
||||
@NotNull Predicate<ConstraintPosition> isErrorPosition) {
|
||||
rows.add(new FunctionArgumentsRow(receiverType, argumentTypes, isErrorPosition));
|
||||
return this;
|
||||
@@ -156,7 +156,7 @@ public class TabledDescriptorRenderer {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Renderer<KtType> getTypeRenderer() {
|
||||
public Renderer<KotlinType> getTypeRenderer() {
|
||||
return Renderers.RENDER_TYPE;
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ public class TabledDescriptorRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
private void renderFunctionArguments(@Nullable KtType receiverType, @NotNull List<KtType> argumentTypes, StringBuilder result) {
|
||||
private void renderFunctionArguments(@Nullable KotlinType receiverType, @NotNull List<KotlinType> argumentTypes, StringBuilder result) {
|
||||
boolean hasReceiver = receiverType != null;
|
||||
if (hasReceiver) {
|
||||
result.append("receiver: ");
|
||||
@@ -196,8 +196,8 @@ public class TabledDescriptorRenderer {
|
||||
}
|
||||
|
||||
result.append("(");
|
||||
for (Iterator<KtType> iterator = argumentTypes.iterator(); iterator.hasNext(); ) {
|
||||
KtType argumentType = iterator.next();
|
||||
for (Iterator<KotlinType> iterator = argumentTypes.iterator(); iterator.hasNext(); ) {
|
||||
KotlinType argumentType = iterator.next();
|
||||
String renderedArgument = getTypeRenderer().render(argumentType);
|
||||
|
||||
result.append(renderedArgument);
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.psi.KtNamedFunction;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeProjection;
|
||||
import org.jetbrains.kotlin.types.Variance;
|
||||
|
||||
@@ -89,13 +89,13 @@ public class MainFunctionDetector {
|
||||
if (parameters.size() != 1) return false;
|
||||
|
||||
ValueParameterDescriptor parameter = parameters.get(0);
|
||||
KtType parameterType = parameter.getType();
|
||||
KotlinType parameterType = parameter.getType();
|
||||
if (!KotlinBuiltIns.isArray(parameterType)) return false;
|
||||
|
||||
List<TypeProjection> typeArguments = parameterType.getArguments();
|
||||
if (typeArguments.size() != 1) return false;
|
||||
|
||||
KtType typeArgument = typeArguments.get(0).getType();
|
||||
KotlinType typeArgument = typeArguments.get(0).getType();
|
||||
if (!KotlinBuiltIns.isString(typeArgument)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import com.intellij.testFramework.LightVirtualFile
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||
import java.util.*
|
||||
|
||||
@@ -131,7 +131,7 @@ public abstract class KtCodeFragment(
|
||||
|
||||
companion object {
|
||||
public val IMPORT_SEPARATOR: String = ","
|
||||
public val RUNTIME_TYPE_EVALUATOR: Key<Function1<KtExpression, KtType?>> = Key.create("RUNTIME_TYPE_EVALUATOR")
|
||||
public val RUNTIME_TYPE_EVALUATOR: Key<Function1<KtExpression, KotlinType?>> = Key.create("RUNTIME_TYPE_EVALUATOR")
|
||||
public val ADDITIONAL_CONTEXT_FOR_LAMBDA: Key<Function0<KtElement?>> = Key.create("ADDITIONAL_CONTEXT_FOR_LAMBDA")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.intellij.openapi.util.Key
|
||||
import org.jetbrains.kotlin.psi.KtCodeFragment
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
public val SUPPRESS_DIAGNOSTICS_IN_DEBUG_MODE: Key<Boolean> = Key.create<Boolean>("SUPPRESS_DIAGNOSTICS_IN_DEBUG_MODE")
|
||||
|
||||
@@ -36,10 +36,10 @@ public var KtFile.suppressDiagnosticsInDebugMode: Boolean
|
||||
|
||||
public val DEBUG_TYPE_REFERENCE_STRING: String = "DebugTypeKotlinRulezzzz"
|
||||
|
||||
public val DEBUG_TYPE_INFO: Key<KtType> = Key.create<KtType>("DEBUG_TYPE_INFO")
|
||||
public var KtTypeReference.debugTypeInfo: KtType?
|
||||
public val DEBUG_TYPE_INFO: Key<KotlinType> = Key.create<KotlinType>("DEBUG_TYPE_INFO")
|
||||
public var KtTypeReference.debugTypeInfo: KotlinType?
|
||||
get() = getUserData(DEBUG_TYPE_INFO)
|
||||
set(type: KtType?) {
|
||||
set(type: KotlinType?) {
|
||||
if (type != null && this.getText() == DEBUG_TYPE_REFERENCE_STRING) {
|
||||
putUserData(DEBUG_TYPE_INFO, type)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
class AllUnderImportsScope(descriptor: DeclarationDescriptor) : KtScope {
|
||||
@@ -51,19 +51,19 @@ class AllUnderImportsScope(descriptor: DeclarationDescriptor) : KtScope {
|
||||
return scopes.flatMap { it.getFunctions(name, location) }
|
||||
}
|
||||
|
||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KtType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
|
||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
|
||||
return scopes.flatMap { it.getSyntheticExtensionProperties(receiverTypes, name, location) }
|
||||
}
|
||||
|
||||
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KtType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
|
||||
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
|
||||
return scopes.flatMap { it.getSyntheticExtensionFunctions(receiverTypes, name, location) }
|
||||
}
|
||||
|
||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KtType>): Collection<PropertyDescriptor> {
|
||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> {
|
||||
return scopes.flatMap { it.getSyntheticExtensionProperties(receiverTypes) }
|
||||
}
|
||||
|
||||
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KtType>): Collection<FunctionDescriptor> {
|
||||
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> {
|
||||
return scopes.flatMap { it.getSyntheticExtensionFunctions(receiverTypes) }
|
||||
}
|
||||
|
||||
|
||||
@@ -18,15 +18,15 @@ package org.jetbrains.kotlin.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
public class AnalyzerScriptParameter {
|
||||
@NotNull
|
||||
private final Name name;
|
||||
@NotNull
|
||||
private final KtType type;
|
||||
private final KotlinType type;
|
||||
|
||||
public AnalyzerScriptParameter(@NotNull Name name, @NotNull KtType type) {
|
||||
public AnalyzerScriptParameter(@NotNull Name name, @NotNull KotlinType type) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class AnalyzerScriptParameter {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public KtType getType() {
|
||||
public KotlinType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getAnnotationEntries
|
||||
import org.jetbrains.kotlin.resolve.constants.ArrayValue
|
||||
import org.jetbrains.kotlin.resolve.constants.EnumValue
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isRepeatableAnnotation
|
||||
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget.*
|
||||
@@ -71,7 +71,7 @@ public class AnnotationChecker(private val additionalCheckers: Iterable<Addition
|
||||
}
|
||||
|
||||
private fun checkEntries(entries: List<KtAnnotationEntry>, actualTargets: TargetList, trace: BindingTrace) {
|
||||
val entryTypesWithAnnotations = hashMapOf<KtType, MutableList<AnnotationUseSiteTarget?>>()
|
||||
val entryTypesWithAnnotations = hashMapOf<KotlinType, MutableList<AnnotationUseSiteTarget?>>()
|
||||
|
||||
for (entry in entries) {
|
||||
checkAnnotationEntry(entry, actualTargets, trace)
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.storage.StorageManager;
|
||||
import org.jetbrains.kotlin.types.ErrorUtils;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
@@ -147,13 +147,13 @@ public class AnnotationResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public KtType resolveAnnotationType(@NotNull LexicalScope scope, @NotNull KtAnnotationEntry entryElement, @NotNull BindingTrace trace) {
|
||||
public KotlinType resolveAnnotationType(@NotNull LexicalScope scope, @NotNull KtAnnotationEntry entryElement, @NotNull BindingTrace trace) {
|
||||
KtTypeReference typeReference = entryElement.getTypeReference();
|
||||
if (typeReference == null) {
|
||||
return ErrorUtils.createErrorType("No type reference: " + entryElement.getText());
|
||||
}
|
||||
|
||||
KtType type = typeResolver.resolveType(scope, typeReference, trace, true);
|
||||
KotlinType type = typeResolver.resolveType(scope, typeReference, trace, true);
|
||||
if (!(type.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor)) {
|
||||
return ErrorUtils.createErrorType("Not an annotation: " + type);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.resolve.scopes.KtScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.Qualifier;
|
||||
import org.jetbrains.kotlin.types.DeferredType;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.expressions.CaptureKind;
|
||||
import org.jetbrains.kotlin.types.expressions.JetTypeInfo;
|
||||
import org.jetbrains.kotlin.types.expressions.PreliminaryDeclarationVisitor;
|
||||
@@ -77,7 +77,7 @@ public interface BindingContext {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public KtType getType(@NotNull KtExpression expression) {
|
||||
public KotlinType getType(@NotNull KtExpression expression) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -91,10 +91,10 @@ public interface BindingContext {
|
||||
|
||||
WritableSlice<KtExpression, CompileTimeConstant<?>> COMPILE_TIME_VALUE = Slices.createSimpleSlice();
|
||||
|
||||
WritableSlice<KtTypeReference, KtType> TYPE = Slices.createSimpleSlice();
|
||||
WritableSlice<KtTypeReference, KotlinType> TYPE = Slices.createSimpleSlice();
|
||||
WritableSlice<KtExpression, JetTypeInfo> EXPRESSION_TYPE_INFO = new BasicWritableSlice<KtExpression, JetTypeInfo>(DO_NOTHING);
|
||||
WritableSlice<KtExpression, KtType> EXPECTED_EXPRESSION_TYPE = new BasicWritableSlice<KtExpression, KtType>(DO_NOTHING);
|
||||
WritableSlice<KtFunction, KtType> EXPECTED_RETURN_TYPE = new BasicWritableSlice<KtFunction, KtType>(DO_NOTHING);
|
||||
WritableSlice<KtExpression, KotlinType> EXPECTED_EXPRESSION_TYPE = new BasicWritableSlice<KtExpression, KotlinType>(DO_NOTHING);
|
||||
WritableSlice<KtFunction, KotlinType> EXPECTED_RETURN_TYPE = new BasicWritableSlice<KtFunction, KotlinType>(DO_NOTHING);
|
||||
WritableSlice<KtExpression, DataFlowInfo> DATAFLOW_INFO_AFTER_CONDITION = Slices.createSimpleSlice();
|
||||
|
||||
/**
|
||||
@@ -131,7 +131,7 @@ public interface BindingContext {
|
||||
WritableSlice<KtExpression, ResolvedCall<FunctionDescriptor>> INDEXED_LVALUE_GET = Slices.createSimpleSlice();
|
||||
WritableSlice<KtExpression, ResolvedCall<FunctionDescriptor>> INDEXED_LVALUE_SET = Slices.createSimpleSlice();
|
||||
|
||||
WritableSlice<KtExpression, KtType> SMARTCAST = Slices.createSimpleSlice();
|
||||
WritableSlice<KtExpression, KotlinType> SMARTCAST = Slices.createSimpleSlice();
|
||||
|
||||
WritableSlice<KtWhenExpression, Boolean> EXHAUSTIVE_WHEN = Slices.createSimpleSlice();
|
||||
|
||||
@@ -256,7 +256,7 @@ public interface BindingContext {
|
||||
<K, V> ImmutableMap<K, V> getSliceContents(@NotNull ReadOnlySlice<K, V> slice);
|
||||
|
||||
@Nullable
|
||||
KtType getType(@NotNull KtExpression expression);
|
||||
KotlinType getType(@NotNull KtExpression expression);
|
||||
|
||||
void addOwnDataTo(@NotNull BindingTrace trace, boolean commitDiagnostics);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.MutableDiagnosticsWithSuppression;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
import org.jetbrains.kotlin.types.expressions.JetTypeInfo;
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
|
||||
@@ -81,11 +81,11 @@ public class BindingContextUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static KtType getTypeNotNull(
|
||||
public static KotlinType getTypeNotNull(
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull KtExpression expression
|
||||
) {
|
||||
KtType result = bindingContext.getType(expression);
|
||||
KotlinType result = bindingContext.getType(expression);
|
||||
if (result == null) {
|
||||
throw new IllegalStateException("Type must be not null for " + expression);
|
||||
}
|
||||
@@ -140,8 +140,8 @@ public class BindingContextUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static KtType updateRecordedType(
|
||||
@Nullable KtType type,
|
||||
public static KotlinType updateRecordedType(
|
||||
@Nullable KotlinType type,
|
||||
@NotNull KtExpression expression,
|
||||
@NotNull BindingTrace trace,
|
||||
boolean shouldBeMadeNullable
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.util.slicedMap.ReadOnlySlice;
|
||||
import org.jetbrains.kotlin.util.slicedMap.WritableSlice;
|
||||
|
||||
@@ -47,11 +47,11 @@ public interface BindingTrace extends DiagnosticSink {
|
||||
* Expression type should be taken from EXPRESSION_TYPE_INFO slice
|
||||
*/
|
||||
@Nullable
|
||||
KtType getType(@NotNull KtExpression expression);
|
||||
KotlinType getType(@NotNull KtExpression expression);
|
||||
|
||||
/**
|
||||
* Expression type should be recorded into EXPRESSION_TYPE_INFO slice
|
||||
* (either updated old or a new one)
|
||||
*/
|
||||
void recordType(@NotNull KtExpression expression, @Nullable KtType type);
|
||||
void recordType(@NotNull KtExpression expression, @Nullable KotlinType type);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics;
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.MutableDiagnosticsWithSuppression;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.expressions.JetTypeInfo;
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
|
||||
import org.jetbrains.kotlin.util.slicedMap.*;
|
||||
@@ -67,7 +67,7 @@ public class BindingTraceContext implements BindingTrace {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public KtType getType(@NotNull KtExpression expression) {
|
||||
public KotlinType getType(@NotNull KtExpression expression) {
|
||||
return BindingTraceContext.this.getType(expression);
|
||||
}
|
||||
|
||||
@@ -131,13 +131,13 @@ public class BindingTraceContext implements BindingTrace {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public KtType getType(@NotNull KtExpression expression) {
|
||||
public KotlinType getType(@NotNull KtExpression expression) {
|
||||
JetTypeInfo typeInfo = get(BindingContext.EXPRESSION_TYPE_INFO, expression);
|
||||
return typeInfo != null ? typeInfo.getType() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordType(@NotNull KtExpression expression, @Nullable KtType type) {
|
||||
public void recordType(@NotNull KtExpression expression, @Nullable KotlinType type) {
|
||||
JetTypeInfo typeInfo = get(BindingContext.EXPRESSION_TYPE_INFO, expression);
|
||||
typeInfo = typeInfo != null ? typeInfo.replaceType(type) : TypeInfoFactoryKt.createTypeInfo(type);
|
||||
record(BindingContext.EXPRESSION_TYPE_INFO, expression, typeInfo);
|
||||
|
||||
@@ -262,10 +262,10 @@ public class BodyResolver {
|
||||
: FunctionDescriptorUtil.getFunctionInnerScope(scopeForSupertypeResolution, primaryConstructor, trace);
|
||||
final ExpressionTypingServices typeInferrer = expressionTypingServices; // TODO : flow
|
||||
|
||||
final Map<KtTypeReference, KtType> supertypes = Maps.newLinkedHashMap();
|
||||
final Map<KtTypeReference, KotlinType> supertypes = Maps.newLinkedHashMap();
|
||||
final ResolvedCall<?>[] primaryConstructorDelegationCall = new ResolvedCall[1];
|
||||
KtVisitorVoid visitor = new KtVisitorVoid() {
|
||||
private void recordSupertype(KtTypeReference typeReference, KtType supertype) {
|
||||
private void recordSupertype(KtTypeReference typeReference, KotlinType supertype) {
|
||||
if (supertype == null) return;
|
||||
supertypes.put(typeReference, supertype);
|
||||
}
|
||||
@@ -275,7 +275,7 @@ public class BodyResolver {
|
||||
if (descriptor.getKind() == ClassKind.INTERFACE) {
|
||||
trace.report(DELEGATION_IN_INTERFACE.on(specifier));
|
||||
}
|
||||
KtType supertype = trace.getBindingContext().get(BindingContext.TYPE, specifier.getTypeReference());
|
||||
KotlinType supertype = trace.getBindingContext().get(BindingContext.TYPE, specifier.getTypeReference());
|
||||
recordSupertype(specifier.getTypeReference(), supertype);
|
||||
if (supertype != null) {
|
||||
DeclarationDescriptor declarationDescriptor = supertype.getConstructor().getDeclarationDescriptor();
|
||||
@@ -289,7 +289,7 @@ public class BodyResolver {
|
||||
KtExpression delegateExpression = specifier.getDelegateExpression();
|
||||
if (delegateExpression != null) {
|
||||
LexicalScope scope = scopeForConstructor == null ? scopeForMemberResolution : scopeForConstructor;
|
||||
KtType expectedType = supertype != null ? supertype : NO_EXPECTED_TYPE;
|
||||
KotlinType expectedType = supertype != null ? supertype : NO_EXPECTED_TYPE;
|
||||
typeInferrer.getType(scope, delegateExpression, expectedType, outerDataFlowInfo, trace);
|
||||
}
|
||||
if (primaryConstructor == null) {
|
||||
@@ -317,7 +317,7 @@ public class BodyResolver {
|
||||
trace, scopeForConstructor,
|
||||
CallMaker.makeCall(ReceiverValue.NO_RECEIVER, null, call), NO_EXPECTED_TYPE, outerDataFlowInfo, false);
|
||||
if (results.isSuccess()) {
|
||||
KtType supertype = results.getResultingDescriptor().getReturnType();
|
||||
KotlinType supertype = results.getResultingDescriptor().getReturnType();
|
||||
recordSupertype(typeReference, supertype);
|
||||
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(supertype);
|
||||
if (classDescriptor != null) {
|
||||
@@ -342,7 +342,7 @@ public class BodyResolver {
|
||||
@Override
|
||||
public void visitDelegationToSuperClassSpecifier(@NotNull KtDelegatorToSuperClass specifier) {
|
||||
KtTypeReference typeReference = specifier.getTypeReference();
|
||||
KtType supertype = trace.getBindingContext().get(BindingContext.TYPE, typeReference);
|
||||
KotlinType supertype = trace.getBindingContext().get(BindingContext.TYPE, typeReference);
|
||||
recordSupertype(typeReference, supertype);
|
||||
if (supertype == null) return;
|
||||
ClassDescriptor superClass = TypeUtils.getClassDescriptor(supertype);
|
||||
@@ -419,15 +419,15 @@ public class BodyResolver {
|
||||
|
||||
private void checkSupertypeList(
|
||||
@NotNull ClassDescriptor supertypeOwner,
|
||||
@NotNull Map<KtTypeReference, KtType> supertypes,
|
||||
@NotNull Map<KtTypeReference, KotlinType> supertypes,
|
||||
@NotNull KtClassOrObject jetClass
|
||||
) {
|
||||
Set<TypeConstructor> allowedFinalSupertypes = getAllowedFinalSupertypes(supertypeOwner, jetClass);
|
||||
Set<TypeConstructor> typeConstructors = Sets.newHashSet();
|
||||
boolean classAppeared = false;
|
||||
for (Map.Entry<KtTypeReference, KtType> entry : supertypes.entrySet()) {
|
||||
for (Map.Entry<KtTypeReference, KotlinType> entry : supertypes.entrySet()) {
|
||||
KtTypeReference typeReference = entry.getKey();
|
||||
KtType supertype = entry.getValue();
|
||||
KotlinType supertype = entry.getValue();
|
||||
|
||||
KtTypeElement typeElement = typeReference.getTypeElement();
|
||||
if (typeElement instanceof KtFunctionType) {
|
||||
@@ -709,7 +709,7 @@ public class BodyResolver {
|
||||
LexicalScope accessorScope = JetScopeUtils.makeScopeForPropertyAccessor(
|
||||
propertyDescriptor, parentScopeForAccessor, trace);
|
||||
|
||||
KtType delegateType = delegatedPropertyResolver.resolveDelegateExpression(
|
||||
KotlinType delegateType = delegatedPropertyResolver.resolveDelegateExpression(
|
||||
delegateExpression, jetProperty, propertyDescriptor, propertyDeclarationInnerScope, accessorScope, trace,
|
||||
outerDataFlowInfo);
|
||||
|
||||
@@ -734,7 +734,7 @@ public class BodyResolver {
|
||||
) {
|
||||
LexicalScope propertyDeclarationInnerScope = JetScopeUtils.getPropertyDeclarationInnerScopeForInitializer(
|
||||
propertyDescriptor, scope, propertyDescriptor.getTypeParameters(), null, trace);
|
||||
KtType expectedTypeForInitializer = property.getTypeReference() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE;
|
||||
KotlinType expectedTypeForInitializer = property.getTypeReference() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE;
|
||||
if (propertyDescriptor.getCompileTimeInitializer() == null) {
|
||||
expressionTypingServices.getType(propertyDeclarationInnerScope, initializer, expectedTypeForInitializer,
|
||||
outerDataFlowInfo, trace);
|
||||
@@ -850,7 +850,7 @@ public class BodyResolver {
|
||||
valueParameterResolver.resolveValueParameters(valueParameters, valueParameterDescriptors, scope, outerDataFlowInfo, trace);
|
||||
}
|
||||
|
||||
private static void computeDeferredType(KtType type) {
|
||||
private static void computeDeferredType(KotlinType type) {
|
||||
// handle type inference loop: function or property body contains a reference to itself
|
||||
// fun f() = { f() }
|
||||
// val x = x
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
||||
import org.jetbrains.kotlin.resolve.constants.TypedCompileTimeConstant;
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeProjection;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
|
||||
@@ -60,7 +60,7 @@ public class CompileTimeConstantUtils {
|
||||
for (KtParameter parameter : parameters) {
|
||||
VariableDescriptor parameterDescriptor = trace.getBindingContext().get(VALUE_PARAMETER, parameter);
|
||||
if (parameterDescriptor == null) continue;
|
||||
KtType parameterType = parameterDescriptor.getType();
|
||||
KotlinType parameterType = parameterDescriptor.getType();
|
||||
KtTypeReference typeReference = parameter.getTypeReference();
|
||||
if (typeReference != null) {
|
||||
if (parameterType.isMarkedNullable()) {
|
||||
@@ -73,7 +73,7 @@ public class CompileTimeConstantUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isAcceptableTypeForAnnotationParameter(@NotNull KtType parameterType) {
|
||||
private static boolean isAcceptableTypeForAnnotationParameter(@NotNull KotlinType parameterType) {
|
||||
ClassDescriptor typeDescriptor = TypeUtils.getClassDescriptor(parameterType);
|
||||
if (typeDescriptor == null) {
|
||||
return false;
|
||||
@@ -91,7 +91,7 @@ public class CompileTimeConstantUtils {
|
||||
if (KotlinBuiltIns.isArray(parameterType)) {
|
||||
List<TypeProjection> arguments = parameterType.getArguments();
|
||||
if (arguments.size() == 1) {
|
||||
KtType arrayType = arguments.get(0).getType();
|
||||
KotlinType arrayType = arguments.get(0).getType();
|
||||
if (arrayType.isMarkedNullable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -24,12 +24,12 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.openapi.util.ModificationTracker
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
public class CompositeBindingContext private constructor(
|
||||
private val delegates: List<BindingContext>
|
||||
) : BindingContext {
|
||||
override fun getType(expression: KtExpression): KtType? {
|
||||
override fun getType(expression: KtExpression): KotlinType? {
|
||||
return delegates.asSequence().map { it.getType(expression) }.firstOrNull { it != null }
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ControlFlowAnalyzer {
|
||||
for (Map.Entry<KtNamedFunction, SimpleFunctionDescriptor> entry : c.getFunctions().entrySet()) {
|
||||
KtNamedFunction function = entry.getKey();
|
||||
SimpleFunctionDescriptor functionDescriptor = entry.getValue();
|
||||
KtType expectedReturnType = !function.hasBlockBody() && !function.hasDeclaredReturnType()
|
||||
KotlinType expectedReturnType = !function.hasBlockBody() && !function.hasDeclaredReturnType()
|
||||
? NO_EXPECTED_TYPE
|
||||
: functionDescriptor.getReturnType();
|
||||
checkFunction(c, function, expectedReturnType);
|
||||
@@ -87,12 +87,12 @@ public class ControlFlowAnalyzer {
|
||||
? propertyDescriptor.getGetter()
|
||||
: propertyDescriptor.getSetter();
|
||||
assert accessorDescriptor != null : "no property accessor descriptor " + accessor.getText();
|
||||
KtType returnType = accessorDescriptor.getReturnType();
|
||||
KotlinType returnType = accessorDescriptor.getReturnType();
|
||||
checkFunction(c, accessor, returnType);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkFunction(@NotNull BodiesResolveContext c, @NotNull KtDeclarationWithBody function, @Nullable KtType expectedReturnType) {
|
||||
private void checkFunction(@NotNull BodiesResolveContext c, @NotNull KtDeclarationWithBody function, @Nullable KotlinType expectedReturnType) {
|
||||
if (!function.hasBody()) return;
|
||||
JetFlowInformationProvider flowInformationProvider = new JetFlowInformationProvider(function, trace);
|
||||
if (c.getTopDownAnalysisMode().isLocalDeclarations()) {
|
||||
|
||||
@@ -168,7 +168,7 @@ public class DeclarationsChecker {
|
||||
|
||||
private void checkBoundsForTypeInClassHeader(@Nullable KtTypeReference typeReference) {
|
||||
if (typeReference != null) {
|
||||
KtType type = trace.getBindingContext().get(TYPE, typeReference);
|
||||
KotlinType type = trace.getBindingContext().get(TYPE, typeReference);
|
||||
if (type != null) {
|
||||
DescriptorResolver.checkBounds(typeReference, type, trace);
|
||||
}
|
||||
@@ -177,7 +177,7 @@ public class DeclarationsChecker {
|
||||
|
||||
private void checkFinalUpperBounds(@Nullable KtTypeReference typeReference) {
|
||||
if (typeReference != null) {
|
||||
KtType type = trace.getBindingContext().get(TYPE, typeReference);
|
||||
KotlinType type = trace.getBindingContext().get(TYPE, typeReference);
|
||||
if (type != null) {
|
||||
DescriptorResolver.checkUpperBoundType(typeReference, type, trace);
|
||||
}
|
||||
@@ -196,7 +196,7 @@ public class DeclarationsChecker {
|
||||
TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) declarationDescriptor;
|
||||
|
||||
// Immediate arguments of supertypes cannot be projected
|
||||
Set<KtType> conflictingTypes = Sets.newLinkedHashSet();
|
||||
Set<KotlinType> conflictingTypes = Sets.newLinkedHashSet();
|
||||
for (TypeProjection projection : projections) {
|
||||
conflictingTypes.add(projection.getType());
|
||||
}
|
||||
@@ -232,7 +232,7 @@ public class DeclarationsChecker {
|
||||
int i = 0;
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : classDescriptor.getTypeConstructor().getParameters()) {
|
||||
if (i >= typeParameterList.size()) return;
|
||||
for (KtType upperBound : typeParameterDescriptor.getUpperBounds()) {
|
||||
for (KotlinType upperBound : typeParameterDescriptor.getUpperBounds()) {
|
||||
EffectiveVisibility upperBoundVisibility = EffectiveVisibility.Companion.forType(upperBound);
|
||||
if (!upperBoundVisibility.sameOrMorePermissive(classVisibility)) {
|
||||
KtTypeParameter typeParameter = typeParameterList.get(i);
|
||||
@@ -249,7 +249,7 @@ public class DeclarationsChecker {
|
||||
boolean isInterface = classDescriptor.getKind() == ClassKind.INTERFACE;
|
||||
List<KtDelegationSpecifier> delegationList = klass.getDelegationSpecifiers();
|
||||
int i = -1;
|
||||
for (KtType superType : classDescriptor.getTypeConstructor().getSupertypes()) {
|
||||
for (KotlinType superType : classDescriptor.getTypeConstructor().getSupertypes()) {
|
||||
i++;
|
||||
if (i >= delegationList.size()) return;
|
||||
ClassDescriptor superDescriptor = TypeUtils.getClassDescriptor(superType);
|
||||
@@ -272,10 +272,10 @@ public class DeclarationsChecker {
|
||||
}
|
||||
}
|
||||
|
||||
private static void removeDuplicateTypes(Set<KtType> conflictingTypes) {
|
||||
for (Iterator<KtType> iterator = conflictingTypes.iterator(); iterator.hasNext(); ) {
|
||||
KtType type = iterator.next();
|
||||
for (KtType otherType : conflictingTypes) {
|
||||
private static void removeDuplicateTypes(Set<KotlinType> conflictingTypes) {
|
||||
for (Iterator<KotlinType> iterator = conflictingTypes.iterator(); iterator.hasNext(); ) {
|
||||
KotlinType type = iterator.next();
|
||||
for (KotlinType otherType : conflictingTypes) {
|
||||
boolean subtypeOf = KotlinTypeChecker.DEFAULT.equalTypes(type, otherType);
|
||||
if (type != otherType && subtypeOf) {
|
||||
iterator.remove();
|
||||
@@ -498,9 +498,9 @@ public class DeclarationsChecker {
|
||||
ReceiverParameterDescriptor receiverParameter = descriptor.getExtensionReceiverParameter();
|
||||
if (receiverParameter == null) return false;
|
||||
|
||||
return TypeUtils.containsSpecialType(receiverParameter.getType(), new Function1<KtType, Boolean>() {
|
||||
return TypeUtils.containsSpecialType(receiverParameter.getType(), new Function1<KotlinType, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(KtType type) {
|
||||
public Boolean invoke(KotlinType type) {
|
||||
return parameter.equals(type.getConstructor().getDeclarationDescriptor());
|
||||
}
|
||||
});
|
||||
@@ -519,7 +519,7 @@ public class DeclarationsChecker {
|
||||
boolean returnTypeIsNullable = true;
|
||||
boolean returnTypeIsPrimitive = true;
|
||||
|
||||
KtType returnType = propertyDescriptor.getReturnType();
|
||||
KotlinType returnType = propertyDescriptor.getReturnType();
|
||||
if (returnType != null) {
|
||||
returnTypeIsNullable = TypeUtils.isNullableType(returnType);
|
||||
returnTypeIsPrimitive = KotlinBuiltIns.isPrimitiveType(returnType);
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
|
||||
import org.jetbrains.kotlin.resolve.validation.OperatorValidator;
|
||||
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator;
|
||||
import org.jetbrains.kotlin.types.DeferredType;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext;
|
||||
@@ -83,10 +83,10 @@ public class DelegatedPropertyResolver {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public KtType getDelegatedPropertyGetMethodReturnType(
|
||||
public KotlinType getDelegatedPropertyGetMethodReturnType(
|
||||
@NotNull PropertyDescriptor propertyDescriptor,
|
||||
@NotNull KtExpression delegateExpression,
|
||||
@NotNull KtType delegateType,
|
||||
@NotNull KotlinType delegateType,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull LexicalScope scope
|
||||
) {
|
||||
@@ -99,13 +99,13 @@ public class DelegatedPropertyResolver {
|
||||
public void resolveDelegatedPropertyGetMethod(
|
||||
@NotNull PropertyDescriptor propertyDescriptor,
|
||||
@NotNull KtExpression delegateExpression,
|
||||
@NotNull KtType delegateType,
|
||||
@NotNull KotlinType delegateType,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull LexicalScope scope
|
||||
) {
|
||||
KtType returnType = getDelegatedPropertyGetMethodReturnType(
|
||||
KotlinType returnType = getDelegatedPropertyGetMethodReturnType(
|
||||
propertyDescriptor, delegateExpression, delegateType, trace, scope);
|
||||
KtType propertyType = propertyDescriptor.getType();
|
||||
KotlinType propertyType = propertyDescriptor.getType();
|
||||
|
||||
/* Do not check return type of get() method of delegate for properties with DeferredType because property type is taken from it */
|
||||
if (!(propertyType instanceof DeferredType) && returnType != null && !KotlinTypeChecker.DEFAULT.isSubtypeOf(returnType, propertyType)) {
|
||||
@@ -119,7 +119,7 @@ public class DelegatedPropertyResolver {
|
||||
public void resolveDelegatedPropertySetMethod(
|
||||
@NotNull PropertyDescriptor propertyDescriptor,
|
||||
@NotNull KtExpression delegateExpression,
|
||||
@NotNull KtType delegateType,
|
||||
@NotNull KotlinType delegateType,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull LexicalScope scope
|
||||
) {
|
||||
@@ -134,7 +134,7 @@ public class DelegatedPropertyResolver {
|
||||
public void resolveDelegatedPropertyPDMethod(
|
||||
@NotNull PropertyDescriptor propertyDescriptor,
|
||||
@NotNull KtExpression delegateExpression,
|
||||
@NotNull KtType delegateType,
|
||||
@NotNull KotlinType delegateType,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull LexicalScope scope
|
||||
) {
|
||||
@@ -172,7 +172,7 @@ public class DelegatedPropertyResolver {
|
||||
private void resolveDelegatedPropertyConventionMethod(
|
||||
@NotNull PropertyDescriptor propertyDescriptor,
|
||||
@NotNull KtExpression delegateExpression,
|
||||
@NotNull KtType delegateType,
|
||||
@NotNull KotlinType delegateType,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull LexicalScope scope,
|
||||
boolean isGet
|
||||
@@ -231,7 +231,7 @@ public class DelegatedPropertyResolver {
|
||||
public OverloadResolutionResults<FunctionDescriptor> getDelegatedPropertyConventionMethod(
|
||||
@NotNull PropertyDescriptor propertyDescriptor,
|
||||
@NotNull KtExpression delegateExpression,
|
||||
@NotNull KtType delegateType,
|
||||
@NotNull KotlinType delegateType,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull LexicalScope scope,
|
||||
boolean isGet,
|
||||
@@ -240,7 +240,7 @@ public class DelegatedPropertyResolver {
|
||||
PropertyAccessorDescriptor accessor = isGet ? propertyDescriptor.getGetter() : propertyDescriptor.getSetter();
|
||||
assert accessor != null : "Delegated property should have getter/setter " + propertyDescriptor + " " + delegateExpression.getText();
|
||||
|
||||
KtType expectedType = isComplete && isGet && !(propertyDescriptor.getType() instanceof DeferredType)
|
||||
KotlinType expectedType = isComplete && isGet && !(propertyDescriptor.getType() instanceof DeferredType)
|
||||
? propertyDescriptor.getType() : TypeUtils.NO_EXPECTED_TYPE;
|
||||
|
||||
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
||||
@@ -305,7 +305,7 @@ public class DelegatedPropertyResolver {
|
||||
assert calleeExpression != null : "CalleeExpression should exists for fake call of convention method";
|
||||
StringBuilder builder = new StringBuilder(calleeExpression.getText());
|
||||
builder.append("(");
|
||||
List<KtType> argumentTypes = Lists.newArrayList();
|
||||
List<KotlinType> argumentTypes = Lists.newArrayList();
|
||||
for (ValueArgument argument : call.getValueArguments()) {
|
||||
argumentTypes.add(context.getType(argument.getArgumentExpression()));
|
||||
|
||||
@@ -316,7 +316,7 @@ public class DelegatedPropertyResolver {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public KtType resolveDelegateExpression(
|
||||
public KotlinType resolveDelegateExpression(
|
||||
@NotNull KtExpression delegateExpression,
|
||||
@NotNull KtProperty jetProperty,
|
||||
@NotNull PropertyDescriptor propertyDescriptor,
|
||||
@@ -332,8 +332,8 @@ public class DelegatedPropertyResolver {
|
||||
if (calleeExpression != null) {
|
||||
traceToResolveDelegatedProperty.record(CONSTRAINT_SYSTEM_COMPLETER, calleeExpression, completer);
|
||||
}
|
||||
KtType delegateType = expressionTypingServices.safeGetType(propertyDeclarationInnerScope, delegateExpression, NO_EXPECTED_TYPE,
|
||||
dataFlowInfo, traceToResolveDelegatedProperty);
|
||||
KotlinType delegateType = expressionTypingServices.safeGetType(propertyDeclarationInnerScope, delegateExpression, NO_EXPECTED_TYPE,
|
||||
dataFlowInfo, traceToResolveDelegatedProperty);
|
||||
traceToResolveDelegatedProperty.commit(new TraceEntryFilter() {
|
||||
@Override
|
||||
public boolean accept(@Nullable WritableSlice<?, ?> slice, Object key) {
|
||||
@@ -351,13 +351,13 @@ public class DelegatedPropertyResolver {
|
||||
@NotNull final LexicalScope accessorScope,
|
||||
@NotNull final BindingTrace trace
|
||||
) {
|
||||
final KtType expectedType = property.getTypeReference() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE;
|
||||
final KotlinType expectedType = property.getTypeReference() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE;
|
||||
return new ConstraintSystemCompleter() {
|
||||
@Override
|
||||
public void completeConstraintSystem(
|
||||
@NotNull ConstraintSystem constraintSystem, @NotNull ResolvedCall<?> resolvedCall
|
||||
) {
|
||||
KtType returnType = resolvedCall.getCandidateDescriptor().getReturnType();
|
||||
KotlinType returnType = resolvedCall.getCandidateDescriptor().getReturnType();
|
||||
if (returnType == null) return;
|
||||
|
||||
TemporaryBindingTrace traceToResolveConventionMethods =
|
||||
@@ -370,7 +370,7 @@ public class DelegatedPropertyResolver {
|
||||
|
||||
if (conventionMethodFound(getMethodResults)) {
|
||||
FunctionDescriptor descriptor = getMethodResults.getResultingDescriptor();
|
||||
KtType returnTypeOfGetMethod = descriptor.getReturnType();
|
||||
KotlinType returnTypeOfGetMethod = descriptor.getReturnType();
|
||||
if (returnTypeOfGetMethod != null) {
|
||||
constraintSystem.addSupertypeConstraint(expectedType, returnTypeOfGetMethod, FROM_COMPLETER.position());
|
||||
}
|
||||
@@ -413,7 +413,7 @@ public class DelegatedPropertyResolver {
|
||||
private void addConstraintForThisValue(ConstraintSystem constraintSystem, FunctionDescriptor resultingDescriptor) {
|
||||
ReceiverParameterDescriptor extensionReceiver = propertyDescriptor.getExtensionReceiverParameter();
|
||||
ReceiverParameterDescriptor dispatchReceiver = propertyDescriptor.getDispatchReceiverParameter();
|
||||
KtType typeOfThis =
|
||||
KotlinType typeOfThis =
|
||||
extensionReceiver != null ? extensionReceiver.getType() :
|
||||
dispatchReceiver != null ? dispatchReceiver.getType() :
|
||||
builtIns.getNullableNothingType();
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics;
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.MutableDiagnosticsWithSuppression;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.expressions.JetTypeInfo;
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
|
||||
import org.jetbrains.kotlin.util.slicedMap.*;
|
||||
@@ -58,7 +58,7 @@ public class DelegatingBindingTrace implements BindingTrace {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public KtType getType(@NotNull KtExpression expression) {
|
||||
public KotlinType getType(@NotNull KtExpression expression) {
|
||||
return DelegatingBindingTrace.this.getType(expression);
|
||||
}
|
||||
|
||||
@@ -139,13 +139,13 @@ public class DelegatingBindingTrace implements BindingTrace {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public KtType getType(@NotNull KtExpression expression) {
|
||||
public KotlinType getType(@NotNull KtExpression expression) {
|
||||
JetTypeInfo typeInfo = get(BindingContext.EXPRESSION_TYPE_INFO, expression);
|
||||
return typeInfo != null ? typeInfo.getType() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordType(@NotNull KtExpression expression, @Nullable KtType type) {
|
||||
public void recordType(@NotNull KtExpression expression, @Nullable KotlinType type) {
|
||||
JetTypeInfo typeInfo = get(BindingContext.EXPRESSION_TYPE_INFO, expression);
|
||||
if (typeInfo == null) {
|
||||
typeInfo = TypeInfoFactoryKt.createTypeInfo(type);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user