@NotNull
  @Override
  public Collection<PsiClass> getPackageClasses(
      @NotNull FqName packageFqName, @NotNull GlobalSearchScope scope) {
    List<PsiClass> result = new ArrayList<PsiClass>();
    List<KotlinLightPackageClassInfo> packageClassesInfos =
        findPackageClassesInfos(packageFqName, scope);
    for (KotlinLightPackageClassInfo info : packageClassesInfos) {
      List<JetFile> files = PackagePartClassUtils.getPackageFilesWithCallables(info.getFiles());
      if (files.isEmpty()) continue;

      IdeaModuleInfo moduleInfo = info.getModuleInfo();
      if (moduleInfo instanceof ModuleSourceInfo) {
        KotlinLightClassForPackage lightClass =
            KotlinLightClassForPackage.Factory.create(
                psiManager, packageFqName, moduleInfo.contentScope(), files);
        if (lightClass == null) continue;

        result.add(lightClass);

        if (files.size() > 1) {
          for (JetFile file : files) {
            result.add(new FakeLightClassForFileOfPackage(psiManager, lightClass, file));
          }
        }
      } else {
        PsiClass clsClass = getLightClassForDecompiledPackage(packageFqName, files);
        if (clsClass != null) {
          result.add(clsClass);
        }
      }
    }
    return result;
  }
Exemplo n.º 2
0
  private void checkEnumEntry(
      @NotNull JetEnumEntry enumEntry, @NotNull ClassDescriptor classDescriptor) {
    DeclarationDescriptor declaration = classDescriptor.getContainingDeclaration();
    assert DescriptorUtils.isEnumClass(declaration)
        : "Enum entry should be declared in enum class: " + classDescriptor;
    ClassDescriptor enumClass = (ClassDescriptor) declaration;

    if (enumEntryUsesDeprecatedSuperConstructor(enumEntry)) {
      trace.report(
          Errors.ENUM_ENTRY_USES_DEPRECATED_SUPER_CONSTRUCTOR.on(enumEntry, classDescriptor));
    }
    String neededDelimiter = enumEntryExpectedDelimiter(enumEntry);
    if (!neededDelimiter.isEmpty()) {
      trace.report(
          Errors.ENUM_ENTRY_USES_DEPRECATED_OR_NO_DELIMITER.on(
              enumEntry, classDescriptor, neededDelimiter));
    }
    if (enumEntryAfterEnumMember(enumEntry)) {
      trace.report(Errors.ENUM_ENTRY_AFTER_ENUM_MEMBER.on(enumEntry, classDescriptor));
    }

    List<JetDelegationSpecifier> delegationSpecifiers = enumEntry.getDelegationSpecifiers();
    ConstructorDescriptor constructor = enumClass.getUnsubstitutedPrimaryConstructor();
    if ((constructor == null || !constructor.getValueParameters().isEmpty())
        && delegationSpecifiers.isEmpty()) {
      trace.report(ENUM_ENTRY_SHOULD_BE_INITIALIZED.on(enumEntry, enumClass));
    }

    for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) {
      JetTypeReference typeReference = delegationSpecifier.getTypeReference();
      if (typeReference != null) {
        JetType type = trace.getBindingContext().get(TYPE, typeReference);
        if (type != null) {
          JetType enumType = enumClass.getDefaultType();
          if (!type.getConstructor().equals(enumType.getConstructor())) {
            trace.report(ENUM_ENTRY_ILLEGAL_TYPE.on(typeReference, enumClass));
          }
        }
      }
    }
  }