Kaydet (Commit) 6f16cfb5 authored tarafından Luboš Luňák's avatar Luboš Luňák

Fix handling range in removeText().

Turns out removeText( SourceRange ) treats it as a token range, so it's
not always character-exact if used for removal of only several characters
from a token (e.g. an identifier).

Change-Id: I0223d52da90f9535d9ef1d48b0f56d69131536c8
üst 0bac488a
......@@ -105,9 +105,22 @@ bool RewritePlugin::insertTextBefore( SourceLocation Loc, StringRef Str )
return true;
}
// These two removeText() overloads should not be merged into one, as the SourceRange
// one uses a token range (which counts token length for some reason), so exact length
// given to this overload would not match afterwards.
bool RewritePlugin::removeText( SourceLocation Start, unsigned Length, RewriteOptions opts )
{
return removeText( SourceRange( Start, Start.getLocWithOffset( Length )), opts );
if( opts.RemoveWholeStatement )
{
SourceRange range( Start, Start.getLocWithOffset( Length - 1 ));
if( !adjustForWholeStatement( &range ))
return reportEditFailure( Start );
Start = range.getBegin();
Length = range.getEnd().getRawEncoding() - range.getBegin().getRawEncoding();
}
if( rewriter.RemoveText( Start, Length, opts ))
return reportEditFailure( Start );
return true;
}
bool RewritePlugin::removeText( SourceRange range, RewriteOptions opts )
......
......@@ -101,7 +101,7 @@ class RewritePlugin
bool insertTextAfterToken( SourceLocation Loc, StringRef Str );
bool insertTextBefore( SourceLocation Loc, StringRef Str );
bool removeText( SourceLocation Start, unsigned Length, RewriteOptions opts = RewriteOptions());
// CharSourceRange not supported, unless really needed, as it makes RemoveSemicolon more complicated
// CharSourceRange not supported, unless really needed, as it needs handling for RemoveWholeStatement.
//bool removeText( CharSourceRange range, RewriteOptions opts = RewriteOptions());
bool removeText( SourceRange range, RewriteOptions opts = RewriteOptions());
bool replaceText( SourceLocation Start, unsigned OrigLength, StringRef NewStr );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment