codetools: search in virtual directory first virtual units

git-svn-id: trunk@23652 -
This commit is contained in:
mattias 2010-02-06 01:23:13 +00:00
parent c5a6b22731
commit 0ca654e75d
3 changed files with 67 additions and 35 deletions

View File

@ -983,10 +983,15 @@ begin
end else begin end else begin
// not found in cache -> search in complete source path // not found in cache -> search in complete source path
SrcPath:=Strings[ctdcsCompleteSrcPath]; if Directory='' then begin
// virtual directory => search virtual unit
Result:=Pool.FindVirtualUnit(AUnitName);
end;
if Result='' then begin
// search in search path // search in search path
SrcPath:=Strings[ctdcsCompleteSrcPath];
Result:=FindUnitSourceInCleanSearchPath(AUnitName,SrcPath,AnyCase); Result:=FindUnitSourceInCleanSearchPath(AUnitName,SrcPath,AnyCase);
end;
if Result='' then begin if Result='' then begin
// search in unit links // search in unit links
{$IFDEF ShowTriedUnits} {$IFDEF ShowTriedUnits}
@ -1236,12 +1241,30 @@ end;
function TCTDirectoryCachePool.FindVirtualUnit(const AUnitName: string): string; function TCTDirectoryCachePool.FindVirtualUnit(const AUnitName: string): string;
var var
e: TCTPascalExtType; e: TCTPascalExtType;
CurUnitName:String;
begin begin
// search normal
for e:=Low(CTPascalExtension) to High(CTPascalExtension) do begin for e:=Low(CTPascalExtension) to High(CTPascalExtension) do begin
if CTPascalExtension[e]='' then continue; if CTPascalExtension[e]='' then continue;
Result:=FindVirtualFile(AUnitName+CTPascalExtension[e]); Result:=FindVirtualFile(AUnitName+CTPascalExtension[e]);
if Result<>'' then exit; if Result<>'' then exit;
end; end;
// search lowercase
CurUnitName:=lowercase(AUnitName);
if CurUnitName<>AUnitName then begin
for e:=Low(CTPascalExtension) to High(CTPascalExtension) do begin
if CTPascalExtension[e]='' then continue;
Result:=FindVirtualFile(CurUnitName+CTPascalExtension[e]);
if Result<>'' then exit;
end;
end;
// search uppercase
CurUnitName:=uppercase(AUnitName);
for e:=Low(CTPascalExtension) to High(CTPascalExtension) do begin
if CTPascalExtension[e]='' then continue;
Result:=FindVirtualFile(CurUnitName+uppercase(CTPascalExtension[e]));
if Result<>'' then exit;
end;
Result:=''; Result:='';
end; end;

View File

@ -734,21 +734,27 @@ function TEventsCodeTool.CreateMethod(ClassNode: TCodeTreeNode;
end; end;
function FindPropertyType(out FindContext: TFindContext): boolean; function FindPropertyType(out FindContext: TFindContext): boolean;
var
Tool: TFindDeclarationTool;
begin begin
Result:=false; Result:=false;
if APropertyPath<>'' then begin if APropertyPath<>'' then begin
// find unit of property // find unit of property
Tool:=nil;
FindContext:=CleanFindContext;
if APropertyUnitName='' then begin if APropertyUnitName='' then begin
FindContext.Tool:=Self; Tool:=Self;
end else begin end else begin
FindContext.Tool:=FindCodeToolForUsedUnit(APropertyUnitName,'',true); Tool:=FindCodeToolForUsedUnit(APropertyUnitName,'',true);
if FindContext.Tool=nil then if Tool=nil then
raise Exception.Create('failed to get codetool for unit '+APropertyUnitName); raise Exception.Create('failed to get codetool for unit '+APropertyUnitName);
end; end;
// find property with type // find property with type
if not FindContext.Tool.FindDeclarationOfPropertyPath( if not Tool.FindDeclarationOfPropertyPath(APropertyPath,FindContext,true)
APropertyPath,FindContext,true) then begin
then exit; DebugLn(['FindPropertyType FindDeclarationOfPropertyPath failed: ',Tool.MainFilename,' APropertyPath=',APropertyPath]);
exit;
end;
if FindContext.Node.Desc<>ctnProperty then if FindContext.Node.Desc<>ctnProperty then
FindContext.Tool.RaiseException( FindContext.Tool.RaiseException(
APropertyPath+' is not a property.' APropertyPath+' is not a property.'

View File

@ -1603,8 +1603,13 @@ begin
NewContext:=CleanFindContext; NewContext:=CleanFindContext;
//DebugLn('TFindDeclarationTool.FindDeclarationOfPropertyPath PropertyPath="',PropertyPath,'"'); //DebugLn('TFindDeclarationTool.FindDeclarationOfPropertyPath PropertyPath="',PropertyPath,'"');
if PropertyPath='' then exit; if PropertyPath='' then exit;
ActivateGlobalWriteLock;
Params:=TFindDeclarationParams.Create;
try
BuildTree(false); BuildTree(false);
//DebugLn(['TFindDeclarationTool.FindDeclarationOfPropertyPath ',Src]);
// first search the class/variable in the interface // first search the class/variable in the interface
StartPos:=1; StartPos:=1;
Identifier:=GetNextIdentifier; Identifier:=GetNextIdentifier;
@ -1612,15 +1617,12 @@ begin
Context.Tool:=Self; Context.Tool:=Self;
Context.Node:=FindDeclarationNodeInInterface(Identifier,true); Context.Node:=FindDeclarationNodeInInterface(Identifier,true);
if Context.Node=nil then begin if Context.Node=nil then begin
//DebugLn(['TFindDeclarationTool.FindDeclarationOfPropertyPath Identifier not found in interface ',Identifier]); DebugLn(['TFindDeclarationTool.FindDeclarationOfPropertyPath Identifier not found in interface ',Identifier]);
exit; exit;
end; end;
Params:=TFindDeclarationParams.Create;
ActivateGlobalWriteLock;
try
Context:=FindBaseTypeOfNode(Params,Context.Node); Context:=FindBaseTypeOfNode(Params,Context.Node);
if Context.Node=nil then begin if Context.Node=nil then begin
//DebugLn(['TFindDeclarationTool.FindDeclarationOfPropertyPath context not found']); DebugLn(['TFindDeclarationTool.FindDeclarationOfPropertyPath context not found']);
exit; exit;
end; end;
// then search the properties // then search the properties
@ -1991,6 +1993,7 @@ begin
NewUnitName:=AnUnitName; NewUnitName:=AnUnitName;
NewInFilename:=AnUnitInFilename; NewInFilename:=AnUnitInFilename;
AFilename:=DirectoryCache.FindUnitSourceInCompletePath( AFilename:=DirectoryCache.FindUnitSourceInCompletePath(
NewUnitName,NewInFilename,false); NewUnitName,NewInFilename,false);
Result:=TCodeBuffer(Scanner.OnLoadSource(Self,AFilename,true)); Result:=TCodeBuffer(Scanner.OnLoadSource(Self,AFilename,true));