mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-26 01:19:36 +02:00
codetools: AddUnitToUsesSection: dotted unit
git-svn-id: trunk@32103 -
This commit is contained in:
parent
e9498b62da
commit
116c4b1bbd
@ -174,6 +174,9 @@ function CompareAtom(p1, p2: PChar; NestedComments: boolean): integer;
|
|||||||
function CompareStringConstants(p1, p2: PChar): integer; // compare case sensitive
|
function CompareStringConstants(p1, p2: PChar): integer; // compare case sensitive
|
||||||
function CompareComments(p1, p2: PChar; NestedComments: boolean): integer; // compare case insensitive
|
function CompareComments(p1, p2: PChar; NestedComments: boolean): integer; // compare case insensitive
|
||||||
|
|
||||||
|
// dotted identifiers
|
||||||
|
function IsDottedIdentifier(const Identifier: string): boolean;
|
||||||
|
|
||||||
// space and special chars
|
// space and special chars
|
||||||
function TrimCodeSpace(const ACode: string): string;
|
function TrimCodeSpace(const ACode: string): string;
|
||||||
function CodeIsOnlySpace(const ACode: string; FromPos, ToPos: integer): boolean;
|
function CodeIsOnlySpace(const ACode: string; FromPos, ToPos: integer): boolean;
|
||||||
@ -4195,6 +4198,23 @@ begin
|
|||||||
if LengthOfLastLine=0 then ;
|
if LengthOfLastLine=0 then ;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function IsDottedIdentifier(const Identifier: string): boolean;
|
||||||
|
var
|
||||||
|
p: PChar;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
if Identifier='' then exit;;
|
||||||
|
p:=PChar(Identifier);
|
||||||
|
repeat
|
||||||
|
if not IsIdentStartChar[p^] then exit;
|
||||||
|
inc(p);
|
||||||
|
while IsIdentChar[p^] do inc(p);
|
||||||
|
if p^<>'.' then break;
|
||||||
|
inc(p);
|
||||||
|
until false;
|
||||||
|
Result:=(p-PChar(Identifier))=length(Identifier);
|
||||||
|
end;
|
||||||
|
|
||||||
function TrimCodeSpace(const ACode: string): string;
|
function TrimCodeSpace(const ACode: string): string;
|
||||||
// turn all lineends and special chars to space
|
// turn all lineends and special chars to space
|
||||||
// space is combined to one char
|
// space is combined to one char
|
||||||
|
@ -210,6 +210,8 @@ type
|
|||||||
procedure MoveCursorToUsesEnd(UsesNode: TCodeTreeNode);
|
procedure MoveCursorToUsesEnd(UsesNode: TCodeTreeNode);
|
||||||
procedure ReadNextUsedUnit(out UnitNameRange, InAtom: TAtomPosition);
|
procedure ReadNextUsedUnit(out UnitNameRange, InAtom: TAtomPosition);
|
||||||
procedure ReadPriorUsedUnit(out UnitNameRange, InAtom: TAtomPosition);
|
procedure ReadPriorUsedUnit(out UnitNameRange, InAtom: TAtomPosition);
|
||||||
|
function ExtractUsedUnitName(UseUnitNode: TCodeTreeNode;
|
||||||
|
InFilename: PAnsiString = nil): string;
|
||||||
|
|
||||||
// comments
|
// comments
|
||||||
function FindCommentInFront(const StartPos: TCodeXYPosition;
|
function FindCommentInFront(const StartPos: TCodeXYPosition;
|
||||||
@ -2559,6 +2561,28 @@ begin
|
|||||||
until false;
|
until false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TPascalReaderTool.ExtractUsedUnitName(UseUnitNode: TCodeTreeNode;
|
||||||
|
InFilename: PAnsiString): string;
|
||||||
|
begin
|
||||||
|
Result:='';
|
||||||
|
if InFilename<>nil then InFilename^:='';
|
||||||
|
if (UseUnitNode=nil) or (UseUnitNode.Desc<>ctnUseUnit) then exit;
|
||||||
|
MoveCursorToCleanPos(UseUnitNode.StartPos);
|
||||||
|
ReadNextAtom;
|
||||||
|
while CurPos.Flag=cafWord do begin
|
||||||
|
if Result<>'' then Result:=Result+'.';
|
||||||
|
Result:=Result+GetAtom;
|
||||||
|
ReadNextAtom;
|
||||||
|
if CurPos.Flag<>cafPoint then break;
|
||||||
|
ReadNextAtom;
|
||||||
|
end;
|
||||||
|
if (InFilename<>nil) and (UpAtomIs('IN')) then begin
|
||||||
|
ReadNextAtom;
|
||||||
|
if not AtomIsStringConstant then exit;
|
||||||
|
InFilename^:=copy(Src,CurPos.StartPos+1,CurPos.EndPos-CurPos.StartPos-2);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TPascalReaderTool.FindCommentInFront(const StartPos: TCodeXYPosition;
|
function TPascalReaderTool.FindCommentInFront(const StartPos: TCodeXYPosition;
|
||||||
const CommentText: string; InvokeBuildTree, SearchInParentNode,
|
const CommentText: string; InvokeBuildTree, SearchInParentNode,
|
||||||
WithCommentBounds, CaseSensitive, IgnoreSpaces, CompareOnlyStart: boolean;
|
WithCommentBounds, CaseSensitive, IgnoreSpaces, CompareOnlyStart: boolean;
|
||||||
|
@ -402,8 +402,9 @@ var UnitPos, InPos: TAtomPosition;
|
|||||||
NewUsesTerm: string;
|
NewUsesTerm: string;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if (OldUnitName='') or (length(OldUnitName)>255) or (NewUnitName='')
|
if (not IsDottedIdentifier(OldUnitName))
|
||||||
or (length(NewUnitName)>255) then exit;
|
or (not IsDottedIdentifier(NewUnitName)) then
|
||||||
|
exit;
|
||||||
if not FindUnitInAllUsesSections(OldUnitName,UnitPos,InPos) then begin
|
if not FindUnitInAllUsesSections(OldUnitName,UnitPos,InPos) then begin
|
||||||
//debugln('TStandardCodeTool.RenameUsedUnit not found: ',OldUnitName,' ');
|
//debugln('TStandardCodeTool.RenameUsedUnit not found: ',OldUnitName,' ');
|
||||||
exit;
|
exit;
|
||||||
@ -663,7 +664,8 @@ var
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var LineStart, LineEnd, Indent, InsertPos, InsertToPos, InsertLen: integer;
|
var
|
||||||
|
LineStart, LineEnd, Indent, InsertPos, InsertToPos, InsertLen: integer;
|
||||||
NewUsesTerm: string;
|
NewUsesTerm: string;
|
||||||
InsertBehind: Boolean;
|
InsertBehind: Boolean;
|
||||||
InsertNode: TCodeTreeNode;
|
InsertNode: TCodeTreeNode;
|
||||||
@ -686,9 +688,10 @@ var LineStart, LineEnd, Indent, InsertPos, InsertToPos, InsertLen: integer;
|
|||||||
InsertPosFound: Boolean;
|
InsertPosFound: Boolean;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if (UsesNode=nil) or (UsesNode.Desc<>ctnUsesSection) or (NewUnitName='')
|
if (UsesNode=nil) or (UsesNode.Desc<>ctnUsesSection)
|
||||||
or (length(NewUnitName)>255) or (UsesNode.StartPos<1)
|
or (UsesNode.StartPos<1) or (UsesNode.EndPos<1)
|
||||||
or (UsesNode.EndPos<1) then exit;
|
or (not IsDottedIdentifier(NewUnitName))
|
||||||
|
then exit;
|
||||||
SourceChangeCache.MainScanner:=Scanner;
|
SourceChangeCache.MainScanner:=Scanner;
|
||||||
Options:=SourceChangeCache.BeautifyCodeOptions;
|
Options:=SourceChangeCache.BeautifyCodeOptions;
|
||||||
|
|
||||||
@ -745,15 +748,7 @@ begin
|
|||||||
BestDiffCnt:=High(integer);
|
BestDiffCnt:=High(integer);
|
||||||
Node:=FirstNormalUsesNode;
|
Node:=FirstNormalUsesNode;
|
||||||
while Node<>nil do begin
|
while Node<>nil do begin
|
||||||
MoveCursorToCleanPos(Node.StartPos);
|
AnUnitName:=ExtractUsedUnitName(Node,@AnUnitInFilename);
|
||||||
ReadNextAtom;
|
|
||||||
AnUnitName:=GetAtom;
|
|
||||||
ReadNextAtom;
|
|
||||||
if UpAtomIs('IN') then begin
|
|
||||||
ReadNextAtom;
|
|
||||||
AnUnitInFilename:=copy(Src,CurPos.StartPos+1,CurPos.EndPos-CurPos.StartPos-2);
|
|
||||||
end else
|
|
||||||
AnUnitInFilename:='';
|
|
||||||
// search unit
|
// search unit
|
||||||
//DebugLn(['TStandardCodeTool.AddUnitToUsesSection Unit=',AnUnitName,' in "',AnUnitInFilename,'"']);
|
//DebugLn(['TStandardCodeTool.AddUnitToUsesSection Unit=',AnUnitName,' in "',AnUnitInFilename,'"']);
|
||||||
NewCode:=FindUnitSource(AnUnitName,AnUnitInFilename,false);
|
NewCode:=FindUnitSource(AnUnitName,AnUnitInFilename,false);
|
||||||
@ -867,10 +862,7 @@ begin
|
|||||||
InsertToPos:=Node.EndPos;
|
InsertToPos:=Node.EndPos;
|
||||||
if (Node=InsertNode) and (not InsertBehind) then
|
if (Node=InsertNode) and (not InsertBehind) then
|
||||||
AddUseUnit(Lines,FirstIndent,Indent,NewUsesTerm);
|
AddUseUnit(Lines,FirstIndent,Indent,NewUsesTerm);
|
||||||
MoveCursorToCleanPos(Node.StartPos);
|
InsertCode:=ExtractUsedUnitName(Node);
|
||||||
ReadNextAtom;
|
|
||||||
InsertCode:=GetAtom;
|
|
||||||
ReadNextAtom;
|
|
||||||
if UpAtomIs('IN') then begin
|
if UpAtomIs('IN') then begin
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
InsertCode:=InsertCode+' '+Options.BeautifyKeyWord('in')+' '+GetAtom;
|
InsertCode:=InsertCode+' '+Options.BeautifyKeyWord('in')+' '+GetAtom;
|
||||||
|
Loading…
Reference in New Issue
Block a user