Skip to content

Commit

Permalink
Fix some review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vmishenev committed Aug 11, 2023
1 parent 053e106 commit 957bc34
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package org.jetbrains.dokka.analysis.kotlin.symbols.kdoc.moduledocs

import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.analysis.kotlin.symbols.plugin.KotlinAnalysis
import org.jetbrains.dokka.analysis.kotlin.symbols.plugin.getPsiFilesFromPaths
import org.jetbrains.dokka.analysis.kotlin.symbols.plugin.getSourceFilePaths
import org.jetbrains.dokka.analysis.kotlin.symbols.kdoc.moduledocs.ModuleAndPackageDocumentation.Classifier.Module
import org.jetbrains.dokka.analysis.kotlin.symbols.kdoc.moduledocs.ModuleAndPackageDocumentation.Classifier.Package
import org.jetbrains.dokka.analysis.kotlin.symbols.kdoc.resolveKDocLink
Expand All @@ -12,10 +10,7 @@ import org.jetbrains.dokka.analysis.markdown.jb.MarkdownParser
import org.jetbrains.dokka.model.doc.DocumentationNode
import org.jetbrains.dokka.utilities.DokkaLogger
import org.jetbrains.kotlin.analysis.api.analyze

import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtFile

internal fun interface ModuleAndPackageDocumentationParsingContext {
fun markdownParserFor(fragment: ModuleAndPackageDocumentationFragment, location: String): MarkdownParser
Expand All @@ -39,7 +34,7 @@ internal fun ModuleAndPackageDocumentationParsingContext(
val analysisContext = kotlinAnalysis[sourceSet]
analyze(analysisContext.mainModule) {
val contextSymbol = when (fragment.classifier) {
Module -> getPackageSymbolIfPackageExists(FqName.topLevel(Name.identifier("")))
Module -> ROOT_PACKAGE_SYMBOL
Package -> getPackageSymbolIfPackageExists(FqName(fragment.name))
}

Expand All @@ -58,13 +53,3 @@ internal fun ModuleAndPackageDocumentationParsingContext(
}
}
}
/*
private fun Collection<DeclarationDescriptor>.sorted() = sortedWith(
compareBy(
{ it is ClassDescriptor },
{ (it as? FunctionDescriptor)?.name },
{ (it as? FunctionDescriptor)?.valueParameters?.size },
{ (it as? FunctionDescriptor)?.valueParameters?.joinToString { it.type.toString() } }
)
)
*/
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal class AnnotationTranslator {
private fun KtAnalysisSession.toDokkaAnnotation(annotationApplication: KtAnnotationApplication) =
Annotations.Annotation(
dri = annotationApplication.classId?.createDRI()
?: throw IllegalStateException("The annotation application does not have class id"),
?: DRI(packageName = "", classNames = ERROR_CLASS_NAME), // classId might be null on a non-existing annotation call,
params = if (annotationApplication is KtAnnotationApplicationWithArgumentsInfo) annotationApplication.arguments.associate {
it.name.asString() to toDokkaAnnotationValue(
it.expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@ internal class DokkaSymbolVisitor(

return visibility.toDokkaVisibility()
}

private fun KtAnalysisSession.visitJavaFieldSymbol(
javaFieldSymbol: KtJavaFieldSymbol,
parent: DRI,
Expand Down Expand Up @@ -570,9 +569,21 @@ internal class DokkaSymbolVisitor(
propertySymbol: KtPropertySymbol,
propertyDRI: DRI
): DFunction = withExceptionCatcher(propertyAccessorSymbol) {
val dri = propertyDRI.copy(
callable = Callable("", null, emptyList())
)
val isGetter = propertyAccessorSymbol is KtPropertyGetterSymbol
// it also covers @JvmName annotation
val name = (if (isGetter) propertySymbol.javaGetterName else propertySymbol.javaSetterName)?.asString() ?: ""

// SyntheticJavaProperty has callableIdIfNonLocal, propertyAccessorSymbol.origin = JAVA_SYNTHETIC_PROPERTY
// For Kotlin properties callableIdIfNonLocal=null
val dri = if (propertyAccessorSymbol.callableIdIfNonLocal != null)
getDRIFromFunctionLike(propertyAccessorSymbol)
else
propertyDRI.copy(
callable = Callable(name, null, propertyAccessorSymbol.valueParameters.map { getTypeReferenceFrom(it.returnType) })
)
// for SyntheticJavaProperty
val inheritedFrom = if(propertyAccessorSymbol.origin == KtSymbolOrigin.JAVA_SYNTHETIC_PROPERTY) dri.copy(callable = null) else null

val isExpect = propertyAccessorSymbol.isExpect
val isActual = propertyAccessorSymbol.isActual

Expand All @@ -583,31 +594,6 @@ internal class DokkaSymbolVisitor(
dri
)
}
val isGetter = propertyAccessorSymbol is KtPropertyGetterSymbol

val name = run {
val modifier = if (isGetter) "get" else "set"
val rawName = propertySymbol.name.asString()
"$modifier${rawName.capitalize()}"
/*
* Kotlin has special rules for conversion around properties that
* start with "is" For more info see:
* https://kotlinlang.org/docs/java-interop.html#getters-and-setters
* https://kotlinlang.org/docs/java-to-kotlin-interop.html#properties
*
* Based on our testing, this rule only applies when the letter after
* the "is" is *not* lowercase. This means that words like "issue" won't
* have the rule applied but "is_foobar" and "is1of" will have the rule applied.
*/
val specialCaseIs = rawName.startsWith("is")
&& rawName.getOrNull(2)?.isLowerCase() == false

if (specialCaseIs) {
if (isGetter) rawName else rawName.replaceFirst("is", "set")
} else {
if (isGetter) "get${rawName.capitalize()}" else "set${rawName.capitalize()}"
}
}

return DFunction(
dri = dri,
Expand All @@ -633,6 +619,7 @@ internal class DokkaSymbolVisitor(
isExpectActual = (isExpect || isActual),
extra = PropertyContainer.withAll(
propertyAccessorSymbol.additionalExtras()?.toSourceSetDependent()?.toAdditionalModifiers(),
inheritedFrom?.let { InheritedMember(it.toSourceSetDependent()) },
getDokkaAnnotationsFrom(propertyAccessorSymbol)?.toSourceSetDependent()?.toAnnotations()
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ internal class TypeTranslator(

is KtClassErrorType -> TypeConstructorWithKind(
GenericTypeConstructor(
dri = DRI("$ERROR_CLASS_NAME $type", "", null),
dri = DRI(packageName = "", classNames = "$ERROR_CLASS_NAME $type"),
projections = emptyList(),

),
Expand All @@ -149,7 +149,7 @@ internal class TypeTranslator(

is KtTypeErrorType -> TypeConstructorWithKind(
GenericTypeConstructor(
dri = DRI("$ERROR_CLASS_NAME $type", "", null),
dri = DRI(packageName = "", classNames = "$ERROR_CLASS_NAME $type"),
projections = emptyList(),

),
Expand Down

0 comments on commit 957bc34

Please sign in to comment.