summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2020-04-27 23:10:12 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-04-27 23:10:12 +0000
commit87c7153d3ca828c7fd8b9b4f5e06774482a3283e (patch)
tree5459317773c29412c98979f07515ba79818fe1d7
parent2a9a745222d1a1a0807ddcabd1778ba3916033a0 (diff)
parentd59dabf580889f8f8cfc3f55b2fa8de4717c679e (diff)
Merge "Handle trailing *\ comment closing." into rvc-dev am: 6445946c05 am: d59dabf580
Change-Id: Ie8b129e10031e88ae8ec6f5e649a7d74c5e894b9
-rw-r--r--src/main/java/com/android/tools/metalava/model/psi/PsiItem.kt6
-rw-r--r--src/test/java/com/android/tools/metalava/DocAnalyzerTest.kt49
2 files changed, 53 insertions, 2 deletions
diff --git a/src/main/java/com/android/tools/metalava/model/psi/PsiItem.kt b/src/main/java/com/android/tools/metalava/model/psi/PsiItem.kt
index a5ca247..1e65543 100644
--- a/src/main/java/com/android/tools/metalava/model/psi/PsiItem.kt
+++ b/src/main/java/com/android/tools/metalava/model/psi/PsiItem.kt
@@ -183,6 +183,10 @@ abstract class PsiItem(
documentation[end - 1] != '\n') {
end--
}
+ // The comment ends with:
+ // * some comment here */
+ var insertNewLine: Boolean = documentation[end - 1] != '\n'
+
var indent: String
var linePrefix = ""
val secondLine = documentation.indexOf('\n')
@@ -204,7 +208,7 @@ abstract class PsiItem(
linePrefix = "* "
}
}
- val s = documentation.substring(0, end) + indent + linePrefix + tagSection + " " + commentLine + "\n" + indent + " */"
+ val s = documentation.substring(0, end) + (if (insertNewLine) "\n" else "") + indent + linePrefix + tagSection + " " + commentLine + "\n" + indent + " */"
return s
}
diff --git a/src/test/java/com/android/tools/metalava/DocAnalyzerTest.kt b/src/test/java/com/android/tools/metalava/DocAnalyzerTest.kt
index f227e29..55ba6c0 100644
--- a/src/test/java/com/android/tools/metalava/DocAnalyzerTest.kt
+++ b/src/test/java/com/android/tools/metalava/DocAnalyzerTest.kt
@@ -2087,4 +2087,51 @@ class DocAnalyzerTest : DriverTest() {
)
)
}
-} \ No newline at end of file
+
+ @Test
+ fun `Trailing comment close`() {
+ check(
+ sourceFiles = arrayOf(
+ java(
+ """
+ package android.widget;
+
+ public class Toolbar {
+ /**
+ * Existing documentation for {@linkplain #getCurrentContentInsetEnd()} here. */
+ public int getCurrentContentInsetEnd() {
+ return 0;
+ }
+ }
+ """
+ ),
+ intRangeAnnotationSource
+ ),
+ checkCompilation = true,
+ docStubs = true,
+ applyApiLevelsXml = """
+ <?xml version="1.0" encoding="utf-8"?>
+ <api version="2">
+ <class name="android/widget/Toolbar" since="21">
+ <method name="getCurrentContentInsetEnd()I" since="24"/>
+ </class>
+ </api>
+ """,
+ stubs = arrayOf(
+ """
+ package android.widget;
+ /** @apiSince 21 */
+ @SuppressWarnings({"unchecked", "deprecation", "all"})
+ public class Toolbar {
+ public Toolbar() { throw new RuntimeException("Stub!"); }
+ /**
+ * Existing documentation for {@linkplain #getCurrentContentInsetEnd()} here.
+ * @apiSince 24
+ */
+ public int getCurrentContentInsetEnd() { throw new RuntimeException("Stub!"); }
+ }
+ """
+ )
+ )
+ }
+}