diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/doxygen/DoxygenCCommentAutoEditStrategyTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/doxygen/DoxygenCCommentAutoEditStrategyTest.java index 2e4ed51f504..60ba475db90 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/doxygen/DoxygenCCommentAutoEditStrategyTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/doxygen/DoxygenCCommentAutoEditStrategyTest.java @@ -329,8 +329,8 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest { // /** // * X // */ - // enum A { B,//!< B - // C }; //!< C + // enum A { B,/**< B */ + // C }; /**< C */ public void testAutoDocCommentContent13() throws CoreException { assertAutoEditBehaviour(); } @@ -342,7 +342,7 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest { // /** // * X // */ - // enum A { B,//!< B + // enum A { B,/**< B */ // C };//!< C public void testAutoDocCommentContent14() throws CoreException { assertAutoEditBehaviour(); @@ -356,7 +356,7 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest { // * X // */ // enum A { B,//!< B - // C };//!< C + // C };/**< C */ public void testAutoDocCommentContent15() throws CoreException { assertAutoEditBehaviour(); } @@ -499,6 +499,45 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest { assertAutoEditBehaviour(); } + // /*!X + // enum A { B, + // C }; + + // /*! + // * X + // */ + // enum A { B,/*!< B */ + // C }; /*!< C */ + public void testAutoDocCommentContent22() throws CoreException { + assertAutoEditBehaviour(); + } + + // /*!X + // enum A { B, + // C };//!< C + + // /*! + // * X + // */ + // enum A { B,/*!< B */ + // C };//!< C + public void testAutoDocCommentContent23() throws CoreException { + assertAutoEditBehaviour(); + } + + // /*!X + // enum A { B,//!< B + // C }; + + // /*! + // * X + // */ + // enum A { B,//!< B + // C };/*!< C */ + public void testAutoDocCommentContent24() throws CoreException { + assertAutoEditBehaviour(); + } + /** Declarations **/ // /**X diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/doxygen/DoxygenCCommentSingleAutoEditStrategyTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/doxygen/DoxygenCCommentSingleAutoEditStrategyTest.java index c46c0397482..f1338662800 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/doxygen/DoxygenCCommentSingleAutoEditStrategyTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/doxygen/DoxygenCCommentSingleAutoEditStrategyTest.java @@ -351,8 +351,8 @@ public class DoxygenCCommentSingleAutoEditStrategyTest extends AbstractAutoEditT // /// // /// X - // enum A { B,//!< B - // C }; //!< C + // enum A { B,///< B + // C }; ///< C public void testAutoDocCommentContent13() throws CoreException { assertAutoEditBehaviour(); } @@ -363,7 +363,7 @@ public class DoxygenCCommentSingleAutoEditStrategyTest extends AbstractAutoEditT // /// // /// X - // enum A { B,//!< B + // enum A { B,///< B // C };//!< C public void testAutoDocCommentContent14() throws CoreException { assertAutoEditBehaviour(); @@ -376,7 +376,7 @@ public class DoxygenCCommentSingleAutoEditStrategyTest extends AbstractAutoEditT // /// // /// X // enum A { B,//!< B - // C };//!< C + // C };///< C public void testAutoDocCommentContent15() throws CoreException { assertAutoEditBehaviour(); } @@ -387,8 +387,8 @@ public class DoxygenCCommentSingleAutoEditStrategyTest extends AbstractAutoEditT // /// // /// X - // enum A { B,//!< B - // C }; //!< C + // enum A { B,///< B + // C }; ///< C public void _testAutoDocCommentContent16() throws CoreException { /* * Indenting in the presence of tabs is not handled at the moment. @@ -498,6 +498,42 @@ public class DoxygenCCommentSingleAutoEditStrategyTest extends AbstractAutoEditT assertAutoEditBehaviour(); } + // //!X + // enum A { B, + // C }; + + // //! + // //! X + // enum A { B,//!< B + // C }; //!< C + public void testAutoDocCommentContent22() throws CoreException { + assertAutoEditBehaviour(); + } + + // //!X + // enum A { B, + // C };//!< C + + // //! + // //! X + // enum A { B,//!< B + // C };//!< C + public void testAutoDocCommentContent23() throws CoreException { + assertAutoEditBehaviour(); + } + + // //!X + // enum A { B,//!< B + // C }; + + // //! + // //! X + // enum A { B,//!< B + // C };//!< C + public void testAutoDocCommentContent24() throws CoreException { + assertAutoEditBehaviour(); + } + /** Declarations **/ // ///X diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/doctools/doxygen/DoxygenMultilineAutoEditStrategy.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/doctools/doxygen/DoxygenMultilineAutoEditStrategy.java index 9d9e5e44c07..3788b85fa5b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/doctools/doxygen/DoxygenMultilineAutoEditStrategy.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/doctools/doxygen/DoxygenMultilineAutoEditStrategy.java @@ -18,6 +18,7 @@ package org.eclipse.cdt.ui.text.doctools.doxygen; import java.util.LinkedHashSet; import java.util.Optional; +import java.util.regex.Pattern; import org.eclipse.cdt.core.dom.ast.ExpansionOverlapsBoundaryException; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; @@ -68,7 +69,15 @@ import org.eclipse.jface.text.TextUtilities; */ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAutoEditStrategy implements DefaultMultilineCommentAutoEditStrategy.IDocCustomizer { - private static final String SINGLELINE_COMMENT_PRECEDING = "//!< "; //$NON-NLS-1$ + private static final String SINGLELINE_COMMENT_PRECEDING_1 = "//!< "; //$NON-NLS-1$ + private static final String SINGLELINE_COMMENT_PRECEDING_2 = "///< "; //$NON-NLS-1$ + private static final String SINGLELINE_COMMENT_PRECEDING_3 = "/*!< "; //$NON-NLS-1$ + private static final String SINGLELINE_COMMENT_PRECEDING_4 = "/**< "; //$NON-NLS-1$ + private static final Pattern STYLE_1 = Pattern.compile("\\s*//!"); //$NON-NLS-1$ + private static final Pattern STYLE_2 = Pattern.compile("\\s*///"); //$NON-NLS-1$ + private static final Pattern STYLE_3 = Pattern.compile("\\s*\\/\\*+!"); //$NON-NLS-1$ + private static final Pattern STYLE_4 = Pattern.compile("\\s*\\/\\*\\*+"); //$NON-NLS-1$ + private static final String SINGLELINE_COMMENT_ENDING = " */"; //$NON-NLS-1$ private static final String CLASS = "class "; //$NON-NLS-1$ private static final String ENUM = "enum "; //$NON-NLS-1$ private static final String THROW = "throw "; //$NON-NLS-1$ @@ -407,7 +416,7 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut } try { - alterDoc(doc, declToDocument); + alterDoc(doc, declToDocument, partition); } catch (BadLocationException ble) { /*ignore*/ } @@ -497,9 +506,27 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut /* * Add post-declaration comments to enumerators, after initializing a doc-comment on an enumeration */ - private void alterDoc(IDocument doc, IASTNode dec) throws BadLocationException { + private void alterDoc(IDocument doc, IASTNode dec, ITypedRegion partition) throws BadLocationException { if (dec instanceof IASTSimpleDeclaration && ((IASTSimpleDeclaration) dec).getDeclSpecifier() instanceof IASTEnumerationSpecifier) { + + String partComment = doc.get(partition.getOffset(), partition.getLength()); + String preceding; + String ending = ""; //$NON-NLS-1$ + if (STYLE_1.matcher(partComment).find()) { + preceding = SINGLELINE_COMMENT_PRECEDING_1; + } else if (STYLE_2.matcher(partComment).find()) { + preceding = SINGLELINE_COMMENT_PRECEDING_2; + } else if (STYLE_3.matcher(partComment).find()) { + preceding = SINGLELINE_COMMENT_PRECEDING_3; + ending = SINGLELINE_COMMENT_ENDING; + } else if (STYLE_4.matcher(partComment).find()) { + preceding = SINGLELINE_COMMENT_PRECEDING_4; + ending = SINGLELINE_COMMENT_ENDING; + } else { + preceding = SINGLELINE_COMMENT_PRECEDING_1; + } + IASTEnumerationSpecifier spc = (IASTEnumerationSpecifier) ((IASTSimpleDeclaration) dec).getDeclSpecifier(); IASTEnumerator[] enms = spc.getEnumerators(); @@ -534,7 +561,7 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut IASTNodeLocation loc = enumerator.getName().getFileLocation(); if (loc != null) { int nodeOffset = loc.getNodeOffset() + loc.getNodeLength(); - String cmt = SINGLELINE_COMMENT_PRECEDING + enumerator.getName(); + String cmt = preceding + enumerator.getName() + ending; IRegion line = doc.getLineInformationOfOffset(nodeOffset); if (!doc.get(line.getOffset(), line.getLength()).contains("//")) { //$NON-NLS-1$ noCollisions &= entries.add(new Entry(line.getOffset(), line.getLength(), cmt));