From ccf46cda1d480eafafbef169faae2dd470650d86 Mon Sep 17 00:00:00 2001 From: mattias Date: Sat, 30 Sep 2017 13:14:44 +0000 Subject: [PATCH] codetools: fixed RemoveUnitFromAllUsesSections git-svn-id: trunk@55944 - --- components/codetools/stdcodetools.pas | 48 ++++++++++----------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/components/codetools/stdcodetools.pas b/components/codetools/stdcodetools.pas index 605bffac6a..008e8c6255 100644 --- a/components/codetools/stdcodetools.pas +++ b/components/codetools/stdcodetools.pas @@ -1183,8 +1183,13 @@ end; function TStandardCodeTool.RemoveUnitFromAllUsesSections( const AnUnitName: string; SourceChangeCache: TSourceChangeCache): boolean; -var - SectionNode, Node: TCodeTreeNode; + + function RemoveFromSection(UsesNode: TCodeTreeNode): boolean; + begin + Result:=(UsesNode=nil) + or (RemoveUnitFromUsesSection(UsesNode,AnUnitName,SourceChangeCache)); + end; + begin Result:=false; if (AnUnitName='') or (SourceChangeCache=nil) then exit; @@ -1192,21 +1197,8 @@ begin SourceChangeCache.BeginUpdate; try - SectionNode:=Tree.Root; - while (SectionNode<>nil) do begin - Node:=SectionNode.FirstChild; - while (Node<>nil) and (Node.Desc=ctnIdentifier) do - Node:=Node.NextBrother; - if (Node<>nil) - and (Node.Desc=ctnUsesSection) then begin - if not RemoveUnitFromUsesSection(Node,AnUnitName, - SourceChangeCache) - then begin - exit; - end; - end; - SectionNode:=SectionNode.NextBrother; - end; + if not RemoveFromSection(FindMainUsesNode) then exit; + if not RemoveFromSection(FindImplementationUsesNode) then exit; finally Result:=SourceChangeCache.EndUpdate; end; @@ -1214,24 +1206,18 @@ end; function TStandardCodeTool.FixUsedUnitCase( SourceChangeCache: TSourceChangeCache): boolean; -var - SectionNode: TCodeTreeNode; + + function FixUsesSection(UsesNode: TCodeTreeNode): boolean; + begin + Result:=(UsesNode=nil) or FixUsedUnitCaseInUsesSection(UsesNode,SourceChangeCache); + end; + begin //debugln('TStandardCodeTool.FixUsedUnitCase ',MainFilename); Result:=false; BuildTree(lsrImplementationUsesSectionEnd); - SectionNode:=Tree.Root; - while (SectionNode<>nil) do begin - if (SectionNode.FirstChild<>nil) - and (SectionNode.FirstChild.Desc=ctnUsesSection) then begin - if not FixUsedUnitCaseInUsesSection( - SectionNode.FirstChild,SourceChangeCache) - then begin - exit; - end; - end; - SectionNode:=SectionNode.NextBrother; - end; + if not FixUsesSection(FindMainUsesNode) then exit; + if not FixUsesSection(FindImplementationUsesNode) then exit; Result:=true; end;