Пример #1
0
 public static boolean dependsOnTypeParameters(
     @NotNull KotlinType type, @NotNull Collection<TypeParameterDescriptor> typeParameters) {
   return dependsOnTypeConstructors(
       type,
       CollectionsKt.map(
           typeParameters,
           new Function1<TypeParameterDescriptor, TypeConstructor>() {
             @Override
             public TypeConstructor invoke(
                 @NotNull TypeParameterDescriptor typeParameterDescriptor) {
               return typeParameterDescriptor.getTypeConstructor();
             }
           }));
 }
Пример #2
0
  @NotNull
  public static <H> H selectMostSpecificMember(
      @NotNull Collection<H> overridables,
      @NotNull Function1<H, CallableDescriptor> descriptorByHandle) {
    assert !overridables.isEmpty() : "Should have at least one overridable descriptor";

    if (overridables.size() == 1) {
      return CollectionsKt.first(overridables);
    }

    Collection<H> candidates = new ArrayList<H>(2);
    List<CallableDescriptor> callableMemberDescriptors =
        CollectionsKt.map(overridables, descriptorByHandle);

    H transitivelyMostSpecific = CollectionsKt.first(overridables);
    CallableDescriptor transitivelyMostSpecificDescriptor =
        descriptorByHandle.invoke(transitivelyMostSpecific);

    for (H overridable : overridables) {
      CallableDescriptor descriptor = descriptorByHandle.invoke(overridable);
      if (isMoreSpecificThenAllOf(descriptor, callableMemberDescriptors)) {
        candidates.add(overridable);
      }
      if (isMoreSpecific(descriptor, transitivelyMostSpecificDescriptor)
          && !isMoreSpecific(transitivelyMostSpecificDescriptor, descriptor)) {
        transitivelyMostSpecific = overridable;
      }
    }

    if (candidates.isEmpty()) {
      return transitivelyMostSpecific;
    } else if (candidates.size() == 1) {
      return CollectionsKt.first(candidates);
    }

    H firstNonFlexible = null;
    for (H candidate : candidates) {
      //noinspection ConstantConditions
      if (!FlexibleTypesKt.isFlexible(descriptorByHandle.invoke(candidate).getReturnType())) {
        firstNonFlexible = candidate;
        break;
      }
    }
    if (firstNonFlexible != null) {
      return firstNonFlexible;
    }

    return CollectionsKt.first(candidates);
  }
Пример #3
0
  @NotNull
  public static KotlinType substituteParameters(
      @NotNull ClassDescriptor clazz, @NotNull List<KotlinType> typeArguments) {
    List<TypeProjection> projections =
        CollectionsKt.map(
            typeArguments,
            new Function1<KotlinType, TypeProjection>() {
              @Override
              public TypeProjection invoke(KotlinType type) {
                return new TypeProjectionImpl(type);
              }
            });

    return substituteProjectionsForParameters(clazz, projections);
  }
Пример #4
0
  @NotNull
  @ReadOnly
  public List<ClassDescriptor> getDescriptorsForExtraCompanionObjects() {
    final KtObjectDeclaration allowedCompanionObject = getCompanionObjectIfAllowed();

    return CollectionsKt.map(
        CollectionsKt.filter(
            declarationProvider.getOwnerInfo().getCompanionObjects(),
            new Function1<KtObjectDeclaration, Boolean>() {
              @Override
              public Boolean invoke(KtObjectDeclaration companionObject) {
                return companionObject != allowedCompanionObject;
              }
            }),
        new Function1<KtObjectDeclaration, ClassDescriptor>() {
          @Override
          public ClassDescriptor invoke(KtObjectDeclaration companionObject) {
            return extraCompanionObjectDescriptors.invoke(companionObject);
          }
        });
  }