Search in sources :

Example 1 with KotlinJavascriptMetadata

use of org.jetbrains.kotlin.utils.KotlinJavascriptMetadata in project kotlin by JetBrains.

the class JsConfig method getModuleDescriptors.

@NotNull
public List<JsModuleDescriptor<ModuleDescriptorImpl>> getModuleDescriptors() {
    init();
    if (moduleDescriptors != null)
        return moduleDescriptors;
    moduleDescriptors = new SmartList<JsModuleDescriptor<ModuleDescriptorImpl>>();
    List<ModuleDescriptorImpl> kotlinModuleDescriptors = new ArrayList<ModuleDescriptorImpl>();
    for (KotlinJavascriptMetadata metadataEntry : metadata) {
        JsModuleDescriptor<ModuleDescriptorImpl> descriptor = createModuleDescriptor(metadataEntry);
        moduleDescriptors.add(descriptor);
        kotlinModuleDescriptors.add(descriptor.getData());
    }
    for (JsModuleDescriptor<ModuleDescriptorImpl> module : moduleDescriptors) {
        // TODO: remove downcast
        setDependencies(module.getData(), kotlinModuleDescriptors);
    }
    moduleDescriptors = Collections.unmodifiableList(moduleDescriptors);
    return moduleDescriptors;
}
Also used : JsModuleDescriptor(org.jetbrains.kotlin.serialization.js.JsModuleDescriptor) ArrayList(java.util.ArrayList) KotlinJavascriptMetadata(org.jetbrains.kotlin.utils.KotlinJavascriptMetadata) ModuleDescriptorImpl(org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with KotlinJavascriptMetadata

use of org.jetbrains.kotlin.utils.KotlinJavascriptMetadata in project kotlin by JetBrains.

the class LibrarySourcesConfig method checkLibFilesAndReportErrors.

private boolean checkLibFilesAndReportErrors(@NotNull JsConfig.Reporter report, @Nullable Function1<VirtualFile, Unit> action) {
    List<String> libraries = getLibraries();
    if (libraries.isEmpty()) {
        return false;
    }
    VirtualFileSystem fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL);
    VirtualFileSystem jarFileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.JAR_PROTOCOL);
    Set<String> modules = new HashSet<String>();
    for (String path : libraries) {
        VirtualFile file;
        File filePath = new File(path);
        if (!filePath.exists()) {
            report.error("Path '" + path + "' does not exist");
            return true;
        }
        if (path.endsWith(".jar") || path.endsWith(".zip")) {
            file = jarFileSystem.findFileByPath(path + URLUtil.JAR_SEPARATOR);
        } else {
            file = fileSystem.findFileByPath(path);
        }
        if (file == null) {
            report.error("File '" + path + "' does not exist or could not be read");
            return true;
        }
        List<KotlinJavascriptMetadata> metadataList = KotlinJavascriptMetadataUtils.loadMetadata(filePath);
        if (metadataList.isEmpty()) {
            report.warning("'" + path + "' is not a valid Kotlin Javascript library");
            continue;
        }
        for (KotlinJavascriptMetadata metadata : metadataList) {
            if (!metadata.getVersion().isCompatible()) {
                report.error("File '" + path + "' was compiled with an incompatible version of Kotlin. " + "The binary version of its metadata is " + metadata.getVersion() + ", expected version is " + JsMetadataVersion.INSTANCE);
                return true;
            }
            if (!modules.add(metadata.getModuleName())) {
                report.warning("Module \"" + metadata.getModuleName() + "\" is defined in more, than one file");
            }
        }
        if (action != null) {
            action.invoke(file);
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileSystem(com.intellij.openapi.vfs.VirtualFileSystem) KotlinJavascriptMetadata(org.jetbrains.kotlin.utils.KotlinJavascriptMetadata) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

KotlinJavascriptMetadata (org.jetbrains.kotlin.utils.KotlinJavascriptMetadata)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 VirtualFileSystem (com.intellij.openapi.vfs.VirtualFileSystem)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 NotNull (org.jetbrains.annotations.NotNull)1 ModuleDescriptorImpl (org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl)1 JsModuleDescriptor (org.jetbrains.kotlin.serialization.js.JsModuleDescriptor)1