Search in sources :

Example 1 with DeserializedClassDescriptor

use of org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor in project kotlin by JetBrains.

the class AbstractLoadJavaTest method doTestCompiledKotlin.

private void doTestCompiledKotlin(@NotNull String ktFileName, @NotNull ConfigurationKind configurationKind, boolean useTypeTableInSerializer) throws Exception {
    File ktFile = new File(ktFileName);
    File txtFile = new File(ktFileName.replaceFirst("\\.kt$", ".txt"));
    CompilerConfiguration configuration = newConfiguration(configurationKind, TestJdkKind.MOCK_JDK, getAnnotationsJar());
    if (useTypeTableInSerializer) {
        configuration.put(JVMConfigurationKeys.USE_TYPE_TABLE, true);
    }
    KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(getTestRootDisposable(), configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
    ModuleDescriptor module = compileKotlinToDirAndGetModule(Collections.singletonList(ktFile), tmpdir, environment);
    PackageViewDescriptor packageFromSource = module.getPackage(TEST_PACKAGE_FQNAME);
    Assert.assertEquals("test", packageFromSource.getName().asString());
    PackageViewDescriptor packageFromBinary = LoadDescriptorUtil.loadTestPackageAndBindingContextFromJavaRoot(tmpdir, getTestRootDisposable(), getJdkKind(), configurationKind, true).first;
    for (DeclarationDescriptor descriptor : DescriptorUtils.getAllDescriptors(packageFromBinary.getMemberScope())) {
        if (descriptor instanceof ClassDescriptor) {
            assert descriptor instanceof DeserializedClassDescriptor : DescriptorUtils.getFqName(descriptor) + " is loaded as " + descriptor.getClass();
        }
    }
    DescriptorValidator.validate(errorTypesForbidden(), packageFromSource);
    DescriptorValidator.validate(new DeserializedScopeValidationVisitor(), packageFromBinary);
    Configuration comparatorConfiguration = COMPARATOR_CONFIGURATION.checkPrimaryConstructors(true).checkPropertyAccessors(true);
    compareDescriptors(packageFromSource, packageFromBinary, comparatorConfiguration, txtFile);
}
Also used : DeserializedClassDescriptor(org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor) CompilerConfiguration(org.jetbrains.kotlin.config.CompilerConfiguration) KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) CompilerConfiguration(org.jetbrains.kotlin.config.CompilerConfiguration) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File) DeserializedClassDescriptor(org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor)

Example 2 with DeserializedClassDescriptor

use of org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor in project kotlin by JetBrains.

the class KotlinTypeMapper method checkOwnerCompatibility.

private void checkOwnerCompatibility(@NotNull FunctionDescriptor descriptor) {
    if (!(descriptor instanceof DeserializedCallableMemberDescriptor))
        return;
    KotlinJvmBinaryClass ownerClass = null;
    DeclarationDescriptor container = descriptor.getContainingDeclaration();
    if (container instanceof DeserializedClassDescriptor) {
        SourceElement source = ((DeserializedClassDescriptor) container).getSource();
        if (source instanceof KotlinJvmBinarySourceElement) {
            ownerClass = ((KotlinJvmBinarySourceElement) source).getBinaryClass();
        }
    } else if (container instanceof LazyJavaPackageFragment) {
        SourceElement source = ((LazyJavaPackageFragment) container).getSource();
        if (source instanceof KotlinJvmBinaryPackageSourceElement) {
            ownerClass = ((KotlinJvmBinaryPackageSourceElement) source).getRepresentativeBinaryClass();
        }
    }
    if (ownerClass != null) {
        JvmBytecodeBinaryVersion version = ownerClass.getClassHeader().getBytecodeVersion();
        if (!version.isCompatible()) {
            incompatibleClassTracker.record(ownerClass);
        }
    }
}
Also used : DeserializedCallableMemberDescriptor(org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor) LazyJavaPackageFragment(org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageFragment) JvmBytecodeBinaryVersion(org.jetbrains.kotlin.load.java.JvmBytecodeBinaryVersion) DeserializedClassDescriptor(org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor)

Aggregations

DeserializedClassDescriptor (org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor)2 File (java.io.File)1 KotlinCoreEnvironment (org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment)1 CompilerConfiguration (org.jetbrains.kotlin.config.CompilerConfiguration)1 JvmBytecodeBinaryVersion (org.jetbrains.kotlin.load.java.JvmBytecodeBinaryVersion)1 LazyJavaPackageFragment (org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageFragment)1 KtFile (org.jetbrains.kotlin.psi.KtFile)1 DeserializedCallableMemberDescriptor (org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor)1