From 5584a2102faf5af771494a257a7b5113b3fe39bf Mon Sep 17 00:00:00 2001 From: Jay Arthanareeswaran Date: Wed, 25 Sep 2024 09:14:03 +0530 Subject: [PATCH] [23] Markdown doc comments with codeblock don't parse Javadoc tags afterwards (#1665) Test case for https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2980 Also by: --- .../ui/tests/hover/MarkdownCommentTests.java | 150 +++++++++++++++++- 1 file changed, 149 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/hover/MarkdownCommentTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/hover/MarkdownCommentTests.java index f7c03e78fa3..9c05bf02e20 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/hover/MarkdownCommentTests.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/hover/MarkdownCommentTests.java @@ -808,4 +808,152 @@ void paraAfterCode() { } """; assertHtmlContent(expectedContent, actualHtmlContent); } -} + @Test + public void testGH2980() throws CoreException { + String source= """ + package p; + + public class X { + /// This is a test Javadoc for method test1() + /// ```java + /// test1(42); + /// ``` + /// @param a some parameter for test1 + public void test1(int a) {} + /// + /// This is a test Javadoc for method test2() + /// 'test2(0)' + /// @param b some parameter for test1 + public void test2(int b) {} + /// This is a test Javadoc for method test3() + /// ```java + /// int r = test3(); + /// System.out.println(r); + /// ``` + /// @return an int value + public int test3() { + return 0; + } + /// This is a test Javadoc for method test4() + /// Invocation method 1: + /// ```java + /// int r = test4(); + /// System.out.println(r); + /// ``` + /// Invocation method 2: + /// ```java + /// System.out.println(test4()); + /// ``` + /// @return an int value + /// @param i an int param + public int test4(int i) { + return 0; + } + } + """; + ICompilationUnit cu= getWorkingCopy("/TestSetupProject/src/p/X.java", source, null); + assertNotNull("X.java", cu); + + IType type= cu.getType("X"); + + IMethod method= type.getMethods()[0]; + String actualHtmlContent= getHoverHtmlContent(cu, method); + String expectedContent= """ +

This is a test Javadoc for method test1()

+
test1(42);
+					
+
Parameters:
a some parameter for test1
+ """; + assertHtmlContent(expectedContent, actualHtmlContent); + + method= type.getMethods()[1]; + actualHtmlContent= getHoverHtmlContent(cu, method); + expectedContent= """ +

This is a test Javadoc for method test2() + 'test2(0)'

+
Parameters:
b some parameter for test1
+ """; + assertHtmlContent(expectedContent, actualHtmlContent); + + method= type.getMethods()[2]; + actualHtmlContent= getHoverHtmlContent(cu, method); + expectedContent= """ +

This is a test Javadoc for method test3()

+
int r = test3();
+					System.out.println(r);
+					
+
Returns:
an int value
+ """; + method= type.getMethods()[3]; + actualHtmlContent= getHoverHtmlContent(cu, method); + expectedContent= """ +

This is a test Javadoc for method test4() + Invocation method 1:

+
int r = test4();
+					System.out.println(r);
+					
+

Invocation method 2:

+
System.out.println(test4());
+					
+
Parameters:
i an int param
Returns:
an int value
+ """; + assertHtmlContent(expectedContent, actualHtmlContent); + } + @Test + public void testFenceLenFour_1() throws CoreException { + String source= """ + /// ```` + /// ``` + /// @param is not a tag here because this is nested literal *markdown* + /// ``` + /// ```` + public class FenceLenFour { + } + """; + ICompilationUnit cu= getWorkingCopy("/TestSetupProject/src/p/FenceLenFour.java", source, null); + assertNotNull("FenceLenFour.java", cu); + + String expectedContent= """ +
```
+				@param is not a tag here because this is nested literal *markdown*
+				```
+				
+ """; + IType type= cu.getType("FenceLenFour"); + String actualHtmlContent= getHoverHtmlContent(cu, type); + assertHtmlContent(expectedContent, actualHtmlContent); + } + @Test + public void testFenceLenFour_2() throws CoreException { + String source= """ + public class FenceLenFour { + /// ````` + /// ```` + /// ``` + /// @param is not a tag here because this is nested literal *markdown* + /// ``` + /// ```` + /// ````` + /// @return an int value + /// @param i real param + public int foo(int i) { + return 0; + } + } + """; + ICompilationUnit cu= getWorkingCopy("/TestSetupProject/src/p/FenceLenFour.java", source, null); + assertNotNull("FenceLenFour.java", cu); + + String expectedContent= """ +
```
+				@param is not a tag here because this is nested literal *markdown*
+				```
+				
+
Returns:
an int value
+ """; + IType type= cu.getType("FenceLenFour"); + IMethod method= type.getMethods()[0]; + String actualHtmlContent= getHoverHtmlContent(cu, method); + assertHtmlContent(expectedContent, actualHtmlContent); + } +} \ No newline at end of file