diff --git a/components/codetools/codecompletiontool.pas b/components/codetools/codecompletiontool.pas index 869adf3db6..1d863aa391 100644 --- a/components/codetools/codecompletiontool.pas +++ b/components/codetools/codecompletiontool.pas @@ -401,6 +401,8 @@ type function ApplyClassCompletion(AddMissingProcBodies: boolean): boolean; function ProcExistsInCodeCompleteClass( const NameAndParamsUpCase: string; SearchInAncestors: boolean = true): boolean; + function FindProcInCodeCompleteClass(const NameAndParamsUpCase: string; + SearchInAncestors: boolean = true): TFindContext; function VarExistsInCodeCompleteClass(const UpperName: string): boolean; procedure AddClassInsertion( const CleanDef, Def, IdentifierName: string; @@ -475,46 +477,65 @@ end; function TCodeCompletionCodeTool.ProcExistsInCodeCompleteClass( const NameAndParamsUpCase: string; SearchInAncestors: boolean): boolean; +begin + Result:=FindProcInCodeCompleteClass(NameAndParamsUpCase,SearchInAncestors).Node<>nil; +end; + +function TCodeCompletionCodeTool.FindProcInCodeCompleteClass( + const NameAndParamsUpCase: string; SearchInAncestors: boolean): TFindContext; // NameAndParams should be uppercase and contains the proc name and the // parameter list without names and default values // and should not contain any comments and no result type var ANodeExt: TCodeTreeNodeExtension; Params: TFindDeclarationParams; - ClassNode, CompletingChildNode: TCodeTreeNode; + ClassNode, StartNode: TCodeTreeNode; Tool: TFindDeclarationTool; Vis: TClassSectionVisibility; begin - Result:=false; + Result:=CleanFindContext; // search in new nodes, which will be inserted ANodeExt:=FirstInsert; while ANodeExt<>nil do begin if CompareTextIgnoringSpace(ANodeExt.Txt,NameAndParamsUpCase,true)=0 then - exit(true); + begin + Result.Tool:=Self; + Result.Node:=CodeCompleteClassNode; + exit; + end; ANodeExt:=ANodeExt.Next; end; // search in current class - Result:=(FindProcNode(FCompletingFirstEntryNode,NameAndParamsUpCase,mgMethod,[phpInUpperCase])<>nil); - if (not Result) and SearchInAncestors then - begin - //search in ancestor classes - Params:=TFindDeclarationParams.Create; - try - ClassNode:=CodeCompleteClassNode; - Tool:=Self; - while not Result and Tool.FindAncestorOfClass(ClassNode,Params,True) do begin - Tool:=Params.NewCodeTool; - ClassNode:=Params.NewNode; - CompletingChildNode:=GetFirstClassIdentifier(ClassNode); - if Tool=Self then - Vis := csvPrivateAndHigher - else - Vis := csvProtectedAndHigher; - Result := (Tool.FindProcNode(CompletingChildNode,NameAndParamsUpCase,mgMethod,[phpInUpperCase], Vis)<>nil); + Result.Node:=FindProcNode(FCompletingFirstEntryNode,NameAndParamsUpCase,mgMethod, + [phpInUpperCase]); + if Result.Node<>nil then begin + Result.Tool:=Self; + exit; + end; + if not SearchInAncestors then exit; + //search in ancestor classes + Params:=TFindDeclarationParams.Create; + try + ClassNode:=CodeCompleteClassNode; + Tool:=Self; + while Tool.FindAncestorOfClass(ClassNode,Params,True) do + begin + Tool:=Params.NewCodeTool; + ClassNode:=Params.NewNode; + StartNode:=GetFirstClassIdentifier(ClassNode); + if Tool=Self then + Vis := csvPrivateAndHigher + else + Vis := csvProtectedAndHigher; + Result.Node := Tool.FindProcNode(StartNode,NameAndParamsUpCase, + mgMethod,[phpInUpperCase], Vis); + if Result.Node<>nil then begin + Result.Tool:=Tool; + exit; end; - finally - Params.Free; end; + finally + Params.Free; end; end; diff --git a/components/codetools/codetoolmanager.pas b/components/codetools/codetoolmanager.pas index 7980f4129a..09f4f50cd7 100644 --- a/components/codetools/codetoolmanager.pas +++ b/components/codetools/codetoolmanager.pas @@ -545,7 +545,6 @@ type TreeOfPCodeXYPosition: TAVLTree // positions in this unit are processed and removed from the tree ): boolean; - // resourcestring sections function GatherResourceStringSections( Code: TCodeBuffer; X,Y: integer; diff --git a/components/codetools/eventcodetool.pas b/components/codetools/eventcodetool.pas index 8de2a406f1..c6235c5243 100644 --- a/components/codetools/eventcodetool.pas +++ b/components/codetools/eventcodetool.pas @@ -961,11 +961,12 @@ begin +FindContext.Tool.ExtractProcHead(FindContext.Node, [phpWithoutClassName, phpWithoutName, phpInUpperCase]); end; - if not ProcExistsInCodeCompleteClass(CleanMethodDefinition,not AddOverride) then begin + if not ProcExistsInCodeCompleteClass(CleanMethodDefinition,not AddOverride) + then begin + // insert method definition into class {$IFDEF VerboseMethodPropEdit} DebugLn('[TEventsCodeTool.CreateMethod] insert method definition to class'); {$ENDIF} - // insert method definition into class InsertCall:=''; if CompareTextIgnoringSpace(CallAncestorMethod,'inherited',false)=0 then InsertCall:=CallAncestorMethod+';'; diff --git a/components/codetools/finddeclarationtool.pas b/components/codetools/finddeclarationtool.pas index 09c2da0894..f69578f90b 100644 --- a/components/codetools/finddeclarationtool.pas +++ b/components/codetools/finddeclarationtool.pas @@ -920,6 +920,8 @@ type out NewPos: TCodeXYPosition; out NewTopLine, BlockTopLine, BlockBottomLine: integer): boolean; function FindDeclarationWithMainUsesSection(const Identifier: string; out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean; + function FindClassMember(aClassNode: TCodeTreeNode; + const Identifier: String; SearchInAncestors: boolean): TFindContext; function FindDeclarationOfPropertyPath(const PropertyPath: string; out NewContext: TFindContext; IgnoreTypeLess: boolean = false): boolean; function FindDeclarationOfPropertyPath(const PropertyPath: string; @@ -7445,6 +7447,32 @@ begin end; end; +function TFindDeclarationTool.FindClassMember(aClassNode: TCodeTreeNode; + const Identifier: String; SearchInAncestors: boolean): TFindContext; +var + Params: TFindDeclarationParams; +begin + Result.Tool:=Self; + Result.Node:=FindClassMember(aClassNode,PChar(Identifier)); + if Result.Node<>nil then exit; + if not SearchInAncestors then begin + Result:=CleanFindContext; + exit; + end; + Params:=TFindDeclarationParams.Create; + try + while Result.Tool.FindAncestorOfClass(aClassNode,Params,True) do begin + Result.Tool:=Params.NewCodeTool; + aClassNode:=Params.NewNode; + Result.Node:=Result.Tool.FindClassMember(aClassNode,PChar(Identifier)); + if Result.Node<>nil then exit; + end; + Result:=CleanFindContext; + finally + Params.Free; + end; +end; + function TFindDeclarationTool.FindAncestorOfClass(ClassNode: TCodeTreeNode; Params: TFindDeclarationParams; FindClassContext: boolean): boolean; var