mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-18 10:39:21 +02:00
codetools: AddUnitToMainUsesSection using flags, test
git-svn-id: trunk@63404 -
This commit is contained in:
parent
5bb7d9bdd1
commit
665ab3cba6
@ -708,13 +708,22 @@ type
|
|||||||
UnitNamePairs: TStringToStringTree): boolean;
|
UnitNamePairs: TStringToStringTree): boolean;
|
||||||
function AddUnitToMainUsesSection(Code: TCodeBuffer;
|
function AddUnitToMainUsesSection(Code: TCodeBuffer;
|
||||||
const NewUnitName, NewUnitInFile: string;
|
const NewUnitName, NewUnitInFile: string;
|
||||||
AsLast: boolean = false; CheckSpecialUnits: boolean = true): boolean;
|
const Flags: TAddUsesFlags = []): boolean; overload;
|
||||||
|
function AddUnitToMainUsesSection(Code: TCodeBuffer;
|
||||||
|
const NewUnitName, NewUnitInFile: string;
|
||||||
|
AsLast: boolean; CheckSpecialUnits: boolean = true): boolean; overload; deprecated;
|
||||||
function AddUnitToMainUsesSectionIfNeeded(Code: TCodeBuffer;
|
function AddUnitToMainUsesSectionIfNeeded(Code: TCodeBuffer;
|
||||||
const NewUnitName, NewUnitInFile: string;
|
const NewUnitName, NewUnitInFile: string;
|
||||||
AsLast: boolean = false; CheckSpecialUnits: boolean = true): boolean;
|
const Flags: TAddUsesFlags = []): boolean;
|
||||||
|
function AddUnitToMainUsesSectionIfNeeded(Code: TCodeBuffer;
|
||||||
|
const NewUnitName, NewUnitInFile: string;
|
||||||
|
AsLast: boolean; CheckSpecialUnits: boolean = true): boolean; overload; deprecated;
|
||||||
function AddUnitToImplementationUsesSection(Code: TCodeBuffer;
|
function AddUnitToImplementationUsesSection(Code: TCodeBuffer;
|
||||||
const NewUnitName, NewUnitInFile: string;
|
const NewUnitName, NewUnitInFile: string;
|
||||||
AsLast: boolean = false; CheckSpecialUnits: boolean = true): boolean;
|
const Flags: TAddUsesFlags = []): boolean;
|
||||||
|
function AddUnitToImplementationUsesSection(Code: TCodeBuffer;
|
||||||
|
const NewUnitName, NewUnitInFile: string;
|
||||||
|
AsLast: boolean; CheckSpecialUnits: boolean = true): boolean; overload; deprecated;
|
||||||
function RemoveUnitFromAllUsesSections(Code: TCodeBuffer;
|
function RemoveUnitFromAllUsesSections(Code: TCodeBuffer;
|
||||||
const AnUnitName: string): boolean;
|
const AnUnitName: string): boolean;
|
||||||
function FindUsedUnitFiles(Code: TCodeBuffer; var MainUsesSection: TStrings
|
function FindUsedUnitFiles(Code: TCodeBuffer; var MainUsesSection: TStrings
|
||||||
@ -5056,8 +5065,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TCodeToolManager.AddUnitToMainUsesSection(Code: TCodeBuffer;
|
function TCodeToolManager.AddUnitToMainUsesSection(Code: TCodeBuffer;
|
||||||
const NewUnitName, NewUnitInFile: string; AsLast: boolean;
|
const NewUnitName, NewUnitInFile: string; const Flags: TAddUsesFlags
|
||||||
CheckSpecialUnits: boolean = true): boolean;
|
): boolean;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
@ -5066,15 +5075,27 @@ begin
|
|||||||
if not InitCurCodeTool(Code) then exit;
|
if not InitCurCodeTool(Code) then exit;
|
||||||
try
|
try
|
||||||
Result:=FCurCodeTool.AddUnitToMainUsesSection(NewUnitName, NewUnitInFile,
|
Result:=FCurCodeTool.AddUnitToMainUsesSection(NewUnitName, NewUnitInFile,
|
||||||
SourceChangeCache,AsLast,CheckSpecialUnits);
|
SourceChangeCache,Flags);
|
||||||
except
|
except
|
||||||
on e: Exception do Result:=HandleException(e);
|
on e: Exception do Result:=HandleException(e);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCodeToolManager.AddUnitToMainUsesSectionIfNeeded(Code: TCodeBuffer;
|
function TCodeToolManager.AddUnitToMainUsesSection(Code: TCodeBuffer;
|
||||||
const NewUnitName, NewUnitInFile: string; AsLast: boolean;
|
const NewUnitName, NewUnitInFile: string; AsLast: boolean;
|
||||||
CheckSpecialUnits: boolean): boolean;
|
CheckSpecialUnits: boolean = true): boolean;
|
||||||
|
var
|
||||||
|
Flags: TAddUsesFlags;
|
||||||
|
begin
|
||||||
|
Flags:=[];
|
||||||
|
if AsLast then Include(Flags,aufLast);
|
||||||
|
if not CheckSpecialUnits then Include(Flags,aufNotCheckSpecialUnit);
|
||||||
|
Result:=AddUnitToMainUsesSection(Code,NewUnitName,NewUnitInFile,Flags);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TCodeToolManager.AddUnitToMainUsesSectionIfNeeded(Code: TCodeBuffer;
|
||||||
|
const NewUnitName, NewUnitInFile: string; const Flags: TAddUsesFlags
|
||||||
|
): boolean;
|
||||||
var
|
var
|
||||||
NamePos, InPos: TAtomPosition;
|
NamePos, InPos: TAtomPosition;
|
||||||
begin
|
begin
|
||||||
@ -5086,15 +5107,27 @@ begin
|
|||||||
try
|
try
|
||||||
if not FCurCodeTool.FindUnitInAllUsesSections(NewUnitName,NamePos,InPos) then
|
if not FCurCodeTool.FindUnitInAllUsesSections(NewUnitName,NamePos,InPos) then
|
||||||
Result:=FCurCodeTool.AddUnitToMainUsesSection(NewUnitName, NewUnitInFile,
|
Result:=FCurCodeTool.AddUnitToMainUsesSection(NewUnitName, NewUnitInFile,
|
||||||
SourceChangeCache,AsLast,CheckSpecialUnits);
|
SourceChangeCache,Flags);
|
||||||
except
|
except
|
||||||
on e: Exception do Result:=HandleException(e);
|
on e: Exception do Result:=HandleException(e);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCodeToolManager.AddUnitToImplementationUsesSection(Code: TCodeBuffer;
|
function TCodeToolManager.AddUnitToMainUsesSectionIfNeeded(Code: TCodeBuffer;
|
||||||
const NewUnitName, NewUnitInFile: string; AsLast: boolean;
|
const NewUnitName, NewUnitInFile: string; AsLast: boolean;
|
||||||
CheckSpecialUnits: boolean): boolean;
|
CheckSpecialUnits: boolean): boolean;
|
||||||
|
var
|
||||||
|
Flags: TAddUsesFlags;
|
||||||
|
begin
|
||||||
|
Flags:=[];
|
||||||
|
if AsLast then Include(Flags,aufLast);
|
||||||
|
if not CheckSpecialUnits then Include(Flags,aufNotCheckSpecialUnit);
|
||||||
|
Result:=AddUnitToMainUsesSectionIfNeeded(Code,NewUnitName,NewUnitInFile,Flags);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TCodeToolManager.AddUnitToImplementationUsesSection(Code: TCodeBuffer;
|
||||||
|
const NewUnitName, NewUnitInFile: string; const Flags: TAddUsesFlags
|
||||||
|
): boolean;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
@ -5104,12 +5137,24 @@ begin
|
|||||||
try
|
try
|
||||||
Result:=FCurCodeTool.AddUnitToImplementationUsesSection(
|
Result:=FCurCodeTool.AddUnitToImplementationUsesSection(
|
||||||
NewUnitName, NewUnitInFile,
|
NewUnitName, NewUnitInFile,
|
||||||
SourceChangeCache,AsLast,CheckSpecialUnits);
|
SourceChangeCache,Flags);
|
||||||
except
|
except
|
||||||
on e: Exception do Result:=HandleException(e);
|
on e: Exception do Result:=HandleException(e);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCodeToolManager.AddUnitToImplementationUsesSection(Code: TCodeBuffer;
|
||||||
|
const NewUnitName, NewUnitInFile: string; AsLast: boolean;
|
||||||
|
CheckSpecialUnits: boolean): boolean;
|
||||||
|
var
|
||||||
|
Flags: TAddUsesFlags;
|
||||||
|
begin
|
||||||
|
Flags:=[];
|
||||||
|
if AsLast then Include(Flags,aufLast);
|
||||||
|
if not CheckSpecialUnits then Include(Flags,aufNotCheckSpecialUnit);
|
||||||
|
Result:=AddUnitToImplementationUsesSection(Code,NewUnitName,NewUnitInFile,Flags);
|
||||||
|
end;
|
||||||
|
|
||||||
function TCodeToolManager.RemoveUnitFromAllUsesSections(Code: TCodeBuffer;
|
function TCodeToolManager.RemoveUnitFromAllUsesSections(Code: TCodeBuffer;
|
||||||
const AnUnitName: string): boolean;
|
const AnUnitName: string): boolean;
|
||||||
begin
|
begin
|
||||||
|
@ -72,6 +72,11 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
TUsesSection = (usMain, usImplementation);
|
TUsesSection = (usMain, usImplementation);
|
||||||
|
TAddUsesFlag = (
|
||||||
|
aufLast,
|
||||||
|
aufNotCheckSpecialUnit
|
||||||
|
);
|
||||||
|
TAddUsesFlags = set of TAddUsesFlag;
|
||||||
|
|
||||||
TOnFindDefinePropertyForContext = procedure(Sender: TObject;
|
TOnFindDefinePropertyForContext = procedure(Sender: TObject;
|
||||||
const ClassContext, AncestorClassContext: TFindContext;
|
const ClassContext, AncestorClassContext: TFindContext;
|
||||||
@ -112,18 +117,14 @@ type
|
|||||||
SourceChangeCache: TSourceChangeCache): boolean;
|
SourceChangeCache: TSourceChangeCache): boolean;
|
||||||
function AddUnitToUsesSection(UsesNode: TCodeTreeNode;
|
function AddUnitToUsesSection(UsesNode: TCodeTreeNode;
|
||||||
const NewUnitName, NewUnitInFile: string;
|
const NewUnitName, NewUnitInFile: string;
|
||||||
SourceChangeCache: TSourceChangeCache;
|
SourceChangeCache: TSourceChangeCache; const Flags: TAddUsesFlags = []): boolean;
|
||||||
AsLast: boolean = false; CheckSpecialUnits: boolean = true): boolean;
|
|
||||||
function AddUnitToSpecificUsesSection(UsesSection: TUsesSection;
|
function AddUnitToSpecificUsesSection(UsesSection: TUsesSection;
|
||||||
const NewUnitName, NewUnitInFile: string;
|
const NewUnitName, NewUnitInFile: string;
|
||||||
SourceChangeCache: TSourceChangeCache;
|
SourceChangeCache: TSourceChangeCache; const Flags: TAddUsesFlags = []): boolean;
|
||||||
AsLast: boolean = false; CheckSpecialUnits: boolean = true): boolean;
|
|
||||||
function AddUnitToMainUsesSection(const NewUnitName, NewUnitInFile: string;
|
function AddUnitToMainUsesSection(const NewUnitName, NewUnitInFile: string;
|
||||||
SourceChangeCache: TSourceChangeCache;
|
SourceChangeCache: TSourceChangeCache; const Flags: TAddUsesFlags = []): boolean;
|
||||||
AsLast: boolean = false; CheckSpecialUnits: boolean = true): boolean;
|
|
||||||
function AddUnitToImplementationUsesSection(const NewUnitName, NewUnitInFile: string;
|
function AddUnitToImplementationUsesSection(const NewUnitName, NewUnitInFile: string;
|
||||||
SourceChangeCache: TSourceChangeCache;
|
SourceChangeCache: TSourceChangeCache; const Flags: TAddUsesFlags = []): boolean;
|
||||||
AsLast: boolean = false; CheckSpecialUnits: boolean = true): boolean;
|
|
||||||
function UnitExistsInUsesSection(UsesSection: TUsesSection;
|
function UnitExistsInUsesSection(UsesSection: TUsesSection;
|
||||||
const AnUnitName: string): boolean;
|
const AnUnitName: string): boolean;
|
||||||
function UnitExistsInUsesSection(UsesNode: TCodeTreeNode;
|
function UnitExistsInUsesSection(UsesNode: TCodeTreeNode;
|
||||||
@ -632,8 +633,7 @@ end;
|
|||||||
|
|
||||||
function TStandardCodeTool.AddUnitToUsesSection(UsesNode: TCodeTreeNode;
|
function TStandardCodeTool.AddUnitToUsesSection(UsesNode: TCodeTreeNode;
|
||||||
const NewUnitName, NewUnitInFile: string;
|
const NewUnitName, NewUnitInFile: string;
|
||||||
SourceChangeCache: TSourceChangeCache; AsLast: boolean;
|
SourceChangeCache: TSourceChangeCache; const Flags: TAddUsesFlags): boolean;
|
||||||
CheckSpecialUnits: boolean): boolean;
|
|
||||||
const
|
const
|
||||||
SpecialUnits: array[1..5] of string = (
|
SpecialUnits: array[1..5] of string = (
|
||||||
'cmem',
|
'cmem',
|
||||||
@ -732,7 +732,7 @@ var
|
|||||||
UsesInsertPolicy: TUsesInsertPolicy;
|
UsesInsertPolicy: TUsesInsertPolicy;
|
||||||
Prio: LongInt;
|
Prio: LongInt;
|
||||||
FirstNormalUsesNode: TCodeTreeNode;
|
FirstNormalUsesNode: TCodeTreeNode;
|
||||||
InsertPosFound: Boolean;
|
InsertPosFound, CheckSpecialUnits: Boolean;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if (UsesNode=nil) or (UsesNode.Desc<>ctnUsesSection)
|
if (UsesNode=nil) or (UsesNode.Desc<>ctnUsesSection)
|
||||||
@ -746,9 +746,10 @@ begin
|
|||||||
|
|
||||||
Prio:=SpecialUnitPriority(PChar(NewUnitName));
|
Prio:=SpecialUnitPriority(PChar(NewUnitName));
|
||||||
UsesInsertPolicy:=Beauty.UsesInsertPolicy;
|
UsesInsertPolicy:=Beauty.UsesInsertPolicy;
|
||||||
if AsLast then
|
if aufLast in Flags then
|
||||||
UsesInsertPolicy:=uipLast;
|
UsesInsertPolicy:=uipLast;
|
||||||
InsertPosFound:=false;
|
InsertPosFound:=false;
|
||||||
|
CheckSpecialUnits:=not (aufNotCheckSpecialUnit in Flags);
|
||||||
if CheckSpecialUnits and (Prio<=High(SpecialUnits)) then begin
|
if CheckSpecialUnits and (Prio<=High(SpecialUnits)) then begin
|
||||||
// this is a special unit, insert at the beginning
|
// this is a special unit, insert at the beginning
|
||||||
InsertBehind:=false;
|
InsertBehind:=false;
|
||||||
@ -940,23 +941,23 @@ end;
|
|||||||
|
|
||||||
function TStandardCodeTool.AddUnitToMainUsesSection(const NewUnitName,
|
function TStandardCodeTool.AddUnitToMainUsesSection(const NewUnitName,
|
||||||
NewUnitInFile: string; SourceChangeCache: TSourceChangeCache;
|
NewUnitInFile: string; SourceChangeCache: TSourceChangeCache;
|
||||||
AsLast: boolean; CheckSpecialUnits: boolean): boolean;
|
const Flags: TAddUsesFlags): boolean;
|
||||||
begin
|
begin
|
||||||
Result:=AddUnitToSpecificUsesSection(usMain, NewUnitName, NewUnitInFile, SourceChangeCache,
|
Result:=AddUnitToSpecificUsesSection(usMain, NewUnitName, NewUnitInFile,
|
||||||
AsLast, CheckSpecialUnits);
|
SourceChangeCache, Flags);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TStandardCodeTool.AddUnitToImplementationUsesSection(const NewUnitName,
|
function TStandardCodeTool.AddUnitToImplementationUsesSection(
|
||||||
NewUnitInFile: string; SourceChangeCache: TSourceChangeCache;
|
const NewUnitName, NewUnitInFile: string;
|
||||||
AsLast: boolean; CheckSpecialUnits: boolean): boolean;
|
SourceChangeCache: TSourceChangeCache; const Flags: TAddUsesFlags): boolean;
|
||||||
begin
|
begin
|
||||||
Result:=AddUnitToSpecificUsesSection(usImplementation, NewUnitName, NewUnitInFile, SourceChangeCache,
|
Result:=AddUnitToSpecificUsesSection(usImplementation,
|
||||||
AsLast, CheckSpecialUnits);
|
NewUnitName, NewUnitInFile, SourceChangeCache, Flags);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TStandardCodeTool.AddUnitToSpecificUsesSection(UsesSection: TUsesSection;
|
function TStandardCodeTool.AddUnitToSpecificUsesSection(
|
||||||
const NewUnitName, NewUnitInFile: string; SourceChangeCache: TSourceChangeCache;
|
UsesSection: TUsesSection; const NewUnitName, NewUnitInFile: string;
|
||||||
AsLast: boolean; CheckSpecialUnits: boolean): boolean;
|
SourceChangeCache: TSourceChangeCache; const Flags: TAddUsesFlags): boolean;
|
||||||
var
|
var
|
||||||
UsesNode, OtherUsesNode, SectionNode, Node: TCodeTreeNode;
|
UsesNode, OtherUsesNode, SectionNode, Node: TCodeTreeNode;
|
||||||
NewUsesTerm: string;
|
NewUsesTerm: string;
|
||||||
@ -1001,7 +1002,7 @@ begin
|
|||||||
if not (FindUnitInUsesSection(UsesNode,NewUnitName,Junk,Junk))
|
if not (FindUnitInUsesSection(UsesNode,NewUnitName,Junk,Junk))
|
||||||
then begin
|
then begin
|
||||||
if not AddUnitToUsesSection(UsesNode,NewUnitName,NewUnitInFile,
|
if not AddUnitToUsesSection(UsesNode,NewUnitName,NewUnitInFile,
|
||||||
SourceChangeCache,AsLast,CheckSpecialUnits)
|
SourceChangeCache,Flags)
|
||||||
then
|
then
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
@ -12,7 +12,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, LazLoggerBase, fpcunit, testregistry,
|
Classes, SysUtils, LazLoggerBase, fpcunit, testregistry,
|
||||||
CodeToolManager, StdCodeTools, CodeCache, LinkScanner;
|
CodeToolManager, StdCodeTools, CodeCache, LinkScanner, SourceChanger;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -32,12 +32,19 @@ type
|
|||||||
private
|
private
|
||||||
procedure DoTestAddUnitWarn(Title: string; Src, Expected: array of string;
|
procedure DoTestAddUnitWarn(Title: string; Src, Expected: array of string;
|
||||||
WarnID, Comment: string; TurnOn: boolean);
|
WarnID, Comment: string; TurnOn: boolean);
|
||||||
|
procedure DoTestAddUnitToMainUses(NewUnitName, NewUnitInFilename,
|
||||||
|
UsesSrc, ExpectedUsesSrc: string; const Flags: TAddUsesFlags);
|
||||||
published
|
published
|
||||||
procedure TestCTStdFindBlockStart;
|
procedure TestCTStdFindBlockStart;
|
||||||
procedure TestCTRemoveUnitFromAllUsesSections;
|
procedure TestCTUses_AddUses_Start;
|
||||||
procedure TestCTAddUnitWarnProgram;
|
procedure TestCTUses_AddUses_Append;
|
||||||
procedure TestCTAddUnitWarnProgramNoName;
|
procedure TestCTUses_AddUses_AppendKeepSpaces;
|
||||||
procedure TestCTAddUnitWarnUnit;
|
procedure TestCTUses_AddUses_AppendKeepComment; // ToDo
|
||||||
|
procedure TestCTUses_AddUses_Append_DottedNoBreak;
|
||||||
|
procedure TestCTUses_RemoveFromAllUsesSections;
|
||||||
|
procedure TestCTAddWarn5025_Program;
|
||||||
|
procedure TestCTAddWarn5025_ProgramNoName;
|
||||||
|
procedure TestCTAddWarn5025_Unit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -222,6 +229,35 @@ begin
|
|||||||
CheckDiff(Title,s,Code.Source);
|
CheckDiff(Title,s,Code.Source);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestCTStdCodetools.DoTestAddUnitToMainUses(NewUnitName, NewUnitInFilename, UsesSrc, ExpectedUsesSrc: string;
|
||||||
|
const Flags: TAddUsesFlags);
|
||||||
|
var
|
||||||
|
Header: String;
|
||||||
|
Footer: String;
|
||||||
|
Code: TCodeBuffer;
|
||||||
|
Src: String;
|
||||||
|
begin
|
||||||
|
Header:='program TestStdCodeTools;'+LineEnding;
|
||||||
|
Footer:=LineEnding
|
||||||
|
+'begin'+LineEnding
|
||||||
|
+'end.'+LineEnding;
|
||||||
|
Code:=CodeToolBoss.CreateFile('TestStdCodeTools.pas');
|
||||||
|
Code.Source:=Header+UsesSrc+Footer;
|
||||||
|
if not CodeToolBoss.AddUnitToMainUsesSectionIfNeeded(Code,NewUnitName,NewUnitInFilename,Flags) then
|
||||||
|
begin
|
||||||
|
AssertEquals('AddUnitToMainUsesSectionIfNeeded failed: '+CodeToolBoss.ErrorMessage,true,false);
|
||||||
|
end else begin
|
||||||
|
Src:=Code.Source;
|
||||||
|
AssertEquals('AddUnitToMainUsesSectionIfNeeded altered header: ',Header,LeftStr(Src,length(Header)));
|
||||||
|
System.Delete(Src,1,length(Header));
|
||||||
|
AssertEquals('AddUnitToMainUsesSectionIfNeeded altered footer: ',Footer,RightStr(Src,length(Footer)));
|
||||||
|
System.Delete(Src,length(Src)-length(Footer)+1,length(Footer));
|
||||||
|
if ExpectedUsesSrc<>Src then
|
||||||
|
debugln(Code.Source);
|
||||||
|
AssertEquals('AddUnitToMainUsesSectionIfNeeded: ',ExpectedUsesSrc,Src);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTestCTStdCodetools.TestCTStdFindBlockStart;
|
procedure TTestCTStdCodetools.TestCTStdFindBlockStart;
|
||||||
var
|
var
|
||||||
Code: TCodeBuffer;
|
Code: TCodeBuffer;
|
||||||
@ -278,12 +314,69 @@ begin
|
|||||||
Test('begin,try,finally,|end,end','try1','try1finally');
|
Test('begin,try,finally,|end,end','try1','try1finally');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTestCTStdCodetools.TestCTRemoveUnitFromAllUsesSections;
|
procedure TTestCTStdCodetools.TestCTUses_AddUses_Start;
|
||||||
|
begin
|
||||||
|
DoTestAddUnitToMainUses('Foo','',
|
||||||
|
'',
|
||||||
|
LineEnding+'uses Foo;'+LineEnding,
|
||||||
|
[]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestCTStdCodetools.TestCTUses_AddUses_Append;
|
||||||
|
begin
|
||||||
|
DoTestAddUnitToMainUses('Foo','',
|
||||||
|
'uses Abc;'+LineEnding,
|
||||||
|
'uses Abc, Foo;'+LineEnding,
|
||||||
|
[]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestCTStdCodetools.TestCTUses_AddUses_AppendKeepSpaces;
|
||||||
|
begin
|
||||||
|
DoTestAddUnitToMainUses('Foo','',
|
||||||
|
'uses Go, Bla;'+LineEnding,
|
||||||
|
'uses Go, Bla, Foo;'+LineEnding,
|
||||||
|
[]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestCTStdCodetools.TestCTUses_AddUses_AppendKeepComment;
|
||||||
|
begin
|
||||||
|
exit;
|
||||||
|
|
||||||
|
DoTestAddUnitToMainUses('Foo','',
|
||||||
|
'uses Go, {Comment} Bla;'+LineEnding,
|
||||||
|
'uses Go, {Comment} Bla, Foo;'+LineEnding,
|
||||||
|
[]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestCTStdCodetools.TestCTUses_AddUses_Append_DottedNoBreak;
|
||||||
|
var
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
|
OldLineLength: Integer;
|
||||||
|
OldDoNotSplitLineInFront: TAtomTypes;
|
||||||
|
begin
|
||||||
|
Beauty:=CodeToolBoss.SourceChangeCache.BeautifyCodeOptions;
|
||||||
|
OldLineLength:=Beauty.LineLength;
|
||||||
|
OldDoNotSplitLineInFront:=Beauty.DoNotSplitLineInFront;
|
||||||
|
try
|
||||||
|
Beauty.LineLength:=35;
|
||||||
|
Beauty.DoNotSplitLineInFront:=Beauty.DoNotSplitLineInFront+[atPoint];// test that atPoint has no effect
|
||||||
|
DoTestAddUnitToMainUses('System.SysUtils','',
|
||||||
|
'uses System.Classes;'+LineEnding,
|
||||||
|
'uses System.Classes,'+LineEnding
|
||||||
|
+' System.SysUtils;'+LineEnding,
|
||||||
|
[]);
|
||||||
|
finally
|
||||||
|
Beauty.LineLength:=OldLineLength;
|
||||||
|
Beauty.DoNotSplitLineInFront:=OldDoNotSplitLineInFront;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestCTStdCodetools.TestCTUses_RemoveFromAllUsesSections;
|
||||||
|
|
||||||
function GetSource(UsesSrc: string): string;
|
function GetSource(UsesSrc: string): string;
|
||||||
begin
|
begin
|
||||||
Result:='program TestStdCodeTools;'+LineEnding
|
Result:='program TestStdCodeTools;'+LineEnding
|
||||||
+UsesSrc
|
+UsesSrc;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure Test(RemoveUnit, UsesSrc, ExpectedUsesSrc: string);
|
procedure Test(RemoveUnit, UsesSrc, ExpectedUsesSrc: string);
|
||||||
@ -293,7 +386,7 @@ procedure TTestCTStdCodetools.TestCTRemoveUnitFromAllUsesSections;
|
|||||||
Code: TCodeBuffer;
|
Code: TCodeBuffer;
|
||||||
Src: String;
|
Src: String;
|
||||||
begin
|
begin
|
||||||
Header:='program TestStdCodeTools;'+LineEnding;
|
Header:=GetSource('');
|
||||||
Footer:=LineEnding
|
Footer:=LineEnding
|
||||||
+'begin'+LineEnding
|
+'begin'+LineEnding
|
||||||
+'end.'+LineEnding;
|
+'end.'+LineEnding;
|
||||||
@ -369,7 +462,7 @@ begin
|
|||||||
);
|
);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTestCTStdCodetools.TestCTAddUnitWarnProgram;
|
procedure TTestCTStdCodetools.TestCTAddWarn5025_Program;
|
||||||
begin
|
begin
|
||||||
DoTestAddUnitWarn(
|
DoTestAddUnitWarn(
|
||||||
'TestCTAddUnitWarn',
|
'TestCTAddUnitWarn',
|
||||||
@ -382,7 +475,7 @@ begin
|
|||||||
,'end.'],'5025','',false);
|
,'end.'],'5025','',false);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTestCTStdCodetools.TestCTAddUnitWarnProgramNoName;
|
procedure TTestCTStdCodetools.TestCTAddWarn5025_ProgramNoName;
|
||||||
begin
|
begin
|
||||||
DoTestAddUnitWarn(
|
DoTestAddUnitWarn(
|
||||||
'TestCTAddUnitWarn',
|
'TestCTAddUnitWarn',
|
||||||
@ -393,7 +486,7 @@ begin
|
|||||||
,'end.'],'5025','',false);
|
,'end.'],'5025','',false);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTestCTStdCodetools.TestCTAddUnitWarnUnit;
|
procedure TTestCTStdCodetools.TestCTAddWarn5025_Unit;
|
||||||
begin
|
begin
|
||||||
DoTestAddUnitWarn(
|
DoTestAddUnitWarn(
|
||||||
'TestCTAddUnitWarn',
|
'TestCTAddUnitWarn',
|
||||||
|
@ -52,7 +52,7 @@ uses
|
|||||||
LCLProc, Forms, Controls, Dialogs,
|
LCLProc, Forms, Controls, Dialogs,
|
||||||
// CodeTools
|
// CodeTools
|
||||||
CodeToolsConfig, ExprEval, DefineTemplates, BasicCodeTools, CodeToolsCfgScript,
|
CodeToolsConfig, ExprEval, DefineTemplates, BasicCodeTools, CodeToolsCfgScript,
|
||||||
LinkScanner, CodeToolManager, CodeCache, CodeTree, FileProcs,
|
LinkScanner, CodeToolManager, CodeCache, CodeTree, FileProcs, StdCodeTools,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
FPCAdds, LazUtilities, FileUtil, LazFileUtils, LazFileCache, LazMethodList,
|
FPCAdds, LazUtilities, FileUtil, LazFileUtils, LazFileCache, LazMethodList,
|
||||||
LazLoggerBase, LazUTF8, Laz2_XMLCfg, Maps,
|
LazLoggerBase, LazUTF8, Laz2_XMLCfg, Maps,
|
||||||
@ -3622,7 +3622,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
s:=AnUnit.GetUsesUnitName;
|
s:=AnUnit.GetUsesUnitName;
|
||||||
if s<>'' then // add unit to uses section
|
if s<>'' then // add unit to uses section
|
||||||
CodeToolBoss.AddUnitToMainUsesSectionIfNeeded(MainUnitInfo.Source,s,'',true);
|
CodeToolBoss.AddUnitToMainUsesSectionIfNeeded(MainUnitInfo.Source,s,'',[aufLast]);
|
||||||
end;
|
end;
|
||||||
EndUpdate;
|
EndUpdate;
|
||||||
UnitModified(AnUnit);
|
UnitModified(AnUnit);
|
||||||
|
Loading…
Reference in New Issue
Block a user