diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/DocCommentHighlightingTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/DocCommentHighlightingTest.java index b12a3a0ad73..a3adb83cbe9 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/DocCommentHighlightingTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/DocCommentHighlightingTest.java @@ -126,8 +126,8 @@ public class DocCommentHighlightingTest extends BaseUITestCase { } } - protected List/**/ findRangesColored(RGB rgb) { - List result= new ArrayList(); + protected List findRangesColored(RGB rgb) { + List result= new ArrayList(); IEditorPart p= get(); ISourceViewer vw= ((CEditor)p).getViewer(); Accessor a= new Accessor(vw, TextViewer.class); @@ -156,8 +156,8 @@ public class DocCommentHighlightingTest extends BaseUITestCase { return null; } - private List/**/ mkPositions(int[][] raw) { - List result= new ArrayList(); + private List mkPositions(int[][] raw) { + List result= new ArrayList(); for(int i=0; i*/ expected= mkPositions(new int[][] {comment1, scomment1}); + List expected= mkPositions(new int[][] {comment1, scomment1}); assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB)); } public void testDCOM_B() throws BadLocationException, InterruptedException { DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerB"), true); runEventQueue(1000); - List/**/ expected= mkPositions(new int[][] {comment2, scomment2}); + List expected= mkPositions(new int[][] {comment2, scomment2}); assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB)); } public void testDCOM_C() throws BadLocationException, InterruptedException { DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerC"), true); runEventQueue(1000); - List/**/ expected= mkPositions(new int[][] {comment3, scomment3}); + List expected= mkPositions(new int[][] {comment3, scomment3}); assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB)); } public void testDCOM_ABC() throws BadLocationException, InterruptedException { DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerABC"), true); runEventQueue(1000); - List/**/ expected= mkPositions(new int[][] {comment1, comment2, comment3, scomment1, scomment2, scomment3}); + List expected= mkPositions(new int[][] {comment1, comment2, comment3, scomment1, scomment2, scomment3}); assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB)); } public void testDCOM_BDFG() throws BadLocationException, InterruptedException { DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerBDFG"), true); runEventQueue(1000); - List/**/ expected= mkPositions(new int[][] {comment2, comment4, comment6, comment7, comment8, scomment2}); + List expected= mkPositions(new int[][] {comment2, comment4, comment6, comment7, comment8, scomment2}); assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB)); } public void testDCOM_PUNC() throws BadLocationException, InterruptedException { DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerPUNC"), true); runEventQueue(1000); - List/**/ expected= mkPositions(new int[][] {comment9, comment10, scomment4, scomment5, comment11, comment12, scomment7}); + List expected= mkPositions(new int[][] {comment9, comment10, scomment4, scomment5, comment11, comment12, scomment7}); assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB)); } } 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 2b2b9da6a4a..3818e2bc7f1 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 @@ -236,10 +236,43 @@ public class DoxygenCCommentAutoEditStrategyTest extends DefaultCCommentAutoEdit // * @param x // */ // {} - public void _testAutoDocCommentContent9() throws CoreException { + public void testAutoDocCommentContent9() throws CoreException { + assertAutoEditBehaviour(); + } + + // /** + // * + // */ + // void foo_bar(int x) + // /**X + // {} + + // /** + // * + // */ + // void foo_bar(int x) + // /** + // * X + // * @param x + // */ + // {} + public void testAutoDocCommentContent9b() throws CoreException { + assertAutoEditBehaviour(); + } + + // void foo_bar(int x) + // { + // /**X + // } + + // void foo_bar(int x) + // { + // /** + // * X + // */ + // } + public void testAutoDocCommentContent9c() throws CoreException { assertAutoEditBehaviour(); - // TODO - desired behaviour when there is a comment preceding the declaration - // needs defining } // void foo_bar(int x) @@ -352,6 +385,41 @@ public class DoxygenCCommentAutoEditStrategyTest extends DefaultCCommentAutoEdit assertAutoEditBehaviour(); } + // class D { + // public: + // /**X + // virtual void foo(D x) = 0; + // }; + + // class D { + // public: + // /** + // * X + // * @param x + // */ + // virtual void foo(D x) = 0; + // }; + public void testAutoDocCommentContent18() throws CoreException { + assertAutoEditBehaviour(); + } + + // class D { + // public: + // /**X + // virtual void foo(D x); + // }; + + // class D { + // public: + // /** + // * X + // */ + // virtual void foo(D x); + // }; + public void testAutoDocCommentContent19() throws CoreException { + assertAutoEditBehaviour(); + } + protected void assertAutoEditBehaviour() throws CoreException { CTextTools textTools = CUIPlugin.getDefault().getTextTools(); final IDocument doc = new Document(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/doctools/DefaultMultilineCommentAutoEditStrategy.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/doctools/DefaultMultilineCommentAutoEditStrategy.java index a67fa311ca6..b88b09015d0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/doctools/DefaultMultilineCommentAutoEditStrategy.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/doctools/DefaultMultilineCommentAutoEditStrategy.java @@ -34,7 +34,9 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; +import org.eclipse.cdt.core.dom.ast.IASTNodeSelector; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ITranslationUnit; @@ -109,7 +111,7 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg if (offset == -1 || doc.getLength() == 0) return; - final StringBuffer buf= new StringBuffer(c.text); + final StringBuilder buf= new StringBuilder(c.text); try { // find start of line IRegion line= doc.getLineInformationOfOffset(c.offset); @@ -134,17 +136,25 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg try { doc.replace(c.offset, 0, indentation+" "+MULTILINE_END); // close the comment in order to parse //$NON-NLS-1$ buf.append("\n"); //$NON-NLS-1$ - + // as we are auto-closing, the comment becomes eligible for auto-doc'ing - IASTDeclaration dec= findFollowingDeclaration(getAST(), offset); - - // TODO - it is also needed to support auto-tagging when closing a comment - // within a function declaration. See DoxygenCCommentAutoEditStrategyTest._testAutoDocCommentContent9() - // and DoxygenCCommentAutoEditStrategyTest._testAutoDocCommentContent10() + IASTDeclaration dec= null; + IASTTranslationUnit ast= getAST(); + if(ast != null) { + dec= findFollowingDeclaration(ast, offset); + if(dec == null) { + IASTNodeSelector ans= ast.getNodeSelector(ast.getFilePath()); + IASTNode node= ans.findEnclosingNode(offset, 0); + if(node instanceof IASTDeclaration) { + dec= (IASTDeclaration) node; + } + } + } + if(dec!=null) { ITypedRegion partition= TextUtilities.getPartition(doc, ICPartitions.C_PARTITIONING /* this! */, offset, false); - StringBuffer content= customizeAfterNewLineForDeclaration(doc, dec, partition); + StringBuilder content= customizeAfterNewLineForDeclaration(doc, dec, partition); buf.append(indent(content, indentation + MULTILINE_MID)); } @@ -160,8 +170,8 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg } } - protected StringBuffer customizeAfterNewLineForDeclaration(IDocument doc, IASTDeclaration dec, ITypedRegion region) { - return new StringBuffer(); + protected StringBuilder customizeAfterNewLineForDeclaration(IDocument doc, IASTDeclaration dec, ITypedRegion region) { + return new StringBuilder(); } /* @@ -307,8 +317,8 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg * @param buffer * @param indent */ - protected static final StringBuffer indent(StringBuffer buffer, String indent) { - StringBuffer result= new StringBuffer(); + protected static final StringBuilder indent(StringBuilder buffer, String indent) { + StringBuilder result= new StringBuilder(); BufferedReader br= new BufferedReader(new StringReader(buffer.toString())); try { for(String line= br.readLine(); line!=null; line= br.readLine()) { 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 35f19c9d08f..4d994a0ddf8 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 @@ -31,6 +31,8 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy; @@ -45,11 +47,33 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut private static final String PARAM = "@param "; //$NON-NLS-1$ private static final String RETURN = "@return\n"; //$NON-NLS-1$ - /** - * Default constructor - */ - public DoxygenMultilineAutoEditStrategy() { + protected boolean documentPureVirtuals= true; + public DoxygenMultilineAutoEditStrategy() { + } + + /** + * @param decl the function declarator to document + * @param ds the function specifier to document + * @return content describing the specified function + */ + protected StringBuilder documentFunction(IASTFunctionDeclarator decl, IASTDeclSpecifier ds) { + StringBuilder result= new StringBuilder(); + + result.append(documentFunctionParameters(getParameterDecls(decl))); + + boolean hasReturn= true; + if(ds instanceof IASTSimpleDeclSpecifier) { + IASTSimpleDeclSpecifier sds= (IASTSimpleDeclSpecifier) ds; + if(sds.getType()==IASTSimpleDeclSpecifier.t_void) { + hasReturn= false; + } + } + if(hasReturn) { + result.append(documentFunctionReturn()); + } + + return result; } /** @@ -58,7 +82,7 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut * @return a buffer containing the comment content to generate to describe the parameters of * the specified {@link IASTParameterDeclaration} objects. */ - protected StringBuffer paramTags(IASTParameterDeclaration[] decls) { + protected StringBuffer documentFunctionParameters(IASTParameterDeclaration[] decls) { StringBuffer result= new StringBuffer(); for(int i=0; i entries= new LinkedHashSet(); for(IASTEnumerator enumerator : enms) { - IASTNodeLocation[] locs= enumerator.getName().getNodeLocations(); - if(locs.length==1) { - int nodeOffset= locs[0].getNodeOffset()+locs[0].getNodeLength(); + IASTNodeLocation loc= enumerator.getName().getFileLocation(); + if(loc != null) { + int nodeOffset= loc.getNodeOffset()+loc.getNodeLength(); String cmt= SINGLELINE_COMMENT_PRECEDING+enumerator.getName(); 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)); } - } else { - // TODO } }