-
Notifications
You must be signed in to change notification settings - Fork 409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support inner
modifier for java non-static
classes
#3347
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
293 changes: 293 additions & 0 deletions
293
...c/test/kotlin/org/jetbrains/dokka/analysis/test/jvm/java/InnerModifierJavaAnalysisTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,293 @@ | ||
/* | ||
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package org.jetbrains.dokka.analysis.test.jvm.java | ||
|
||
import org.jetbrains.dokka.analysis.test.api.javaTestProject | ||
import org.jetbrains.dokka.analysis.test.api.parse | ||
import org.jetbrains.dokka.model.* | ||
import org.jetbrains.dokka.model.properties.WithExtraProperties | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertTrue | ||
|
||
class InnerModifierJavaAnalysisTest { | ||
|
||
@Test | ||
fun `top level java declarations should not have kotlin inner modifier`() { | ||
val testProject = javaTestProject { | ||
javaFile(pathFromSrc = "JavaClass.java") { | ||
+"public class JavaClass { }" | ||
} | ||
javaFile(pathFromSrc = "JavaEnum.java") { | ||
+"public enum JavaEnum { S; }" | ||
} | ||
javaFile(pathFromSrc = "JavaInterface.java") { | ||
+"public interface JavaInterface { }" | ||
} | ||
javaFile(pathFromSrc = "JavaAnnotation.java") { | ||
+"public @interface JavaAnnotation { }" | ||
} | ||
} | ||
|
||
val module = testProject.parse() | ||
val pkg = module.packages.single() | ||
|
||
assertEquals(4, pkg.classlikes.size) | ||
|
||
pkg.classlikes.forEach { | ||
@Suppress("UNCHECKED_CAST") | ||
assertTrue((it as WithExtraProperties<Documentable>).kotlinOnlyModifiers().isEmpty()) | ||
} | ||
} | ||
|
||
@Test | ||
fun `java declarations nested inside interfaces should not have kotlin inner modifier`() { | ||
val testProject = javaTestProject { | ||
javaFile(pathFromSrc = "JavaInterface.java") { | ||
+""" | ||
public interface JavaInterface { | ||
public class InnerClass { } | ||
public static class NestedClass { } | ||
public enum InnerEnum {S} | ||
public static enum NestedEnum {S} | ||
public interface InnerInterface { } | ||
public static interface NestedInterface { } | ||
public @interface InnerAnnotation { } | ||
public static @interface NestedAnnotation { } | ||
} | ||
""" | ||
} | ||
} | ||
|
||
val module = testProject.parse() | ||
val pkg = module.packages.single() | ||
val javaInterface = pkg.classlikes.single() | ||
|
||
assertTrue(javaInterface is DInterface) | ||
assertEquals(8, javaInterface.classlikes.size) | ||
|
||
javaInterface.classlikes.forEach { | ||
@Suppress("UNCHECKED_CAST") | ||
assertTrue((it as WithExtraProperties<Documentable>).kotlinOnlyModifiers().isEmpty()) | ||
} | ||
} | ||
|
||
@Test | ||
fun `java declarations nested inside annotation interface should not have kotlin inner modifier`() { | ||
val testProject = javaTestProject { | ||
javaFile(pathFromSrc = "JavaAnnotation.java") { | ||
+""" | ||
public @interface JavaAnnotation { | ||
public class InnerClass { } | ||
public static class NestedClass { } | ||
public enum InnerEnum {S} | ||
public static enum NestedEnum {S} | ||
public interface InnerInterface { } | ||
public static interface NestedInterface { } | ||
public @interface InnerAnnotation { } | ||
public static @interface NestedAnnotation { } | ||
} | ||
""" | ||
} | ||
} | ||
|
||
val module = testProject.parse() | ||
val pkg = module.packages.single() | ||
val javaAnnotation = pkg.classlikes.single() | ||
|
||
assertTrue(javaAnnotation is DAnnotation) | ||
assertEquals(8, javaAnnotation.classlikes.size) | ||
|
||
javaAnnotation.classlikes.forEach { | ||
@Suppress("UNCHECKED_CAST") | ||
assertTrue((it as WithExtraProperties<Documentable>).kotlinOnlyModifiers().isEmpty()) | ||
} | ||
} | ||
|
||
// java classes tests | ||
|
||
@Test | ||
fun `java class nested inside class should have kotlin inner modifiers`() { | ||
val testProject = javaTestProject { | ||
javaFile(pathFromSrc = "JavaClass.java") { | ||
+""" | ||
public class JavaClass { | ||
public class NestedClass { } | ||
} | ||
""" | ||
} | ||
} | ||
|
||
val module = testProject.parse() | ||
val pkg = module.packages.single() | ||
val javaClass = pkg.classlikes.single() | ||
|
||
assertTrue(javaClass is DClass) | ||
assertEquals("JavaClass", javaClass.name) | ||
|
||
val nestedClass = javaClass.classlikes.single() | ||
|
||
assertTrue(nestedClass is DClass) | ||
assertEquals("NestedClass", nestedClass.name) | ||
|
||
assertEquals( | ||
setOf(ExtraModifiers.KotlinOnlyModifiers.Inner), | ||
nestedClass.kotlinOnlyModifiers().values.single() | ||
) | ||
} | ||
|
||
@Test | ||
fun `static java class nested inside class should not have kotlin inner modifiers`() { | ||
val testProject = javaTestProject { | ||
javaFile(pathFromSrc = "JavaClass.java") { | ||
+""" | ||
public class JavaClass { | ||
public static class NestedClass { } | ||
} | ||
""" | ||
} | ||
} | ||
|
||
val module = testProject.parse() | ||
val pkg = module.packages.single() | ||
val javaClass = pkg.classlikes.single() | ||
|
||
assertTrue(javaClass is DClass) | ||
assertEquals("JavaClass", javaClass.name) | ||
|
||
val nestedClass = javaClass.classlikes.single() | ||
|
||
assertTrue(nestedClass is DClass) | ||
assertEquals("NestedClass", nestedClass.name) | ||
|
||
assertTrue(nestedClass.kotlinOnlyModifiers().isEmpty()) | ||
} | ||
|
||
@Test | ||
fun `java non-classes nested inside class should not have kotlin inner modifier`() { | ||
val testProject = javaTestProject { | ||
javaFile(pathFromSrc = "JavaClass.java") { | ||
+""" | ||
public class JavaClass { | ||
public enum InnerEnum {S} | ||
public static enum NestedEnum {S} | ||
public interface InnerInterface { } | ||
public static interface NestedInterface { } | ||
public @interface InnerAnnotation { } | ||
public static @interface NestedAnnotation { } | ||
} | ||
""" | ||
} | ||
} | ||
|
||
val module = testProject.parse() | ||
val pkg = module.packages.single() | ||
val javaClass = pkg.classlikes.single() | ||
|
||
assertTrue(javaClass is DClass) | ||
assertEquals(6, javaClass.classlikes.size) | ||
|
||
javaClass.classlikes.forEach { | ||
@Suppress("UNCHECKED_CAST") | ||
assertTrue((it as WithExtraProperties<Documentable>).kotlinOnlyModifiers().isEmpty()) | ||
} | ||
} | ||
|
||
// java enums tests | ||
|
||
@Test | ||
fun `static java class nested inside enum should not have kotlin inner modifiers`() { | ||
val testProject = javaTestProject { | ||
javaFile(pathFromSrc = "JavaEnum.java") { | ||
+""" | ||
public enum JavaEnum { S; | ||
public static class NestedClass { } | ||
} | ||
""" | ||
} | ||
} | ||
|
||
val module = testProject.parse() | ||
val pkg = module.packages.single() | ||
val javaEnum = pkg.classlikes.single() | ||
|
||
assertTrue(javaEnum is DEnum) | ||
assertEquals("JavaEnum", javaEnum.name) | ||
|
||
val nestedClass = javaEnum.classlikes.single() | ||
|
||
assertTrue(nestedClass is DClass) | ||
assertEquals("NestedClass", nestedClass.name) | ||
|
||
assertTrue(nestedClass.kotlinOnlyModifiers().isEmpty()) | ||
} | ||
|
||
@Test | ||
fun `java class nested inside enum should have kotlin inner modifiers`() { | ||
val testProject = javaTestProject { | ||
javaFile(pathFromSrc = "JavaEnum.java") { | ||
+""" | ||
public enum JavaEnum { S; | ||
public class NestedClass { } | ||
} | ||
""" | ||
} | ||
} | ||
|
||
val module = testProject.parse() | ||
val pkg = module.packages.single() | ||
val javaEnum = pkg.classlikes.single() | ||
|
||
assertTrue(javaEnum is DEnum) | ||
assertEquals("JavaEnum", javaEnum.name) | ||
|
||
val nestedClass = javaEnum.classlikes.single() | ||
|
||
assertTrue(nestedClass is DClass) | ||
assertEquals("NestedClass", nestedClass.name) | ||
|
||
assertEquals( | ||
setOf(ExtraModifiers.KotlinOnlyModifiers.Inner), | ||
nestedClass.kotlinOnlyModifiers().values.single() | ||
) | ||
} | ||
|
||
@Test | ||
fun `java non-classes nested inside enum should not have kotlin inner modifier`() { | ||
val testProject = javaTestProject { | ||
javaFile(pathFromSrc = "JavaEnum.java") { | ||
+""" | ||
public enum JavaEnum { S; | ||
public enum InnerEnum {S} | ||
public static enum NestedEnum {S} | ||
public interface InnerInterface { } | ||
public static interface NestedInterface { } | ||
public @interface InnerAnnotation { } | ||
public static @interface NestedAnnotation { } | ||
} | ||
""" | ||
} | ||
} | ||
|
||
val module = testProject.parse() | ||
val pkg = module.packages.single() | ||
val javaEnum = pkg.classlikes.single() | ||
|
||
assertTrue(javaEnum is DEnum) | ||
assertEquals(6, javaEnum.classlikes.size) | ||
|
||
javaEnum.classlikes.forEach { | ||
@Suppress("UNCHECKED_CAST") | ||
assertTrue((it as WithExtraProperties<Documentable>).kotlinOnlyModifiers().isEmpty()) | ||
} | ||
} | ||
|
||
// copied from org.jetbrains.dokka.base.signatures.KotlinSignatureUtils | ||
private fun <T : Documentable> WithExtraProperties<T>.kotlinOnlyModifiers(): SourceSetDependent<Set<ExtraModifiers>> { | ||
return extra[AdditionalModifiers]?.content?.entries?.associate { | ||
it.key to it.value.filterIsInstance<ExtraModifiers.KotlinOnlyModifiers>().toSet() | ||
} ?: emptyMap() | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, for some reason I didn't expect Java to handle root packages correctly, but apparently it works :)