forked from qt-creator/qt-creator
Changed string-wrapping quickfix to handle @"strings".
This commit is contained in:
@@ -759,7 +759,7 @@ class WrapStringLiteral: public QuickFixOperation
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WrapStringLiteral()
|
WrapStringLiteral()
|
||||||
: stringLiteral(0)
|
: stringLiteral(0), isObjCStringLiteral(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
virtual QString description() const
|
virtual QString description() const
|
||||||
@@ -778,6 +778,8 @@ public:
|
|||||||
if (!stringLiteral)
|
if (!stringLiteral)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
isObjCStringLiteral = charAt(startOf(stringLiteral)) == QLatin1Char('@');
|
||||||
|
|
||||||
// check if it is already wrapped in QLatin1String or -Literal
|
// check if it is already wrapped in QLatin1String or -Literal
|
||||||
if (index-2 < 0)
|
if (index-2 < 0)
|
||||||
return index;
|
return index;
|
||||||
@@ -805,12 +807,20 @@ public:
|
|||||||
|
|
||||||
virtual void createChangeSet()
|
virtual void createChangeSet()
|
||||||
{
|
{
|
||||||
insert(startOf(stringLiteral), "QLatin1String(");
|
const int startPos = startOf(stringLiteral);
|
||||||
|
const QLatin1String replacement("QLatin1String(");
|
||||||
|
|
||||||
|
if (isObjCStringLiteral)
|
||||||
|
replace(startPos, startPos + 1, replacement);
|
||||||
|
else
|
||||||
|
insert(startPos, replacement);
|
||||||
|
|
||||||
insert(endOf(stringLiteral), ")");
|
insert(endOf(stringLiteral), ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StringLiteralAST *stringLiteral;
|
StringLiteralAST *stringLiteral;
|
||||||
|
bool isObjCStringLiteral;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of anonymous namespace
|
} // end of anonymous namespace
|
||||||
@@ -1040,6 +1050,11 @@ QString QuickFixOperation::textOf(const AST *ast) const
|
|||||||
return textOf(startOf(ast), endOf(ast));
|
return textOf(startOf(ast), endOf(ast));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QChar QuickFixOperation::charAt(int offset) const
|
||||||
|
{
|
||||||
|
return textOf(offset, offset + 1).at(0);
|
||||||
|
}
|
||||||
|
|
||||||
void QuickFixOperation::apply()
|
void QuickFixOperation::apply()
|
||||||
{
|
{
|
||||||
Range range;
|
Range range;
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ protected:
|
|||||||
|
|
||||||
QString textOf(int firstOffset, int lastOffset) const;
|
QString textOf(int firstOffset, int lastOffset) const;
|
||||||
QString textOf(const CPlusPlus::AST *ast) const;
|
QString textOf(const CPlusPlus::AST *ast) const;
|
||||||
|
QChar charAt(int offset) const;
|
||||||
|
|
||||||
struct Range {
|
struct Range {
|
||||||
Range() {}
|
Range() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user