All Downloads are FREE. Search and download functionalities are using the official Maven repository.

proguard.util.kotlin.asserter.constraint.MultiFileFacadeIntegrity Maven / Gradle / Ivy

Go to download

ProGuardCORE is a free library to read, analyze, modify, and write Java class files.

There is a newer version: 9.1.6
Show newest version
package proguard.util.kotlin.asserter.constraint;

import proguard.classfile.Clazz;
import proguard.classfile.kotlin.KotlinMultiFileFacadeKindMetadata;
import proguard.util.StringUtil;
import proguard.util.kotlin.asserter.AssertUtil;

public class MultiFileFacadeIntegrity extends AbstractKotlinMetadataConstraint {

  @Override
  public void visitKotlinMultiFileFacadeMetadata(
      Clazz clazz, KotlinMultiFileFacadeKindMetadata kotlinMultiFileFacadeKindMetadata) {
    AssertUtil util = new AssertUtil(clazz.getName(), reporter, programClassPool, libraryClassPool);

    // Make sure part classes are actually present in one of the class pools.
    kotlinMultiFileFacadeKindMetadata.referencedPartClasses.forEach(
        referencedPartClass -> {
          util.reportIfNullReference(
              "multi-file part class \"" + referencedPartClass.getName() + "\"",
              referencedPartClass);
          util.reportIfClassDangling(
              "multi-file part class \"" + referencedPartClass.getName() + "\"",
              referencedPartClass);
        });

    // Multi file class facades and parts are distinct Kotlin metadata types,
    // hence, a facade referencing itself as a part is invalid metadata.
    boolean referencesItself =
        kotlinMultiFileFacadeKindMetadata.partClassNames.contains(clazz.getName());
    if (referencesItself) {
      String error =
          String.format(
              "Multi file facade class \"%s\" contains a reference to itself in its part metadata: %s.",
              clazz.getName(),
              StringUtil.listToString(kotlinMultiFileFacadeKindMetadata.partClassNames));
      reporter.report(error);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy