Exemplo n.º 1
0
 private static Variance merge(Variance positionOfOuter, Variance projectionKind) {
   // Inv<Inv<out X>>, X is in invariant position
   if (positionOfOuter == INVARIANT) return INVARIANT;
   // Out<X>, X is in out-position
   if (projectionKind == INVARIANT) return positionOfOuter;
   // Out<Out<X>>, X is in out-position
   // In<In<X>>, X is in out-position
   // Out<In<X>>, X is in in-position
   // In<Out<X>>, X is in in-position
   return positionOfOuter.superpose(projectionKind);
 }
Exemplo n.º 2
0
  @NotNull
  private static ClassDescriptor createClass(
      @NotNull PackageFragmentDescriptor packageFragment,
      @NotNull String name,
      @NotNull String... typeParameters) {
    MutableClassDescriptor descriptor =
        new MutableClassDescriptor(
            packageFragment,
            packageFragment.getMemberScope(),
            ClassKind.CLASS,
            false,
            Name.identifier(name));
    List<TypeParameterDescriptor> typeParameterDescriptors =
        new ArrayList<TypeParameterDescriptor>(typeParameters.length);
    for (int i = 0; i < typeParameters.length; i++) {
      String[] s = typeParameters[i].split(" ");
      Variance variance = Variance.valueOf(s[0].toUpperCase() + "_VARIANCE");
      String typeParameterName = s[1];
      TypeParameterDescriptorImpl typeParameter =
          TypeParameterDescriptorImpl.createForFurtherModification(
              descriptor,
              Annotations.EMPTY,
              false,
              variance,
              Name.identifier(typeParameterName),
              i);
      typeParameter.setInitialized();
      typeParameterDescriptors.add(typeParameter);
    }

    descriptor.setModality(Modality.FINAL);
    descriptor.setVisibility(Visibilities.PUBLIC);
    descriptor.setTypeParameterDescriptors(typeParameterDescriptors);
    descriptor.createTypeConstructor();

    return descriptor;
  }