From fb13a79dee48721355691edf5ecb7cb6edfc1ed1 Mon Sep 17 00:00:00 2001 From: mattias Date: Thu, 19 Jan 2012 16:11:45 +0000 Subject: [PATCH] codetools: identifier completion: method specifiers git-svn-id: trunk@34796 - --- components/codetools/identcompletiontool.pas | 45 +++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/components/codetools/identcompletiontool.pas b/components/codetools/identcompletiontool.pas index bfc4c51b78..a97ebefb65 100644 --- a/components/codetools/identcompletiontool.pas +++ b/components/codetools/identcompletiontool.pas @@ -353,7 +353,8 @@ type const Context: TFindContext; BeautifyCodeOptions: TBeautifyCodeOptions); procedure GatherUnitnames; procedure GatherSourceNames(const Context: TFindContext); - procedure GatherContextKeywords(const Context: TFindContext; CleanPos: integer); + procedure GatherContextKeywords(const Context: TFindContext; + CleanPos: integer; BeautifyCodeOptions: TBeautifyCodeOptions); procedure InitCollectIdentifiers(const CursorPos: TCodeXYPosition; var IdentifierList: TIdentifierList); procedure ParseSourceTillCollectionStart(const CursorPos: TCodeXYPosition; @@ -1422,18 +1423,20 @@ begin end; end; -procedure TIdentCompletionTool.GatherContextKeywords(const Context: TFindContext; - CleanPos: integer); +procedure TIdentCompletionTool.GatherContextKeywords( + const Context: TFindContext; CleanPos: integer; + BeautifyCodeOptions: TBeautifyCodeOptions); type TPropertySpecifier = ( psIndex,psRead,psWrite,psStored,psImplements,psDefault,psNoDefault ); TPropertySpecifiers = set of TPropertySpecifier; - procedure Add(const Keyword: string); + procedure Add(Keyword: string); var NewItem: TIdentifierListItem; begin + KeyWord:=BeautifyCodeOptions.BeautifyKeyWord(Keyword); NewItem:=TIdentifierListItem.Create( icompExact,false,0, CurrentIdentifierList.CreateIdentifier(Keyword), @@ -1503,12 +1506,31 @@ type until (CleanPosSrcLen); end; + procedure AddMethodSpecifiers; + var + i: Integer; + begin + for i:=0 to IsKeyWordMethodSpecifier.Count-1 do + Add(IsKeyWordMethodSpecifier.GetItem(i).KeyWord+';'); + end; + var Node: TCodeTreeNode; SubNode: TCodeTreeNode; + NodeInFront: TCodeTreeNode; + p: Integer; begin Node:=Context.Node; //debugln(['TIdentCompletionTool.GatherContextKeywords ',Node.DescAsString]); + NodeInFront:=Node; + repeat + NodeInFront:=NodeInFront.FirstChild; + while (NodeInFront<>nil) and (NodeInFront.EndPos<=CleanPos) + and (NodeInFront.NextBrother<>nil) + and (NodeInFront.NextBrother.StartPos<=CleanPos) do + NodeInFront:=NodeInFront.NextBrother; + until (NodeInFront=nil) or (NodeInFront.FirstChild=nil); + //debugln(['TIdentCompletionTool.GatherContextKeywords ',Node.DescAsString,' ',NodeInFront.DescAsString]); case Node.Desc of ctnClass,ctnObject,ctnRecordType,ctnObjCCategory,ctnObjCClass, @@ -1537,6 +1559,10 @@ begin CheckProperty(SubNode); end; end; + if NodeInFront<>nil then begin + if NodeInFront.Desc=ctnProcedure then + AddMethodSpecifiers; + end; end; ctnClassInterface,ctnDispinterface,ctnObjCProtocol,ctnCPPClass: @@ -1572,6 +1598,15 @@ begin Add('function'); end; + ctnProcedureHead: + begin + MoveCursorBehindProcName(Node); + p:=CurPos.StartPos; + while (p>=1) and (Src[p] in [' ',#9]) do dec(p); + if CleanPos>=p then + AddMethodSpecifiers; + end; + ctnVarDefinition: if Node.Parent.Desc in [ctnClass,ctnObject,ctnRecordType,ctnObjCCategory,ctnObjCClass] +AllClassBaseSections @@ -2141,7 +2176,7 @@ begin FindContextClassAndAncestors(IdentStartXY, FICTClassAndAncestors); CursorContext:=CreateFindContext(Self,CursorNode); - GatherContextKeywords(CursorContext,IdentStartPos); + GatherContextKeywords(CursorContext,IdentStartPos,BeautifyCodeOptions); // search and gather identifiers in context if (GatherContext.Tool<>nil) and (GatherContext.Node<>nil) then begin