Skip to content

Commit

Permalink
Issue with code fence > 3 in markdown comment (#3006)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarthana authored Sep 30, 2024
1 parent a7d37f7 commit 82ee020
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,15 @@ protected boolean commentParse() {
int lastStarPosition = -1;

// Init scanner position
this.markdown = this.source[this.javadocStart + 1] == '/';
this.linePtr = getLineNumber(this.firstTagPosition);
int realStart = this.linePtr==1 ? this.javadocStart : this.scanner.getLineEnd(this.linePtr-1)+1;
if (realStart < this.javadocStart) realStart = this.javadocStart;
int realStart = this.javadocStart;
if (!this.markdown) {
realStart = this.linePtr==1 ? this.javadocStart : this.scanner.getLineEnd(this.linePtr-1)+1;
if (realStart < this.javadocStart) realStart = this.javadocStart;
} else {
this.linePtr = getLineNumber(realStart);
}
this.scanner.resetTo(realStart, this.javadocEnd);
this.index = realStart;
if (realStart == this.javadocStart) {
Expand All @@ -191,7 +197,6 @@ protected boolean commentParse() {
}
int previousPosition = this.index;
char nextCharacter = 0;
this.markdown = this.source[this.javadocStart + 1] == '/';
this.markdownHelper = IMarkdownCommentHelper.create(this);
if (realStart == this.javadocStart) {
nextCharacter = readChar(); // second '*' or '/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ public void recordFenceChar(char previous, char next, boolean lineStarted) {
int required = this.insideFencedCodeBlock ? this.fenceLength : 3;
if (++this.fenceCharCount == required) {
this.insideFencedCodeBlock^=true;
this.fenceLength = this.fenceCharCount;
}
if (this.insideFencedCodeBlock && this.fenceCharCount >= this.fenceLength)
this.fenceLength = this.fenceCharCount;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ protected Map getCompilerOptions() {
options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
options.put(CompilerOptions.OPTION_DocCommentSupport, this.docCommentSupport);
options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, this.reportInvalidJavadoc);
options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR);
if (!CompilerOptions.IGNORE.equals(this.reportInvalidJavadoc)) {
options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, this.reportInvalidJavadocVisibility);
}
Expand Down Expand Up @@ -612,4 +613,100 @@ public static void main(String[] args) {
this.reportMissingJavadocTags = bkup;
}
}
public void test022() {
String bkup = this.reportMissingJavadocTags;
try {
this.reportMissingJavadocTags = CompilerOptions.IGNORE;
this.runConformTest(new String[] {
"X.java",
"""
import java.lang.annotation.Documented;
/**
* Reference type {@link Documented}:
*/
public class X {
public static void main(String[] args) {
System.out.println("Hello");
}
}
"""},
"Hello");
} finally {
this.reportMissingJavadocTags = bkup;
}
}
public void test023() {
String bkup = this.reportMissingJavadocTags;
try {
this.reportMissingJavadocTags = CompilerOptions.IGNORE;
this.runNegativeTest(new String[] {
"X.java",
"""
import java.lang.annotation.Documented;
/**
* Reference type but no reference here - :
*/
public class X {
public static void main(String[] args) {
System.out.println("Hello");
}
}
"""},
"----------\n" +
"1. ERROR in X.java (at line 1)\n" +
" import java.lang.annotation.Documented;\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"The import java.lang.annotation.Documented is never used\n" +
"----------\n");
} finally {
this.reportMissingJavadocTags = bkup;
}
}
public void test024() {
String bkup = this.reportMissingJavadocTags;
try {
this.reportMissingJavadocTags = CompilerOptions.IGNORE;
this.runConformTest(new String[] { "X.java",
"""
import java.lang.annotation.Documented;
///
/// Reference type {@link Documented}:
///
public class X {
public static void main(String[] args) {
System.out.println("Hello");
}
}
"""},
"Hello");
} finally {
this.reportMissingJavadocTags = bkup;
}
}
public void test025() {
String bkup = this.reportMissingJavadocTags;
try {
this.reportMissingJavadocTags = CompilerOptions.IGNORE;
this.runNegativeTest(new String[] { "X.java",
"""
import java.lang.annotation.Documented;
///
/// Reference type but no reference here:
///
public class X {
public static void main(String[] args) {
System.out.println("Hello");
}
}
"""},
"----------\n" +
"1. ERROR in X.java (at line 1)\n" +
" import java.lang.annotation.Documented;\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"The import java.lang.annotation.Documented is never used\n" +
"----------\n");
} finally {
this.reportMissingJavadocTags = bkup;
}
}
}

0 comments on commit 82ee020

Please sign in to comment.