use of org.jetbrains.annotations.NotNull in project kotlin by JetBrains.
the class ErrorUtils method createErrorFunction.
@NotNull
private static SimpleFunctionDescriptor createErrorFunction(@NotNull ErrorScope ownerScope) {
ErrorSimpleFunctionDescriptorImpl function = new ErrorSimpleFunctionDescriptorImpl(ERROR_CLASS, ownerScope);
function.initialize(null, null, // TODO
Collections.<TypeParameterDescriptorImpl>emptyList(), // TODO
Collections.<ValueParameterDescriptor>emptyList(), createErrorType("<ERROR FUNCTION RETURN TYPE>"), Modality.OPEN, Visibilities.PUBLIC);
return function;
}
use of org.jetbrains.annotations.NotNull in project kotlin by JetBrains.
the class ErrorUtils method createErrorProperty.
@NotNull
private static PropertyDescriptorImpl createErrorProperty() {
PropertyDescriptorImpl descriptor = PropertyDescriptorImpl.create(ERROR_CLASS, Annotations.Companion.getEMPTY(), Modality.OPEN, Visibilities.PUBLIC, true, Name.special("<ERROR PROPERTY>"), CallableMemberDescriptor.Kind.DECLARATION, SourceElement.NO_SOURCE, false, false, false, false, false, false);
descriptor.setType(ERROR_PROPERTY_TYPE, Collections.<TypeParameterDescriptor>emptyList(), null, (KotlinType) null);
return descriptor;
}
use of org.jetbrains.annotations.NotNull in project kotlin by JetBrains.
the class TypeSubstitutor method unsafeSubstitute.
@NotNull
private TypeProjection unsafeSubstitute(@NotNull TypeProjection originalProjection, int recursionDepth) throws SubstitutionException {
assertRecursionDepth(recursionDepth, originalProjection, substitution);
if (originalProjection.isStarProjection())
return originalProjection;
// The type is within the substitution range, i.e. T or T?
KotlinType type = originalProjection.getType();
if (DynamicTypesKt.isDynamic(type) || type.unwrap() instanceof RawType) {
// todo investigate
return originalProjection;
}
TypeProjection replacement = substitution.get(type);
Variance originalProjectionKind = originalProjection.getProjectionKind();
if (replacement == null && FlexibleTypesKt.isFlexible(type) && !TypeCapabilitiesKt.isCustomTypeVariable(type)) {
FlexibleType flexibleType = FlexibleTypesKt.asFlexibleType(type);
TypeProjection substitutedLower = unsafeSubstitute(new TypeProjectionImpl(originalProjectionKind, flexibleType.getLowerBound()), recursionDepth + 1);
TypeProjection substitutedUpper = unsafeSubstitute(new TypeProjectionImpl(originalProjectionKind, flexibleType.getUpperBound()), recursionDepth + 1);
Variance substitutedProjectionKind = substitutedLower.getProjectionKind();
assert (substitutedProjectionKind == substitutedUpper.getProjectionKind()) && originalProjectionKind == Variance.INVARIANT || originalProjectionKind == substitutedProjectionKind : "Unexpected substituted projection kind: " + substitutedProjectionKind + "; original: " + originalProjectionKind;
KotlinType substitutedFlexibleType = KotlinTypeFactory.flexibleType(TypeSubstitutionKt.asSimpleType(substitutedLower.getType()), TypeSubstitutionKt.asSimpleType(substitutedUpper.getType()));
return new TypeProjectionImpl(substitutedProjectionKind, substitutedFlexibleType);
}
if (KotlinBuiltIns.isNothing(type) || type.isError())
return originalProjection;
if (replacement != null) {
VarianceConflictType varianceConflict = conflictType(originalProjectionKind, replacement.getProjectionKind());
// Captured type might be substituted in an opposite projection:
// out 'Captured (in Int)' = out Int
// in 'Captured (out Int)' = in Int
boolean allowVarianceConflict = CapturedTypeConstructorKt.isCaptured(type);
if (!allowVarianceConflict) {
//noinspection EnumSwitchStatementWhichMissesCases
switch(varianceConflict) {
case OUT_IN_IN_POSITION:
throw new SubstitutionException("Out-projection in in-position");
case IN_IN_OUT_POSITION:
// todo use the right type parameter variance and upper bound
return new TypeProjectionImpl(Variance.OUT_VARIANCE, type.getConstructor().getBuiltIns().getNullableAnyType());
}
}
KotlinType substitutedType;
CustomTypeVariable typeVariable = TypeCapabilitiesKt.getCustomTypeVariable(type);
if (replacement.isStarProjection()) {
return replacement;
} else if (typeVariable != null) {
substitutedType = typeVariable.substitutionResult(replacement.getType());
} else {
// this is a simple type T or T?: if it's T, we should just take replacement, if T? - we make replacement nullable
substitutedType = TypeUtils.makeNullableIfNeeded(replacement.getType(), type.isMarkedNullable());
}
// substitutionType.annotations = replacement.annotations ++ type.annotations
if (!type.getAnnotations().isEmpty()) {
Annotations typeAnnotations = filterOutUnsafeVariance(substitution.filterAnnotations(type.getAnnotations()));
substitutedType = TypeUtilsKt.replaceAnnotations(substitutedType, new CompositeAnnotations(substitutedType.getAnnotations(), typeAnnotations));
}
Variance resultingProjectionKind = varianceConflict == VarianceConflictType.NO_CONFLICT ? combine(originalProjectionKind, replacement.getProjectionKind()) : originalProjectionKind;
return new TypeProjectionImpl(resultingProjectionKind, substitutedType);
}
// The type is not within the substitution range, i.e. Foo, Bar<T> etc.
return substituteCompoundType(originalProjection, recursionDepth);
}
use of org.jetbrains.annotations.NotNull in project kotlin by JetBrains.
the class TypeUtils method substituteProjectionsForParameters.
@NotNull
public static KotlinType substituteProjectionsForParameters(@NotNull ClassDescriptor clazz, @NotNull List<TypeProjection> projections) {
List<TypeParameterDescriptor> clazzTypeParameters = clazz.getTypeConstructor().getParameters();
if (clazzTypeParameters.size() != projections.size()) {
throw new IllegalArgumentException("type parameter counts do not match: " + clazz + ", " + projections);
}
Map<TypeConstructor, TypeProjection> substitutions = org.jetbrains.kotlin.utils.CollectionsKt.newHashMapWithExpectedSize(clazzTypeParameters.size());
for (int i = 0; i < clazzTypeParameters.size(); ++i) {
TypeConstructor typeConstructor = clazzTypeParameters.get(i).getTypeConstructor();
substitutions.put(typeConstructor, projections.get(i));
}
return TypeSubstitutor.create(substitutions).substitute(clazz.getDefaultType(), Variance.INVARIANT);
}
use of org.jetbrains.annotations.NotNull in project kotlin by JetBrains.
the class TypeUtils method makeUnsubstitutedType.
@NotNull
public static SimpleType makeUnsubstitutedType(ClassifierDescriptor classifierDescriptor, MemberScope unsubstitutedMemberScope) {
if (ErrorUtils.isError(classifierDescriptor)) {
return ErrorUtils.createErrorType("Unsubstituted type for " + classifierDescriptor);
}
TypeConstructor typeConstructor = classifierDescriptor.getTypeConstructor();
List<TypeProjection> arguments = getDefaultTypeProjections(typeConstructor.getParameters());
return KotlinTypeFactory.simpleType(Annotations.Companion.getEMPTY(), typeConstructor, arguments, false, unsubstitutedMemberScope);
}
Aggregations