Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qt-creator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Hunger
qt-creator
Commits
85458519
Commit
85458519
authored
15 years ago
by
Roberto Raggi
Browse files
Options
Downloads
Patches
Plain Diff
Split create/apply change set.
parent
6594f7a2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/plugins/cppeditor/cppquickfix.cpp
+27
-25
27 additions, 25 deletions
src/plugins/cppeditor/cppquickfix.cpp
src/plugins/cppeditor/cppquickfix.h
+6
-3
6 additions, 3 deletions
src/plugins/cppeditor/cppquickfix.h
with
33 additions
and
28 deletions
src/plugins/cppeditor/cppquickfix.cpp
+
27
−
25
View file @
85458519
...
@@ -139,14 +139,13 @@ public:
...
@@ -139,14 +139,13 @@ public:
return
-
1
;
return
-
1
;
}
}
virtual
void
apply
()
virtual
void
createChangeSet
()
{
{
setTopLevelNode
(
pattern
);
replace
(
pattern
->
binary_op_token
,
QLatin1String
(
"||"
));
replace
(
pattern
->
binary_op_token
,
QLatin1String
(
"||"
));
replace
(
left
->
unary_op_token
,
QLatin1String
(
"!("
));
replace
(
left
->
unary_op_token
,
QLatin1String
(
"!("
));
replace
(
right
->
unary_op_token
,
QLatin1String
(
""
));
replace
(
right
->
unary_op_token
,
QLatin1String
(
""
));
insert
(
endOf
(
pattern
),
QLatin1String
(
")"
));
insert
(
endOf
(
pattern
),
QLatin1String
(
")"
));
applyChanges
(
pattern
);
}
}
private
:
private
:
...
@@ -230,8 +229,9 @@ public:
...
@@ -230,8 +229,9 @@ public:
return
-
1
;
return
-
1
;
}
}
virtual
void
apply
()
virtual
void
createChangeSet
()
{
{
setTopLevelNode
(
declaration
);
SpecifierListAST
*
specifiers
=
declaration
->
decl_specifier_list
;
SpecifierListAST
*
specifiers
=
declaration
->
decl_specifier_list
;
const
QString
declSpecifiers
=
textOf
(
startOf
(
specifiers
->
firstToken
()),
endOf
(
specifiers
->
lastToken
()
-
1
));
const
QString
declSpecifiers
=
textOf
(
startOf
(
specifiers
->
firstToken
()),
endOf
(
specifiers
->
lastToken
()
-
1
));
...
@@ -250,8 +250,6 @@ public:
...
@@ -250,8 +250,6 @@ public:
}
}
insert
(
endOf
(
declaration
->
semicolon_token
),
text
);
insert
(
endOf
(
declaration
->
semicolon_token
),
text
);
applyChanges
(
declaration
);
}
}
private
:
private
:
...
@@ -303,11 +301,11 @@ public:
...
@@ -303,11 +301,11 @@ public:
return
-
1
;
return
-
1
;
}
}
virtual
void
apply
()
virtual
void
createChangeSet
()
{
{
setTopLevelNode
(
_statement
);
insert
(
endOf
(
_statement
->
firstToken
()
-
1
),
QLatin1String
(
" {"
));
insert
(
endOf
(
_statement
->
firstToken
()
-
1
),
QLatin1String
(
" {"
));
insert
(
endOf
(
_statement
->
lastToken
()
-
1
),
"
\n
}"
);
insert
(
endOf
(
_statement
->
lastToken
()
-
1
),
"
\n
}"
);
applyChanges
(
_statement
);
}
}
private
:
private
:
...
@@ -358,8 +356,9 @@ public:
...
@@ -358,8 +356,9 @@ public:
return
-
1
;
return
-
1
;
}
}
virtual
void
apply
()
virtual
void
createChangeSet
()
{
{
setTopLevelNode
(
pattern
);
const
QString
name
=
textOf
(
core
);
const
QString
name
=
textOf
(
core
);
QString
declaration
=
textOf
(
condition
);
QString
declaration
=
textOf
(
condition
);
declaration
+=
QLatin1String
(
";
\n
"
);
declaration
+=
QLatin1String
(
";
\n
"
);
...
@@ -367,8 +366,6 @@ public:
...
@@ -367,8 +366,6 @@ public:
insert
(
startOf
(
pattern
),
declaration
);
insert
(
startOf
(
pattern
),
declaration
);
insert
(
endOf
(
pattern
->
lparen_token
),
name
);
insert
(
endOf
(
pattern
->
lparen_token
),
name
);
replace
(
condition
,
name
);
replace
(
condition
,
name
);
applyChanges
(
pattern
);
}
}
private
:
private
:
...
@@ -431,8 +428,9 @@ public:
...
@@ -431,8 +428,9 @@ public:
return
-
1
;
return
-
1
;
}
}
virtual
void
apply
()
virtual
void
createChangeSet
()
{
{
setTopLevelNode
(
pattern
);
const
QString
name
=
textOf
(
core
);
const
QString
name
=
textOf
(
core
);
const
QString
initializer
=
textOf
(
condition
->
declarator
->
initializer
);
const
QString
initializer
=
textOf
(
condition
->
declarator
->
initializer
);
QString
declaration
=
textOf
(
startOf
(
condition
),
endOf
(
condition
->
declarator
->
equals_token
-
1
));
QString
declaration
=
textOf
(
startOf
(
condition
),
endOf
(
condition
->
declarator
->
equals_token
-
1
));
...
@@ -448,8 +446,6 @@ public:
...
@@ -448,8 +446,6 @@ public:
insert
(
startOf
(
pattern
),
declaration
);
insert
(
startOf
(
pattern
),
declaration
);
insert
(
endOf
(
pattern
->
lparen_token
),
name
);
insert
(
endOf
(
pattern
->
lparen_token
),
name
);
replace
(
condition
,
newCondition
);
replace
(
condition
,
newCondition
);
applyChanges
(
pattern
);
}
}
private
:
private
:
...
@@ -529,7 +525,7 @@ public:
...
@@ -529,7 +525,7 @@ public:
return
-
1
;
return
-
1
;
}
}
virtual
void
apply
()
virtual
void
createChangeSet
()
{
{
Token
binaryToken
=
tokenAt
(
condition
->
binary_op_token
);
Token
binaryToken
=
tokenAt
(
condition
->
binary_op_token
);
...
@@ -541,6 +537,7 @@ public:
...
@@ -541,6 +537,7 @@ public:
void
splitAndCondition
()
void
splitAndCondition
()
{
{
setTopLevelNode
(
pattern
);
StatementAST
*
ifTrueStatement
=
pattern
->
statement
;
StatementAST
*
ifTrueStatement
=
pattern
->
statement
;
// take the right-expression from the condition.
// take the right-expression from the condition.
...
@@ -558,12 +555,11 @@ public:
...
@@ -558,12 +555,11 @@ public:
insert
(
endOf
(
pattern
->
rparen_token
),
nestedIfStatement
);
insert
(
endOf
(
pattern
->
rparen_token
),
nestedIfStatement
);
insert
(
endOf
(
ifTrueStatement
),
"
\n
}"
);
// finish the compound statement
insert
(
endOf
(
ifTrueStatement
),
"
\n
}"
);
// finish the compound statement
applyChanges
(
pattern
);
}
}
void
splitOrCondition
()
void
splitOrCondition
()
{
{
setTopLevelNode
(
pattern
);
StatementAST
*
ifTrueStatement
=
pattern
->
statement
;
StatementAST
*
ifTrueStatement
=
pattern
->
statement
;
CompoundStatementAST
*
compoundStatement
=
ifTrueStatement
->
asCompoundStatement
();
CompoundStatementAST
*
compoundStatement
=
ifTrueStatement
->
asCompoundStatement
();
...
@@ -592,8 +588,6 @@ public:
...
@@ -592,8 +588,6 @@ public:
elseIfStatement
+=
body
;
elseIfStatement
+=
body
;
insert
(
endOf
(
pattern
),
elseIfStatement
);
insert
(
endOf
(
pattern
),
elseIfStatement
);
applyChanges
(
pattern
);
}
}
private
:
private
:
...
@@ -607,7 +601,8 @@ private:
...
@@ -607,7 +601,8 @@ private:
QuickFixOperation
::
QuickFixOperation
(
CPlusPlus
::
Document
::
Ptr
doc
,
QuickFixOperation
::
QuickFixOperation
(
CPlusPlus
::
Document
::
Ptr
doc
,
const
CPlusPlus
::
Snapshot
&
snapshot
,
const
CPlusPlus
::
Snapshot
&
snapshot
,
CPPEditor
*
editor
)
CPPEditor
*
editor
)
:
_doc
(
doc
),
_snapshot
(
snapshot
),
_editor
(
editor
)
:
_doc
(
doc
),
_snapshot
(
snapshot
),
_editor
(
editor
),
_topLevelNode
(
0
)
{
}
{
}
QuickFixOperation
::~
QuickFixOperation
()
QuickFixOperation
::~
QuickFixOperation
()
...
@@ -616,6 +611,12 @@ QuickFixOperation::~QuickFixOperation()
...
@@ -616,6 +611,12 @@ QuickFixOperation::~QuickFixOperation()
CPPEditor
*
QuickFixOperation
::
editor
()
const
CPPEditor
*
QuickFixOperation
::
editor
()
const
{
return
_editor
;
}
{
return
_editor
;
}
CPlusPlus
::
AST
*
QuickFixOperation
::
topLevelNode
()
const
{
return
_topLevelNode
;
}
void
QuickFixOperation
::
setTopLevelNode
(
CPlusPlus
::
AST
*
topLevelNode
)
{
_topLevelNode
=
topLevelNode
;
}
const
Utils
::
ChangeSet
&
QuickFixOperation
::
changeSet
()
const
const
Utils
::
ChangeSet
&
QuickFixOperation
::
changeSet
()
const
{
return
_changeSet
;
}
{
return
_changeSet
;
}
...
@@ -752,18 +753,18 @@ QString QuickFixOperation::textOf(AST *ast) const
...
@@ -752,18 +753,18 @@ QString QuickFixOperation::textOf(AST *ast) const
return
textOf
(
startOf
(
ast
),
endOf
(
ast
));
return
textOf
(
startOf
(
ast
),
endOf
(
ast
));
}
}
void
QuickFixOperation
::
applyChange
s
(
AST
*
ast
)
void
QuickFixOperation
::
applyChange
Set
(
)
{
{
Range
range
;
Range
range
;
if
(
ast
)
if
(
_topLevelNode
)
range
=
createRange
(
ast
);
range
=
createRange
(
_topLevelNode
);
_textCursor
.
beginEditBlock
();
_textCursor
.
beginEditBlock
();
_changeSet
.
write
(
&
_textCursor
);
_changeSet
.
write
(
&
_textCursor
);
if
(
ast
)
if
(
_topLevelNode
)
reindent
(
range
);
reindent
(
range
);
_textCursor
.
endEditBlock
();
_textCursor
.
endEditBlock
();
...
@@ -867,7 +868,8 @@ void CPPQuickFixCollector::complete(const TextEditor::CompletionItem &item)
...
@@ -867,7 +868,8 @@ void CPPQuickFixCollector::complete(const TextEditor::CompletionItem &item)
void
CPPQuickFixCollector
::
perform
(
QuickFixOperationPtr
op
)
void
CPPQuickFixCollector
::
perform
(
QuickFixOperationPtr
op
)
{
{
op
->
setTextCursor
(
_editor
->
textCursor
());
op
->
setTextCursor
(
_editor
->
textCursor
());
op
->
apply
();
op
->
createChangeSet
();
op
->
applyChangeSet
();
}
}
void
CPPQuickFixCollector
::
cleanup
()
void
CPPQuickFixCollector
::
cleanup
()
...
...
This diff is collapsed.
Click to expand it.
src/plugins/cppeditor/cppquickfix.h
+
6
−
3
View file @
85458519
...
@@ -77,7 +77,11 @@ public:
...
@@ -77,7 +77,11 @@ public:
CPPEditor
*
editor
()
const
;
CPPEditor
*
editor
()
const
;
const
Utils
::
ChangeSet
&
changeSet
()
const
;
const
Utils
::
ChangeSet
&
changeSet
()
const
;
virtual
void
apply
()
=
0
;
CPlusPlus
::
AST
*
topLevelNode
()
const
;
void
setTopLevelNode
(
CPlusPlus
::
AST
*
topLevelNode
);
virtual
void
createChangeSet
()
=
0
;
void
applyChangeSet
();
protected
:
protected
:
const
CPlusPlus
::
Token
&
tokenAt
(
unsigned
index
)
const
;
const
CPlusPlus
::
Token
&
tokenAt
(
unsigned
index
)
const
;
...
@@ -112,14 +116,13 @@ protected:
...
@@ -112,14 +116,13 @@ protected:
Range
createRange
(
CPlusPlus
::
AST
*
ast
)
const
;
// ### rename me
Range
createRange
(
CPlusPlus
::
AST
*
ast
)
const
;
// ### rename me
void
reindent
(
const
Range
&
range
);
void
reindent
(
const
Range
&
range
);
void
applyChanges
(
CPlusPlus
::
AST
*
ast
=
0
);
private
:
private
:
CPlusPlus
::
Document
::
Ptr
_doc
;
CPlusPlus
::
Document
::
Ptr
_doc
;
CPlusPlus
::
Snapshot
_snapshot
;
CPlusPlus
::
Snapshot
_snapshot
;
QTextCursor
_textCursor
;
QTextCursor
_textCursor
;
Utils
::
ChangeSet
_changeSet
;
Utils
::
ChangeSet
_changeSet
;
CPPEditor
*
_editor
;
CPPEditor
*
_editor
;
CPlusPlus
::
AST
*
_topLevelNode
;
};
};
class
CPPQuickFixCollector
:
public
TextEditor
::
IQuickFixCollector
class
CPPQuickFixCollector
:
public
TextEditor
::
IQuickFixCollector
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment