summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libs/qmljs/qmljscodeformatter.cpp317
-rw-r--r--src/libs/qmljs/qmljscodeformatter.h15
-rw-r--r--src/plugins/qmljseditor/qmljseditor.cpp2
-rw-r--r--src/plugins/qmljstools/qmljscodestylesettingspage.cpp2
-rw-r--r--src/plugins/qmljstools/qmljsindenter.cpp4
-rw-r--r--src/plugins/qmljstools/qmljsqtstylecodeformatter.cpp328
-rw-r--r--src/plugins/qmljstools/qmljsqtstylecodeformatter.h13
-rw-r--r--src/plugins/qmljstools/qmljsrefactoringchanges.cpp2
-rw-r--r--tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp2
9 files changed, 348 insertions, 337 deletions
diff --git a/src/libs/qmljs/qmljscodeformatter.cpp b/src/libs/qmljs/qmljscodeformatter.cpp
index d8a4fb1ed1..5bbc32cf4f 100644
--- a/src/libs/qmljs/qmljscodeformatter.cpp
+++ b/src/libs/qmljs/qmljscodeformatter.cpp
@@ -989,3 +989,320 @@ void CodeFormatter::dump() const
}
qDebug() << "Current indent depth:" << m_indentDepth;
}
+
+QtStyleCodeFormatter::QtStyleCodeFormatter()
+ : m_indentSize(4)
+{}
+
+void QtStyleCodeFormatter::setIndentSize(int size)
+{
+ m_indentSize = size;
+}
+
+void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedIndentDepth) const
+{
+ const State &parentState = state();
+ const Token &tk = currentToken();
+ const int tokenPosition = column(tk.begin());
+ const bool firstToken = (tokenIndex() == 0);
+ const bool lastToken = (tokenIndex() == tokenCount() - 1);
+
+ switch (newState) {
+ case objectdefinition_open: {
+ // special case for things like "gradient: Gradient {"
+ if (parentState.type == binding_assignment)
+ *savedIndentDepth = state(1).savedIndentDepth;
+
+ if (firstToken)
+ *savedIndentDepth = tokenPosition;
+
+ *indentDepth = *savedIndentDepth + m_indentSize;
+ break;
+ }
+
+ case binding_or_objectdefinition:
+ if (firstToken)
+ *indentDepth = *savedIndentDepth = tokenPosition;
+ break;
+
+ case binding_assignment:
+ case objectliteral_assignment:
+ if (lastToken)
+ *indentDepth = *savedIndentDepth + 4;
+ else
+ *indentDepth = column(tokenAt(tokenIndex() + 1).begin());
+ break;
+
+ case expression_or_objectdefinition:
+ *indentDepth = tokenPosition;
+ break;
+
+ case expression_or_label:
+ if (*indentDepth == tokenPosition)
+ *indentDepth += 2*m_indentSize;
+ else
+ *indentDepth = tokenPosition;
+ break;
+
+ case expression:
+ if (*indentDepth == tokenPosition) {
+ // expression_or_objectdefinition doesn't want the indent
+ // expression_or_label already has it
+ if (parentState.type != expression_or_objectdefinition
+ && parentState.type != expression_or_label
+ && parentState.type != binding_assignment) {
+ *indentDepth += 2*m_indentSize;
+ }
+ }
+ // expression_or_objectdefinition and expression_or_label have already consumed the first token
+ else if (parentState.type != expression_or_objectdefinition
+ && parentState.type != expression_or_label) {
+ *indentDepth = tokenPosition;
+ }
+ break;
+
+ case expression_maybe_continuation:
+ // set indent depth to indent we'd get if the expression ended here
+ for (int i = 1; state(i).type != topmost_intro; ++i) {
+ const int type = state(i).type;
+ if (isExpressionEndState(type) && !isBracelessState(type)) {
+ *indentDepth = state(i - 1).savedIndentDepth;
+ break;
+ }
+ }
+ break;
+
+ case bracket_open:
+ if (parentState.type == expression && state(1).type == binding_assignment) {
+ *savedIndentDepth = state(2).savedIndentDepth;
+ *indentDepth = *savedIndentDepth + m_indentSize;
+ } else if (parentState.type == objectliteral_assignment) {
+ *savedIndentDepth = parentState.savedIndentDepth;
+ *indentDepth = *savedIndentDepth + m_indentSize;
+ } else if (!lastToken) {
+ *indentDepth = tokenPosition + 1;
+ } else {
+ *indentDepth = *savedIndentDepth + m_indentSize;
+ }
+ break;
+
+ case function_start:
+ if (parentState.type == expression) {
+ // undo the continuation indent of the expression
+ *indentDepth = parentState.savedIndentDepth;
+ *savedIndentDepth = *indentDepth;
+ }
+ break;
+
+ case do_statement_while_paren_open:
+ case statement_with_condition_paren_open:
+ case signal_arglist_open:
+ case function_arglist_open:
+ case paren_open:
+ case condition_paren_open:
+ if (!lastToken)
+ *indentDepth = tokenPosition + 1;
+ else
+ *indentDepth += m_indentSize;
+ break;
+
+ case ternary_op:
+ if (!lastToken)
+ *indentDepth = tokenPosition + tk.length + 1;
+ else
+ *indentDepth += m_indentSize;
+ break;
+
+ case jsblock_open:
+ // closing brace should be aligned to case
+ if (parentState.type == case_cont) {
+ *savedIndentDepth = parentState.savedIndentDepth;
+ break;
+ }
+ // fallthrough
+ case substatement_open:
+ // special case for "foo: {" and "property int foo: {"
+ if (parentState.type == binding_assignment)
+ *savedIndentDepth = state(1).savedIndentDepth;
+ *indentDepth = *savedIndentDepth + m_indentSize;
+ break;
+
+ case substatement:
+ *indentDepth += m_indentSize;
+ break;
+
+ case objectliteral_open:
+ if (parentState.type == expression
+ || parentState.type == objectliteral_assignment) {
+ // undo the continuation indent of the expression
+ if (state(1).type == expression_or_label)
+ *indentDepth = state(1).savedIndentDepth;
+ else
+ *indentDepth = parentState.savedIndentDepth;
+ *savedIndentDepth = *indentDepth;
+ }
+ *indentDepth += m_indentSize;
+ break;
+
+
+ case statement_with_condition:
+ case statement_with_block:
+ case if_statement:
+ case do_statement:
+ case switch_statement:
+ if (firstToken || parentState.type == binding_assignment)
+ *savedIndentDepth = tokenPosition;
+ // ### continuation
+ *indentDepth = *savedIndentDepth; // + 2*m_indentSize;
+ // special case for 'else if'
+ if (!firstToken
+ && newState == if_statement
+ && parentState.type == substatement
+ && state(1).type == else_clause) {
+ *indentDepth = state(1).savedIndentDepth;
+ *savedIndentDepth = *indentDepth;
+ }
+ break;
+
+ case maybe_else: {
+ // set indent to outermost braceless savedIndent
+ int outermostBraceless = 0;
+ while (isBracelessState(state(outermostBraceless + 1).type))
+ ++outermostBraceless;
+ *indentDepth = state(outermostBraceless).savedIndentDepth;
+ // this is where the else should go, if one appears - aligned to if_statement
+ *savedIndentDepth = state().savedIndentDepth;
+ break;
+ }
+
+ case condition_open:
+ // fixed extra indent when continuing 'if (', but not for 'else if ('
+ if (tokenPosition <= *indentDepth + m_indentSize)
+ *indentDepth += 2*m_indentSize;
+ else
+ *indentDepth = tokenPosition + 1;
+ break;
+
+ case case_start:
+ *savedIndentDepth = tokenPosition;
+ break;
+
+ case case_cont:
+ *indentDepth += m_indentSize;
+ break;
+
+ case multiline_comment_start:
+ *indentDepth = tokenPosition + 2;
+ break;
+
+ case multiline_comment_cont:
+ *indentDepth = tokenPosition;
+ break;
+ }
+}
+
+void QtStyleCodeFormatter::adjustIndent(const QList<Token> &tokens, int lexerState, int *indentDepth) const
+{
+ Q_UNUSED(lexerState)
+
+ State topState = state();
+ State previousState = state(1);
+
+ // keep user-adjusted indent in multiline comments
+ if (topState.type == multiline_comment_start
+ || topState.type == multiline_comment_cont) {
+ if (!tokens.isEmpty()) {
+ *indentDepth = column(tokens.at(0).begin());
+ return;
+ }
+ }
+
+ const int kind = extendedTokenKind(tokenAt(0));
+ switch (kind) {
+ case LeftBrace:
+ if (topState.type == substatement
+ || topState.type == binding_assignment
+ || topState.type == case_cont) {
+ *indentDepth = topState.savedIndentDepth;
+ }
+ break;
+ case RightBrace: {
+ if (topState.type == jsblock_open && previousState.type == case_cont) {
+ *indentDepth = previousState.savedIndentDepth;
+ break;
+ }
+ for (int i = 0; state(i).type != topmost_intro; ++i) {
+ const int type = state(i).type;
+ if (type == objectdefinition_open
+ || type == jsblock_open
+ || type == substatement_open
+ || type == objectliteral_open) {
+ *indentDepth = state(i).savedIndentDepth;
+ break;
+ }
+ }
+ break;
+ }
+ case RightBracket:
+ for (int i = 0; state(i).type != topmost_intro; ++i) {
+ const int type = state(i).type;
+ if (type == bracket_open) {
+ *indentDepth = state(i).savedIndentDepth;
+ break;
+ }
+ }
+ break;
+
+ case LeftBracket:
+ case LeftParenthesis:
+ case Delimiter:
+ if (topState.type == expression_maybe_continuation)
+ *indentDepth = topState.savedIndentDepth;
+ break;
+
+ case Else:
+ if (topState.type == maybe_else) {
+ *indentDepth = topState.savedIndentDepth;
+ } else if (topState.type == expression_maybe_continuation) {
+ bool hasElse = false;
+ for (int i = 1; state(i).type != topmost_intro; ++i) {
+ const int type = state(i).type;
+ if (type == else_clause)
+ hasElse = true;
+ if (type == if_statement) {
+ if (hasElse) {
+ hasElse = false;
+ } else {
+ *indentDepth = state(i).savedIndentDepth;
+ break;
+ }
+ }
+ }
+ }
+ break;
+
+ case Colon:
+ if (topState.type == ternary_op) {
+ *indentDepth -= 2;
+ }
+ break;
+
+ case Question:
+ if (topState.type == expression_maybe_continuation)
+ *indentDepth = topState.savedIndentDepth;
+ break;
+
+ case Default:
+ case Case:
+ for (int i = 0; state(i).type != topmost_intro; ++i) {
+ const int type = state(i).type;
+ if (type == switch_statement || type == case_cont) {
+ *indentDepth = state(i).savedIndentDepth;
+ break;
+ } else if (type == topmost_intro) {
+ break;
+ }
+ }
+ break;
+ }
+}
diff --git a/src/libs/qmljs/qmljscodeformatter.h b/src/libs/qmljs/qmljscodeformatter.h
index 7af62d5485..7b5865f0e8 100644
--- a/src/libs/qmljs/qmljscodeformatter.h
+++ b/src/libs/qmljs/qmljscodeformatter.h
@@ -315,6 +315,21 @@ private:
int m_tabSize;
};
+class QMLJS_EXPORT QtStyleCodeFormatter : public CodeFormatter
+{
+public:
+ QtStyleCodeFormatter();
+
+ void setIndentSize(int size);
+
+protected:
+ virtual void onEnter(int newState, int *indentDepth, int *savedIndentDepth) const;
+ virtual void adjustIndent(const QList<QmlJS::Token> &tokens, int lexerState, int *indentDepth) const;
+
+private:
+ int m_indentSize;
+};
+
} // namespace QmlJS
#endif // QMLJSCODEFORMATTER_H
diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp
index 20249d7ebf..b0d481db5b 100644
--- a/src/plugins/qmljseditor/qmljseditor.cpp
+++ b/src/plugins/qmljseditor/qmljseditor.cpp
@@ -1486,7 +1486,7 @@ void QmlJSTextEditorWidget::unCommentSelection()
void QmlJSTextEditorWidget::setTabSettings(const TextEditor::TabSettings &ts)
{
- QmlJSTools::QtStyleCodeFormatter formatter(ts);
+ QmlJSTools::CreatorCodeFormatter formatter(ts);
formatter.invalidateCache(document());
TextEditor::BaseTextEditorWidget::setTabSettings(ts);
diff --git a/src/plugins/qmljstools/qmljscodestylesettingspage.cpp b/src/plugins/qmljstools/qmljscodestylesettingspage.cpp
index 25d1c92f6d..e4c05dccbc 100644
--- a/src/plugins/qmljstools/qmljscodestylesettingspage.cpp
+++ b/src/plugins/qmljstools/qmljscodestylesettingspage.cpp
@@ -148,7 +148,7 @@ void QmlJSCodeStylePreferencesWidget::updatePreview()
? m_preferences->currentTabSettings()
: TextEditorSettings::instance()->codeStyle()->tabSettings();
m_ui->previewTextEdit->setTabSettings(ts);
- QtStyleCodeFormatter formatter(ts);
+ CreatorCodeFormatter formatter(ts);
formatter.invalidateCache(doc);
QTextBlock block = doc->firstBlock();
diff --git a/src/plugins/qmljstools/qmljsindenter.cpp b/src/plugins/qmljstools/qmljsindenter.cpp
index 13ffc9621a..3c08e61490 100644
--- a/src/plugins/qmljstools/qmljsindenter.cpp
+++ b/src/plugins/qmljstools/qmljsindenter.cpp
@@ -66,7 +66,7 @@ void Indenter::indentBlock(QTextDocument *doc,
{
Q_UNUSED(doc)
- QmlJSTools::QtStyleCodeFormatter codeFormatter(tabSettings);
+ QmlJSTools::CreatorCodeFormatter codeFormatter(tabSettings);
codeFormatter.updateStateUntil(block);
const int depth = codeFormatter.indentFor(block);
@@ -84,6 +84,6 @@ void Indenter::indentBlock(QTextDocument *doc,
void Indenter::invalidateCache(QTextDocument *doc)
{
- QmlJSTools::QtStyleCodeFormatter codeFormatter;
+ QmlJSTools::CreatorCodeFormatter codeFormatter;
codeFormatter.invalidateCache(doc);
}
diff --git a/src/plugins/qmljstools/qmljsqtstylecodeformatter.cpp b/src/plugins/qmljstools/qmljsqtstylecodeformatter.cpp
index 3961c88046..1e589afe81 100644
--- a/src/plugins/qmljstools/qmljsqtstylecodeformatter.cpp
+++ b/src/plugins/qmljstools/qmljsqtstylecodeformatter.cpp
@@ -40,23 +40,17 @@ using namespace QmlJS;
using namespace QmlJSTools;
using namespace TextEditor;
-QtStyleCodeFormatter::QtStyleCodeFormatter()
- : m_indentSize(4)
+CreatorCodeFormatter::CreatorCodeFormatter()
{
}
-QtStyleCodeFormatter::QtStyleCodeFormatter(const TextEditor::TabSettings &tabSettings)
- : m_indentSize(tabSettings.m_indentSize)
+CreatorCodeFormatter::CreatorCodeFormatter(const TextEditor::TabSettings &tabSettings)
{
setTabSize(tabSettings.m_tabSize);
+ setIndentSize(tabSettings.m_indentSize);
}
-void QtStyleCodeFormatter::setIndentSize(int size)
-{
- m_indentSize = size;
-}
-
-void QtStyleCodeFormatter::saveBlockData(QTextBlock *block, const BlockData &data) const
+void CreatorCodeFormatter::saveBlockData(QTextBlock *block, const BlockData &data) const
{
TextBlockUserData *userData = BaseTextDocumentLayout::userData(*block);
QmlJSCodeFormatterData *cppData = static_cast<QmlJSCodeFormatterData *>(userData->codeFormatterData());
@@ -67,7 +61,7 @@ void QtStyleCodeFormatter::saveBlockData(QTextBlock *block, const BlockData &dat
cppData->m_data = data;
}
-bool QtStyleCodeFormatter::loadBlockData(const QTextBlock &block, BlockData *data) const
+bool CreatorCodeFormatter::loadBlockData(const QTextBlock &block, BlockData *data) const
{
TextBlockUserData *userData = BaseTextDocumentLayout::testUserData(block);
if (!userData)
@@ -80,320 +74,12 @@ bool QtStyleCodeFormatter::loadBlockData(const QTextBlock &block, BlockData *dat
return true;
}
-void QtStyleCodeFormatter::saveLexerState(QTextBlock *block, int state) const
+void CreatorCodeFormatter::saveLexerState(QTextBlock *block, int state) const
{
BaseTextDocumentLayout::setLexerState(*block, state);
}
-int QtStyleCodeFormatter::loadLexerState(const QTextBlock &block) const
+int CreatorCodeFormatter::loadLexerState(const QTextBlock &block) const
{
return BaseTextDocumentLayout::lexerState(block);
}
-
-void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedIndentDepth) const
-{
- const State &parentState = state();
- const Token &tk = currentToken();
- const int tokenPosition = column(tk.begin());
- const bool firstToken = (tokenIndex() == 0);
- const bool lastToken = (tokenIndex() == tokenCount() - 1);
-
- switch (newState) {
- case objectdefinition_open: {
- // special case for things like "gradient: Gradient {"
- if (parentState.type == binding_assignment)
- *savedIndentDepth = state(1).savedIndentDepth;
-
- if (firstToken)
- *savedIndentDepth = tokenPosition;
-
- *indentDepth = *savedIndentDepth + m_indentSize;
- break;
- }
-
- case binding_or_objectdefinition:
- if (firstToken)
- *indentDepth = *savedIndentDepth = tokenPosition;
- break;
-
- case binding_assignment:
- case objectliteral_assignment:
- if (lastToken)
- *indentDepth = *savedIndentDepth + 4;
- else
- *indentDepth = column(tokenAt(tokenIndex() + 1).begin());
- break;
-
- case expression_or_objectdefinition:
- *indentDepth = tokenPosition;
- break;
-
- case expression_or_label:
- if (*indentDepth == tokenPosition)
- *indentDepth += 2*m_indentSize;
- else
- *indentDepth = tokenPosition;
- break;
-
- case expression:
- if (*indentDepth == tokenPosition) {
- // expression_or_objectdefinition doesn't want the indent
- // expression_or_label already has it
- if (parentState.type != expression_or_objectdefinition
- && parentState.type != expression_or_label
- && parentState.type != binding_assignment) {
- *indentDepth += 2*m_indentSize;
- }
- }
- // expression_or_objectdefinition and expression_or_label have already consumed the first token
- else if (parentState.type != expression_or_objectdefinition
- && parentState.type != expression_or_label) {
- *indentDepth = tokenPosition;
- }
- break;
-
- case expression_maybe_continuation:
- // set indent depth to indent we'd get if the expression ended here
- for (int i = 1; state(i).type != topmost_intro; ++i) {
- const int type = state(i).type;
- if (isExpressionEndState(type) && !isBracelessState(type)) {
- *indentDepth = state(i - 1).savedIndentDepth;
- break;
- }
- }
- break;
-
- case bracket_open:
- if (parentState.type == expression && state(1).type == binding_assignment) {
- *savedIndentDepth = state(2).savedIndentDepth;
- *indentDepth = *savedIndentDepth + m_indentSize;
- } else if (parentState.type == objectliteral_assignment) {
- *savedIndentDepth = parentState.savedIndentDepth;
- *indentDepth = *savedIndentDepth + m_indentSize;
- } else if (!lastToken) {
- *indentDepth = tokenPosition + 1;
- } else {
- *indentDepth = *savedIndentDepth + m_indentSize;
- }
- break;
-
- case function_start:
- if (parentState.type == expression) {
- // undo the continuation indent of the expression
- *indentDepth = parentState.savedIndentDepth;
- *savedIndentDepth = *indentDepth;
- }
- break;
-
- case do_statement_while_paren_open:
- case statement_with_condition_paren_open:
- case signal_arglist_open:
- case function_arglist_open:
- case paren_open:
- case condition_paren_open:
- if (!lastToken)
- *indentDepth = tokenPosition + 1;
- else
- *indentDepth += m_indentSize;
- break;
-
- case ternary_op:
- if (!lastToken)
- *indentDepth = tokenPosition + tk.length + 1;
- else
- *indentDepth += m_indentSize;
- break;
-
- case jsblock_open:
- // closing brace should be aligned to case
- if (parentState.type == case_cont) {
- *savedIndentDepth = parentState.savedIndentDepth;
- break;
- }
- // fallthrough
- case substatement_open:
- // special case for "foo: {" and "property int foo: {"
- if (parentState.type == binding_assignment)
- *savedIndentDepth = state(1).savedIndentDepth;
- *indentDepth = *savedIndentDepth + m_indentSize;
- break;
-
- case substatement:
- *indentDepth += m_indentSize;
- break;
-
- case objectliteral_open:
- if (parentState.type == expression
- || parentState.type == objectliteral_assignment) {
- // undo the continuation indent of the expression
- if (state(1).type == expression_or_label)
- *indentDepth = state(1).savedIndentDepth;
- else
- *indentDepth = parentState.savedIndentDepth;
- *savedIndentDepth = *indentDepth;
- }
- *indentDepth += m_indentSize;
- break;
-
-
- case statement_with_condition:
- case statement_with_block:
- case if_statement:
- case do_statement:
- case switch_statement:
- if (firstToken || parentState.type == binding_assignment)
- *savedIndentDepth = tokenPosition;
- // ### continuation
- *indentDepth = *savedIndentDepth; // + 2*m_indentSize;
- // special case for 'else if'
- if (!firstToken
- && newState == if_statement
- && parentState.type == substatement
- && state(1).type == else_clause) {
- *indentDepth = state(1).savedIndentDepth;
- *savedIndentDepth = *indentDepth;
- }
- break;
-
- case maybe_else: {
- // set indent to outermost braceless savedIndent
- int outermostBraceless = 0;
- while (isBracelessState(state(outermostBraceless + 1).type))
- ++outermostBraceless;
- *indentDepth = state(outermostBraceless).savedIndentDepth;
- // this is where the else should go, if one appears - aligned to if_statement
- *savedIndentDepth = state().savedIndentDepth;
- break;
- }
-
- case condition_open:
- // fixed extra indent when continuing 'if (', but not for 'else if ('
- if (tokenPosition <= *indentDepth + m_indentSize)
- *indentDepth += 2*m_indentSize;
- else
- *indentDepth = tokenPosition + 1;
- break;
-
- case case_start:
- *savedIndentDepth = tokenPosition;
- break;
-
- case case_cont:
- *indentDepth += m_indentSize;
- break;
-
- case multiline_comment_start:
- *indentDepth = tokenPosition + 2;
- break;
-
- case multiline_comment_cont:
- *indentDepth = tokenPosition;
- break;
- }
-}
-
-void QtStyleCodeFormatter::adjustIndent(const QList<Token> &tokens, int lexerState, int *indentDepth) const
-{
- Q_UNUSED(lexerState)
-
- State topState = state();
- State previousState = state(1);
-
- // keep user-adjusted indent in multiline comments
- if (topState.type == multiline_comment_start
- || topState.type == multiline_comment_cont) {
- if (!tokens.isEmpty()) {
- *indentDepth = column(tokens.at(0).begin());
- return;
- }
- }
-
- const int kind = extendedTokenKind(tokenAt(0));
- switch (kind) {
- case LeftBrace:
- if (topState.type == substatement
- || topState.type == binding_assignment
- || topState.type == case_cont) {
- *indentDepth = topState.savedIndentDepth;
- }
- break;
- case RightBrace: {
- if (topState.type == jsblock_open && previousState.type == case_cont) {
- *indentDepth = previousState.savedIndentDepth;
- break;
- }
- for (int i = 0; state(i).type != topmost_intro; ++i) {
- const int type = state(i).type;
- if (type == objectdefinition_open
- || type == jsblock_open
- || type == substatement_open
- || type == objectliteral_open) {
- *indentDepth = state(i).savedIndentDepth;
- break;
- }
- }
- break;
- }
- case RightBracket:
- for (int i = 0; state(i).type != topmost_intro; ++i) {
- const int type = state(i).type;
- if (type == bracket_open) {
- *indentDepth = state(i).savedIndentDepth;
- break;
- }
- }
- break;
-
- case LeftBracket:
- case LeftParenthesis:
- case Delimiter:
- if (topState.type == expression_maybe_continuation)
- *indentDepth = topState.savedIndentDepth;
- break;
-
- case Else:
- if (topState.type == maybe_else) {
- *indentDepth = topState.savedIndentDepth;
- } else if (topState.type == expression_maybe_continuation) {
- bool hasElse = false;
- for (int i = 1; state(i).type != topmost_intro; ++i) {
- const int type = state(i).type;
- if (type == else_clause)
- hasElse = true;
- if (type == if_statement) {
- if (hasElse) {
- hasElse = false;
- } else {
- *indentDepth = state(i).savedIndentDepth;
- break;
- }
- }
- }
- }
- break;
-
- case Colon:
- if (topState.type == ternary_op) {
- *indentDepth -= 2;
- }
- break;
-
- case Question:
- if (topState.type == expression_maybe_continuation)
- *indentDepth = topState.savedIndentDepth;
- break;
-
- case Default:
- case Case:
- for (int i = 0; state(i).type != topmost_intro; ++i) {
- const int type = state(i).type;
- if (type == switch_statement || type == case_cont) {
- *indentDepth = state(i).savedIndentDepth;
- break;
- } else if (type == topmost_intro) {
- break;
- }
- }
- break;
- }
-}
diff --git a/src/plugins/qmljstools/qmljsqtstylecodeformatter.h b/src/plugins/qmljstools/qmljsqtstylecodeformatter.h
index 9668c498c9..f48ec9754b 100644
--- a/src/plugins/qmljstools/qmljsqtstylecodeformatter.h
+++ b/src/plugins/qmljstools/qmljsqtstylecodeformatter.h
@@ -44,18 +44,13 @@ namespace TextEditor {
namespace QmlJSTools {
-class QMLJSTOOLS_EXPORT QtStyleCodeFormatter : public QmlJS::CodeFormatter
+class QMLJSTOOLS_EXPORT CreatorCodeFormatter : public QmlJS::QtStyleCodeFormatter
{
public:
- QtStyleCodeFormatter();
- explicit QtStyleCodeFormatter(const TextEditor::TabSettings &tabSettings);
-
- void setIndentSize(int size);
+ CreatorCodeFormatter();
+ explicit CreatorCodeFormatter(const TextEditor::TabSettings &tabSettings);
protected:
- virtual void onEnter(int newState, int *indentDepth, int *savedIndentDepth) const;
- virtual void adjustIndent(const QList<QmlJS::Token> &tokens, int lexerState, int *indentDepth) const;
-
virtual void saveBlockData(QTextBlock *block, const BlockData &data) const;
virtual bool loadBlockData(const QTextBlock &block, BlockData *data) const;
@@ -63,8 +58,6 @@ protected:
virtual int loadLexerState(const QTextBlock &block) const;
private:
- int m_indentSize;
-
class QmlJSCodeFormatterData: public TextEditor::CodeFormatterData
{
public:
diff --git a/src/plugins/qmljstools/qmljsrefactoringchanges.cpp b/src/plugins/qmljstools/qmljsrefactoringchanges.cpp
index 56b9d8486b..cc89dd521d 100644
--- a/src/plugins/qmljstools/qmljsrefactoringchanges.cpp
+++ b/src/plugins/qmljstools/qmljsrefactoringchanges.cpp
@@ -65,7 +65,7 @@ public:
const TextEditor::TabSettings &tabSettings =
ProjectExplorer::actualTabSettings(fileName, textEditor);
- QtStyleCodeFormatter codeFormatter(tabSettings);
+ CreatorCodeFormatter codeFormatter(tabSettings);
codeFormatter.updateStateUntil(block);
do {
diff --git a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp
index acfa4608b0..6b8a86fb34 100644
--- a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp
+++ b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp
@@ -135,7 +135,7 @@ void checkIndent(QList<Line> data, int style = 0)
QString text = concatLines(data);
QTextDocument document(text);
- QtStyleCodeFormatter formatter;
+ CreatorCodeFormatter formatter;
int i = 0;
foreach (const Line &l, data) {