Skip to content

Commit 1784afe

Browse files
handled white space before url
1 parent 57aea09 commit 1784afe

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,11 @@ else if (this.tagValue == TAG_VALUE_VALUE) {
15931593
case TokenNameUNDERSCORE:
15941594
case TokenNameIdentifier :
15951595
char[] identifier = this.scanner.getCurrentIdentifierSource();
1596-
if (this.source[this.scanner.getCurrentTokenStartPosition() - 1] == '(') {
1596+
int pos = this.scanner.getCurrentTokenStartPosition() - 1;
1597+
while (pos >= 0 && Character.isWhitespace(this.source[pos])) {
1598+
pos--;
1599+
}
1600+
if (pos >= 0 && this.source[pos] == '(') {
15971601
if (isURLScheme(identifier)) {
15981602
if (isFollowedByURLPattern()) {
15991603
if (typeRef == null) {

org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterMarkdownTest.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,4 +2071,69 @@ public class Markdown() {}
20712071
assertTrue(tags.fragments().get(1) instanceof TextElement);
20722072
}
20732073
}
2074+
2075+
public void testMarkdownURLs4531_09() throws JavaModelException {
2076+
String source = """
2077+
/// @see [Ex Si]( http://ex.com)
2078+
public class Markdown() {}
2079+
""";
2080+
this.workingCopies = new ICompilationUnit[1];
2081+
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/gh3761/Markdown.java", source, null);
2082+
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
2083+
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
2084+
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
2085+
Javadoc javadoc = typedeclaration.getJavadoc();
2086+
TagElement tags = (TagElement) javadoc.tags().get(0);
2087+
assertEquals("fragments count does not match", 2, tags.fragments().size());
2088+
assertTrue(tags.fragments().get(0) instanceof TextElement);
2089+
assertTrue(tags.fragments().get(1) instanceof TagElement);
2090+
TagElement fragTag = (TagElement) tags.fragments().get(1);
2091+
assertTrue(fragTag.fragments().get(0) instanceof TextElement);
2092+
assertTrue(fragTag.fragments().get(1) instanceof SimpleName);
2093+
}
2094+
}
2095+
2096+
public void testMarkdownURLs4531_10() throws JavaModelException {
2097+
String source = """
2098+
/// @see [Ex Si][java.lang.String]
2099+
public class Markdown() {}
2100+
""";
2101+
2102+
this.workingCopies = new ICompilationUnit[1];
2103+
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/gh3761/Markdown.java", source, null);
2104+
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
2105+
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
2106+
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
2107+
Javadoc javadoc = typedeclaration.getJavadoc();
2108+
TagElement tags = (TagElement) javadoc.tags().get(0);
2109+
assertEquals("fragments count does not match", 2, tags.fragments().size());
2110+
assertTrue(tags.fragments().get(0) instanceof TextElement);
2111+
assertTrue(tags.fragments().get(1) instanceof TagElement);
2112+
TagElement fragTag = (TagElement) tags.fragments().get(1);
2113+
assertTrue(fragTag.fragments().get(0) instanceof TextElement);
2114+
assertTrue(fragTag.fragments().get(1) instanceof QualifiedName);
2115+
}
2116+
}
2117+
2118+
public void testMarkdownURLs4531_11() throws JavaModelException {
2119+
String source = """
2120+
/// @see [Ex Si][ java.lang.String]
2121+
public class Markdown() {}
2122+
""";
2123+
2124+
this.workingCopies = new ICompilationUnit[1];
2125+
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/gh3761/Markdown.java", source, null);
2126+
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
2127+
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
2128+
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
2129+
Javadoc javadoc = typedeclaration.getJavadoc();
2130+
TagElement tags = (TagElement) javadoc.tags().get(0);
2131+
assertEquals("fragments count does not match", 2, tags.fragments().size());
2132+
assertTrue(tags.fragments().get(0) instanceof TextElement);
2133+
assertTrue(tags.fragments().get(1) instanceof TagElement);
2134+
TagElement fragTag = (TagElement) tags.fragments().get(1);
2135+
assertTrue(fragTag.fragments().get(0) instanceof TextElement);
2136+
assertTrue(fragTag.fragments().get(1) instanceof QualifiedName);
2137+
}
2138+
}
20742139
}

0 commit comments

Comments
 (0)