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
cc79467d
Commit
cc79467d
authored
15 years ago
by
Erik Verbruggen
Browse files
Options
Downloads
Patches
Plain Diff
Added CString->NSString quick-fix.
parent
59a4b03b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/plugins/cppeditor/cppquickfix.cpp
+68
-0
68 additions, 0 deletions
src/plugins/cppeditor/cppquickfix.cpp
with
68 additions
and
0 deletions
src/plugins/cppeditor/cppquickfix.cpp
+
68
−
0
View file @
cc79467d
...
...
@@ -833,6 +833,72 @@ private:
bool
isObjCStringLiteral
;
};
class
CStringToNSString
:
public
QuickFixOperation
{
public:
CStringToNSString
()
:
stringLiteral
(
0
),
qlatin1Call
(
0
)
{}
virtual
QString
description
()
const
{
return
QLatin1String
(
"Convert to Objective-C string literal"
);
}
// ### tr?
virtual
int
match
(
const
QList
<
AST
*>
&
path
)
{
if
(
path
.
isEmpty
())
return
-
1
;
int
index
=
path
.
size
()
-
1
;
stringLiteral
=
path
[
index
]
->
asStringLiteral
();
if
(
!
stringLiteral
)
return
-
1
;
if
(
charAt
(
startOf
(
stringLiteral
))
==
QLatin1Char
(
'@'
))
return
-
1
;
// check if it is already wrapped in QLatin1String or -Literal
if
(
index
-
2
<
0
)
return
index
;
CallAST
*
call
=
path
[
index
-
1
]
->
asCall
();
PostfixExpressionAST
*
postfixExp
=
path
[
index
-
2
]
->
asPostfixExpression
();
if
(
call
&&
postfixExp
&&
postfixExp
->
base_expression
&&
postfixExp
->
postfix_expression_list
&&
postfixExp
->
postfix_expression_list
->
value
==
call
)
{
NameAST
*
callName
=
postfixExp
->
base_expression
->
asName
();
if
(
!
callName
)
return
index
;
if
(
!
(
postfixExp
->
postfix_expression_list
->
next
))
{
QByteArray
callNameString
(
tokenAt
(
callName
->
firstToken
()).
spell
());
if
(
callNameString
==
"QLatin1String"
||
callNameString
==
"QLatin1Literal"
)
qlatin1Call
=
postfixExp
;
}
}
return
index
;
}
virtual
void
createChangeSet
()
{
if
(
qlatin1Call
)
{
replace
(
startOf
(
qlatin1Call
),
startOf
(
stringLiteral
),
QLatin1String
(
"@"
));
remove
(
endOf
(
stringLiteral
),
endOf
(
qlatin1Call
));
}
else
{
insert
(
startOf
(
stringLiteral
),
"@"
);
}
}
private
:
StringLiteralAST
*
stringLiteral
;
PostfixExpressionAST
*
qlatin1Call
;
};
}
// end of anonymous namespace
...
...
@@ -1144,6 +1210,7 @@ int CPPQuickFixCollector::startCompletion(TextEditor::ITextEditable *editable)
QSharedPointer
<
UseInverseOp
>
useInverseOp
(
new
UseInverseOp
());
QSharedPointer
<
FlipBinaryOp
>
flipBinaryOp
(
new
FlipBinaryOp
());
QSharedPointer
<
WrapStringLiteral
>
wrapStringLiteral
(
new
WrapStringLiteral
());
QSharedPointer
<
CStringToNSString
>
wrapCString
(
new
CStringToNSString
());
QList
<
QuickFixOperationPtr
>
candidates
;
candidates
.
append
(
rewriteLogicalAndOp
);
...
...
@@ -1155,6 +1222,7 @@ int CPPQuickFixCollector::startCompletion(TextEditor::ITextEditable *editable)
candidates
.
append
(
useInverseOp
);
candidates
.
append
(
flipBinaryOp
);
candidates
.
append
(
wrapStringLiteral
);
candidates
.
append
(
wrapCString
);
QMap
<
int
,
QList
<
QuickFixOperationPtr
>
>
matchedOps
;
...
...
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