Skip to content

Commit

Permalink
Resolve rebase conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnatBeresnev committed Oct 31, 2023
1 parent b1ae758 commit c978c5f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 303 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -285,52 +285,6 @@ class SampleAnalysisTest {
}
}

@Test
fun `should return null for existing sample when resolving with the wrong source set`() {
val testProject = mixedJvmTestProject {
dokkaConfiguration {
kotlinSourceSet {
// settings samples dir only for the kotlin source set
samples = setOf("/samples/fooSample.kt")
}
}

javaSourceSet {
// creating a file in java source set to make sure it gets created
javaFile("org/jetbrains/dokka/test/Foo.java") {
+"""
public class Foo {}
"""
}
}

sampleFile("/samples/fooSample.kt", fqPackageName = "org.jetbrains.dokka.sample") {
+"""
fun foo() {
println("foo")
}
"""
}
}

testProject.useServices { context ->
sampleAnalysisEnvironmentCreator.use {
val sampleFromJavaSourceSet = resolveSample(
sourceSet = context.defaultJavaSourceSet(),
fullyQualifiedLink = "org.jetbrains.dokka.sample.foo"
)
assertNull(sampleFromJavaSourceSet)

val sampleFromKotlinSourceSet = resolveSample(
sourceSet = context.defaultKotlinSourceSet(),
fullyQualifiedLink = "org.jetbrains.dokka.sample.foo"
)
assertNotNull(sampleFromKotlinSourceSet)
assertEquals("println(\"foo\")", sampleFromKotlinSourceSet.body)
}
}
}

@Test
fun `should return null if sample is resolved just by class name`() {
val testProject = kotlinJvmTestProject {
Expand Down Expand Up @@ -372,7 +326,7 @@ class SampleAnalysisTest {
@Test
fun `should return null if trying to resolve a non-kotlin sample link`() {
val testProject = mixedJvmTestProject {
kotlinSourceSet {
kotlinSourceDirectory {
javaFile("org/jetbrains/test/sample/JavaClass.java") {
+"""
public class JavaClass {
Expand All @@ -393,7 +347,7 @@ class SampleAnalysisTest {
val collectingLogger = CollectingDokkaConsoleLogger()
testProject.useServices(collectingLogger) { context ->
sampleAnalysisEnvironmentCreator.use {
val kotlinSourceSet = context.defaultKotlinSourceSet()
val kotlinSourceSet = context.singleSourceSet()

val byClassName = resolveSample(kotlinSourceSet, "org.jetbrains.test.sample.JavaClass")
assertNull(byClassName)
Expand Down Expand Up @@ -551,4 +505,8 @@ class SampleAnalysisTest {
""".trimIndent()
)
}

@Test
@Ignore // TODO [beresnev] should be implemented when there's api for KMP projects
fun `should return null for existing sample when resolving with the wrong source set`() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ internal object TestProjectAnalyzer {
val internalAnalysisPlugin = context.plugin<InternalKotlinAnalysisPlugin>()
return TestAnalysisServices(
sampleAnalysisEnvironmentCreator = publicAnalysisPlugin.querySingle { sampleAnalysisEnvironmentCreator },
moduleAndPackageDocumentationReader = internalAnalysisPlugin.querySingle { moduleAndPackageDocumentationReader }
moduleAndPackageDocumentationReader = internalAnalysisPlugin.querySingle {
moduleAndPackageDocumentationReader
}
)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.querySingle
import org.jetbrains.dokka.utilities.DokkaLogger
import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.codegen.optimization.common.analyze
import org.jetbrains.kotlin.psi.KtBlockExpression
import org.jetbrains.kotlin.psi.KtDeclarationWithBody
import org.jetbrains.kotlin.psi.KtFile
Expand All @@ -29,27 +30,27 @@ internal class SymbolSampleAnalysisEnvironmentCreator(
private val context: DokkaContext,
) : SampleAnalysisEnvironmentCreator {

private val symbolAnalysisPlugin = context.plugin<SymbolsAnalysisPlugin>()
private val projectKotlinAnalysis = context.plugin<SymbolsAnalysisPlugin>().querySingle { kotlinAnalysis }

override fun <T> use(block: SampleAnalysisEnvironment.() -> T): T {
return runBlocking(Dispatchers.Default) {
SamplesKotlinAnalysis(
sourceSets = context.configuration.sourceSets,
context = context,
projectKotlinAnalysis = symbolAnalysisPlugin.querySingle { kotlinAnalysis }
).use { kotlinAnalysis ->
val sampleAnalysis = SymbolSampleAnalysisEnvironment(
kotlinAnalysis = kotlinAnalysis,
sourceSets = context.configuration.sourceSets, context = context
).use { samplesKotlinAnalysis ->
val sampleAnalysisEnvironment = SymbolSampleAnalysisEnvironment(
samplesKotlinAnalysis = samplesKotlinAnalysis,
projectKotlinAnalysis = projectKotlinAnalysis,
dokkaLogger = context.logger
)
block(sampleAnalysis)
block(sampleAnalysisEnvironment)
}
}
}
}

private class SymbolSampleAnalysisEnvironment(
private val kotlinAnalysis: KotlinAnalysis,
private val samplesKotlinAnalysis: KotlinAnalysis,
private val projectKotlinAnalysis: KotlinAnalysis,
private val dokkaLogger: DokkaLogger,
) : SampleAnalysisEnvironment {

Expand All @@ -76,8 +77,10 @@ private class SymbolSampleAnalysisEnvironment(
}

private fun findPsiElement(sourceSet: DokkaSourceSet, fqLink: String): PsiElement? {
val analysisContext = kotlinAnalysis[sourceSet]
return analyze(analysisContext.mainModule) {
val ktSourceModule = samplesKotlinAnalysis.getModuleOrNull(sourceSet)
?: projectKotlinAnalysis.getModule(sourceSet)

return analyze(ktSourceModule) {
resolveKDocTextLinkSymbol(fqLink)?.psi
}
}
Expand Down

0 comments on commit c978c5f

Please sign in to comment.