Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vmishenev committed Aug 18, 2023
1 parent 61e0309 commit 9e65b29
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class KotlinArrayDocumentableReplacerTest : BaseAbstractTest() {
}
sourceSet {
sourceRoots = listOf("src/main/kotlin/basic/TestJS.kt")
analysisPlatform = "jvm"
analysisPlatform = "js"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class DescriptorSuperPropertiesTest : BaseAbstractTest() {
}
}

// protected is publicAPI
// incorrect test https://github.com/Kotlin/dokka/issues/3128
@Test
fun `kotlin inheriting java should not append anything since field is public api`() {
val configuration = dokkaConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ class ObviousAndInheritedFunctionsDocumentableFilterTest : BaseAbstractTest() {
}
}

@JavaCode
@ParameterizedTest
@MethodSource(value = ["nonSuppressingObviousConfiguration", "nonSuppressingInheritedConfiguration"])
@JavaCode
fun `should not suppress toString, equals and hashcode if custom config is provided in Java`(nonSuppressingConfiguration: DokkaConfigurationImpl) {
testInline(
"""
Expand Down
2 changes: 2 additions & 0 deletions plugins/base/src/test/kotlin/utils/TagsAnnotations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ annotation class OnlyDescriptorsMPP(val reason: String = "")

/**
* For test containing .java code
* These tests are disabled in K2 due to Standlone prototype. https://github.com/Kotlin/dokka/issues/3114
*/
@Target(
AnnotationTarget.CLASS,
Expand All @@ -55,6 +56,7 @@ annotation class JavaCode

/**
* For test using JDK
* These tests are disabled in K2 due to Standlone prototype. https://github.com/Kotlin/dokka/issues/3114
*/
@Target(
AnnotationTarget.CLASS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ internal class DefaultPsiToDocumentableTranslator : AsyncSourceToDocumentableTra
val projectProvider = context.plugin<JavaAnalysisPlugin>().querySingle { projectProvider }
val project = projectProvider.getProject(sourceSet, context)

val sourceRoots = sourceSet.sourceRoots.filter { directory -> directory.isDirectory || directory.extension == "java" }
val sourceRootsExtractor = context.plugin<JavaAnalysisPlugin>().querySingle { sourceRootsExtractor }
val sourceRoots = sourceRootsExtractor.extract(sourceSet, context)

val localFileSystem = VirtualFileManager.getInstance().getFileSystem("file")

Expand Down
4 changes: 0 additions & 4 deletions subprojects/analysis-kotlin-symbols/ide/api/ide.api

This file was deleted.

13 changes: 0 additions & 13 deletions subprojects/analysis-kotlin-symbols/ide/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

5 changes: 5 additions & 0 deletions subprojects/analysis-kotlin-symbols/plugin/api/plugin.api
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public final class org/jetbrains/dokka/analysis/kotlin/symbols/plugin/SymbolsAna
public final fun getSymbolToDocumentableTranslator ()Lorg/jetbrains/dokka/plugability/Extension;
}

public final class org/jetbrains/dokka/analysis/kotlin/symbols/services/KotlinAnalysisSourceRootsExtractor : org/jetbrains/dokka/analysis/java/SourceRootsExtractor {
public fun <init> ()V
public fun extract (Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;Lorg/jetbrains/dokka/plugability/DokkaContext;)Ljava/util/List;
}

public class org/jetbrains/dokka/analysis/kotlin/symbols/services/KotlinSampleProvider : org/jetbrains/dokka/analysis/kotlin/internal/SampleProvider {
public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V
public fun close ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,98 +40,6 @@ internal fun Platform.toTargetPlatform() = when (this) {
Platform.jvm -> JvmPlatforms.defaultJvmPlatform
}

/**
* Collect source file path from the given [root] store them in [result].
*
* E.g., for `project/app/src` as a [root], this will walk the file tree and
* collect all `.kt` and `.java` files under that folder.
*
* Note that this util gracefully skips [IOException] during file tree traversal.
*/
internal fun collectSourceFilePaths(
root: Path,
result: MutableSet<String>
) {
// NB: [Files#walk] throws an exception if there is an issue during IO.
// With [Files#walkFileTree] with a custom visitor, we can take control of exception handling.
Files.walkFileTree(
root,
object : SimpleFileVisitor<Path>() {
override fun preVisitDirectory(dir: Path, attrs: BasicFileAttributes): FileVisitResult {
return if (Files.isReadable(dir))
FileVisitResult.CONTINUE
else
FileVisitResult.SKIP_SUBTREE
}

override fun visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult {
if (!Files.isRegularFile(file) || !Files.isReadable(file))
return FileVisitResult.CONTINUE
val ext = file.toFile().extension
if (ext == KotlinFileType.EXTENSION || ext == "java"/*JavaFileType.DEFAULT_EXTENSION*/) {
result.add(file.toString())
}
return FileVisitResult.CONTINUE
}

override fun visitFileFailed(file: Path, exc: IOException?): FileVisitResult {
// TODO: report or log [IOException]?
// NB: this intentionally swallows the exception, hence fail-safe.
// Skipping subtree doesn't make any sense, since this is not a directory.
// Skipping sibling may drop valid file paths afterward, so we just continue.
return FileVisitResult.CONTINUE
}
}
)
}

/**
* Collect source file path as [String] from the given source roots in [sourceRoot].
*
* this util collects all `.kt` and `.java` files under source roots.
*/
internal fun getSourceFilePaths(
sourceRoot: Collection<String>,
includeDirectoryRoot: Boolean = false,
): Set<String> {
val result = mutableSetOf<String>()
sourceRoot.forEach { srcRoot ->
val path = Paths.get(srcRoot)
if (Files.isDirectory(path)) {
// E.g., project/app/src
collectSourceFilePaths(path, result)
if (includeDirectoryRoot) {
result.add(srcRoot)
}
} else {
// E.g., project/app/src/some/pkg/main.kt
result.add(srcRoot)
}
}

return result
}

internal inline fun <reified T : PsiFileSystemItem> getPsiFilesFromPaths(
project: Project,
paths: Collection<String>,
): List<T> {
val fs = StandardFileSystems.local()
val psiManager = PsiManager.getInstance(project)
val result = mutableListOf<T>()
for (path in paths) {
val vFile = fs.findFileByPath(path) ?: continue
val psiFileSystemItem =
if (vFile.isDirectory)
psiManager.findDirectory(vFile) as? T
else
psiManager.findFile(vFile) as? T
psiFileSystemItem?.let { result.add(it) }
}
return result
}


private fun getJdkHomeFromSystemProperty(): File? {
val javaHome = File(System.getProperty("java.home"))
if (!javaHome.exists()) {
Expand All @@ -158,7 +66,7 @@ internal fun getLanguageVersionSettings(
)
}


// it should be changed after https://github.com/Kotlin/dokka/issues/3114
internal fun createAnalysisSession(
classpath: List<File>,
sourceRoots: Set<File>,
Expand Down Expand Up @@ -243,3 +151,95 @@ internal fun createAnalysisSession(
)
return Pair(analysisSession, sourceModule ?: throw IllegalStateException())
}

// ----------- copy-paste from Analysis API ----------------------------------------------------------------------------
/**
* Collect source file path from the given [root] store them in [result].
*
* E.g., for `project/app/src` as a [root], this will walk the file tree and
* collect all `.kt` and `.java` files under that folder.
*
* Note that this util gracefully skips [IOException] during file tree traversal.
*/
internal fun collectSourceFilePaths(
root: Path,
result: MutableSet<String>
) {
// NB: [Files#walk] throws an exception if there is an issue during IO.
// With [Files#walkFileTree] with a custom visitor, we can take control of exception handling.
Files.walkFileTree(
root,
object : SimpleFileVisitor<Path>() {
override fun preVisitDirectory(dir: Path, attrs: BasicFileAttributes): FileVisitResult {
return if (Files.isReadable(dir))
FileVisitResult.CONTINUE
else
FileVisitResult.SKIP_SUBTREE
}

override fun visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult {
if (!Files.isRegularFile(file) || !Files.isReadable(file))
return FileVisitResult.CONTINUE
val ext = file.toFile().extension
if (ext == KotlinFileType.EXTENSION || ext == "java"/*JavaFileType.DEFAULT_EXTENSION*/) {
result.add(file.toString())
}
return FileVisitResult.CONTINUE
}

override fun visitFileFailed(file: Path, exc: IOException?): FileVisitResult {
// TODO: report or log [IOException]?
// NB: this intentionally swallows the exception, hence fail-safe.
// Skipping subtree doesn't make any sense, since this is not a directory.
// Skipping sibling may drop valid file paths afterward, so we just continue.
return FileVisitResult.CONTINUE
}
}
)
}

/**
* Collect source file path as [String] from the given source roots in [sourceRoot].
*
* this util collects all `.kt` and `.java` files under source roots.
*/
internal fun getSourceFilePaths(
sourceRoot: Collection<String>,
includeDirectoryRoot: Boolean = false,
): Set<String> {
val result = mutableSetOf<String>()
sourceRoot.forEach { srcRoot ->
val path = Paths.get(srcRoot)
if (Files.isDirectory(path)) {
// E.g., project/app/src
collectSourceFilePaths(path, result)
if (includeDirectoryRoot) {
result.add(srcRoot)
}
} else {
// E.g., project/app/src/some/pkg/main.kt
result.add(srcRoot)
}
}

return result
}

internal inline fun <reified T : PsiFileSystemItem> getPsiFilesFromPaths(
project: Project,
paths: Collection<String>,
): List<T> {
val fs = StandardFileSystems.local()
val psiManager = PsiManager.getInstance(project)
val result = mutableListOf<T>()
for (path in paths) {
val vFile = fs.findFileByPath(path) ?: continue
val psiFileSystemItem =
if (vFile.isDirectory)
psiManager.findDirectory(vFile) as? T
else
psiManager.findFile(vFile) as? T
psiFileSystemItem?.let { result.add(it) }
}
return result
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.jetbrains.dokka.analysis.kotlin.symbols.kdoc.java.KotlinInheritDocTag
import org.jetbrains.dokka.analysis.kotlin.symbols.kdoc.java.DescriptorKotlinDocCommentCreator
import org.jetbrains.dokka.analysis.kotlin.symbols.kdoc.java.KotlinDocCommentParser
import org.jetbrains.dokka.analysis.kotlin.symbols.kdoc.moduledocs.ModuleAndPackageDocumentationReader
import org.jetbrains.dokka.analysis.kotlin.symbols.services.KotlinAnalysisSourceRootsExtractor
import org.jetbrains.dokka.analysis.kotlin.symbols.services.*
import org.jetbrains.dokka.analysis.kotlin.symbols.services.KotlinDocumentableSourceLanguageParser
import org.jetbrains.dokka.analysis.kotlin.symbols.services.SymbolExternalDocumentablesProvider
Expand Down Expand Up @@ -116,6 +117,10 @@ class SymbolsAnalysisPlugin : DokkaPlugin() {
plugin<InternalKotlinAnalysisPlugin>().sampleProviderFactory providing ::KotlinSampleProviderFactory
}

internal val sourceRootsExtractor by extending {
javaAnalysisPlugin.sourceRootsExtractor providing { KotlinAnalysisSourceRootsExtractor() }
}

@OptIn(DokkaPluginApiPreview::class)
override fun pluginApiPreviewAcknowledgement(): PluginApiPreviewAcknowledgement = PluginApiPreviewAcknowledgement
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.jetbrains.dokka.analysis.kotlin.symbols.services

import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.analysis.java.SourceRootsExtractor
import org.jetbrains.dokka.plugability.DokkaContext
import java.io.File

class KotlinAnalysisSourceRootsExtractor : SourceRootsExtractor {
override fun extract(sourceSet: DokkaConfiguration.DokkaSourceSet, context: DokkaContext): List<File> {
return sourceSet.sourceRoots.filter { directory -> directory.isDirectory || directory.extension == "java" }
}
}

0 comments on commit 9e65b29

Please sign in to comment.