From cd190875cc8352a41248bc00e412d69bf42cae52 Mon Sep 17 00:00:00 2001 From: hirschen <falco.hirschenberger@itwm.fraunhofer.de> Date: Tue, 29 Sep 2009 16:31:02 +0200 Subject: [PATCH] fix indentation of template functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit template functions where treated as unfinished lines by the indenter and so the result of: template<typename T> void myFunc() { } was indented as: template<typename T> void myFunc() { } which is pretty ugly and non-standard. Merge-request: 1615 Reviewed-by: Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> --- src/shared/indenter/constants.cpp | 4 +++- src/shared/indenter/indenter.h | 1 + src/shared/indenter/indenter_impl.h | 7 ++++--- src/shared/indenter/test/main.cpp | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/shared/indenter/constants.cpp b/src/shared/indenter/constants.cpp index 1998df0945f..a10b584c8f5 100644 --- a/src/shared/indenter/constants.cpp +++ b/src/shared/indenter/constants.cpp @@ -49,7 +49,8 @@ Constants::Constants() : m_iflikeKeyword(QLatin1String("\\b(?:catch|do|for|if|while|foreach)\\b")), m_caseLabel(QLatin1String("^\\s*(?:case\\b(?:[^:]|::)+" "|(?:public|protected|private|signals|Q_SIGNALS|default)(?:\\s+slots|\\s+Q_SLOTS)?\\s*" - "):")) + "):")), + m_templateFunc(QLatin1String("template<.*>")) { m_literal.setMinimal(true); m_inlineCComment.setMinimal(true); @@ -59,4 +60,5 @@ Constants::Constants() : Q_ASSERT(m_braceX.isValid()); Q_ASSERT(m_iflikeKeyword.isValid()); Q_ASSERT(m_caseLabel.isValid()); + Q_ASSERT(m_templateFunc.isValid()); } diff --git a/src/shared/indenter/indenter.h b/src/shared/indenter/indenter.h index 813e4569061..2ce3dca669c 100644 --- a/src/shared/indenter/indenter.h +++ b/src/shared/indenter/indenter.h @@ -54,6 +54,7 @@ struct Constants { QRegExp m_braceX; QRegExp m_iflikeKeyword; QRegExp m_caseLabel; + QRegExp m_templateFunc; }; /* The "linizer" is a group of functions and variables to iterate diff --git a/src/shared/indenter/indenter_impl.h b/src/shared/indenter/indenter_impl.h index 254ba12f113..7255cfa8c92 100644 --- a/src/shared/indenter/indenter_impl.h +++ b/src/shared/indenter/indenter_impl.h @@ -647,10 +647,11 @@ bool Indenter<Iterator>::isUnfinishedLine() if ( ! m_constants.m_bracesSemicolon.contains(lastCh) && !yyLine->endsWith(m_constants.m_3dots) ) { /* It doesn't end with ';' or similar. If it's neither - "Q_OBJECT" nor "if ( x )", it must be an unfinished line. + "Q_OBJECT" nor "if ( x )" nor is a template function, it must be an unfinished line. */ - unf = ( yyLine->contains(m_constants.m_qobject) == 0 && - !matchBracelessControlStatement() ); + unf = ( !yyLine->contains(m_constants.m_qobject) && + !matchBracelessControlStatement() && + !yyLine->contains(m_constants.m_templateFunc) ); } else if ( lastCh == semicolon ) { if ( lastParen(*yyLine) == openingParenthesis ) { /* diff --git a/src/shared/indenter/test/main.cpp b/src/shared/indenter/test/main.cpp index 17be8316544..d1a30923b4b 100644 --- a/src/shared/indenter/test/main.cpp +++ b/src/shared/indenter/test/main.cpp @@ -143,7 +143,7 @@ int format(const QString &fileName) if (p.last().endsWith(colon)) typedIn = colon; - const int indent = Indenter::instance().indentForBottomLine(p.constBegin(), p.constEnd(), typedIn); + const int indent = Indenter::instance().indentForBottomLine(it, p.constBegin(), p.constEnd(), typedIn); const QString trimmed = line.trimmed(); // Indent the line in the list so that the formatter code sees the indented line. -- GitLab