From 8b013f8d0eb8af5ce5f0a48ba30b1783ec144398 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Wed, 19 Jun 2024 22:03:30 -0400 Subject: [PATCH] Add support for inline tags within an inlined return - modify AbstractCommentParser to keep track when we are in an inlined return statement and to add inline tags as fragments - add addFragmentToInlineReturn() method - add new test to JavadocTest_16 - fixes #1026 --- .../parser/AbstractCommentParser.java | 25 +++++++++++++------ .../compiler/regression/JavadocTest_16.java | 23 +++++++++++++++-- .../jdt/core/dom/DocCommentParser.java | 25 ++++++++++++++++++- 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java index 65e58de3e7e..13fb15e6992 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2022 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -90,6 +90,7 @@ public abstract class AbstractCommentParser implements JavadocTagConstants { // Flags protected boolean lineStarted = false; protected boolean inlineTagStarted = false; + protected boolean inlineReturn= false; protected boolean abort = false; protected int kind; protected int tagValue = NO_TAG_VALUE; @@ -251,7 +252,7 @@ protected boolean commentParse() { openingBraces = 0; } } else if ((!this.lineStarted || previousChar == '{') || lookForTagsInSnippets()) { - if (this.inlineTagStarted) { + if (this.inlineTagStarted && !inlineReturn) { setInlineTagStarted(false); // bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=53279 // Cannot have @ inside inline comment @@ -352,6 +353,9 @@ protected boolean commentParse() { if (!isFormatterParser && !considerTagAsPlainText) this.textStart = this.index; setInlineTagStarted(false); + if (this.inlineReturn) { + addFragmentToInlineReturn(); + } } else { if (!this.lineStarted) { this.textStart = previousPosition; @@ -368,23 +372,26 @@ protected boolean commentParse() { if (considerTagAsPlainText) { openingBraces++; } else if (this.inlineTagStarted) { + if (this.tagValue == TAG_RETURN_VALUE) { + this.inlineReturn= true; + } + if (this.lineStarted && this.textStart != -1 && this.textStart < textEndPosition) { + pushText(this.textStart, textEndPosition); + } setInlineTagStarted(false); // bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=53279 // Cannot have opening brace in inline comment - if (this.reportProblems) { + if (this.reportProblems && !this.inlineReturn || peekChar() != '@') { int end = previousPosition 1) { + ASTNode lastNode= (ASTNode) fragments.get(size - 1); + if (lastNode instanceof TagElement lastTag) { + if (!lastTag.getTagName().equals(TagElement.TAG_RETURN)) { + ASTNode secondLastNode= (ASTNode) fragments.get(size - 2); + if (secondLastNode instanceof TagElement prevTag && prevTag.getTagName().equals(TagElement.TAG_RETURN)) { + fragments.remove(size - 1); + prevTag.fragments().add(lastNode); + this.inlineTagStart= prevTag.getStartPosition(); + this.inlineTagStarted= true; + prevTag.setSourceRange(prevTag.getStartPosition(), lastNode.getStartPosition() + lastNode.getLength() - prevTag.getStartPosition()); + } + } else { + this.inlineReturn= false; + } + } + } + } /* * Add stored tag elements to associated comment. */