Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,40 @@ protected boolean parseReference() throws InvalidInputException {
return parseReference(false);
}

// Parses a complete URL reference starting from current position
protected boolean parseURLReference(int pos, boolean advanceEndPos) throws InvalidInputException {
char[]fullURL = null;
int firstTokenStartPos;
StringBuilder urlBuilder = new StringBuilder();
char c;
firstTokenStartPos = pos;
while (pos < this.source.length) {
c = this.source[pos];
if (c == '[') // invalid syntax for url
return false;
if (c == '(' || c == ' ') {
pos++;
continue;
}
if (c == '\n' || c == '\r' || c == ')') {
break;
}
urlBuilder.append(c);
pos++;
}
if (advanceEndPos)
this.index = pos;
fullURL = urlBuilder.toString().toCharArray();

this.identifierPtr = 0;
this.identifierStack[this.identifierPtr] = fullURL;
this.identifierPositionStack[this.identifierPtr] = (((long) firstTokenStartPos) << 32) + (pos - 1);
this.identifierLengthStack[this.identifierLengthPtr] = 1;
Object typeRef = createTypeReference(TerminalToken.TokenNameInvalid, true);
pushSeeRef(typeRef);
return true;
}

/*
* Parse a reference in @see tag
*/
Expand Down Expand Up @@ -3617,6 +3651,7 @@ protected boolean verifySpaceOrEndComment() {
// Whitespace or inline tag closing brace
char ch = peekChar();
switch (ch) {
case ')':
case ']':
// TODO: Check if we need to exclude escaped ]
if (this.markdown)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ protected boolean parseMarkdownLinks(int previousPosition) throws InvalidInputEx
// move it past '['
currentChar = readChar();
start = this.index;
} else if (peekChar() == '(') {
valid = parseURLReference(this.index, true);
} else {
break loop;
}
Expand All @@ -602,7 +604,8 @@ protected boolean parseMarkdownLinks(int previousPosition) throws InvalidInputEx
int eofBkup = this.scanner.eofPosition;
this.scanner.resetTo(start, Math.max(this.javadocEnd, this.index));
this.tagValue = TAG_LINK_VALUE;
valid = parseReference(true);
if (!valid)
valid = parseReference(true);
this.tagValue = NO_TAG_VALUE;
this.scanner.eofPosition = eofBkup;
this.markdownHelper.resetLineStart();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1931,4 +1931,250 @@ public class Markdown() {}
assertEquals("Incorrect TextElement value", "Where is my **bold text**???", textElement.getText());
}
}
public void testMarkdownURLs4531_01() throws JavaModelException {
String source = """
/// @see [Ex Si](ex.com)
public class Markdown() {}
""";
this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/gh3761/Markdown.java", source, null);
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
Javadoc javadoc = typedeclaration.getJavadoc();
TagElement tags = (TagElement) javadoc.tags().get(0);
assertEquals("fragments count does not match", 2, tags.fragments().size());
TagElement tagElement = (TagElement) tags.fragments().get(1);
List<?> tagFragments = tagElement.fragments();
assertTrue(tagFragments.get(0) instanceof TextElement);
assertTrue(tagFragments.get(1) instanceof SimpleName);
}
}

public void testMarkdownURLs4531_02() throws JavaModelException {
String source = """
/// @see [Ex Si](http://ex.com)
public class Markdown() {}
""";
this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/gh3761/Markdown.java", source, null);
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
Javadoc javadoc = typedeclaration.getJavadoc();
TagElement tags = (TagElement) javadoc.tags().get(0);
assertEquals("fragments count does not match", 2, tags.fragments().size());
TagElement tagElement = (TagElement) tags.fragments().get(1);
List<?> tagFragments = tagElement.fragments();
assertTrue(tagFragments.get(0) instanceof TextElement);
assertTrue(tagFragments.get(1) instanceof SimpleName);
}
}

public void testMarkdownURLs4531_03() throws JavaModelException {
String source = """
/// @see [Ex Si](https://ex.com/a)
public class Markdown() {}
""";
this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/gh3761/Markdown.java", source, null);
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
Javadoc javadoc = typedeclaration.getJavadoc();
TagElement tags = (TagElement) javadoc.tags().get(0);
assertEquals("fragments count does not match", 2, tags.fragments().size());
TagElement tagElement = (TagElement) tags.fragments().get(1);
List<?> tagFragments = tagElement.fragments();
assertTrue(tagFragments.get(0) instanceof TextElement);
assertTrue(tagFragments.get(1) instanceof SimpleName);
}
}

public void testMarkdownURLs4531_04() throws JavaModelException {
String source = """
/// @see [Ex Si](https://www.ex.net/a)
public class Markdown() {}
""";
this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/gh3761/Markdown.java", source, null);
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
Javadoc javadoc = typedeclaration.getJavadoc();
TagElement tags = (TagElement) javadoc.tags().get(0);
assertEquals("fragments count does not match", 2, tags.fragments().size());
TagElement tagElement = (TagElement) tags.fragments().get(1);
List<?> tagFragments = tagElement.fragments();
assertTrue(tagFragments.get(0) instanceof TextElement);
assertTrue(tagFragments.get(1) instanceof SimpleName);
}
}

// invalid syntax
public void testMarkdownURLs4531_05() throws JavaModelException {
String source = """
/// @see [Ex Si][http://ex.com]
public class Markdown() {}
""";
this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/gh3761/Markdown.java", source, null);
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
Javadoc javadoc = typedeclaration.getJavadoc();
TagElement tags = (TagElement) javadoc.tags().get(0);
assertEquals("fragments count does not match", 3, tags.fragments().size());
assertTrue(tags.fragments().get(0) instanceof TextElement);
assertTrue(tags.fragments().get(1) instanceof TextElement);
assertTrue(tags.fragments().get(2) instanceof TextElement);
}
}

// [)[) - invalid condition
public void testMarkdownURLs4531_06() throws JavaModelException {
String source = """
/// @see [Ex Si)[http://ex.com)
public class Markdown() {}
""";
this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/gh3761/Markdown.java", source, null);
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
Javadoc javadoc = typedeclaration.getJavadoc();
assertEquals("Tags count does not match", 1, javadoc.tags().size());
TagElement tags = (TagElement) javadoc.tags().get(0);
assertTrue(tags.fragments().get(0) instanceof TextElement);
assertTrue(tags.fragments().get(1) instanceof TextElement);
}
}

// (](] - invalid condition
public void testMarkdownURLs4531_07() throws JavaModelException {
String source = """
/// @see (Ex Si](http://ex.com]
public class Markdown() {}
""";
this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/gh3761/Markdown.java", source, null);
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
Javadoc javadoc = typedeclaration.getJavadoc();
TagElement tags = (TagElement) javadoc.tags().get(0);
assertEquals("fragments count does not match", 1, tags.fragments().size());
assertTrue(tags.fragments().get(0) instanceof TextElement);
}
}

// ()[] - invalid condition
public void testMarkdownURLs4531_08() throws JavaModelException {
String source = """
/// @see (Ex Si)[http://ex.com]
public class Markdown() {}
""";
this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/gh3761/Markdown.java", source, null);
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
Javadoc javadoc = typedeclaration.getJavadoc();
TagElement tags = (TagElement) javadoc.tags().get(0);
assertEquals("fragments count does not match", 2, tags.fragments().size());
assertTrue(tags.fragments().get(0) instanceof TextElement);
assertTrue(tags.fragments().get(1) instanceof TextElement);
}
}

public void testMarkdownURLs4531_09() throws JavaModelException {
String source = """
/// @see [Ex Si]( http://ex.com)
public class Markdown() {}
""";
this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/gh3761/Markdown.java", source, null);
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
Javadoc javadoc = typedeclaration.getJavadoc();
TagElement tags = (TagElement) javadoc.tags().get(0);
assertEquals("fragments count does not match", 2, tags.fragments().size());
assertTrue(tags.fragments().get(0) instanceof TextElement);
assertTrue(tags.fragments().get(1) instanceof TagElement);
TagElement fragTag = (TagElement) tags.fragments().get(1);
assertTrue(fragTag.fragments().get(0) instanceof TextElement);
assertTrue(fragTag.fragments().get(1) instanceof SimpleName);
}
}

public void testMarkdownURLs4531_10() throws JavaModelException {
String source = """
/// @see [Ex Si][java.lang.String]
public class Markdown() {}
""";

this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/gh3761/Markdown.java", source, null);
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
Javadoc javadoc = typedeclaration.getJavadoc();
TagElement tags = (TagElement) javadoc.tags().get(0);
assertEquals("fragments count does not match", 2, tags.fragments().size());
assertTrue(tags.fragments().get(0) instanceof TextElement);
assertTrue(tags.fragments().get(1) instanceof TagElement);
TagElement fragTag = (TagElement) tags.fragments().get(1);
assertTrue(fragTag.fragments().get(0) instanceof TextElement);
assertTrue(fragTag.fragments().get(1) instanceof QualifiedName);
}
}

public void testMarkdownURLs4531_11() throws JavaModelException {
String source = """
/// @see [Ex Si][ java.lang.String]
public class Markdown() {}
""";

this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/gh3761/Markdown.java", source, null);
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
Javadoc javadoc = typedeclaration.getJavadoc();
TagElement tags = (TagElement) javadoc.tags().get(0);
assertEquals("fragments count does not match", 2, tags.fragments().size());
assertTrue(tags.fragments().get(0) instanceof TextElement);
assertTrue(tags.fragments().get(1) instanceof TagElement);
TagElement fragTag = (TagElement) tags.fragments().get(1);
assertTrue(fragTag.fragments().get(0) instanceof TextElement);
assertTrue(fragTag.fragments().get(1) instanceof QualifiedName);
}
}

public void testMarkdownURLs4531_12() throws JavaModelException {
String source = """
/// @see [Ex Si](http://ex.com ) [Ex Si]( https://www.ex.com)
public class Markdown() {}
""";
this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/gh3761/Markdown.java", source, null);
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
Javadoc javadoc = typedeclaration.getJavadoc();
TagElement tags = (TagElement) javadoc.tags().get(0);
assertEquals("fragments count does not match", 4, tags.fragments().size());
assertTrue(tags.fragments().get(0) instanceof TextElement);
assertTrue(tags.fragments().get(1) instanceof TagElement);
TagElement tagFrag1 = (TagElement) tags.fragments().get(1);
SimpleName simplName1 = (SimpleName) tagFrag1.fragments().get(1);
assertEquals("SimpleName1 value not match", "http://ex.com", simplName1.getIdentifier());
assertTrue(tags.fragments().get(0) instanceof TextElement);
assertTrue(tags.fragments().get(1) instanceof TagElement);
TagElement tagFrag2 = (TagElement) tags.fragments().get(3);
SimpleName simplName2 = (SimpleName) tagFrag2.fragments().get(1);
assertEquals("SimpleName2 value not match", "https://www.ex.com", simplName2.getIdentifier());
}
}
}
Loading
Loading