From 164c2c3331491b5fab60b625ee192a7e1580e493 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Thu, 16 Sep 2010 15:06:09 +0000 Subject: [PATCH] Bug 323561 - No Doxygen template comments for extern "C" void myFunc(int param) Patch from Marc-Andre Laperle --- .../DoxygenMultilineAutoEditStrategy.java | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) 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 837a4a8c878..42888368110 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 @@ -20,6 +20,7 @@ import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITypedRegion; import org.eclipse.jface.text.TextUtilities; +import org.eclipse.cdt.core.dom.ast.ExpansionOverlapsBoundaryException; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; @@ -35,7 +36,9 @@ 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.ICPPASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; +import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy; /** @@ -169,16 +172,45 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut protected StringBuilder customizeAfterNewLineForDeclaration(IDocument doc, IASTDeclaration dec, ITypedRegion partition) { fLineDelimiter = TextUtilities.getDefaultLineDelimiter(doc); - while(dec instanceof ICPPASTTemplateDeclaration) /* if? */ - dec= ((ICPPASTTemplateDeclaration)dec).getDeclaration(); + IASTDeclaration declToDocument = dec; + + if(declToDocument instanceof ICPPASTLinkageSpecification) { + ICPPASTLinkageSpecification linkageSpecification = (ICPPASTLinkageSpecification)declToDocument; + IASTDeclaration[] declarations = linkageSpecification.getDeclarations(); + + if(declarations.length == 1) { + + boolean isCurlyExtern = false; + IToken token = null; + + try { + token = declarations[0].getTrailingSyntax(); + } catch (UnsupportedOperationException e) { + return new StringBuilder(); + } catch (ExpansionOverlapsBoundaryException e) { + return new StringBuilder(); + } + + if(token != null && token.getType() == IToken.tRBRACE) { + isCurlyExtern = true; + } + + if(!isCurlyExtern) { + declToDocument = declarations[0]; + } + } + } + + while(declToDocument instanceof ICPPASTTemplateDeclaration) /* if? */ + declToDocument= ((ICPPASTTemplateDeclaration)declToDocument).getDeclaration(); - if(dec instanceof IASTFunctionDefinition) { - IASTFunctionDefinition fd= (IASTFunctionDefinition) dec; + if(declToDocument instanceof IASTFunctionDefinition) { + IASTFunctionDefinition fd= (IASTFunctionDefinition) declToDocument; return documentFunction(fd.getDeclarator(), fd.getDeclSpecifier()); } - if(dec instanceof IASTSimpleDeclaration) { - IASTSimpleDeclaration sdec= (IASTSimpleDeclaration) dec; + if(declToDocument instanceof IASTSimpleDeclaration) { + IASTSimpleDeclaration sdec= (IASTSimpleDeclaration) declToDocument; StringBuilder result= new StringBuilder(); if(sdec.getDeclSpecifier() instanceof IASTCompositeTypeSpecifier) { @@ -201,7 +233,7 @@ public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAut } try { - alterDoc(doc, dec); + alterDoc(doc, declToDocument); } catch(BadLocationException ble) { /*ignore*/ }