Search in sources :

Example 91 with NotNull

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;
}
Also used : ErrorSimpleFunctionDescriptorImpl(org.jetbrains.kotlin.types.error.ErrorSimpleFunctionDescriptorImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 92 with NotNull

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;
}
Also used : PropertyDescriptorImpl(org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 93 with NotNull

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);
}
Also used : CompositeAnnotations(org.jetbrains.kotlin.descriptors.annotations.CompositeAnnotations) CompositeAnnotations(org.jetbrains.kotlin.descriptors.annotations.CompositeAnnotations) FilteredAnnotations(org.jetbrains.kotlin.descriptors.annotations.FilteredAnnotations) Annotations(org.jetbrains.kotlin.descriptors.annotations.Annotations) NotNull(org.jetbrains.annotations.NotNull)

Example 94 with NotNull

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);
}
Also used : TypeParameterDescriptor(org.jetbrains.kotlin.descriptors.TypeParameterDescriptor) IntegerValueTypeConstructor(org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstructor) NotNull(org.jetbrains.annotations.NotNull)

Example 95 with NotNull

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);
}
Also used : IntegerValueTypeConstructor(org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstructor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)8141 VirtualFile (com.intellij.openapi.vfs.VirtualFile)888 ArrayList (java.util.ArrayList)809 PsiElement (com.intellij.psi.PsiElement)764 Project (com.intellij.openapi.project.Project)647 File (java.io.File)627 Nullable (org.jetbrains.annotations.Nullable)518 List (java.util.List)400 PsiFile (com.intellij.psi.PsiFile)358 Module (com.intellij.openapi.module.Module)336 IOException (java.io.IOException)325 TextRange (com.intellij.openapi.util.TextRange)260 Document (com.intellij.openapi.editor.Document)173 ContainerUtil (com.intellij.util.containers.ContainerUtil)173 BasePhpElementVisitor (com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpElementVisitor)169 ASTNode (com.intellij.lang.ASTNode)167 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)167 Map (java.util.Map)156 java.util (java.util)154 IElementType (com.intellij.psi.tree.IElementType)146