summaryrefslogtreecommitdiff
path: root/src/libs/qmljs/qmljscodeformatter.cpp
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2011-09-07 13:30:48 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2011-09-14 11:02:45 +0200
commit16b4a6fe733b9973311ae19c6ecc90b1a6c53f36 (patch)
treebcc70f823600c6aef5a820cff6df3e6af44701db /src/libs/qmljs/qmljscodeformatter.cpp
parentbbc48690e85adbe5ea8a5ffe14d5ba26fc7a3b7c (diff)
downloadqt-creator-16b4a6fe733b9973311ae19c6ecc90b1a6c53f36.tar.gz
QmlJS indenter: Fix labelled statements and break/continue with label.
Also do some cleanup to make handling of substatements nicer. Change-Id: I78773fc81d9b0058fa97c5cef393cca34b7fd885 Reviewed-on: http://codereview.qt-project.org/4413 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
Diffstat (limited to 'src/libs/qmljs/qmljscodeformatter.cpp')
-rw-r--r--src/libs/qmljs/qmljscodeformatter.cpp34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/libs/qmljs/qmljscodeformatter.cpp b/src/libs/qmljs/qmljscodeformatter.cpp
index eb7e61642d..b02075e4f8 100644
--- a/src/libs/qmljs/qmljscodeformatter.cpp
+++ b/src/libs/qmljs/qmljscodeformatter.cpp
@@ -252,6 +252,12 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
default: enter(expression); continue; // really? identifier and more tokens might already be gone
} break;
+ case expression_or_label:
+ switch (kind) {
+ case Colon: turnInto(labelled_statement); break;
+ default: enter(expression); continue;
+ } break;
+
case expression:
if (tryInsideExpression())
break;
@@ -346,6 +352,12 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
case RightBrace: leave(true); break;
} break;
+ case labelled_statement:
+ if (tryStatement())
+ break;
+ leave(true); // error recovery
+ break;
+
case substatement:
// prefer substatement_open over block_open
if (kind != LeftBrace) {
@@ -426,7 +438,11 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
case RightParenthesis: leave(); leave(true); break;
} break;
- break;
+ case breakcontinue_statement:
+ switch (kind) {
+ case Identifier: leave(true); break;
+ default: leave(true); continue; // try again
+ } break;
case case_start:
switch (kind) {
@@ -466,11 +482,22 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
int topState = m_currentState.top().type;
+ // if there's no colon on the same line, it's not a label
+ if (topState == expression_or_label)
+ enter(expression);
+ // if not followed by an identifier on the same line, it's done
+ else if (topState == breakcontinue_statement)
+ leave(true);
+
+ topState = m_currentState.top().type;
+
+ // some states might be continued on the next line
if (topState == expression
|| topState == expression_or_objectdefinition
|| topState == objectliteral_assignment) {
enter(expression_maybe_continuation);
}
+ // multi-line comment start?
if (topState != multiline_comment_start
&& topState != multiline_comment_cont
&& (lexerState & Scanner::MultiLineMask) == Scanner::MultiLineComment) {
@@ -680,7 +707,6 @@ bool CodeFormatter::tryStatement()
case Break:
case Continue:
enter(breakcontinue_statement);
- leave(true);
return true;
case Throw:
enter(throw_statement);
@@ -717,7 +743,10 @@ bool CodeFormatter::tryStatement()
enter(jsblock_open);
return true;
case Identifier:
+ enter(expression_or_label);
+ return true;
case Delimiter:
+ case Var:
case PlusPlus:
case MinusMinus:
case Import:
@@ -755,7 +784,6 @@ bool CodeFormatter::isExpressionEndState(int type) const
type == objectdefinition_open ||
type == if_statement ||
type == else_clause ||
- type == do_statement ||
type == jsblock_open ||
type == substatement_open ||
type == bracket_open ||