codetools: test needed unit for defineproperties

git-svn-id: trunk@56213 -
This commit is contained in:
mattias 2017-10-26 17:49:46 +00:00
parent 87cee22c65
commit 085ac5259b
2 changed files with 32 additions and 6 deletions

View File

@ -2005,13 +2005,16 @@ begin
end; end;
Expected:=#7'Strings'#1#6#5'First'#6#6'Second'#0#0; Expected:=#7'Strings'#1#6#5'First'#6#6'Second'#0#0;
TestWriteDescendant('TestDefineProperites_ListOfStrings',ARoot,nil,[ TestWriteDescendant('TestDefineProperites_ListOfStrings',ARoot,nil,[
CSPDefaultExecCustomCSP+'(Lines,[#7''Strings''#1#6#5''First''#6#6''Second''#0#0]);', CSPDefaultExecCustomProc+'(Lines,[#7''Strings''#1#6#5''First''#6#6''Second''#0#0]);',
'']); '']);
Lines2:=TStringList.Create; Lines2:=TStringList.Create;
ExecCustomCSP(Lines2,[Expected]); ExecCustomCSP(Lines2,[Expected]);
AssertEquals('read TStrings.Text',ARoot.Lines.Text,Lines2.Text); AssertEquals('read TStrings.Text',ARoot.Lines.Text,Lines2.Text);
AssertEquals('NeededUnits.Count',1,Writer.NeededUnits.Count);
AssertEquals('NeededUnits[0]',Writer.ExecCustomProcUnit,Writer.NeededUnits[0]);
finally finally
Lines2.Free; Lines2.Free;
FreeAndNil(ARoot.FLines); FreeAndNil(ARoot.FLines);

View File

@ -53,7 +53,8 @@ const
CSPDefaultSignatureBegin = CSPDefaultSignature+' - Begin'; CSPDefaultSignatureBegin = CSPDefaultSignature+' - Begin';
CSPDefaultSignatureEnd = CSPDefaultSignature+' - End'; CSPDefaultSignatureEnd = CSPDefaultSignature+' - End';
CSPDefaultAccessClass = 'TPasStreamAccess'; CSPDefaultAccessClass = 'TPasStreamAccess';
CSPDefaultExecCustomCSP = 'ExecCustomCSP'; CSPDefaultExecCustomProc = 'ExecCustomCSP';
CSPDefaultExecCustomProcUnit = 'LazPasReadUtil';
CSPDefaultMaxColumn = 80; CSPDefaultMaxColumn = 80;
CWPSkipParentName = '-'; CWPSkipParentName = '-';
type type
@ -91,13 +92,15 @@ type
FCurIndent: integer; FCurIndent: integer;
FCurrentPos: Integer; FCurrentPos: Integer;
FDefaultDefineProperties: CodePointer; FDefaultDefineProperties: CodePointer;
FExecCustomData: string; FExecCustomProc: string;
FExecCustomProcUnit: string;
FIgnoreChildren: Boolean; FIgnoreChildren: Boolean;
FIndentStep: integer; FIndentStep: integer;
FLineEnding: string; FLineEnding: string;
FLookupRoot: TComponent; FLookupRoot: TComponent;
FMaxColumn: integer; FMaxColumn: integer;
FNeedAccessClass: boolean; FNeedAccessClass: boolean;
FNeededUnits: TStrings;
FOnDefineProperties: TCWPDefinePropertiesEvent; FOnDefineProperties: TCWPDefinePropertiesEvent;
FOnFindAncestor: TCWPFindAncestorEvent; FOnFindAncestor: TCWPFindAncestorEvent;
FOnGetMethodName: TCWPGetMethodName; FOnGetMethodName: TCWPGetMethodName;
@ -113,6 +116,7 @@ type
FStream: TStream; FStream: TStream;
procedure AddToAncestorList(Component: TComponent); procedure AddToAncestorList(Component: TComponent);
procedure DetermineAncestor(Component: TComponent); procedure DetermineAncestor(Component: TComponent);
procedure SetNeededUnits(const AValue: TStrings);
procedure SetRoot(const AValue: TComponent); procedure SetRoot(const AValue: TComponent);
procedure WriteComponentData(Instance: TComponent); procedure WriteComponentData(Instance: TComponent);
procedure WriteChildren(Component: TComponent; Step: TCWPChildrenStep); procedure WriteChildren(Component: TComponent; Step: TCWPChildrenStep);
@ -144,6 +148,7 @@ type
function GetEnumExpr(TypeInfo: PTypeInfo; Value: integer; function GetEnumExpr(TypeInfo: PTypeInfo; Value: integer;
AllowOutOfRange: boolean): string; AllowOutOfRange: boolean): string;
function CreatedByAncestor(Component: TComponent): boolean; function CreatedByAncestor(Component: TComponent): boolean;
procedure AddNeededUnit(const AnUnitName: string);
procedure Indent; procedure Indent;
procedure Unindent; procedure Unindent;
property Stream: TStream read FStream; property Stream: TStream read FStream;
@ -173,8 +178,10 @@ type
property AccessClass: string read FAccessClass property AccessClass: string read FAccessClass
write FAccessClass; // classname used to access protected TComponent members like SetChildOrder write FAccessClass; // classname used to access protected TComponent members like SetChildOrder
property NeedAccessClass: boolean read FNeedAccessClass write FNeedAccessClass; // some property needed AccessClass property NeedAccessClass: boolean read FNeedAccessClass write FNeedAccessClass; // some property needed AccessClass
property ExecCustomData: string read FExecCustomData write FExecCustomData; property ExecCustomProc: string read FExecCustomProc write FExecCustomProc;
property ExecCustomProcUnit: string read FExecCustomProcUnit write FExecCustomProcUnit;
property MaxColumn: integer read FMaxColumn write FMaxColumn default CSPDefaultMaxColumn; property MaxColumn: integer read FMaxColumn write FMaxColumn default CSPDefaultMaxColumn;
property NeededUnits: TStrings read FNeededUnits write SetNeededUnits;
end; end;
procedure WriteComponentToPasStream(AComponent: TComponent; AStream: TStream); procedure WriteComponentToPasStream(AComponent: TComponent; AStream: TStream);
@ -395,6 +402,12 @@ begin
end; end;
end; end;
procedure TCompWriterPas.SetNeededUnits(const AValue: TStrings);
begin
if FNeededUnits=AValue then Exit;
FNeededUnits.Assign(AValue);
end;
procedure TCompWriterPas.SetRoot(const AValue: TComponent); procedure TCompWriterPas.SetRoot(const AValue: TComponent);
begin begin
FRoot:=AValue; FRoot:=AValue;
@ -1040,8 +1053,9 @@ begin
begin begin
WriteIndent; WriteIndent;
s:=GetPath; s:=GetPath;
s:=ExecCustomData+'('+s+',['; s:=ExecCustomProc+'('+s+',[';
Write(s); Write(s);
AddNeededUnit(ExecCustomProcUnit);
Col:=CurIndent+length(s)+1; Col:=CurIndent+length(s)+1;
Indent; Indent;
NeedComma:=false; NeedComma:=false;
@ -1384,7 +1398,9 @@ begin
FAssignOp:=':='; FAssignOp:=':=';
FSignature:=CSPDefaultSignature; FSignature:=CSPDefaultSignature;
FMaxColumn:=CSPDefaultMaxColumn; FMaxColumn:=CSPDefaultMaxColumn;
FExecCustomData:=CSPDefaultExecCustomCSP; FExecCustomProc:=CSPDefaultExecCustomProc;
FExecCustomProcUnit:=CSPDefaultExecCustomProcUnit;
FNeededUnits:=TStringList.Create;
FAccessClass:=CSPDefaultAccessClass; FAccessClass:=CSPDefaultAccessClass;
C:=TAccessComp.Create(nil); C:=TAccessComp.Create(nil);
FDefaultDefineProperties:=TMethod(@C.DefineProperties).Code; FDefaultDefineProperties:=TMethod(@C.DefineProperties).Code;
@ -1393,6 +1409,7 @@ end;
destructor TCompWriterPas.Destroy; destructor TCompWriterPas.Destroy;
begin begin
FreeAndNil(FNeededUnits);
inherited Destroy; inherited Destroy;
end; end;
@ -1511,6 +1528,12 @@ begin
and SameText(Component.Name,TComponent(FAncestor).Name) and SameText(Component.Name,TComponent(FAncestor).Name)
end; end;
procedure TCompWriterPas.AddNeededUnit(const AnUnitName: string);
begin
if FNeededUnits.IndexOf(AnUnitName)>=0 then exit;
FNeededUnits.Add(AnUnitName);
end;
procedure TCompWriterPas.Indent; procedure TCompWriterPas.Indent;
begin begin
CurIndent:=CurIndent+IndentStep; CurIndent:=CurIndent+IndentStep;