Kapt: Fix star indentation in stub Javadoc (KT-30163)
This commit is contained in:
+22
-6
@@ -17,7 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.kapt3.stubs
|
package org.jetbrains.kotlin.kapt3.stubs
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiWhiteSpace
|
import com.intellij.psi.PsiRecursiveElementVisitor
|
||||||
import com.intellij.psi.impl.source.tree.LeafPsiElement
|
import com.intellij.psi.impl.source.tree.LeafPsiElement
|
||||||
import com.sun.tools.javac.parser.Tokens
|
import com.sun.tools.javac.parser.Tokens
|
||||||
import com.sun.tools.javac.tree.DCTree
|
import com.sun.tools.javac.tree.DCTree
|
||||||
@@ -128,13 +128,29 @@ class KDocCommentKeeper(private val kaptContext: KaptContextForStubGeneration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun extractCommentText(docComment: KDoc): String {
|
private fun extractCommentText(docComment: KDoc): String {
|
||||||
return docComment.children.dropWhile { it is PsiWhiteSpace || it.isKDocStart() }
|
return buildString {
|
||||||
.dropLastWhile { it is PsiWhiteSpace || it.isKDocEnd() }
|
docComment.accept(object : PsiRecursiveElementVisitor() {
|
||||||
.joinToString("") { it.text }
|
override fun visitElement(element: PsiElement) {
|
||||||
|
if (element is LeafPsiElement) {
|
||||||
|
if (element.isKDocLeadingAsterisk()) {
|
||||||
|
val indent = takeLastWhile { it == ' ' || it == '\t' }.length
|
||||||
|
if (indent > 0) {
|
||||||
|
delete(length - indent, length)
|
||||||
|
}
|
||||||
|
} else if (!element.isKDocStart() && !element.isKDocEnd()) {
|
||||||
|
append(element.text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
super.visitElement(element)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}.trimIndent().trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun PsiElement.isKDocStart() = this is LeafPsiElement && elementType == KDocTokens.START
|
private fun LeafPsiElement.isKDocStart() = elementType == KDocTokens.START
|
||||||
private fun PsiElement.isKDocEnd() = this is LeafPsiElement && elementType == KDocTokens.END
|
private fun LeafPsiElement.isKDocEnd() = elementType == KDocTokens.END
|
||||||
|
private fun LeafPsiElement.isKDocLeadingAsterisk() = elementType == KDocTokens.LEADING_ASTERISK
|
||||||
}
|
}
|
||||||
|
|
||||||
private class KDocComment(val body: String) : Tokens.Comment {
|
private class KDocComment(val body: String) : Tokens.Comment {
|
||||||
|
|||||||
+5
@@ -194,6 +194,11 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi
|
|||||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/javaKeywordsInPackageNames.kt");
|
runTest("plugins/kapt3/kapt3-compiler/testData/converter/javaKeywordsInPackageNames.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("javadoc.kt")
|
||||||
|
public void testJavadoc() throws Exception {
|
||||||
|
runTest("plugins/kapt3/kapt3-compiler/testData/converter/javadoc.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("jvmOverloads.kt")
|
@TestMetadata("jvmOverloads.kt")
|
||||||
public void testJvmOverloads() throws Exception {
|
public void testJvmOverloads() throws Exception {
|
||||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/jvmOverloads.kt");
|
runTest("plugins/kapt3/kapt3-compiler/testData/converter/jvmOverloads.kt");
|
||||||
|
|||||||
+1
-1
@@ -56,7 +56,7 @@ class KotlinKapt3IntegrationTests : AbstractKotlinKapt3IntegrationTest(), Java9T
|
|||||||
fun testComments() = test("Simple", "test.MyAnnotation") { _, _, env ->
|
fun testComments() = test("Simple", "test.MyAnnotation") { _, _, env ->
|
||||||
fun commentOf(className: String) = env.elementUtils.getDocComment(env.elementUtils.getTypeElement(className))
|
fun commentOf(className: String) = env.elementUtils.getDocComment(env.elementUtils.getTypeElement(className))
|
||||||
|
|
||||||
assert(commentOf("test.Simple") == " * KDoc comment.\n")
|
assert(commentOf("test.Simple") == " KDoc comment.\n")
|
||||||
assert(commentOf("test.EnumClass") == null) // simple comment - not saved
|
assert(commentOf("test.EnumClass") == null) // simple comment - not saved
|
||||||
assert(commentOf("test.MyAnnotation") == null) // multiline comment - not saved
|
assert(commentOf("test.MyAnnotation") == null) // multiline comment - not saved
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,9 +118,9 @@ public final class Test {
|
|||||||
import java.lang.System;
|
import java.lang.System;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * Test2
|
* Test2
|
||||||
* * Multiline
|
* Multiline
|
||||||
* * documentation.
|
* documentation.
|
||||||
*/
|
*/
|
||||||
@kotlin.Metadata()
|
@kotlin.Metadata()
|
||||||
public final class Test2 {
|
public final class Test2 {
|
||||||
@@ -184,7 +184,7 @@ public final class Test4 {
|
|||||||
import java.lang.System;
|
import java.lang.System;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * `/ * Failure * /`
|
* `/ * Failure * /`
|
||||||
*/
|
*/
|
||||||
@kotlin.Metadata()
|
@kotlin.Metadata()
|
||||||
public abstract interface TestComponent {
|
public abstract interface TestComponent {
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package javadoc
|
||||||
|
|
||||||
|
/** Simple */
|
||||||
|
class A
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multi
|
||||||
|
* line
|
||||||
|
* comment.
|
||||||
|
*/
|
||||||
|
class B {
|
||||||
|
/** Nested
|
||||||
|
* member
|
||||||
|
* comment. */
|
||||||
|
val a = ""
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mixed
|
||||||
|
* tabs/spaces
|
||||||
|
*/
|
||||||
|
val b = ""
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List:
|
||||||
|
* * first item
|
||||||
|
* * second item
|
||||||
|
*/
|
||||||
|
val c = ""
|
||||||
|
|
||||||
|
/**
|
||||||
|
Without
|
||||||
|
stars
|
||||||
|
*/
|
||||||
|
val d = ""
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package javadoc;
|
||||||
|
|
||||||
|
import java.lang.System;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple
|
||||||
|
*/
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public final class A {
|
||||||
|
|
||||||
|
public A() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
|
||||||
|
package javadoc;
|
||||||
|
|
||||||
|
import java.lang.System;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multi
|
||||||
|
* line
|
||||||
|
* comment.
|
||||||
|
*/
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public final class B {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nested
|
||||||
|
* member
|
||||||
|
* comment.
|
||||||
|
*/
|
||||||
|
@org.jetbrains.annotations.NotNull()
|
||||||
|
private final java.lang.String a = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mixed
|
||||||
|
* tabs/spaces
|
||||||
|
*/
|
||||||
|
@org.jetbrains.annotations.NotNull()
|
||||||
|
private final java.lang.String b = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List:
|
||||||
|
* * first item
|
||||||
|
* * second item
|
||||||
|
*/
|
||||||
|
@org.jetbrains.annotations.NotNull()
|
||||||
|
private final java.lang.String c = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Without
|
||||||
|
* stars
|
||||||
|
*/
|
||||||
|
@org.jetbrains.annotations.NotNull()
|
||||||
|
private final java.lang.String d = "";
|
||||||
|
|
||||||
|
@org.jetbrains.annotations.NotNull()
|
||||||
|
public final java.lang.String getA() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@org.jetbrains.annotations.NotNull()
|
||||||
|
public final java.lang.String getB() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@org.jetbrains.annotations.NotNull()
|
||||||
|
public final java.lang.String getC() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@org.jetbrains.annotations.NotNull()
|
||||||
|
public final java.lang.String getD() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public B() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ package test;
|
|||||||
import java.lang.System;
|
import java.lang.System;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * KDoc comment.
|
* KDoc comment.
|
||||||
*/
|
*/
|
||||||
@kotlin.Suppress(names = {"UNRESOLVED_REFERENCE"})
|
@kotlin.Suppress(names = {"UNRESOLVED_REFERENCE"})
|
||||||
@kotlin.Metadata()
|
@kotlin.Metadata()
|
||||||
|
|||||||
Reference in New Issue
Block a user