コード例 #1
0
 public void renderClassDescriptor(
     ClassDescriptor descriptor, StringBuilder builder, String keyword) {
   if (descriptor.getKind() != ClassKind.CLASS_OBJECT) {
     renderVisibility(descriptor.getVisibility(), builder);
   }
   if (descriptor.getKind() != ClassKind.TRAIT
       && descriptor.getKind() != ClassKind.OBJECT
       && descriptor.getKind() != ClassKind.CLASS_OBJECT) {
     renderModality(descriptor.getModality(), builder);
   }
   builder.append(renderKeyword(keyword));
   if (descriptor.getKind() != ClassKind.CLASS_OBJECT) {
     builder.append(" ");
     renderName(descriptor, builder);
     renderTypeParameters(descriptor.getTypeConstructor().getParameters(), builder);
   }
   if (!descriptor.equals(JetStandardClasses.getNothing())) {
     Collection<? extends JetType> supertypes = descriptor.getTypeConstructor().getSupertypes();
     if (supertypes.isEmpty()
         || supertypes.size() == 1 && JetStandardClasses.isAny(supertypes.iterator().next())) {
     } else {
       builder.append(" : ");
       for (Iterator<? extends JetType> iterator = supertypes.iterator(); iterator.hasNext(); ) {
         JetType supertype = iterator.next();
         builder.append(renderType(supertype));
         if (iterator.hasNext()) {
           builder.append(", ");
         }
       }
     }
   }
 }
コード例 #2
0
 private void findAndDisconnectLoopsInTypeHierarchy(List<JetType> supertypes) {
   for (Iterator<JetType> iterator = supertypes.iterator(); iterator.hasNext(); ) {
     JetType supertype = iterator.next();
     if (isReachable(supertype.getConstructor(), this, new HashSet<TypeConstructor>())) {
       iterator.remove();
     }
   }
 }
コード例 #3
0
 private void appendTypes(StringBuilder result, List<JetType> types, boolean shortNamesOnly) {
   for (Iterator<JetType> iterator = types.iterator(); iterator.hasNext(); ) {
     result.append(renderType(iterator.next(), shortNamesOnly));
     if (iterator.hasNext()) {
       result.append(", ");
     }
   }
 }
コード例 #4
0
 protected void renderValueParameters(FunctionDescriptor descriptor, StringBuilder builder) {
   if (descriptor.getValueParameters().isEmpty()) {
     renderEmptyValueParameters(builder);
   }
   for (Iterator<ValueParameterDescriptor> iterator = descriptor.getValueParameters().iterator();
       iterator.hasNext(); ) {
     renderValueParameter(iterator.next(), !iterator.hasNext(), builder);
   }
 }
コード例 #5
0
 private void appendTypeProjections(
     @NotNull List<TypeProjection> typeProjections, @NotNull StringBuilder builder) {
   for (Iterator<TypeProjection> iterator = typeProjections.iterator(); iterator.hasNext(); ) {
     TypeProjection typeProjection = iterator.next();
     if (typeProjection.getProjectionKind() != Variance.INVARIANT) {
       builder.append(typeProjection.getProjectionKind()).append(" ");
     }
     builder.append(renderType(typeProjection.getType()));
     if (iterator.hasNext()) {
       builder.append(", ");
     }
   }
 }
コード例 #6
0
 private void appendTypeProjections(
     StringBuilder result, List<TypeProjection> typeProjections, boolean shortNamesOnly) {
   for (Iterator<TypeProjection> iterator = typeProjections.iterator(); iterator.hasNext(); ) {
     TypeProjection typeProjection = iterator.next();
     if (typeProjection.getProjectionKind() != Variance.INVARIANT) {
       result.append(typeProjection.getProjectionKind()).append(" ");
     }
     result.append(renderType(typeProjection.getType(), shortNamesOnly));
     if (iterator.hasNext()) {
       result.append(", ");
     }
   }
 }
コード例 #7
0
  /* CLASSES */
  private void renderClass(@NotNull ClassDescriptor klass, @NotNull StringBuilder builder) {
    if (!startFromName) {
      renderAnnotations(klass, builder);
      renderVisibility(klass.getVisibility(), builder);
      if (!(klass.getKind() == ClassKind.TRAIT && klass.getModality() == Modality.ABSTRACT
          || klass.getKind().isObject() && klass.getModality() == Modality.FINAL)) {
        renderModality(klass.getModality(), builder);
      }
      renderInner(klass.isInner(), builder);
      builder.append(renderKeyword(getClassKindPrefix(klass)));
    }

    if (klass.getKind() != ClassKind.CLASS_OBJECT || verbose) {
      builder.append(" ");
      renderName(klass, builder);
    }

    List<TypeParameterDescriptor> typeParameters = klass.getTypeConstructor().getParameters();
    renderTypeParameters(typeParameters, builder, false);

    if (!klass.getKind().isObject() && classWithPrimaryConstructor) {
      ConstructorDescriptor primaryConstructor = klass.getUnsubstitutedPrimaryConstructor();
      if (primaryConstructor != null) {
        renderValueParameters(primaryConstructor, builder);
      }
    }

    if (!klass.equals(KotlinBuiltIns.getInstance().getNothing())) {
      Collection<JetType> supertypes = klass.getTypeConstructor().getSupertypes();
      if (supertypes.isEmpty()
          || !alwaysRenderAny
              && supertypes.size() == 1
              && KotlinBuiltIns.getInstance().isAny(supertypes.iterator().next())) {
      } else {
        builder.append(" : ");
        for (Iterator<JetType> iterator = supertypes.iterator(); iterator.hasNext(); ) {
          JetType supertype = iterator.next();
          builder.append(renderType(supertype));
          if (iterator.hasNext()) {
            builder.append(", ");
          }
        }
      }
    }

    renderWhereSuffix(typeParameters, builder);
  }
コード例 #8
0
 private boolean renderTypeParameters(
     List<TypeParameterDescriptor> typeParameters, StringBuilder builder) {
   if (!typeParameters.isEmpty()) {
     builder.append(lt());
     for (Iterator<TypeParameterDescriptor> iterator = typeParameters.iterator();
         iterator.hasNext(); ) {
       TypeParameterDescriptor typeParameterDescriptor = iterator.next();
       typeParameterDescriptor.accept(subVisitor, builder);
       if (iterator.hasNext()) {
         builder.append(", ");
       }
     }
     builder.append(">");
     return true;
   }
   return false;
 }
コード例 #9
0
 private void renderTypeParameters(
     @NotNull List<TypeParameterDescriptor> typeParameters,
     @NotNull StringBuilder builder,
     boolean withSpace) {
   if (!typeParameters.isEmpty()) {
     builder.append(lt());
     for (Iterator<TypeParameterDescriptor> iterator = typeParameters.iterator();
         iterator.hasNext(); ) {
       TypeParameterDescriptor typeParameterDescriptor = iterator.next();
       renderTypeParameter(typeParameterDescriptor, builder, false);
       if (iterator.hasNext()) {
         builder.append(", ");
       }
     }
     builder.append(">");
     if (withSpace) {
       builder.append(" ");
     }
   }
 }
コード例 #10
0
  private List<TypeParameterDescriptor> modifyTypeParametersAccordingToSuperMethods(
      List<TypeParameterDescriptor> autoTypeParameters) {
    List<TypeParameterDescriptor> result = Lists.newArrayList();

    for (TypeParameterDescriptor autoParameter : autoTypeParameters) {
      int index = autoParameter.getIndex();
      TypeParameterDescriptorImpl modifiedTypeParameter =
          autoTypeParameterToModified.get(autoParameter);

      List<Iterator<JetType>> upperBoundFromSuperFunctionsIterators = Lists.newArrayList();
      for (FunctionDescriptor superFunction : superFunctions) {
        upperBoundFromSuperFunctionsIterators.add(
            superFunction.getTypeParameters().get(index).getUpperBounds().iterator());
      }

      for (JetType autoUpperBound : autoParameter.getUpperBounds()) {
        List<TypeAndVariance> upperBoundsFromSuperFunctions = Lists.newArrayList();

        for (Iterator<JetType> iterator : upperBoundFromSuperFunctionsIterators) {
          assert iterator.hasNext();
          upperBoundsFromSuperFunctions.add(new TypeAndVariance(iterator.next(), INVARIANT));
        }

        JetType modifiedUpperBound =
            modifyTypeAccordingToSuperMethods(
                autoUpperBound, upperBoundsFromSuperFunctions, UPPER_BOUND);
        modifiedTypeParameter.addUpperBound(modifiedUpperBound);
      }

      for (Iterator<JetType> iterator : upperBoundFromSuperFunctionsIterators) {
        assert !iterator.hasNext();
      }

      modifiedTypeParameter.setInitialized();
      result.add(modifiedTypeParameter);
    }

    return result;
  }