1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 01:45:33 +02:00

Bug 552334 - Generate enum doxygen comments according to comment style

Change-Id: I49f8188cc9c5421c90a48fb96a5b476de10ef251
Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
This commit is contained in:
Marco Stornelli 2020-01-12 19:38:51 +01:00
parent 830bf8074c
commit 0c5b5771b9
3 changed files with 116 additions and 14 deletions

View file

@ -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

View file

@ -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

View file

@ -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));