codetools: test for finding specialize identifier in list of ancestors

git-svn-id: trunk@50339 -
This commit is contained in:
mattias 2015-11-16 20:46:28 +00:00
parent 5b690a20f0
commit a8546cf427
7 changed files with 58 additions and 4 deletions

1
.gitattributes vendored
View File

@ -988,6 +988,7 @@ components/codetools/sourcelog.pas svneol=native#text/pascal
components/codetools/stdcodetools.pas svneol=native#text/pascal components/codetools/stdcodetools.pas svneol=native#text/pascal
components/codetools/tests/fdt_basic.pas svneol=native#text/plain components/codetools/tests/fdt_basic.pas svneol=native#text/plain
components/codetools/tests/fdt_classhelper.pas svneol=native#text/plain components/codetools/tests/fdt_classhelper.pas svneol=native#text/plain
components/codetools/tests/fdt_generics.pas svneol=native#text/plain
components/codetools/tests/fdt_nestedclasses.pas svneol=native#text/plain components/codetools/tests/fdt_nestedclasses.pas svneol=native#text/plain
components/codetools/tests/fdt_objccategory.pas svneol=native#text/plain components/codetools/tests/fdt_objccategory.pas svneol=native#text/plain
components/codetools/tests/fdt_objcclass.pas svneol=native#text/plain components/codetools/tests/fdt_objcclass.pas svneol=native#text/plain

View File

@ -0,0 +1,34 @@
{
./testcodetools --format=plain --suite=TestFindDeclaration_Generics
}
unit fdt_generics;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
type
generic TGenBaseAction<T> = class
BaseName: T{declaration:fdt_generics.TGenBaseAction.T};
end;
generic TGenCustomAction<T> = class(specialize TGenBaseAction{declaration:fdt_generics.TGenBaseAction}<T>)
CustomName: T;
end;
generic TGenAction<T> = class(specialize TGenCustomAction{declaration:fdt_generics.TGenCustomAction}<T>)
ActionName: T;
end;
implementation
procedure DoSomething;
begin
end;
end.

View File

@ -1,3 +1,6 @@
{
./testcodetools --format=plain --suite=TestFindDeclaration_NestedClasses
}
unit fdt_nestedclasses; unit fdt_nestedclasses;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}

View File

@ -1,5 +1,5 @@
{ {
./finddeclarationtest --format=plain --suite=TestFindDeclaration_TypeHelper ./testcodetools --format=plain --suite=TestFindDeclaration_TypeHelper
} }
unit fdt_typehelper; unit fdt_typehelper;

View File

@ -8,6 +8,7 @@
./testcodetools --format=plain --suite=TestFindDeclaration_TypeHelper ./testcodetools --format=plain --suite=TestFindDeclaration_TypeHelper
./testcodetools --format=plain --suite=TestFindDeclaration_ObjCClass ./testcodetools --format=plain --suite=TestFindDeclaration_ObjCClass
./testcodetools --format=plain --suite=TestFindDeclaration_ObjCCategory ./testcodetools --format=plain --suite=TestFindDeclaration_ObjCCategory
./testcodetools --format=plain --suite=TestFindDeclaration_Generics
FPC tests: FPC tests:
./testcodetools --format=plain --suite=TestFindDeclaration_FPCTests ./testcodetools --format=plain --suite=TestFindDeclaration_FPCTests
@ -48,6 +49,7 @@ type
procedure TestFindDeclaration_TypeHelper; procedure TestFindDeclaration_TypeHelper;
procedure TestFindDeclaration_ObjCClass; procedure TestFindDeclaration_ObjCClass;
procedure TestFindDeclaration_ObjCCategory; procedure TestFindDeclaration_ObjCCategory;
procedure TestFindDeclaration_Generics;
procedure TestFindDeclaration_FPCTests; procedure TestFindDeclaration_FPCTests;
procedure TestFindDeclaration_LazTests; procedure TestFindDeclaration_LazTests;
end; end;
@ -73,17 +75,22 @@ procedure TTestFindDeclaration.FindDeclarations(Filename: string);
Result:=''; Result:='';
while Node<>nil do begin while Node<>nil do begin
case Node.Desc of case Node.Desc of
ctnTypeDefinition,ctnVarDefinition,ctnConstDefinition: ctnTypeDefinition,ctnVarDefinition,ctnConstDefinition,ctnGenericName,ctnGenericParameter:
PrependPath(GetIdentifier(@Tool.Src[Node.StartPos]),Result); PrependPath(GetIdentifier(@Tool.Src[Node.StartPos]),Result);
ctnGenericParams:
if Node.Parent.FirstChild.Desc=ctnGenericName then
PrependPath(GetIdentifier(@Tool.Src[Node.Parent.FirstChild.StartPos]),Result);
ctnInterface,ctnUnit: ctnInterface,ctnUnit:
PrependPath(Tool.GetSourceName(false),Result); PrependPath(Tool.GetSourceName(false),Result);
ctnProcedure: ctnProcedure:
PrependPath(Tool.ExtractProcName(Node,[]),Result); PrependPath(Tool.ExtractProcName(Node,[]),Result);
ctnProperty: ctnProperty:
PrependPath(Tool.ExtractPropName(Node,false),Result); PrependPath(Tool.ExtractPropName(Node,false),Result);
//else debugln(['NodeAsPath ',Node.DescAsString]);
end; end;
Node:=Node.Parent; Node:=Node.Parent;
end; end;
debugln(['NodeAsPath ',Result]);
end; end;
var var
@ -292,6 +299,11 @@ begin
FindDeclarations('fdt_objccategory.pas'); FindDeclarations('fdt_objccategory.pas');
end; end;
procedure TTestFindDeclaration.TestFindDeclaration_Generics;
begin
FindDeclarations('fdt_generics.pas');
end;
procedure TTestFindDeclaration.TestFindDeclaration_FPCTests; procedure TTestFindDeclaration.TestFindDeclaration_FPCTests;
begin begin
TestFiles('fpctests'); TestFiles('fpctests');

View File

@ -40,7 +40,7 @@
<PackageName Value="fpcunitconsolerunner"/> <PackageName Value="fpcunitconsolerunner"/>
</Item2> </Item2>
</RequiredPackages> </RequiredPackages>
<Units Count="11"> <Units Count="12">
<Unit0> <Unit0>
<Filename Value="testcodetools.lpr"/> <Filename Value="testcodetools.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
@ -87,6 +87,10 @@
<Filename Value="rt_explodewith.pas"/> <Filename Value="rt_explodewith.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
</Unit10> </Unit10>
<Unit11>
<Filename Value="fdt_generics.pas"/>
<IsPartOfProject Value="True"/>
</Unit11>
</Units> </Units>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>

View File

@ -30,7 +30,7 @@ uses
{$IFDEF Darwin} {$IFDEF Darwin}
fdt_objccategory, fdt_objcclass, fdt_objccategory, fdt_objcclass,
{$ENDIF} {$ENDIF}
fdt_basic, fdt_with, rt_explodewith; fdt_basic, fdt_with, rt_explodewith, fdt_generics;
const const
ConfigFilename = 'codetools.config'; ConfigFilename = 'codetools.config';