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
// search in search path Result:=Pool.FindVirtualUnit(AUnitName);
Result:=FindUnitSourceInCleanSearchPath(AUnitName,SrcPath,AnyCase); end;
if Result='' then begin
// search in search path
SrcPath:=Strings[ctdcsCompleteSrcPath];
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.'
@ -775,9 +781,9 @@ begin
try try
if (ClassNode=nil) or (ClassNode.Desc<>ctnClass) or (AMethodName='') if (ClassNode=nil) or (ClassNode.Desc<>ctnClass) or (AMethodName='')
or (ATypeInfo=nil) or (SourceChangeCache=nil) or (Scanner=nil) then exit; or (ATypeInfo=nil) or (SourceChangeCache=nil) or (Scanner=nil) then exit;
{$IFDEF CTDEBUG} { $IFDEF CTDEBUG}
DebugLn(['[TEventsCodeTool.CreateMethod] A AMethodName="',AMethodName,'" in "',MainFilename,'" UseTypeInfoForParameters=',UseTypeInfoForParameters]); DebugLn(['[TEventsCodeTool.CreateMethod] A AMethodName="',AMethodName,'" in "',MainFilename,'" UseTypeInfoForParameters=',UseTypeInfoForParameters]);
{$ENDIF} { $ENDIF}
// initialize class for code completion // initialize class for code completion
CodeCompleteClassNode:=ClassNode; CodeCompleteClassNode:=ClassNode;
CodeCompleteSrcChgCache:=SourceChangeCache; CodeCompleteSrcChgCache:=SourceChangeCache;
@ -798,9 +804,9 @@ begin
[phpWithoutClassName, phpWithoutName, phpInUpperCase]); [phpWithoutClassName, phpWithoutName, phpInUpperCase]);
end; end;
if not ProcExistsInCodeCompleteClass(CleanMethodDefinition) then begin if not ProcExistsInCodeCompleteClass(CleanMethodDefinition) then begin
{$IFDEF CTDEBUG} { $IFDEF CTDEBUG}
DebugLn('[TEventsCodeTool.CreateMethod] insert method definition to class'); DebugLn('[TEventsCodeTool.CreateMethod] insert method definition to class');
{$ENDIF} { $ENDIF}
// insert method definition into class // insert method definition into class
InsertCall:=''; InsertCall:='';
if UseTypeInfoForParameters then begin if UseTypeInfoForParameters then begin
@ -829,9 +835,9 @@ begin
phpWithoutParamTypes])); phpWithoutParamTypes]));
end; end;
end; end;
{$IFDEF CTDEBUG} { $IFDEF CTDEBUG}
DebugLn('[TEventsCodeTool.CreateMethod] MethodDefinition="',MethodDefinition,'"'); DebugLn('[TEventsCodeTool.CreateMethod] MethodDefinition="',MethodDefinition,'"');
{$ENDIF} { $ENDIF}
if Section in [pcsPublished,pcsPublic] then if Section in [pcsPublished,pcsPublic] then
NewSection:=ncpPublishedProcs NewSection:=ncpPublishedProcs
else else
@ -856,9 +862,9 @@ begin
AddClassInsertion(CleanMethodDefinition, MethodDefinition, AMethodName, AddClassInsertion(CleanMethodDefinition, MethodDefinition, AMethodName,
NewSection,nil,ProcBody); NewSection,nil,ProcBody);
end; end;
{$IFDEF CTDEBUG} { $IFDEF CTDEBUG}
DebugLn('[TEventsCodeTool.CreateMethod] invoke class completion'); DebugLn('[TEventsCodeTool.CreateMethod] invoke class completion');
{$ENDIF} { $ENDIF}
if not InsertAllNewClassParts then if not InsertAllNewClassParts then
RaiseException(ctsErrorDuringInsertingNewClassParts); RaiseException(ctsErrorDuringInsertingNewClassParts);
if not CreateMissingProcBodies then if not CreateMissingProcBodies then
@ -869,9 +875,9 @@ begin
// apply the changes // apply the changes
if not SourceChangeCache.Apply then if not SourceChangeCache.Apply then
RaiseException(ctsUnableToApplyChanges); RaiseException(ctsUnableToApplyChanges);
{$IFDEF CTDEBUG} { $IFDEF CTDEBUG}
DebugLn('[TEventsCodeTool.CreateMethod] END'); DebugLn('[TEventsCodeTool.CreateMethod] END');
{$ENDIF} { $ENDIF}
Result:=true; Result:=true;
finally finally
FreeClassInsertionList; FreeClassInsertionList;

View File

@ -1603,24 +1603,26 @@ begin
NewContext:=CleanFindContext; NewContext:=CleanFindContext;
//DebugLn('TFindDeclarationTool.FindDeclarationOfPropertyPath PropertyPath="',PropertyPath,'"'); //DebugLn('TFindDeclarationTool.FindDeclarationOfPropertyPath PropertyPath="',PropertyPath,'"');
if PropertyPath='' then exit; if PropertyPath='' then exit;
BuildTree(false);
// first search the class/variable in the interface
StartPos:=1;
Identifier:=GetNextIdentifier;
if Identifier='' then exit;
Context.Tool:=Self;
Context.Node:=FindDeclarationNodeInInterface(Identifier,true);
if Context.Node=nil then begin
//DebugLn(['TFindDeclarationTool.FindDeclarationOfPropertyPath Identifier not found in interface ',Identifier]);
exit;
end;
Params:=TFindDeclarationParams.Create;
ActivateGlobalWriteLock; ActivateGlobalWriteLock;
Params:=TFindDeclarationParams.Create;
try try
BuildTree(false);
//DebugLn(['TFindDeclarationTool.FindDeclarationOfPropertyPath ',Src]);
// first search the class/variable in the interface
StartPos:=1;
Identifier:=GetNextIdentifier;
if Identifier='' then exit;
Context.Tool:=Self;
Context.Node:=FindDeclarationNodeInInterface(Identifier,true);
if Context.Node=nil then begin
DebugLn(['TFindDeclarationTool.FindDeclarationOfPropertyPath Identifier not found in interface ',Identifier]);
exit;
end;
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
@ -1988,9 +1990,10 @@ begin
begin begin
RaiseException('TFindDeclarationTool.FindUnitSource Invalid Data'); RaiseException('TFindDeclarationTool.FindUnitSource Invalid Data');
end; end;
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));