mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-07 21:38:00 +02:00
codetools: added TFindDeclarationTool.FindClassMember
git-svn-id: branches/fixes_1_8@55239 -
This commit is contained in:
parent
2f00ddbe1f
commit
a0d5e25efe
@ -394,6 +394,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;
|
||||
@ -468,46 +470,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;
|
||||
|
||||
|
@ -539,7 +539,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;
|
||||
|
@ -949,11 +949,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+';';
|
||||
|
@ -910,6 +910,8 @@ type
|
||||
out NewPos: TCodeXYPosition; out NewTopLine: 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;
|
||||
@ -7357,6 +7359,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
|
||||
|
Loading…
Reference in New Issue
Block a user