• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.jetbrains.dokka
2 
3 import com.intellij.openapi.Disposable
4 import com.intellij.openapi.components.BaseComponent
5 import com.intellij.openapi.extensions.ExtensionPointName
6 import com.intellij.openapi.module.Module
7 import com.intellij.openapi.project.Project
8 import com.intellij.openapi.projectRoots.Sdk
9 import com.intellij.openapi.projectRoots.SdkAdditionalData
10 import com.intellij.openapi.projectRoots.SdkModificator
11 import com.intellij.openapi.projectRoots.SdkTypeId
12 import com.intellij.openapi.roots.*
13 import com.intellij.openapi.roots.impl.ProjectOrderEnumerator
14 import com.intellij.openapi.util.Condition
15 import com.intellij.openapi.util.Key
16 import com.intellij.openapi.util.UserDataHolderBase
17 import com.intellij.openapi.vfs.StandardFileSystems
18 import com.intellij.openapi.vfs.VfsUtilCore.getVirtualFileForJar
19 import com.intellij.openapi.vfs.VirtualFile
20 import com.intellij.openapi.vfs.VirtualFileFilter
21 import com.intellij.psi.search.GlobalSearchScope
22 import com.intellij.util.messages.MessageBus
23 import org.jetbrains.jps.model.module.JpsModuleSourceRootType
24 import org.jetbrains.kotlin.cli.common.config.ContentRoot
25 import org.jetbrains.kotlin.cli.common.config.KotlinSourceRoot
26 import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot
27 import org.jetbrains.kotlin.cli.jvm.config.JvmContentRoot
28 import org.picocontainer.PicoContainer
29 import java.io.File
30 
31 /**
32  * Workaround for the lack of ability to create a ProjectFileIndex implementation using only
33  * classes from projectModel-{api,impl}.
34  */
35 class CoreProjectFileIndex(private val project: Project, contentRoots: List<ContentRoot>) : ProjectFileIndex, ModuleFileIndex {
iterateContentnull36     override fun iterateContent(p0: ContentIterator, p1: VirtualFileFilter?): Boolean {
37         throw UnsupportedOperationException()
38     }
39 
iterateContentUnderDirectorynull40     override fun iterateContentUnderDirectory(p0: VirtualFile, p1: ContentIterator, p2: VirtualFileFilter?): Boolean {
41         throw UnsupportedOperationException()
42     }
43 
isInLibrarynull44     override fun isInLibrary(p0: VirtualFile): Boolean {
45         throw UnsupportedOperationException()
46     }
47 
<lambda>null48     val sourceRoots = contentRoots.filter { it !is JvmClasspathRoot }
49     val classpathRoots = contentRoots.filterIsInstance<JvmClasspathRoot>()
50 
51     val module: Module = object : UserDataHolderBase(), Module {
isDisposednull52         override fun isDisposed(): Boolean {
53             throw UnsupportedOperationException()
54         }
55 
getOptionValuenull56         override fun getOptionValue(p0: String): String? {
57             throw UnsupportedOperationException()
58         }
59 
clearOptionnull60         override fun clearOption(p0: String) {
61             throw UnsupportedOperationException()
62         }
63 
getNamenull64         override fun getName(): String = "<Dokka module>"
65 
66         override fun getModuleWithLibrariesScope(): GlobalSearchScope {
67             throw UnsupportedOperationException()
68         }
69 
getModuleWithDependentsScopenull70         override fun getModuleWithDependentsScope(): GlobalSearchScope {
71             throw UnsupportedOperationException()
72         }
73 
getModuleContentScopenull74         override fun getModuleContentScope(): GlobalSearchScope {
75             throw UnsupportedOperationException()
76         }
77 
isLoadednull78         override fun isLoaded(): Boolean {
79             throw UnsupportedOperationException()
80         }
81 
setOptionnull82         override fun setOption(p0: String, p1: String?) {
83             throw UnsupportedOperationException()
84         }
85 
getModuleWithDependenciesScopenull86         override fun getModuleWithDependenciesScope(): GlobalSearchScope {
87             throw UnsupportedOperationException()
88         }
89 
getModuleWithDependenciesAndLibrariesScopenull90         override fun getModuleWithDependenciesAndLibrariesScope(p0: Boolean): GlobalSearchScope {
91             throw UnsupportedOperationException()
92         }
93 
getProjectnull94         override fun getProject(): Project = this@CoreProjectFileIndex.project
95 
96         override fun getModuleContentWithDependenciesScope(): GlobalSearchScope {
97             throw UnsupportedOperationException()
98         }
99 
getModuleFilePathnull100         override fun getModuleFilePath(): String {
101             throw UnsupportedOperationException()
102         }
103 
getModuleTestsWithDependentsScopenull104         override fun getModuleTestsWithDependentsScope(): GlobalSearchScope {
105             throw UnsupportedOperationException()
106         }
107 
getModuleScopenull108         override fun getModuleScope(): GlobalSearchScope {
109             throw UnsupportedOperationException()
110         }
111 
getModuleScopenull112         override fun getModuleScope(p0: Boolean): GlobalSearchScope {
113             throw UnsupportedOperationException()
114         }
115 
getModuleRuntimeScopenull116         override fun getModuleRuntimeScope(p0: Boolean): GlobalSearchScope {
117             throw UnsupportedOperationException()
118         }
119 
getModuleFilenull120         override fun getModuleFile(): VirtualFile? {
121             throw UnsupportedOperationException()
122         }
123 
getExtensionsnull124         override fun <T : Any?> getExtensions(p0: ExtensionPointName<T>): Array<out T> {
125             throw UnsupportedOperationException()
126         }
127 
getComponentnull128         override fun getComponent(p0: String): BaseComponent? {
129             throw UnsupportedOperationException()
130         }
131 
getComponentnull132         override fun <T : Any?> getComponent(p0: Class<T>, p1: T): T {
133             throw UnsupportedOperationException()
134         }
135 
getComponentnull136         override fun <T : Any?> getComponent(interfaceClass: Class<T>): T? {
137             if (interfaceClass == ModuleRootManager::class.java) {
138                 return moduleRootManager as T
139             }
140             throw UnsupportedOperationException()
141         }
142 
getDisposednull143         override fun getDisposed(): Condition<*> {
144             throw UnsupportedOperationException()
145         }
146 
getComponentsnull147         override fun <T : Any?> getComponents(p0: Class<T>): Array<out T> {
148             throw UnsupportedOperationException()
149         }
150 
getPicoContainernull151         override fun getPicoContainer(): PicoContainer {
152             throw UnsupportedOperationException()
153         }
154 
hasComponentnull155         override fun hasComponent(p0: Class<*>): Boolean {
156             throw UnsupportedOperationException()
157         }
158 
getMessageBusnull159         override fun getMessageBus(): MessageBus {
160             throw UnsupportedOperationException()
161         }
162 
disposenull163         override fun dispose() {
164             throw UnsupportedOperationException()
165         }
166     }
167 
168     private val sdk: Sdk = object : Sdk, RootProvider {
getFilesnull169         override fun getFiles(rootType: OrderRootType): Array<out VirtualFile> = classpathRoots
170             .mapNotNull { StandardFileSystems.local().findFileByPath(it.file.path) }
171             .toTypedArray()
172 
addRootSetChangedListenernull173         override fun addRootSetChangedListener(p0: RootProvider.RootSetChangedListener) {
174             throw UnsupportedOperationException()
175         }
176 
addRootSetChangedListenernull177         override fun addRootSetChangedListener(p0: RootProvider.RootSetChangedListener, p1: Disposable) {
178             throw UnsupportedOperationException()
179         }
180 
getUrlsnull181         override fun getUrls(p0: OrderRootType): Array<out String> {
182             throw UnsupportedOperationException()
183         }
184 
removeRootSetChangedListenernull185         override fun removeRootSetChangedListener(p0: RootProvider.RootSetChangedListener) {
186             throw UnsupportedOperationException()
187         }
188 
getSdkModificatornull189         override fun getSdkModificator(): SdkModificator {
190             throw UnsupportedOperationException()
191         }
192 
getNamenull193         override fun getName(): String = "<dokka SDK>"
194 
195         override fun getRootProvider(): RootProvider = this
196 
197         override fun getHomePath(): String? {
198             throw UnsupportedOperationException()
199         }
200 
getVersionStringnull201         override fun getVersionString(): String? {
202             throw UnsupportedOperationException()
203         }
204 
getSdkAdditionalDatanull205         override fun getSdkAdditionalData(): SdkAdditionalData? {
206             throw UnsupportedOperationException()
207         }
208 
clonenull209         override fun clone(): Any {
210             throw UnsupportedOperationException()
211         }
212 
getSdkTypenull213         override fun getSdkType(): SdkTypeId {
214             throw UnsupportedOperationException()
215         }
216 
getHomeDirectorynull217         override fun getHomeDirectory(): VirtualFile? {
218             throw UnsupportedOperationException()
219         }
220 
getUserDatanull221         override fun <T : Any?> getUserData(p0: Key<T>): T? {
222             throw UnsupportedOperationException()
223         }
224 
putUserDatanull225         override fun <T : Any?> putUserData(p0: Key<T>, p1: T?) {
226             throw UnsupportedOperationException()
227         }
228     }
229 
230     private val moduleSourceOrderEntry = object : ModuleSourceOrderEntry {
getFilesnull231         override fun getFiles(p0: OrderRootType): Array<VirtualFile> {
232             throw UnsupportedOperationException()
233         }
234 
getUrlsnull235         override fun getUrls(p0: OrderRootType): Array<String> {
236             throw UnsupportedOperationException()
237         }
238 
acceptnull239         override fun <R : Any?> accept(p0: RootPolicy<R>, p1: R?): R {
240             throw UnsupportedOperationException()
241         }
242 
243 
getPresentableNamenull244         override fun getPresentableName(): String {
245             throw UnsupportedOperationException()
246         }
247 
getOwnerModulenull248         override fun getOwnerModule(): Module = module
249 
250 
251         override fun isValid(): Boolean {
252             throw UnsupportedOperationException()
253         }
254 
compareTonull255         override fun compareTo(other: OrderEntry?): Int {
256             throw UnsupportedOperationException()
257         }
258 
getRootModelnull259         override fun getRootModel(): ModuleRootModel = moduleRootManager
260 
261         override fun isSynthetic(): Boolean {
262             throw UnsupportedOperationException()
263         }
264     }
265 
266     private val sdkOrderEntry = object : JdkOrderEntry {
getFilesnull267         override fun getFiles(p0: OrderRootType): Array<VirtualFile> {
268             throw UnsupportedOperationException()
269         }
270 
getUrlsnull271         override fun getUrls(p0: OrderRootType): Array<String> {
272             throw UnsupportedOperationException()
273         }
274 
acceptnull275         override fun <R : Any?> accept(p0: RootPolicy<R>, p1: R?): R {
276             throw UnsupportedOperationException()
277         }
278 
getJdkNamenull279         override fun getJdkName(): String? {
280             throw UnsupportedOperationException()
281         }
282 
getJdknull283         override fun getJdk(): Sdk = sdk
284 
285         override fun getPresentableName(): String {
286             throw UnsupportedOperationException()
287         }
288 
getOwnerModulenull289         override fun getOwnerModule(): Module {
290             throw UnsupportedOperationException()
291         }
292 
isValidnull293         override fun isValid(): Boolean {
294             throw UnsupportedOperationException()
295         }
296 
getRootFilesnull297         override fun getRootFiles(p0: OrderRootType): Array<out VirtualFile> {
298             throw UnsupportedOperationException()
299         }
300 
getRootUrlsnull301         override fun getRootUrls(p0: OrderRootType): Array<out String> {
302             throw UnsupportedOperationException()
303         }
304 
compareTonull305         override fun compareTo(other: OrderEntry?): Int {
306             throw UnsupportedOperationException()
307         }
308 
isSyntheticnull309         override fun isSynthetic(): Boolean {
310             throw UnsupportedOperationException()
311         }
312 
313     }
314 
315     inner class MyModuleRootManager : ModuleRootManager() {
getExternalSourcenull316         override fun getExternalSource(): ProjectModelExternalSource? {
317             throw UnsupportedOperationException()
318         }
319 
getExcludeRootsnull320         override fun getExcludeRoots(): Array<out VirtualFile> {
321             throw UnsupportedOperationException()
322         }
323 
getContentEntriesnull324         override fun getContentEntries(): Array<out ContentEntry> {
325             throw UnsupportedOperationException()
326         }
327 
getExcludeRootUrlsnull328         override fun getExcludeRootUrls(): Array<out String> {
329             throw UnsupportedOperationException()
330         }
331 
processOrdernull332         override fun <R : Any?> processOrder(p0: RootPolicy<R>, p1: R): R {
333             throw UnsupportedOperationException()
334         }
335 
getSourceRootsnull336         override fun getSourceRoots(p0: Boolean): Array<out VirtualFile> {
337             throw UnsupportedOperationException()
338         }
339 
getSourceRootsnull340         override fun getSourceRoots(): Array<out VirtualFile> {
341             throw UnsupportedOperationException()
342         }
343 
getSourceRootsnull344         override fun getSourceRoots(p0: JpsModuleSourceRootType<*>): MutableList<VirtualFile> {
345             throw UnsupportedOperationException()
346         }
347 
getSourceRootsnull348         override fun getSourceRoots(p0: MutableSet<out JpsModuleSourceRootType<*>>): MutableList<VirtualFile> {
349             throw UnsupportedOperationException()
350         }
351 
getContentRootsnull352         override fun getContentRoots(): Array<out VirtualFile> {
353             throw UnsupportedOperationException()
354         }
355 
orderEntriesnull356         override fun orderEntries(): OrderEnumerator =
357             ProjectOrderEnumerator(project, null).using(object : RootModelProvider {
358                 override fun getModules(): Array<out Module> = arrayOf(module)
359 
360                 override fun getRootModel(p0: Module): ModuleRootModel = this@MyModuleRootManager
361             })
362 
getModuleExtensionnull363         override fun <T : Any?> getModuleExtension(p0: Class<T>): T {
364             throw UnsupportedOperationException()
365         }
366 
getDependencyModuleNamesnull367         override fun getDependencyModuleNames(): Array<out String> {
368             throw UnsupportedOperationException()
369         }
370 
getModulenull371         override fun getModule(): Module = this@CoreProjectFileIndex.module
372 
373         override fun isSdkInherited(): Boolean {
374             throw UnsupportedOperationException()
375         }
376 
getOrderEntriesnull377         override fun getOrderEntries(): Array<out OrderEntry> = arrayOf(moduleSourceOrderEntry, sdkOrderEntry)
378 
379         override fun getSourceRootUrls(): Array<out String> {
380             throw UnsupportedOperationException()
381         }
382 
getSourceRootUrlsnull383         override fun getSourceRootUrls(p0: Boolean): Array<out String> {
384             throw UnsupportedOperationException()
385         }
386 
getSdknull387         override fun getSdk(): Sdk? {
388             throw UnsupportedOperationException()
389         }
390 
getContentRootUrlsnull391         override fun getContentRootUrls(): Array<out String> {
392             throw UnsupportedOperationException()
393         }
394 
getModuleDependenciesnull395         override fun getModuleDependencies(): Array<out Module> {
396             throw UnsupportedOperationException()
397         }
398 
getModuleDependenciesnull399         override fun getModuleDependencies(p0: Boolean): Array<out Module> {
400             throw UnsupportedOperationException()
401         }
402 
getModifiableModelnull403         override fun getModifiableModel(): ModifiableRootModel {
404             throw UnsupportedOperationException()
405         }
406 
isDependsOnnull407         override fun isDependsOn(p0: Module): Boolean {
408             throw UnsupportedOperationException()
409         }
410 
getFileIndexnull411         override fun getFileIndex(): ModuleFileIndex {
412             return this@CoreProjectFileIndex
413         }
414 
getDependenciesnull415         override fun getDependencies(): Array<out Module> {
416             throw UnsupportedOperationException()
417         }
418 
getDependenciesnull419         override fun getDependencies(p0: Boolean): Array<out Module> {
420             throw UnsupportedOperationException()
421         }
422     }
423 
424     val moduleRootManager = MyModuleRootManager()
425 
getContentRootForFilenull426     override fun getContentRootForFile(p0: VirtualFile): VirtualFile? {
427         throw UnsupportedOperationException()
428     }
429 
getContentRootForFilenull430     override fun getContentRootForFile(p0: VirtualFile, p1: Boolean): VirtualFile? {
431         throw UnsupportedOperationException()
432     }
433 
getPackageNameByDirectorynull434     override fun getPackageNameByDirectory(p0: VirtualFile): String? {
435         throw UnsupportedOperationException()
436     }
437 
isInLibrarySourcenull438     override fun isInLibrarySource(file: VirtualFile): Boolean = false
439 
440     override fun getClassRootForFile(file: VirtualFile): VirtualFile? =
441         classpathRoots.firstOrNull { it.contains(file) }?.let { StandardFileSystems.local().findFileByPath(it.file.path) }
442 
getOrderEntriesForFilenull443     override fun getOrderEntriesForFile(file: VirtualFile): List<OrderEntry> =
444         if (classpathRoots.contains(file)) listOf(sdkOrderEntry) else emptyList()
445 
446     override fun isInLibraryClasses(file: VirtualFile): Boolean = classpathRoots.contains(file)
447 
448     override fun isExcluded(p0: VirtualFile): Boolean {
449         throw UnsupportedOperationException()
450     }
451 
getSourceRootForFilenull452     override fun getSourceRootForFile(p0: VirtualFile): VirtualFile? {
453         throw UnsupportedOperationException()
454     }
455 
isUnderIgnorednull456     override fun isUnderIgnored(p0: VirtualFile): Boolean {
457         throw UnsupportedOperationException()
458     }
459 
isLibraryClassFilenull460     override fun isLibraryClassFile(p0: VirtualFile): Boolean {
461         throw UnsupportedOperationException()
462     }
463 
getModuleForFilenull464     override fun getModuleForFile(file: VirtualFile): Module? =
465         if (sourceRoots.contains(file)) module else null
466 
467     private fun List<ContentRoot>.contains(file: VirtualFile): Boolean = any { it.contains(file) }
468 
getModuleForFilenull469     override fun getModuleForFile(p0: VirtualFile, p1: Boolean): Module? {
470         throw UnsupportedOperationException()
471     }
472 
isInSourcenull473     override fun isInSource(p0: VirtualFile): Boolean {
474         throw UnsupportedOperationException()
475     }
476 
isIgnorednull477     override fun isIgnored(p0: VirtualFile): Boolean {
478         throw UnsupportedOperationException()
479     }
480 
isContentSourceFilenull481     override fun isContentSourceFile(p0: VirtualFile): Boolean {
482         throw UnsupportedOperationException()
483     }
484 
isInSourceContentnull485     override fun isInSourceContent(file: VirtualFile): Boolean = sourceRoots.contains(file)
486 
487     override fun iterateContent(p0: ContentIterator): Boolean {
488         throw UnsupportedOperationException()
489     }
490 
isInContentnull491     override fun isInContent(p0: VirtualFile): Boolean {
492         throw UnsupportedOperationException()
493     }
494 
iterateContentUnderDirectorynull495     override fun iterateContentUnderDirectory(p0: VirtualFile, p1: ContentIterator): Boolean {
496         throw UnsupportedOperationException()
497     }
498 
isInTestSourceContentnull499     override fun isInTestSourceContent(file: VirtualFile): Boolean = false
500 
501     override fun isUnderSourceRootOfType(p0: VirtualFile, p1: MutableSet<out JpsModuleSourceRootType<*>>): Boolean {
502         throw UnsupportedOperationException()
503     }
504 
getOrderEntryForFilenull505     override fun getOrderEntryForFile(p0: VirtualFile): OrderEntry? {
506         throw UnsupportedOperationException()
507     }
508 }
509 
510 class CoreProjectRootManager(val projectFileIndex: CoreProjectFileIndex) : ProjectRootManager() {
orderEntriesnull511     override fun orderEntries(): OrderEnumerator {
512         throw UnsupportedOperationException()
513     }
514 
orderEntriesnull515     override fun orderEntries(p0: MutableCollection<out Module>): OrderEnumerator {
516         throw UnsupportedOperationException()
517     }
518 
getContentRootsFromAllModulesnull519     override fun getContentRootsFromAllModules(): Array<out VirtualFile> {
520         throw UnsupportedOperationException()
521     }
522 
setProjectSdknull523     override fun setProjectSdk(p0: Sdk?) {
524         throw UnsupportedOperationException()
525     }
526 
setProjectSdkNamenull527     override fun setProjectSdkName(p0: String) {
528         throw UnsupportedOperationException()
529     }
530 
getModuleSourceRootsnull531     override fun getModuleSourceRoots(p0: MutableSet<out JpsModuleSourceRootType<*>>): MutableList<VirtualFile> {
532         throw UnsupportedOperationException()
533     }
534 
getContentSourceRootsnull535     override fun getContentSourceRoots(): Array<out VirtualFile> {
536         throw UnsupportedOperationException()
537     }
538 
getFileIndexnull539     override fun getFileIndex(): ProjectFileIndex = projectFileIndex
540 
541     override fun getProjectSdkName(): String? {
542         throw UnsupportedOperationException()
543     }
544 
getProjectSdknull545     override fun getProjectSdk(): Sdk? {
546         throw UnsupportedOperationException()
547     }
548 
getContentRootsnull549     override fun getContentRoots(): Array<out VirtualFile> {
550         throw UnsupportedOperationException()
551     }
552 
getContentRootUrlsnull553     override fun getContentRootUrls(): MutableList<String> {
554         throw UnsupportedOperationException()
555     }
556 
557 }
558 
containsnull559 fun ContentRoot.contains(file: VirtualFile) = when (this) {
560     is JvmContentRoot -> {
561         val path = if (file.fileSystem.protocol == StandardFileSystems.JAR_PROTOCOL)
562             getVirtualFileForJar(file)?.path ?: file.path
563         else
564             file.path
565         File(path).startsWith(this.file.absoluteFile)
566     }
567     is KotlinSourceRoot -> File(file.path).startsWith(File(this.path).absoluteFile)
568     else -> false
569 }