mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-05 07:15:39 +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:
parent
830bf8074c
commit
0c5b5771b9
3 changed files with 116 additions and 14 deletions
|
@ -329,8 +329,8 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
|
||||||
// /**
|
// /**
|
||||||
// * X
|
// * X
|
||||||
// */
|
// */
|
||||||
// enum A { B,//!< B
|
// enum A { B,/**< B */
|
||||||
// C }; //!< C
|
// C }; /**< C */
|
||||||
public void testAutoDocCommentContent13() throws CoreException {
|
public void testAutoDocCommentContent13() throws CoreException {
|
||||||
assertAutoEditBehaviour();
|
assertAutoEditBehaviour();
|
||||||
}
|
}
|
||||||
|
@ -342,7 +342,7 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
|
||||||
// /**
|
// /**
|
||||||
// * X
|
// * X
|
||||||
// */
|
// */
|
||||||
// enum A { B,//!< B
|
// enum A { B,/**< B */
|
||||||
// C };//!< C
|
// C };//!< C
|
||||||
public void testAutoDocCommentContent14() throws CoreException {
|
public void testAutoDocCommentContent14() throws CoreException {
|
||||||
assertAutoEditBehaviour();
|
assertAutoEditBehaviour();
|
||||||
|
@ -356,7 +356,7 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
|
||||||
// * X
|
// * X
|
||||||
// */
|
// */
|
||||||
// enum A { B,//!< B
|
// enum A { B,//!< B
|
||||||
// C };//!< C
|
// C };/**< C */
|
||||||
public void testAutoDocCommentContent15() throws CoreException {
|
public void testAutoDocCommentContent15() throws CoreException {
|
||||||
assertAutoEditBehaviour();
|
assertAutoEditBehaviour();
|
||||||
}
|
}
|
||||||
|
@ -499,6 +499,45 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
|
||||||
assertAutoEditBehaviour();
|
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 **/
|
/** Declarations **/
|
||||||
|
|
||||||
// /**X
|
// /**X
|
||||||
|
|
|
@ -351,8 +351,8 @@ public class DoxygenCCommentSingleAutoEditStrategyTest extends AbstractAutoEditT
|
||||||
|
|
||||||
// ///
|
// ///
|
||||||
// /// X
|
// /// X
|
||||||
// enum A { B,//!< B
|
// enum A { B,///< B
|
||||||
// C }; //!< C
|
// C }; ///< C
|
||||||
public void testAutoDocCommentContent13() throws CoreException {
|
public void testAutoDocCommentContent13() throws CoreException {
|
||||||
assertAutoEditBehaviour();
|
assertAutoEditBehaviour();
|
||||||
}
|
}
|
||||||
|
@ -363,7 +363,7 @@ public class DoxygenCCommentSingleAutoEditStrategyTest extends AbstractAutoEditT
|
||||||
|
|
||||||
// ///
|
// ///
|
||||||
// /// X
|
// /// X
|
||||||
// enum A { B,//!< B
|
// enum A { B,///< B
|
||||||
// C };//!< C
|
// C };//!< C
|
||||||
public void testAutoDocCommentContent14() throws CoreException {
|
public void testAutoDocCommentContent14() throws CoreException {
|
||||||
assertAutoEditBehaviour();
|
assertAutoEditBehaviour();
|
||||||
|
@ -376,7 +376,7 @@ public class DoxygenCCommentSingleAutoEditStrategyTest extends AbstractAutoEditT
|
||||||
// ///
|
// ///
|
||||||
// /// X
|
// /// X
|
||||||
// enum A { B,//!< B
|
// enum A { B,//!< B
|
||||||
// C };//!< C
|
// C };///< C
|
||||||
public void testAutoDocCommentContent15() throws CoreException {
|
public void testAutoDocCommentContent15() throws CoreException {
|
||||||
assertAutoEditBehaviour();
|
assertAutoEditBehaviour();
|
||||||
}
|
}
|
||||||
|
@ -387,8 +387,8 @@ public class DoxygenCCommentSingleAutoEditStrategyTest extends AbstractAutoEditT
|
||||||
|
|
||||||
// ///
|
// ///
|
||||||
// /// X
|
// /// X
|
||||||
// enum A { B,//!< B
|
// enum A { B,///< B
|
||||||
// C }; //!< C
|
// C }; ///< C
|
||||||
public void _testAutoDocCommentContent16() throws CoreException {
|
public void _testAutoDocCommentContent16() throws CoreException {
|
||||||
/*
|
/*
|
||||||
* Indenting in the presence of tabs is not handled at the moment.
|
* Indenting in the presence of tabs is not handled at the moment.
|
||||||
|
@ -498,6 +498,42 @@ public class DoxygenCCommentSingleAutoEditStrategyTest extends AbstractAutoEditT
|
||||||
assertAutoEditBehaviour();
|
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 **/
|
/** Declarations **/
|
||||||
|
|
||||||
// ///X
|
// ///X
|
||||||
|
|
|
@ -18,6 +18,7 @@ package org.eclipse.cdt.ui.text.doctools.doxygen;
|
||||||
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ExpansionOverlapsBoundaryException;
|
import org.eclipse.cdt.core.dom.ast.ExpansionOverlapsBoundaryException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||||
|
@ -68,7 +69,15 @@ import org.eclipse.jface.text.TextUtilities;
|
||||||
*/
|
*/
|
||||||
public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAutoEditStrategy
|
public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAutoEditStrategy
|
||||||
implements DefaultMultilineCommentAutoEditStrategy.IDocCustomizer {
|
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 CLASS = "class "; //$NON-NLS-1$
|
||||||
private static final String ENUM = "enum "; //$NON-NLS-1$
|
private static final String ENUM = "enum "; //$NON-NLS-1$
|
||||||
private static final String THROW = "throw "; //$NON-NLS-1$
|
private static final String THROW = "throw "; //$NON-NLS-1$
|
||||||
|
@ -407,7 +416,7 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
alterDoc(doc, declToDocument);
|
alterDoc(doc, declToDocument, partition);
|
||||||
} catch (BadLocationException ble) {
|
} catch (BadLocationException ble) {
|
||||||
/*ignore*/
|
/*ignore*/
|
||||||
}
|
}
|
||||||
|
@ -497,9 +506,27 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut
|
||||||
/*
|
/*
|
||||||
* Add post-declaration comments to enumerators, after initializing a doc-comment on an enumeration
|
* 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
|
if (dec instanceof IASTSimpleDeclaration
|
||||||
&& ((IASTSimpleDeclaration) dec).getDeclSpecifier() instanceof IASTEnumerationSpecifier) {
|
&& ((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();
|
IASTEnumerationSpecifier spc = (IASTEnumerationSpecifier) ((IASTSimpleDeclaration) dec).getDeclSpecifier();
|
||||||
IASTEnumerator[] enms = spc.getEnumerators();
|
IASTEnumerator[] enms = spc.getEnumerators();
|
||||||
|
|
||||||
|
@ -534,7 +561,7 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut
|
||||||
IASTNodeLocation loc = enumerator.getName().getFileLocation();
|
IASTNodeLocation loc = enumerator.getName().getFileLocation();
|
||||||
if (loc != null) {
|
if (loc != null) {
|
||||||
int nodeOffset = loc.getNodeOffset() + loc.getNodeLength();
|
int nodeOffset = loc.getNodeOffset() + loc.getNodeLength();
|
||||||
String cmt = SINGLELINE_COMMENT_PRECEDING + enumerator.getName();
|
String cmt = preceding + enumerator.getName() + ending;
|
||||||
IRegion line = doc.getLineInformationOfOffset(nodeOffset);
|
IRegion line = doc.getLineInformationOfOffset(nodeOffset);
|
||||||
if (!doc.get(line.getOffset(), line.getLength()).contains("//")) { //$NON-NLS-1$
|
if (!doc.get(line.getOffset(), line.getLength()).contains("//")) { //$NON-NLS-1$
|
||||||
noCollisions &= entries.add(new Entry(line.getOffset(), line.getLength(), cmt));
|
noCollisions &= entries.add(new Entry(line.getOffset(), line.getLength(), cmt));
|
||||||
|
|
Loading…
Add table
Reference in a new issue