From eae537252c235feb8cb63c049838f93f6715075a Mon Sep 17 00:00:00 2001 From: mattias Date: Wed, 11 Jan 2012 15:37:19 +0000 Subject: [PATCH] codetools: param completion: extend uses section git-svn-id: trunk@34711 - --- components/codetools/codecompletiontool.pas | 41 +++++++++++++++++--- components/codetools/finddeclarationtool.pas | 7 +++- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/components/codetools/codecompletiontool.pas b/components/codetools/codecompletiontool.pas index 7e9d01d611..db4495602f 100644 --- a/components/codetools/codecompletiontool.pas +++ b/components/codetools/codecompletiontool.pas @@ -37,7 +37,7 @@ - insert header comment for classes ToDo: - -add code for index properties (TList, TFPList, array of, Pointer array) + -add code for array properties (TList, TFPList, array of, Pointer array) TList: property Items[Index: integer]: AType; -> creates via dialog @@ -61,7 +61,6 @@ inherited Destroy; end; - -ProcExists: search procs in ancestors too -VarExists: search vars in ancestors too } unit CodeCompletionTool; @@ -1856,6 +1855,9 @@ var ProcStartPos: LongInt; ExprType: TExpressionType; Context: TFindContext; + HasAtOperator: Boolean; + TypeTool: TFindDeclarationTool; + AliasType: TFindContext; begin Result:=false; @@ -1876,6 +1878,15 @@ begin VarNameAtom,ProcNameAtom,ParameterIndex) then exit; + HasAtOperator:=false; + if (VarNameAtom.StartPos<=SrcLen) + and (Src[VarNameAtom.StartPos]='@') then begin + HasAtOperator:=true; + inc(VarNameAtom.StartPos); + // ToDo: resolve pointer: @p to a PFindContext create p:TFindContext + // ToDo: create event: @OnClick to a TNotifyEvent create a method + exit; + end; if not IsValidIdent(GetAtom(VarNameAtom)) then exit; {$IFDEF CTDEBUG} @@ -1914,6 +1925,7 @@ begin end; // find declaration of parameter list + // ToDo: search in all overloads for the best fit Params.ContextNode:=Context.Node; Params.SetIdentifier(Self,@Src[ProcNameAtom.StartPos],nil); Params.Flags:=fdfDefaultForExpressions+[fdfSearchInAncestors,fdfFindVariable]; @@ -1940,16 +1952,33 @@ begin end; if ParameterNode<>nil then begin //DebugLn('TCodeCompletionCodeTool.CompleteLocalVariableAsParameter ParameterNode=',ParameterNode.DescAsString,' ',copy(Params.NewCodeTool.Src,ParameterNode.StartPos,50)); + TypeTool:=Params.NewCodeTool; TypeNode:=FindTypeNodeOfDefinition(ParameterNode); if TypeNode=nil then begin DebugLn(' CompleteLocalVariableAsParameter Parameter has no type'); exit; end; - NewType:=Trim(copy(Params.NewCodeTool.Src,TypeNode.StartPos, - TypeNode.EndPos-TypeNode.StartPos)); + // default: copy the type + NewType:=TypeTool.ExtractCode(TypeNode.StartPos,TypeNode.EndPos,[]); - // ToDo: find unit of type declaration - MissingUnitName:=''; //GetUnitForUsesSection(Params.NewCodeTool); + // search type + Params.Clear; + Params.ContextNode:=TypeNode; + Params.Flags:=[fdfSearchInParentNodes,fdfSearchInAncestors, + fdfTopLvlResolving]; + AliasType:=CleanFindContext; + ExprType:=TypeTool.FindExpressionResultType(Params, + TypeNode.StartPos,TypeNode.EndPos,@AliasType); + //debugln(['TCodeCompletionCodeTool.CompleteLocalVariableByParameter AliasType=',FindContextToString(AliasType)]); + if AliasType.Node<>nil then begin + // an identifier + MissingUnitName:=GetUnitNameForUsesSection(AliasType.Tool); + //debugln(['TCodeCompletionCodeTool.CompleteLocalVariableByParameter MissingUnitName=',MissingUnitName]); + end; + + if HasAtOperator then begin + + end; DebugLn('TCodeCompletionCodeTool.CompleteLocalVariableAsParameter NewType=',NewType); if NewType='' then diff --git a/components/codetools/finddeclarationtool.pas b/components/codetools/finddeclarationtool.pas index 3130a546b6..601df11641 100644 --- a/components/codetools/finddeclarationtool.pas +++ b/components/codetools/finddeclarationtool.pas @@ -722,8 +722,6 @@ type function FindForwardIdentifier(Params: TFindDeclarationParams; var IsForward: boolean): boolean; function FindNonForwardClass(Params: TFindDeclarationParams): boolean; - function FindExpressionResultType(Params: TFindDeclarationParams; - StartPos, EndPos: integer; AliasType: PFindContext = nil): TExpressionType; function FindCodeToolForUsedUnit(const AnUnitName, AnUnitInFilename: string; ExceptionOnNotFound: boolean): TFindDeclarationTool; function FindUnitSourceWithUnitIdentifier(UsesNode: TCodeTreeNode; @@ -830,12 +828,16 @@ type NodeStack: PCodeTreeNodeStack = nil): TFindContext; function ConvertNodeToExpressionType(Node: TCodeTreeNode; Params: TFindDeclarationParams; AliasType: PFindContext = nil): TExpressionType; + function FindExpressionResultType(Params: TFindDeclarationParams; + StartPos, EndPos: integer; AliasType: PFindContext = nil): TExpressionType; function FindDeclarationAndOverload(const CursorPos: TCodeXYPosition; out ListOfPCodeXYPosition: TFPList; Flags: TFindDeclarationListFlags): boolean; function FindIdentifierContextsAtStatement(CleanPos: integer; out IsSubIdentifier: boolean; out ListOfPFindContext: TFPList): boolean; + + // ancestors function FindClassAndAncestors(ClassNode: TCodeTreeNode; out ListOfPFindContext: TFPList; ExceptionOnNotFound: boolean ): boolean; // without interfaces @@ -851,6 +853,7 @@ type var ListOfPFindContext: TFPList; Params: TFindDeclarationParams; FindClassContext: boolean; ExceptionOnNotFound: boolean = true): boolean; // with interfaces + function FindReferences(const CursorPos: TCodeXYPosition; SkipComments: boolean; out ListOfPCodeXYPosition: TFPList): boolean; function FindUnitReferences(UnitCode: TCodeBuffer;