aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2016-06-30 17:36:22 +0200
committerDmitry Jemerov <yole@jetbrains.com>2016-06-30 17:36:22 +0200
commitb96aaa55185152489adfe6682d7aeececfaf12b4 (patch)
tree7e17b3d995097cda6ae76234edebcc64a9501fd3 /core
parentaf27102b662439b4f7ccdeaf2195c93ba533c7be (diff)
downloaddokka-b96aaa55185152489adfe6682d7aeececfaf12b4.tar.gz
dokka-b96aaa55185152489adfe6682d7aeececfaf12b4.tar.bz2
dokka-b96aaa55185152489adfe6682d7aeececfaf12b4.zip
Don't include internal members in generated javadoc. Resolves #75
Diffstat (limited to 'core')
-rw-r--r--core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt13
-rw-r--r--core/src/test/kotlin/TestAPI.kt75
-rw-r--r--core/src/test/kotlin/javadoc/JavadocTest.kt12
-rw-r--r--core/testdata/javadoc/internal.kt8
4 files changed, 70 insertions, 38 deletions
diff --git a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt
index d2748ee3..e73b19b4 100644
--- a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt
+++ b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt
@@ -3,6 +3,10 @@ package org.jetbrains.dokka
import com.google.inject.Inject
import com.intellij.psi.*
import com.intellij.psi.util.InheritanceUtil
+import org.jetbrains.kotlin.asJava.KtLightElement
+import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
+import org.jetbrains.kotlin.lexer.KtTokens
+import org.jetbrains.kotlin.psi.KtModifierListOwner
fun getSignature(element: PsiElement?) = when(element) {
is PsiClass -> element.qualifiedName
@@ -127,7 +131,14 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder {
private fun skipElementByVisibility(element: Any): Boolean =
!options.includeNonPublic && element is PsiModifierListOwner &&
- (element.hasModifierProperty(PsiModifier.PRIVATE) || element.hasModifierProperty(PsiModifier.PACKAGE_LOCAL))
+ (element.hasModifierProperty(PsiModifier.PRIVATE) ||
+ element.hasModifierProperty(PsiModifier.PACKAGE_LOCAL) ||
+ element.isInternal())
+
+ private fun PsiElement.isInternal(): Boolean {
+ val ktElement = (this as? KtLightElement<*, *>)?.kotlinOrigin ?: return false
+ return (ktElement as? KtModifierListOwner)?.hasModifier(KtTokens.INTERNAL_KEYWORD) ?: false
+ }
fun <T : Any> DocumentationNode.appendMembers(elements: Array<T>, buildFn: T.() -> DocumentationNode) =
appendChildren(elements, RefKind.Member, buildFn)
diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt
index ab2a526b..508b490a 100644
--- a/core/src/test/kotlin/TestAPI.kt
+++ b/core/src/test/kotlin/TestAPI.kt
@@ -16,11 +16,12 @@ import org.junit.Assert
import org.junit.Assert.fail
import java.io.File
-public fun verifyModel(vararg roots: ContentRoot,
- withJdk: Boolean = false,
- withKotlinRuntime: Boolean = false,
- format: String = "html",
- verifier: (DocumentationModule) -> Unit) {
+fun verifyModel(vararg roots: ContentRoot,
+ withJdk: Boolean = false,
+ withKotlinRuntime: Boolean = false,
+ format: String = "html",
+ includeNonPublic: Boolean = true,
+ verifier: (DocumentationModule) -> Unit) {
val messageCollector = object : MessageCollector {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
when (severity) {
@@ -54,7 +55,7 @@ public fun verifyModel(vararg roots: ContentRoot,
addRoots(roots.toList())
}
val options = DocumentationOptions("", format,
- includeNonPublic = true,
+ includeNonPublic = includeNonPublic,
skipEmptyPackages = false,
sourceLinks = listOf<SourceLinkDefinition>(),
generateIndexPages = false)
@@ -64,11 +65,12 @@ public fun verifyModel(vararg roots: ContentRoot,
Disposer.dispose(environment)
}
-public fun verifyModel(source: String,
- withJdk: Boolean = false,
- withKotlinRuntime: Boolean = false,
- format: String = "html",
- verifier: (DocumentationModule) -> Unit) {
+fun verifyModel(source: String,
+ withJdk: Boolean = false,
+ withKotlinRuntime: Boolean = false,
+ format: String = "html",
+ includeNonPublic: Boolean = true,
+ verifier: (DocumentationModule) -> Unit) {
if (!File(source).exists()) {
throw IllegalArgumentException("Can't find test data file $source")
}
@@ -76,22 +78,23 @@ public fun verifyModel(source: String,
withJdk = withJdk,
withKotlinRuntime = withKotlinRuntime,
format = format,
+ includeNonPublic = includeNonPublic,
verifier = verifier)
}
-public fun verifyPackageMember(source: String,
- withJdk: Boolean = false,
- withKotlinRuntime: Boolean = false,
- verifier: (DocumentationNode) -> Unit) {
+fun verifyPackageMember(source: String,
+ withJdk: Boolean = false,
+ withKotlinRuntime: Boolean = false,
+ verifier: (DocumentationNode) -> Unit) {
verifyModel(source, withJdk = withJdk, withKotlinRuntime = withKotlinRuntime) { model ->
val pkg = model.members.single()
verifier(pkg.members.single())
}
}
-public fun verifyJavaModel(source: String,
- withKotlinRuntime: Boolean = false,
- verifier: (DocumentationModule) -> Unit) {
+fun verifyJavaModel(source: String,
+ withKotlinRuntime: Boolean = false,
+ verifier: (DocumentationModule) -> Unit) {
val tempDir = FileUtil.createTempDirectory("dokka", "")
try {
val sourceFile = File(source)
@@ -103,20 +106,20 @@ public fun verifyJavaModel(source: String,
}
}
-public fun verifyJavaPackageMember(source: String,
- withKotlinRuntime: Boolean = false,
- verifier: (DocumentationNode) -> Unit) {
+fun verifyJavaPackageMember(source: String,
+ withKotlinRuntime: Boolean = false,
+ verifier: (DocumentationNode) -> Unit) {
verifyJavaModel(source, withKotlinRuntime) { model ->
val pkg = model.members.single()
verifier(pkg.members.single())
}
}
-public fun verifyOutput(roots: Array<ContentRoot>,
- outputExtension: String,
- withJdk: Boolean = false,
- withKotlinRuntime: Boolean = false,
- outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
+fun verifyOutput(roots: Array<ContentRoot>,
+ outputExtension: String,
+ withJdk: Boolean = false,
+ withKotlinRuntime: Boolean = false,
+ outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
verifyModel(*roots, withJdk = withJdk, withKotlinRuntime = withKotlinRuntime) {
verifyModelOutput(it, outputExtension, outputGenerator, roots.first().path)
}
@@ -134,24 +137,24 @@ private fun verifyModelOutput(it: DocumentationModule,
assertEqualsIgnoringSeparators(expectedOutput, output.toString())
}
-public fun verifyOutput(path: String,
- outputExtension: String,
- withJdk: Boolean = false,
- withKotlinRuntime: Boolean = false,
- outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
+fun verifyOutput(path: String,
+ outputExtension: String,
+ withJdk: Boolean = false,
+ withKotlinRuntime: Boolean = false,
+ outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
verifyOutput(arrayOf(contentRootFromPath(path)), outputExtension, withJdk, withKotlinRuntime, outputGenerator)
}
-public fun verifyJavaOutput(path: String,
- outputExtension: String,
- withKotlinRuntime: Boolean = false,
- outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
+fun verifyJavaOutput(path: String,
+ outputExtension: String,
+ withKotlinRuntime: Boolean = false,
+ outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
verifyJavaModel(path, withKotlinRuntime) { model ->
verifyModelOutput(model, outputExtension, outputGenerator, path)
}
}
-public fun assertEqualsIgnoringSeparators(expectedOutput: String, output: String) {
+fun assertEqualsIgnoringSeparators(expectedOutput: String, output: String) {
Assert.assertEquals(expectedOutput.replace("\r\n", "\n"), output.replace("\r\n", "\n"))
}
diff --git a/core/src/test/kotlin/javadoc/JavadocTest.kt b/core/src/test/kotlin/javadoc/JavadocTest.kt
index 48bc9f6a..b7e75e2c 100644
--- a/core/src/test/kotlin/javadoc/JavadocTest.kt
+++ b/core/src/test/kotlin/javadoc/JavadocTest.kt
@@ -87,12 +87,22 @@ class JavadocTest {
}
}
+ @Test fun testInternalVisibility() {
+ verifyJavadoc("testdata/javadoc/internal.kt", withKotlinRuntime = true, includeNonPublic = false) { doc ->
+ val classDoc = doc.classNamed("foo.Person")!!
+ val constructors = classDoc.constructors()
+ assertEquals(1, constructors.size)
+ assertEquals(1, constructors.single().parameters().size)
+ }
+ }
+
private fun verifyJavadoc(name: String,
withJdk: Boolean = false,
withKotlinRuntime: Boolean = false,
+ includeNonPublic: Boolean = true,
callback: (ModuleNodeAdapter) -> Unit) {
- verifyModel(name, format = "javadoc", withJdk = withJdk, withKotlinRuntime = withKotlinRuntime) { model ->
+ verifyModel(name, format = "javadoc", withJdk = withJdk, withKotlinRuntime = withKotlinRuntime, includeNonPublic = includeNonPublic) { model ->
val doc = ModuleNodeAdapter(model, StandardReporter(DokkaConsoleLogger), "")
callback(doc)
}
diff --git a/core/testdata/javadoc/internal.kt b/core/testdata/javadoc/internal.kt
new file mode 100644
index 00000000..a57ea3b4
--- /dev/null
+++ b/core/testdata/javadoc/internal.kt
@@ -0,0 +1,8 @@
+package foo
+
+data class Person internal constructor(
+ val name: String = "",
+ val age: Int = 0
+) {
+ constructor(age: Int): this("", age)
+}