mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-18 05:49:30 +02:00
Codetools: Improve renaming dotted unit names. Issue #40195.
This commit is contained in:
parent
d28b530b59
commit
2a16d0338e
@ -193,6 +193,7 @@ function DottedIdentifierLength(Identifier: PChar): integer;
|
||||
function GetDottedIdentifier(Identifier: PChar): string;
|
||||
function IsDottedIdentifier(const Identifier: string): boolean;
|
||||
function CompareDottedIdentifiers(Identifier1, Identifier2: PChar): integer;
|
||||
function CompareDottedIdentifiersCaseSens(Identifier1, Identifier2: PChar): integer;
|
||||
function ChompDottedIdentifier(const Identifier: string): string;
|
||||
|
||||
// space and special chars
|
||||
@ -4399,8 +4400,7 @@ begin
|
||||
Result:=CompareIdentifiers(PChar(Identifier1), PChar(Identifier2));
|
||||
end;
|
||||
|
||||
function CompareIdentifiersCaseSensitive(Identifier1, Identifier2: PChar
|
||||
): integer;
|
||||
function CompareIdentifiersCaseSensitive(Identifier1, Identifier2: PChar): integer;
|
||||
begin
|
||||
if (Identifier1<>nil) then begin
|
||||
if (Identifier2<>nil) then begin
|
||||
@ -5258,6 +5258,46 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function CompareDottedIdentifiersCaseSens(Identifier1, Identifier2: PChar): integer;
|
||||
begin
|
||||
if (Identifier1<>nil) then begin
|
||||
if (Identifier2<>nil) then begin
|
||||
while (UpChars[Identifier1[0]]=UpChars[Identifier2[0]]) do begin
|
||||
if (IsDottedIdentChar[Identifier1[0]]) then begin
|
||||
inc(Identifier1);
|
||||
inc(Identifier2);
|
||||
end else begin
|
||||
Result:=0; // for example 'aaA;' 'aAa;'
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
if (IsDottedIdentChar[Identifier1[0]]) then begin
|
||||
if (IsDottedIdentChar[Identifier2[0]]) then begin
|
||||
if UpChars[Identifier1[0]]>UpChars[Identifier2[0]] then
|
||||
Result:=-1 // for example 'aab' 'aaa'
|
||||
else
|
||||
Result:=1; // for example 'aaa' 'aab'
|
||||
end else begin
|
||||
Result:=-1; // for example 'aaa' 'aa;'
|
||||
end;
|
||||
end else begin
|
||||
if (IsDottedIdentChar[Identifier2[0]]) then
|
||||
Result:=1 // for example 'aa;' 'aaa'
|
||||
else
|
||||
Result:=0; // for example 'aa;' 'aa,'
|
||||
end;
|
||||
end else begin
|
||||
Result:=-1; // for example 'aaa' nil
|
||||
end;
|
||||
end else begin
|
||||
if (Identifier2<>nil) then begin
|
||||
Result:=1; // for example nil 'bbb'
|
||||
end else begin
|
||||
Result:=0; // for example nil nil
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function ChompDottedIdentifier(const Identifier: string): string;
|
||||
var
|
||||
p: Integer;
|
||||
|
@ -2895,24 +2895,26 @@ begin
|
||||
CurCodePos:=PCodeXYPosition(ANode.Data);
|
||||
Code:=CurCodePos^.Code;
|
||||
Code.LineColToPosition(CurCodePos^.Y,CurCodePos^.X,IdentStartPos);
|
||||
DebugLn('TCodeToolManager.RenameIdentifier File ',Code.Filename,' Line=',dbgs(CurCodePos^.Y),' Col=',dbgs(CurCodePos^.X),' Identifier=',GetIdentifier(@Code.Source[IdentStartPos]));
|
||||
DebugLn('TCodeToolManager.RenameIdentifier File ',Code.Filename,
|
||||
' Line=',dbgs(CurCodePos^.Y),' Col=',dbgs(CurCodePos^.X),
|
||||
' Identifier=',GetDottedIdentifier(@Code.Source[IdentStartPos]));
|
||||
// search absolute position in source
|
||||
if IdentStartPos<1 then begin
|
||||
SetError(20170421203205,Code, CurCodePos^.Y, CurCodePos^.X, ctsPositionNotInSource);
|
||||
exit;
|
||||
end;
|
||||
// check if old identifier is there
|
||||
if CompareIdentifiers(@Code.Source[IdentStartPos],PChar(Pointer(OldIdentifier)))<>0
|
||||
if CompareDottedIdentifiers(@Code.Source[IdentStartPos],PChar(Pointer(OldIdentifier)))<>0
|
||||
then begin
|
||||
debugln(['TCodeToolManager.RenameIdentifier CONSISTENCY ERROR ',Dbgs(CurCodePos^),' ']);
|
||||
SetError(20170421203210,CurCodePos^.Code,CurCodePos^.Y,CurCodePos^.X,
|
||||
Format(ctsStrExpectedButAtomFound,[OldIdentifier,
|
||||
GetIdentifier(@Code.Source[IdentStartPos])])
|
||||
GetDottedIdentifier(@Code.Source[IdentStartPos])])
|
||||
);
|
||||
exit;
|
||||
end;
|
||||
// change if needed
|
||||
if CompareIdentifiersCaseSensitive(@Code.Source[IdentStartPos],
|
||||
if CompareDottedIdentifiersCaseSens(@Code.Source[IdentStartPos],
|
||||
PChar(Pointer(NewIdentifier)))<>0
|
||||
then begin
|
||||
DebugLn('TCodeToolManager.RenameIdentifier Change ');
|
||||
@ -2930,7 +2932,7 @@ begin
|
||||
inc(SameLineCount);
|
||||
|
||||
end else begin
|
||||
DebugLn('TCodeToolManager.RenameIdentifier KEPT ',GetIdentifier(@Code.Source[IdentStartPos]));
|
||||
DebugLn('TCodeToolManager.RenameIdentifier KEPT ',GetDottedIdentifier(@Code.Source[IdentStartPos]));
|
||||
end;
|
||||
|
||||
LastCodePos := CurCodePos;
|
||||
|
@ -391,7 +391,7 @@ begin
|
||||
|
||||
// rename identifier
|
||||
if Options.Rename then begin
|
||||
if CompareIdentifiers(PChar(Identifier),PChar(CurUnitName))=0 then
|
||||
if CompareDottedIdentifiers(PChar(Identifier),PChar(CurUnitName))=0 then
|
||||
begin
|
||||
IDEMessageDialog(srkmecRenameIdentifier,
|
||||
lisTheIdentifierIsAUnitPleaseUseTheFileSaveAsFunction,
|
||||
|
@ -2626,7 +2626,7 @@ begin
|
||||
Confirm:=(EnvironmentOptions.UnitRenameReferencesAction=urraAsk)
|
||||
and (not WasVirtual);
|
||||
Result:=ReplaceUnitUse(OldFilename,OldUnitName,NewFilename,NewUnitName,
|
||||
true,true,Confirm);
|
||||
false,false,Confirm);
|
||||
if Result<>mrOk then exit;
|
||||
end;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user