Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
flatpak-qt-creator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
d0d0a8c0
Commit
d0d0a8c0
authored
Apr 21, 2011
by
Christian Kamm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
QmlJS: Fix indent of object literals.
Reviewed-by: Roberto Raggi
parent
e3928941
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
5 deletions
+92
-5
src/libs/qmljs/qmljscodeformatter.cpp
src/libs/qmljs/qmljscodeformatter.cpp
+19
-2
src/libs/qmljs/qmljscodeformatter.h
src/libs/qmljs/qmljscodeformatter.h
+2
-0
src/plugins/qmljstools/qmljsqtstylecodeformatter.cpp
src/plugins/qmljstools/qmljsqtstylecodeformatter.cpp
+13
-1
tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp
...o/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp
+58
-2
No files found.
src/libs/qmljs/qmljscodeformatter.cpp
View file @
d0d0a8c0
...
...
@@ -295,9 +295,24 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
if
(
tryInsideExpression
())
break
;
switch
(
kind
)
{
case
Colon
:
enter
(
objectliteral_assignment
);
break
;
case
RightBracket
:
case
RightParenthesis
:
leave
();
continue
;
// error recovery
case
RightBrace
:
leave
();
break
;
}
break
;
// pretty much like expression, but ends with , or }
case
objectliteral_assignment
:
if
(
tryInsideExpression
())
break
;
switch
(
kind
)
{
case
Delimiter
:
enter
(
expression_continuation
);
break
;
case
RightBracket
:
case
RightParenthesis
:
leave
();
continue
;
// error recovery
case
RightBrace
:
leave
();
continue
;
// so we also leave objectliteral_open
case
Comma
:
leave
();
break
;
}
break
;
case
bracket_element_start
:
switch
(
kind
)
{
case
Identifier
:
turnInto
(
bracket_element_maybe_objectdefinition
);
break
;
...
...
@@ -451,7 +466,8 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
int
topState
=
m_currentState
.
top
().
type
;
if
(
topState
==
expression
||
topState
==
expression_or_objectdefinition
)
{
||
topState
==
expression_or_objectdefinition
||
topState
==
objectliteral_assignment
)
{
enter
(
expression_maybe_continuation
);
}
if
(
topState
!=
multiline_comment_start
...
...
@@ -743,7 +759,8 @@ bool CodeFormatter::isExpressionEndState(int type) const
type
==
substatement_open
||
type
==
bracket_open
||
type
==
paren_open
||
type
==
case_cont
;
type
==
case_cont
||
type
==
objectliteral_open
;
}
const
Token
&
CodeFormatter
::
tokenAt
(
int
idx
)
const
...
...
src/libs/qmljs/qmljscodeformatter.h
View file @
d0d0a8c0
...
...
@@ -138,6 +138,8 @@ public: // must be public to make Q_GADGET introspection work
bracket_open
,
// opening [ in expression
objectliteral_open
,
// opening { in expression
objectliteral_assignment
,
// after : in object literal
bracket_element_start
,
// after starting bracket_open or after ',' in bracket_open
bracket_element_maybe_objectdefinition
,
// after an identifier in bracket_element_start
...
...
src/plugins/qmljstools/qmljsqtstylecodeformatter.cpp
View file @
d0d0a8c0
...
...
@@ -117,6 +117,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
break
;
case
binding_assignment
:
case
objectliteral_assignment
:
if
(
lastToken
)
*
indentDepth
=
*
savedIndentDepth
+
4
;
else
...
...
@@ -203,6 +204,16 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
*
indentDepth
=
*
savedIndentDepth
+
m_indentSize
;
break
;
case
objectliteral_open
:
if
(
parentState
.
type
==
expression
||
parentState
.
type
==
objectliteral_assignment
)
{
// undo the continuation indent of the expression
*
indentDepth
=
parentState
.
savedIndentDepth
;
*
savedIndentDepth
=
*
indentDepth
;
}
*
indentDepth
+=
m_indentSize
;
break
;
case
statement_with_condition
:
case
statement_with_block
:
case
if_statement
:
...
...
@@ -290,7 +301,8 @@ void QtStyleCodeFormatter::adjustIndent(const QList<Token> &tokens, int lexerSta
const
int
type
=
state
(
i
).
type
;
if
(
type
==
objectdefinition_open
||
type
==
jsblock_open
||
type
==
substatement_open
)
{
||
type
==
substatement_open
||
type
==
objectliteral_open
)
{
*
indentDepth
=
state
(
i
).
savedIndentDepth
;
break
;
}
...
...
tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp
View file @
d0d0a8c0
...
...
@@ -83,7 +83,10 @@ private Q_SLOTS:
// void gnuStyle();
// void whitesmithsStyle();
void
expressionContinuation
();
void
objectLiteral
();
void
objectLiteral1
();
void
objectLiteral2
();
void
objectLiteral3
();
void
objectLiteral4
();
void
keywordStatement
();
void
namespacedObjects
();
};
...
...
@@ -962,7 +965,7 @@ void tst_QMLCodeFormatter::expressionContinuation()
checkIndent
(
data
);
}
void
tst_QMLCodeFormatter
::
objectLiteral
()
void
tst_QMLCodeFormatter
::
objectLiteral
1
()
{
QList
<
Line
>
data
;
data
<<
Line
(
"function shuffle() {"
)
...
...
@@ -974,6 +977,59 @@ void tst_QMLCodeFormatter::objectLiteral()
checkIndent
(
data
);
}
void
tst_QMLCodeFormatter
::
objectLiteral2
()
{
QList
<
Line
>
data
;
data
<<
Line
(
"var x = {"
)
<<
Line
(
"
\"
x
\"
: 12,"
)
<<
Line
(
"
\"
y
\"
: 34,"
)
<<
Line
(
" z:
\"
abc
\"
"
)
<<
Line
(
"}"
)
;
checkIndent
(
data
);
}
void
tst_QMLCodeFormatter
::
objectLiteral3
()
{
QList
<
Line
>
data
;
data
<<
Line
(
"var x = {"
)
<<
Line
(
" x: {"
)
<<
Line
(
" y: 12,"
)
<<
Line
(
" z: [1, 3]"
)
<<
Line
(
" },"
)
<<
Line
(
"
\"
z
\"
: {"
)
<<
Line
(
" a: 1 + 2 + 3,"
)
<<
Line
(
" b:
\"
12
\"
"
)
<<
Line
(
" },"
)
<<
Line
(
" a: b"
)
<<
Line
(
"}"
)
;
checkIndent
(
data
);
}
void
tst_QMLCodeFormatter
::
objectLiteral4
()
{
QList
<
Line
>
data
;
data
<<
Line
(
"var x = { a: 12, b: 13 }"
)
<<
Line
(
"y = {"
)
<<
Line
(
" a: 1 +"
)
<<
Line
(
" 2 + 3"
)
<<
Line
(
" + 4"
)
<<
Line
(
"}"
)
<<
Line
(
"y = {"
)
<<
Line
(
" a: 1 +"
)
<<
Line
(
" 2 + 3"
)
<<
Line
(
" + 4,"
)
<<
Line
(
" b: {"
)
<<
Line
(
" adef: 1 +"
)
<<
Line
(
" 2 + 3"
)
<<
Line
(
" + 4,"
)
<<
Line
(
" }"
)
<<
Line
(
"}"
)
;
checkIndent
(
data
);
}
void
tst_QMLCodeFormatter
::
keywordStatement
()
{
QList
<
Line
>
data
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment