remove idea-js module
This commit is contained in:
Generated
-1
@@ -42,7 +42,6 @@
|
||||
<element id="module-output" name="serialization" />
|
||||
<element id="module-output" name="idea-completion" />
|
||||
<element id="module-output" name="idea-core" />
|
||||
<element id="module-output" name="idea-js" />
|
||||
<element id="module-output" name="container" />
|
||||
<element id="module-output" name="rmi-interface" />
|
||||
<element id="module-output" name="idea-repl" />
|
||||
|
||||
Generated
-1
@@ -36,7 +36,6 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/idea/idea-completion/idea-completion.iml" filepath="$PROJECT_DIR$/idea/idea-completion/idea-completion.iml" group="ide" />
|
||||
<module fileurl="file://$PROJECT_DIR$/idea/idea-core/idea-core.iml" filepath="$PROJECT_DIR$/idea/idea-core/idea-core.iml" group="ide" />
|
||||
<module fileurl="file://$PROJECT_DIR$/idea/idea-jps-common/idea-jps-common.iml" filepath="$PROJECT_DIR$/idea/idea-jps-common/idea-jps-common.iml" group="ide" />
|
||||
<module fileurl="file://$PROJECT_DIR$/idea/idea-js/idea-js.iml" filepath="$PROJECT_DIR$/idea/idea-js/idea-js.iml" group="ide" />
|
||||
<module fileurl="file://$PROJECT_DIR$/idea/idea-live-templates/idea-live-templates.iml" filepath="$PROJECT_DIR$/idea/idea-live-templates/idea-live-templates.iml" group="ide" />
|
||||
<module fileurl="file://$PROJECT_DIR$/idea/idea-repl/idea-repl.iml" filepath="$PROJECT_DIR$/idea/idea-repl/idea-repl.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/idea-runner/idea-runner.iml" filepath="$PROJECT_DIR$/idea-runner/idea-runner.iml" group="ide" />
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
<orderEntry type="library" scope="RUNTIME" name="junit-plugin" level="project" />
|
||||
<orderEntry type="module" module-name="idea" scope="RUNTIME" />
|
||||
<orderEntry type="module" module-name="util" />
|
||||
<orderEntry type="module" module-name="idea-js" scope="TEST" />
|
||||
<orderEntry type="module" module-name="js.frontend" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="properties" level="project" />
|
||||
</component>
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="intellij-core" level="project" />
|
||||
<orderEntry type="module" module-name="frontend" />
|
||||
<orderEntry type="module" module-name="js.dart-ast" exported="" />
|
||||
<orderEntry type="module" module-name="js.parser" exported="" />
|
||||
<orderEntry type="module" module-name="util" />
|
||||
<orderEntry type="module" module-name="js.serializer" />
|
||||
<orderEntry type="library" name="idea-full" level="project" />
|
||||
<orderEntry type="module" module-name="idea-analysis" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.js
|
||||
|
||||
import com.intellij.openapi.vfs.impl.ArchiveHandler
|
||||
import com.intellij.openapi.vfs.impl.ArchiveHandler.EntryInfo
|
||||
import com.intellij.util.ArrayUtil
|
||||
import gnu.trove.THashMap
|
||||
import org.jetbrains.kotlin.serialization.js.forEachFile
|
||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils
|
||||
|
||||
public open class KotlinJavaScriptHandler(path: String) : ArchiveHandler(path) {
|
||||
|
||||
override fun createEntriesMap(): Map<String, EntryInfo> {
|
||||
val map = THashMap<String, EntryInfo>()
|
||||
map.put("", createRootEntry())
|
||||
|
||||
for(metadata in KotlinJavascriptMetadataUtils.loadMetadata(getFile())) {
|
||||
val moduleName = metadata.moduleName
|
||||
metadata.forEachFile {
|
||||
filePath, fileContent -> getOrCreate(moduleName + "/" + filePath, false, map, fileContent)
|
||||
}
|
||||
}
|
||||
|
||||
return map
|
||||
}
|
||||
|
||||
private fun getOrCreate(
|
||||
entryPath: String,
|
||||
isDirectory: Boolean,
|
||||
map: MutableMap<String, EntryInfo>,
|
||||
content: ByteArray = ArrayUtil.EMPTY_BYTE_ARRAY
|
||||
): EntryInfo {
|
||||
val info = map[entryPath]
|
||||
if (info != null) return info
|
||||
|
||||
val path = splitPath(entryPath)
|
||||
val parentInfo = getOrCreate(path.first, true, map)
|
||||
val newInfo = JsMetaEntryInfo(parentInfo, path.second, isDirectory, content)
|
||||
map[entryPath] = newInfo
|
||||
|
||||
return newInfo
|
||||
}
|
||||
|
||||
override fun contentsToByteArray(relativePath: String): ByteArray {
|
||||
val entryInfo = getEntryInfo(relativePath)
|
||||
return if (entryInfo is JsMetaEntryInfo) entryInfo.content else ArrayUtil.EMPTY_BYTE_ARRAY
|
||||
}
|
||||
|
||||
private class JsMetaEntryInfo(
|
||||
parent: EntryInfo,
|
||||
shortName: String,
|
||||
isDirectory: Boolean,
|
||||
val content: ByteArray
|
||||
) : EntryInfo(shortName, isDirectory, ArchiveHandler.DEFAULT_LENGTH, ArchiveHandler.DEFAULT_TIMESTAMP, parent)
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.js
|
||||
|
||||
import com.intellij.ide.projectView.TreeStructureProvider
|
||||
import com.intellij.ide.projectView.ViewSettings
|
||||
import com.intellij.ide.projectView.impl.nodes.ExternalLibrariesNode
|
||||
import com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode
|
||||
|
||||
public class KotlinJavaScriptLibraryContentsTreeStructureProvider : TreeStructureProvider {
|
||||
|
||||
override fun modify(parent: AbstractTreeNode<*>, children: Collection<AbstractTreeNode<*>>, settings: ViewSettings): Collection<AbstractTreeNode<*>> =
|
||||
if (parent.getProject() == null || parent !is ExternalLibrariesNode) children else filterLibraryNodes(children)
|
||||
|
||||
private fun filterLibraryNodes(children: Collection<AbstractTreeNode<*>>): Collection<AbstractTreeNode<*>> {
|
||||
val filteredChildren = children.filterNot { it is NamedLibraryElementNode && KotlinJavaScriptLibraryManager.LIBRARY_NAME == it.getName() }
|
||||
return if (filteredChildren.size() == children.size()) children else filteredChildren
|
||||
}
|
||||
|
||||
override fun getData(selected: MutableCollection<AbstractTreeNode<*>>?, dataName: String?): Any? = null
|
||||
}
|
||||
@@ -1,310 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.js
|
||||
|
||||
import com.intellij.ProjectTopics
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.ModalityState
|
||||
import com.intellij.openapi.components.ProjectComponent
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.module.ModuleManager
|
||||
import com.intellij.openapi.module.ModuleType
|
||||
import com.intellij.openapi.module.ModuleTypeId
|
||||
import com.intellij.openapi.project.DumbService
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.*
|
||||
import com.intellij.openapi.roots.impl.OrderEntryUtil
|
||||
import com.intellij.openapi.roots.libraries.Library
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.vfs.VfsUtil
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.vfs.VirtualFileManager
|
||||
import com.intellij.openapi.vfs.newvfs.BulkFileListener
|
||||
import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent
|
||||
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
|
||||
import com.intellij.util.FileContentUtilCore
|
||||
import com.intellij.util.PathUtil
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.idea.framework.KotlinJavaScriptLibraryDetectionUtil
|
||||
import org.jetbrains.kotlin.idea.project.ProjectStructureUtil.isJsKotlinModule
|
||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
public class KotlinJavaScriptLibraryManager private constructor(private var myProject: Project?) : ProjectComponent, ModuleRootListener, BulkFileListener {
|
||||
private val myMuted = AtomicBoolean(false)
|
||||
|
||||
private val libraryFileStampMap: MutableMap<String, Long> = Collections.synchronizedMap(hashMapOf())
|
||||
|
||||
override fun getComponentName(): String = "KotlinJavascriptLibraryManager"
|
||||
|
||||
override fun projectOpened() {
|
||||
val project = myProject!!
|
||||
project.messageBus.connect(project).subscribe(ProjectTopics.PROJECT_ROOTS, this)
|
||||
project.messageBus.connect(project).subscribe(VirtualFileManager.VFS_CHANGES, this)
|
||||
DumbService.getInstance(project).smartInvokeLater() { updateProjectLibrary() }
|
||||
}
|
||||
|
||||
override fun projectClosed() {
|
||||
}
|
||||
|
||||
override fun initComponent() {
|
||||
}
|
||||
|
||||
override fun disposeComponent() {
|
||||
myProject = null
|
||||
}
|
||||
|
||||
override fun after(events: List<VFileEvent>) {
|
||||
if (myMuted.get()) return
|
||||
|
||||
val changedFiles = events
|
||||
.filter { it !is MyVFileContentChangeEvent && it is VFileContentChangeEvent }
|
||||
.mapNotNull { it.file }
|
||||
|
||||
val files = update(changedFiles, addToMapIfAbsent = false)
|
||||
val application = ApplicationManager.getApplication()
|
||||
refreshFiles(files, application.isUnitTestMode)
|
||||
}
|
||||
|
||||
override fun before(events: List<VFileEvent>) {
|
||||
}
|
||||
|
||||
override fun beforeRootsChange(event: ModuleRootEvent) {
|
||||
}
|
||||
|
||||
override fun rootsChanged(event: ModuleRootEvent) {
|
||||
if (myMuted.get()) return
|
||||
|
||||
ApplicationManager.getApplication().invokeLater(Runnable {
|
||||
DumbService.getInstance(myProject!!).runWhenSmart() { updateProjectLibrary() }
|
||||
}, ModalityState.NON_MODAL, myProject!!.disposed)
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public fun syncUpdateProjectLibrary(): Unit = updateProjectLibrary(true)
|
||||
|
||||
/**
|
||||
* @param synchronously may be true only in tests.
|
||||
*/
|
||||
private fun updateProjectLibrary(synchronously: Boolean = false) {
|
||||
val project = myProject
|
||||
if (project == null || project.isDisposed) return
|
||||
|
||||
ApplicationManager.getApplication().assertReadAccessAllowed()
|
||||
|
||||
for (module in ModuleManager.getInstance(project).modules) {
|
||||
if (!isModuleApplicable(module)) continue
|
||||
|
||||
if (!isJsKotlinModule(module)) {
|
||||
findLibraryByName(module, LIBRARY_NAME)?.let { resetLibraries(module, ChangesToApply(), LIBRARY_NAME, synchronously) }
|
||||
continue
|
||||
}
|
||||
|
||||
val clsRootUrls: MutableList<String> = arrayListOf()
|
||||
val srcRootUrls: MutableList<String> = arrayListOf()
|
||||
val rootFiles: MutableList<VirtualFile> = arrayListOf()
|
||||
|
||||
ModuleRootManager.getInstance(module).orderEntries().librariesOnly().forEachLibrary() { library ->
|
||||
if (KotlinJavaScriptLibraryDetectionUtil.isKotlinJavaScriptLibrary(library)) {
|
||||
var addSources = false
|
||||
for (clsRootFile in library.getFiles(OrderRootType.CLASSES)) {
|
||||
val path = PathUtil.getLocalPath(clsRootFile)
|
||||
assert(path != null) { "expected not-null path for ${clsRootFile.name}" }
|
||||
|
||||
val metadataList = KotlinJavascriptMetadataUtils.loadMetadata(path!!)
|
||||
if (metadataList.filter { !it.isAbiVersionCompatible }.isNotEmpty()) continue
|
||||
|
||||
VfsUtil.findFileByIoFile(File(path), true)?.let { rootFiles.add(it) }
|
||||
val classRoot = KotlinJavaScriptMetaFileSystem.getInstance().refreshAndFindFileByPath("$path!/")
|
||||
classRoot?.let {
|
||||
clsRootUrls.add(it.url)
|
||||
addSources = true
|
||||
}
|
||||
}
|
||||
if (addSources) {
|
||||
srcRootUrls.addAll(library.getFiles(OrderRootType.SOURCES).map { it.url })
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
val filesToRefresh = update(rootFiles, addToMapIfAbsent = true)
|
||||
|
||||
val changesToApply = ChangesToApply(clsRootUrls, srcRootUrls, filesToRefresh)
|
||||
|
||||
resetLibraries(module, changesToApply, LIBRARY_NAME, synchronously)
|
||||
}
|
||||
}
|
||||
|
||||
private fun resetLibraries(module: Module, changesToApply: ChangesToApply, libraryName: String, synchronously: Boolean) =
|
||||
applyChange(module, changesToApply, synchronously, libraryName)
|
||||
|
||||
private fun applyChange(module: Module, changesToApply: ChangesToApply, synchronously: Boolean, libraryName: String) {
|
||||
if (synchronously) {
|
||||
//for test only
|
||||
val application = ApplicationManager.getApplication()
|
||||
if (!application.isUnitTestMode) {
|
||||
throw IllegalStateException("Synchronous library update may be done only in test mode")
|
||||
}
|
||||
|
||||
val token = application.acquireWriteActionLock(KotlinJavaScriptLibraryManager::class.java)
|
||||
try {
|
||||
applyChangeImpl(module, changesToApply, libraryName)
|
||||
}
|
||||
finally {
|
||||
token.finish()
|
||||
}
|
||||
}
|
||||
else {
|
||||
val commit = Runnable { applyChangeImpl(module, changesToApply, libraryName) }
|
||||
val commitInWriteAction = Runnable { ApplicationManager.getApplication().runWriteAction(commit) }
|
||||
ApplicationManager.getApplication().invokeLater(commitInWriteAction, myProject!!.disposed)
|
||||
}
|
||||
}
|
||||
|
||||
private fun update(changedFiles: List<VirtualFile>, addToMapIfAbsent: Boolean): List<VirtualFile> {
|
||||
if (changedFiles.isEmpty()) return emptyList()
|
||||
|
||||
val files = arrayListOf<VirtualFile>()
|
||||
synchronized(libraryFileStampMap) {
|
||||
changedFiles.forEach { file ->
|
||||
PathUtil.getLocalPath(file)?.let { path ->
|
||||
val timeStamp = libraryFileStampMap.get(path)
|
||||
if (addToMapIfAbsent && timeStamp != file.timeStamp ||
|
||||
!addToMapIfAbsent && timeStamp != null) {
|
||||
libraryFileStampMap[path] = file.timeStamp
|
||||
files.add(file)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return files
|
||||
}
|
||||
|
||||
private fun refreshFiles(files: List<VirtualFile>, synchronously: Boolean) {
|
||||
val events = files.filter { !it.isDirectory && it.isValid }.map { MyVFileContentChangeEvent(it) }
|
||||
if (events.isEmpty()) return
|
||||
|
||||
val commitInWriteAction = Runnable {
|
||||
ApplicationManager.getApplication().runWriteAction() {
|
||||
val publisher = ApplicationManager.getApplication().messageBus.syncPublisher(VirtualFileManager.VFS_CHANGES)
|
||||
publisher.before(events)
|
||||
publisher.after(events)
|
||||
}
|
||||
}
|
||||
|
||||
if (synchronously) {
|
||||
commitInWriteAction.run()
|
||||
}
|
||||
else {
|
||||
ApplicationManager.getApplication().invokeLater(commitInWriteAction, myProject!!.disposed)
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun applyChangeImpl(module: Module, changesToApply: ChangesToApply, libraryName: String) {
|
||||
if (module.isDisposed) return
|
||||
|
||||
refreshFiles(changesToApply.filesToRefresh, synchronously = true)
|
||||
|
||||
val model = ModuleRootManager.getInstance(module).modifiableModel
|
||||
val libraryTableModel = model.moduleLibraryTable.modifiableModel
|
||||
|
||||
var library = findLibraryByName(libraryTableModel, libraryName)
|
||||
|
||||
if (library == null) {
|
||||
if (changesToApply.clsUrlsToAdd.isEmpty()) {
|
||||
model.dispose()
|
||||
return
|
||||
}
|
||||
|
||||
library = libraryTableModel.createLibrary(libraryName)!!
|
||||
}
|
||||
|
||||
if (changesToApply.clsUrlsToAdd.isEmpty()) {
|
||||
libraryTableModel.removeLibrary(library)
|
||||
commitLibraries(null, libraryTableModel, model)
|
||||
return
|
||||
}
|
||||
|
||||
val libraryModel = library.modifiableModel
|
||||
|
||||
val existingClsUrls = library.getUrls(OrderRootType.CLASSES).toSet()
|
||||
val existingSrcUrls = library.getUrls(OrderRootType.SOURCES).toSet()
|
||||
|
||||
if (existingClsUrls == changesToApply.clsUrlsToAdd.toSet() && existingSrcUrls == changesToApply.srcUrlsToAdd.toSet()) {
|
||||
model.dispose()
|
||||
Disposer.dispose(libraryModel)
|
||||
return
|
||||
}
|
||||
|
||||
existingClsUrls.forEach { libraryModel.removeRoot(it, OrderRootType.CLASSES) }
|
||||
existingSrcUrls.forEach { libraryModel.removeRoot(it, OrderRootType.SOURCES) }
|
||||
|
||||
changesToApply.clsUrlsToAdd.forEach { libraryModel.addRoot(it, OrderRootType.CLASSES) }
|
||||
changesToApply.srcUrlsToAdd.forEach { libraryModel.addRoot(it, OrderRootType.SOURCES) }
|
||||
|
||||
commitLibraries(libraryModel, libraryTableModel, model)
|
||||
}
|
||||
|
||||
private fun commitLibraries(libraryModel: Library.ModifiableModel?, tableModel: LibraryTable.ModifiableModel, model: ModifiableRootModel) {
|
||||
try {
|
||||
myMuted.set(true)
|
||||
libraryModel?.commit()
|
||||
tableModel.commit()
|
||||
model.commit()
|
||||
}
|
||||
finally {
|
||||
myMuted.set(false)
|
||||
}
|
||||
}
|
||||
|
||||
private fun isModuleApplicable(module: Module) = ModuleTypeId.JAVA_MODULE == ModuleType.get(module).id
|
||||
|
||||
private fun findLibraryByName(libraryTableModel: LibraryTable.ModifiableModel, libraryName: String) =
|
||||
libraryTableModel.libraries.firstOrNull { libraryName == it.name }
|
||||
|
||||
private fun findLibraryByName(module: Module, libraryName: String) =
|
||||
OrderEntryUtil.findLibraryOrderEntry(ModuleRootManager.getInstance(module), libraryName)?.library
|
||||
|
||||
private class ChangesToApply(val clsUrlsToAdd: List<String> = listOf(), val srcUrlsToAdd: List<String> = listOf(), val filesToRefresh: List<VirtualFile> = listOf())
|
||||
|
||||
private class MyVFileContentChangeEvent(
|
||||
file: VirtualFile
|
||||
) : VFileContentChangeEvent(
|
||||
FileContentUtilCore.FORCE_RELOAD_REQUESTOR,
|
||||
file,
|
||||
file.modificationStamp,
|
||||
-1, /* oldModificationStamp */
|
||||
false /* isFromRefresh */
|
||||
) {
|
||||
override fun getPath(): String = PathUtil.getLocalPath(file.path + KotlinJavaScriptMetaFileSystem.ARCHIVE_SUFFIX)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
public val LIBRARY_NAME: String = "<Kotlin JavaScript library>"
|
||||
|
||||
@JvmStatic
|
||||
public fun getInstance(project: Project): KotlinJavaScriptLibraryManager =
|
||||
project.getComponent(KotlinJavaScriptLibraryManager::class.java)!!
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.js
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.openapi.vfs.JarFileSystem
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.vfs.VirtualFileManager
|
||||
import com.intellij.openapi.vfs.newvfs.ArchiveFileSystem
|
||||
import com.intellij.openapi.vfs.newvfs.VfsImplUtil
|
||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils
|
||||
|
||||
public class KotlinJavaScriptMetaFileSystem : ArchiveFileSystem() {
|
||||
companion object {
|
||||
val ARCHIVE_SUFFIX = ".kjsm_archive"
|
||||
|
||||
@JvmStatic
|
||||
public fun getInstance(): KotlinJavaScriptMetaFileSystem = VirtualFileManager.getInstance().getFileSystem(KotlinJavascriptMetadataUtils.VFS_PROTOCOL) as KotlinJavaScriptMetaFileSystem
|
||||
}
|
||||
|
||||
override fun getProtocol(): String = KotlinJavascriptMetadataUtils.VFS_PROTOCOL
|
||||
|
||||
override fun extractRootPath(path: String): String {
|
||||
val jarSeparatorIndex = path.indexOf(JarFileSystem.JAR_SEPARATOR)
|
||||
assert(jarSeparatorIndex >= 0) { "Path passed to KotlinJavascriptMetaFileSystem must have separator '!/': $path" }
|
||||
return path.substring(0, jarSeparatorIndex + JarFileSystem.JAR_SEPARATOR.length())
|
||||
}
|
||||
|
||||
override fun getHandler(entryFile: VirtualFile): KotlinJavaScriptHandler {
|
||||
val pathToRoot = extractLocalPath(this.extractRootPath(entryFile.path)).removeSuffix()
|
||||
return VfsImplUtil.getHandler<KotlinJavaScriptHandler>(this, "$pathToRoot$ARCHIVE_SUFFIX") {
|
||||
KotlinJavaScriptHandler(it.removeSuffix())
|
||||
}
|
||||
}
|
||||
|
||||
override fun extractLocalPath(rootPath: String): String = StringUtil.trimEnd(rootPath, JarFileSystem.JAR_SEPARATOR)
|
||||
|
||||
override fun composeRootPath(localPath: String): String = localPath.removeSuffix() + JarFileSystem.JAR_SEPARATOR
|
||||
|
||||
override fun findFileByPath(path: String): VirtualFile? = VfsImplUtil.findFileByPath(this, path)
|
||||
|
||||
override fun findFileByPathIfCached(path: String): VirtualFile? = VfsImplUtil.findFileByPathIfCached(this, path)
|
||||
|
||||
override fun refreshAndFindFileByPath(path: String): VirtualFile? = VfsImplUtil.refreshAndFindFileByPath(this, path)
|
||||
|
||||
override fun refresh(asynchronous: Boolean) = VfsImplUtil.refresh(this, asynchronous)
|
||||
|
||||
private fun String.removeSuffix() = substringBeforeLast(ARCHIVE_SUFFIX)
|
||||
}
|
||||
@@ -13,6 +13,5 @@
|
||||
<orderEntry type="module" module-name="idea-analysis" />
|
||||
<orderEntry type="module" module-name="idea-core" />
|
||||
<orderEntry type="module" module-name="util" />
|
||||
<orderEntry type="module" module-name="idea-js" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -48,7 +48,6 @@
|
||||
<orderEntry type="module" module-name="idea-completion" exported="" scope="RUNTIME" />
|
||||
<orderEntry type="module" module-name="idea-test-framework" scope="TEST" />
|
||||
<orderEntry type="module" module-name="js.serializer" />
|
||||
<orderEntry type="module" module-name="idea-js" scope="TEST" />
|
||||
<orderEntry type="module" module-name="kotlinr" />
|
||||
<orderEntry type="module" module-name="idea-repl" scope="TEST" />
|
||||
<orderEntry type="module" module-name="idea-live-templates" exported="" scope="RUNTIME" />
|
||||
|
||||
@@ -28,9 +28,6 @@
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.configuration.ui.NonConfiguredKotlinProjectComponent</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.js.KotlinJavaScriptLibraryManager</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.highlighter.KotlinBeforeResolveHighlightingPass$Factory</implementation-class>
|
||||
</component>
|
||||
@@ -48,10 +45,6 @@
|
||||
<implementation-class>org.jetbrains.kotlin.idea.versions.KotlinUpdatePluginComponent</implementation-class>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<interface-class>org.jetbrains.kotlin.idea.js.KotlinJavaScriptMetaFileSystem</interface-class>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.js.KotlinJavaScriptMetaFileSystem</implementation-class>
|
||||
</component>
|
||||
</application-components>
|
||||
|
||||
<actions>
|
||||
@@ -352,7 +345,6 @@
|
||||
implementation="org.jetbrains.kotlin.idea.refactoring.introduce.introduceParameter.KotlinIntroduceParameterMethodUsageProcessor"/>
|
||||
<inlineActionHandler implementation="org.jetbrains.kotlin.idea.refactoring.inline.KotlinInlineValHandler"/>
|
||||
<treeStructureProvider implementation="org.jetbrains.kotlin.idea.projectView.KotlinProjectViewProvider" order="last" />
|
||||
<treeStructureProvider implementation="org.jetbrains.kotlin.idea.js.KotlinJavaScriptLibraryContentsTreeStructureProvider" order="last"/>
|
||||
|
||||
<colorSettingsPage implementation="org.jetbrains.kotlin.idea.highlighter.KotlinColorSettingsPage"/>
|
||||
<additionalTextAttributes scheme="Default" file="colorScheme/Default_Kotlin.xml"/>
|
||||
|
||||
Reference in New Issue
Block a user