mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-19 22:29:25 +02:00
IDE: renaming methods in source now skips string constants
git-svn-id: trunk@10174 -
This commit is contained in:
parent
60c3b74fff
commit
b49605526a
@ -77,6 +77,8 @@ function GetIdentLen(Identifier: PChar): integer;
|
||||
function GetIdentifier(Identifier: PChar): string;
|
||||
function FindNextIdentifier(const Source: string; StartPos, MaxPos: integer
|
||||
): integer;
|
||||
function FindNextIdentifierSkipStrings(const Source: string;
|
||||
StartPos, MaxPos: integer): integer;
|
||||
|
||||
// line/code ends
|
||||
function LineEndCount(const Txt: string): integer;
|
||||
@ -2589,6 +2591,25 @@ begin
|
||||
inc(Result);
|
||||
end;
|
||||
|
||||
function FindNextIdentifierSkipStrings(const Source: string; StartPos,
|
||||
MaxPos: integer): integer;
|
||||
var
|
||||
c: Char;
|
||||
begin
|
||||
Result:=StartPos;
|
||||
while (Result<=MaxPos) do begin
|
||||
c:=Source[Result];
|
||||
if IsIDStartChar[c] then exit;
|
||||
if c='''' then begin
|
||||
// skip string constant
|
||||
inc(Result);
|
||||
while (Result<=MaxPos) and (not (Source[Result] in ['''',#10,#13])) do
|
||||
inc(Result);
|
||||
end;
|
||||
inc(Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
function GetBlockMinIndent(const Source: string;
|
||||
StartPos, EndPos: integer): integer;
|
||||
var
|
||||
|
@ -356,8 +356,8 @@ type
|
||||
var ListOfPCodeXYPosition: TFPList): boolean;
|
||||
function RenameIdentifier(TreeOfPCodeXYPosition: TAVLTree;
|
||||
const OldIdentifier, NewIdentifier: string): boolean;
|
||||
function ReplaceWord(Code: TCodeBuffer; const OldWord, NewWord: string
|
||||
): boolean;
|
||||
function ReplaceWord(Code: TCodeBuffer; const OldWord, NewWord: string;
|
||||
ChangeStrings: boolean): boolean;
|
||||
|
||||
// resourcestring sections
|
||||
function GatherResourceStringSections(
|
||||
@ -1951,7 +1951,7 @@ begin
|
||||
end;
|
||||
|
||||
function TCodeToolManager.ReplaceWord(Code: TCodeBuffer; const OldWord,
|
||||
NewWord: string): boolean;
|
||||
NewWord: string; ChangeStrings: boolean): boolean;
|
||||
var
|
||||
CursorPos, SectionPos, NearestPos: TCodeXYPosition;
|
||||
begin
|
||||
@ -1961,7 +1961,7 @@ begin
|
||||
{$ENDIF}
|
||||
if not InitCurCodeTool(Code) then exit;
|
||||
try
|
||||
Result:=FCurCodeTool.ReplaceWord(OldWord, NewWord,
|
||||
Result:=FCurCodeTool.ReplaceWord(OldWord, NewWord, ChangeStrings,
|
||||
SourceChangeCache);
|
||||
except
|
||||
on e: Exception do HandleException(e);
|
||||
|
@ -222,11 +222,11 @@ type
|
||||
var MissingIncludeFilesCodeXYPos: TFPList): boolean;
|
||||
|
||||
// search & replace
|
||||
function ReplaceWords(IdentList: TStrings;
|
||||
function ReplaceWords(IdentList: TStrings; ChangeStrings: boolean;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
function FindNearestIdentifierNode(const CursorPos: TCodeXYPosition;
|
||||
IdentTree: TAVLTree): TAVLTreeNode;
|
||||
function ReplaceWord(const OldWord, NewWord: string;
|
||||
function ReplaceWord(const OldWord, NewWord: string; ChangeStrings: boolean;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
|
||||
// expressions
|
||||
@ -2438,7 +2438,7 @@ begin
|
||||
IdentList.Add(OldFormClassName);
|
||||
IdentList.Add(NewFormClassName);
|
||||
end;
|
||||
Result:=ReplaceWords(IdentList,SourceChangeCache);
|
||||
Result:=ReplaceWords(IdentList,false,SourceChangeCache);
|
||||
finally
|
||||
IdentList.Free;
|
||||
end;
|
||||
@ -2472,14 +2472,16 @@ end;
|
||||
|
||||
{-------------------------------------------------------------------------------
|
||||
function TStandardCodeTool.ReplaceWords(IdentList: TStrings;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
ChangeStrings: boolean; SourceChangeCache: TSourceChangeCache): boolean;
|
||||
|
||||
Search in all used sources (not only the cleaned source) for identifiers.
|
||||
It will find all identifiers, except identifiers in compiler directives.
|
||||
This includes identifiers in string constants and comments.
|
||||
|
||||
ChangeStrings = true, means to replace in string constants too
|
||||
-------------------------------------------------------------------------------}
|
||||
function TStandardCodeTool.ReplaceWords(IdentList: TStrings;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
ChangeStrings: boolean; SourceChangeCache: TSourceChangeCache): boolean;
|
||||
|
||||
procedure ReplaceWordsInSource(ACode: TCodeBuffer);
|
||||
var
|
||||
@ -2498,7 +2500,10 @@ function TStandardCodeTool.ReplaceWords(IdentList: TStrings;
|
||||
if EndPos>MaxPos then EndPos:=MaxPos+1;
|
||||
// search all identifiers
|
||||
repeat
|
||||
IdentStart:=FindNextIdentifier(CurSource,StartPos,EndPos-1);
|
||||
if ChangeStrings then
|
||||
IdentStart:=FindNextIdentifier(CurSource,StartPos,EndPos-1)
|
||||
else
|
||||
IdentStart:=FindNextIdentifierSkipStrings(CurSource,StartPos,EndPos-1);
|
||||
if IdentStart<EndPos then begin
|
||||
i:=0;
|
||||
while i<IdentList.Count do begin
|
||||
@ -2591,7 +2596,7 @@ begin
|
||||
end;
|
||||
|
||||
function TStandardCodeTool.ReplaceWord(const OldWord, NewWord: string;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
ChangeStrings: boolean; SourceChangeCache: TSourceChangeCache): boolean;
|
||||
var
|
||||
IdentList: TStringList;
|
||||
begin
|
||||
@ -2603,7 +2608,7 @@ begin
|
||||
try
|
||||
IdentList.Add(OldWord);
|
||||
IdentList.Add(NewWord);
|
||||
Result:=ReplaceWords(IdentList,SourceChangeCache);
|
||||
Result:=ReplaceWords(IdentList,ChangeStrings,SourceChangeCache);
|
||||
finally
|
||||
IdentList.Free;
|
||||
end;
|
||||
@ -4036,7 +4041,8 @@ begin
|
||||
end;
|
||||
end;
|
||||
// rename variable in source
|
||||
if not ReplaceWord(UpperOldVarName,NewVarName,SourceChangeCache) then exit;
|
||||
if not ReplaceWord(UpperOldVarName,NewVarName,false,SourceChangeCache) then
|
||||
exit;
|
||||
Result:=(not ApplyNeeded) or SourceChangeCache.Apply;
|
||||
end else begin
|
||||
// old variable not found -> add it
|
||||
|
@ -11480,7 +11480,7 @@ var
|
||||
if OldClassName<>AComponent.ClassName then begin
|
||||
// replace references to classname, ignoring errors
|
||||
CodeToolBoss.ReplaceWord(DependingUnit.Source,
|
||||
OldClassName,AComponent.ClassName);
|
||||
OldClassName,AComponent.ClassName,false);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -11510,7 +11510,8 @@ var
|
||||
if DependingDesigner<>nil then
|
||||
DependingUnit.Modified:=true;
|
||||
// replace references, ignoring errors
|
||||
CodeToolBoss.ReplaceWord(DependingUnit.Source,OldName,NewName);
|
||||
CodeToolBoss.ReplaceWord(DependingUnit.Source,OldName,NewName,
|
||||
false);
|
||||
end;
|
||||
finally
|
||||
if FRenamingComponents<>nil then begin
|
||||
@ -12153,8 +12154,8 @@ begin
|
||||
OldName:=List[i];
|
||||
NewName:=List[i+1];
|
||||
// replace references, ignoring errors
|
||||
if CodeToolBoss.ReplaceWord(DependingUnit.Source,OldName,NewName) then
|
||||
begin
|
||||
if CodeToolBoss.ReplaceWord(DependingUnit.Source,OldName,NewName,false)
|
||||
then begin
|
||||
// renamed in source, now rename in JIT class
|
||||
FormEditor1.RenameJITMethod(DependingUnit.Component,
|
||||
OldName,NewName);
|
||||
|
Loading…
Reference in New Issue
Block a user