public void addSupertype(@NotNull JetType supertype) {
   assert !supertype.isError() : "Error types must be filtered out in DescriptorResolver";
   if (TypeUtils.getClassDescriptor(supertype) != null) {
     // See the Errors.SUPERTYPE_NOT_A_CLASS_OR_TRAIT
     supertypes.add(supertype);
   }
 }
Example #2
0
  // allowedFinalSupertypes typically contains a enum type of which supertypeOwner is an entry
  private void checkSupertypeList(
      @NotNull MutableClassDescriptor supertypeOwner,
      @NotNull Map<JetTypeReference, JetType> supertypes,
      Set<TypeConstructor> allowedFinalSupertypes) {
    Set<TypeConstructor> typeConstructors = Sets.newHashSet();
    boolean classAppeared = false;
    for (Map.Entry<JetTypeReference, JetType> entry : supertypes.entrySet()) {
      JetTypeReference typeReference = entry.getKey();
      JetType supertype = entry.getValue();

      ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(supertype);
      if (classDescriptor != null) {
        if (classDescriptor.getKind() != ClassKind.TRAIT) {
          if (classAppeared) {
            trace.report(MANY_CLASSES_IN_SUPERTYPE_LIST.on(typeReference));
          } else {
            classAppeared = true;
          }
        }
      } else {
        trace.report(SUPERTYPE_NOT_A_CLASS_OR_TRAIT.on(typeReference));
      }

      TypeConstructor constructor = supertype.getConstructor();
      if (!typeConstructors.add(constructor)) {
        trace.report(SUPERTYPE_APPEARS_TWICE.on(typeReference));
      }

      if (constructor.isSealed() && !allowedFinalSupertypes.contains(constructor)) {
        trace.report(FINAL_SUPERTYPE.on(typeReference));
      }
    }
  }
Example #3
0
 private static void addForClassType(
     ArrayList<String> result, JetType jetType, JetNameValidator validator) {
   ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(jetType);
   if (classDescriptor != null) {
     Name className = classDescriptor.getName();
     addCamelNames(result, className.getName(), validator);
   }
 }
 @Nullable
 private static String getMessageFromAnnotationDescriptor(
     @NotNull AnnotationDescriptor descriptor) {
   ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(descriptor.getType());
   if (classDescriptor != null) {
     ValueParameterDescriptor parameter =
         DescriptorResolverUtils.getAnnotationParameterByName(
             DEFAULT_ANNOTATION_MEMBER_NAME, classDescriptor);
     if (parameter != null) {
       CompileTimeConstant<?> valueArgument = descriptor.getValueArgument(parameter);
       if (valueArgument != null) {
         Object value = valueArgument.getValue();
         if (value instanceof String) {
           return String.valueOf(value);
         }
       }
     }
   }
   return null;
 }
Example #5
0
 private static void addNamesForType(
     ArrayList<String> result, JetType jetType, JetNameValidator validator) {
   JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance();
   JetTypeChecker typeChecker = JetTypeChecker.INSTANCE;
   if (ErrorUtils.containsErrorType(jetType)) return;
   if (typeChecker.equalTypes(standardLibrary.getBooleanType(), jetType)) {
     addName(result, "b", validator);
   } else if (typeChecker.equalTypes(standardLibrary.getIntType(), jetType)) {
     addName(result, "i", validator);
   } else if (typeChecker.equalTypes(standardLibrary.getByteType(), jetType)) {
     addName(result, "byte", validator);
   } else if (typeChecker.equalTypes(standardLibrary.getLongType(), jetType)) {
     addName(result, "l", validator);
   } else if (typeChecker.equalTypes(standardLibrary.getFloatType(), jetType)) {
     addName(result, "fl", validator);
   } else if (typeChecker.equalTypes(standardLibrary.getDoubleType(), jetType)) {
     addName(result, "d", validator);
   } else if (typeChecker.equalTypes(standardLibrary.getShortType(), jetType)) {
     addName(result, "sh", validator);
   } else if (typeChecker.equalTypes(standardLibrary.getCharType(), jetType)) {
     addName(result, "c", validator);
   } else if (typeChecker.equalTypes(standardLibrary.getStringType(), jetType)) {
     addName(result, "s", validator);
   } else {
     if (jetType.getArguments().size() == 1) {
       JetType argument = jetType.getArguments().get(0).getType();
       if (typeChecker.equalTypes(standardLibrary.getArrayType(argument), jetType)) {
         if (typeChecker.equalTypes(standardLibrary.getBooleanType(), argument)) {
           addName(result, "booleans", validator);
         } else if (typeChecker.equalTypes(standardLibrary.getIntType(), argument)) {
           addName(result, "ints", validator);
         } else if (typeChecker.equalTypes(standardLibrary.getByteType(), argument)) {
           addName(result, "bytes", validator);
         } else if (typeChecker.equalTypes(standardLibrary.getLongType(), argument)) {
           addName(result, "longs", validator);
         } else if (typeChecker.equalTypes(standardLibrary.getFloatType(), argument)) {
           addName(result, "floats", validator);
         } else if (typeChecker.equalTypes(standardLibrary.getDoubleType(), argument)) {
           addName(result, "doubles", validator);
         } else if (typeChecker.equalTypes(standardLibrary.getShortType(), argument)) {
           addName(result, "shorts", validator);
         } else if (typeChecker.equalTypes(standardLibrary.getCharType(), argument)) {
           addName(result, "chars", validator);
         } else if (typeChecker.equalTypes(standardLibrary.getStringType(), argument)) {
           addName(result, "strings", validator);
         } else {
           ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(argument);
           if (classDescriptor != null) {
             Name className = classDescriptor.getName();
             addName(
                 result, "arrayOf" + StringUtil.capitalize(className.getName()) + "s", validator);
           }
         }
       } else {
         addForClassType(result, jetType, validator);
       }
     } else {
       addForClassType(result, jetType, validator);
     }
   }
 }
Example #6
0
 @Override
 public boolean apply(JetType type) {
   return !ErrorUtils.isErrorType(type) && (TypeUtils.getClassDescriptor(type) != null);
 }
 @Override
 public boolean apply(JetType type) {
   assert !type.isError() : "Error types must be filtered out in DescriptorResolver";
   return TypeUtils.getClassDescriptor(type) != null;
 }