mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-02 13:00:15 +01:00
codetools: find main declaration: find corresponding method parameter, bug #16398
git-svn-id: trunk@26223 -
This commit is contained in:
parent
5977b88aca
commit
234a5b2de1
@ -1421,7 +1421,14 @@ begin
|
||||
//DebugLn(['TFindDeclarationTool.FindDeclaration CleanPosIsDeclarationIdentifier']);
|
||||
NewTool:=Self;
|
||||
NewNode:=CursorNode;
|
||||
CleanCursorPos:=GetIdentStartPosition(Src,CleanCursorPos);
|
||||
if CursorNode.Desc=ctnVarDefinition then begin
|
||||
// if this is is a parmater, try to find the corresponding declaration
|
||||
NewNode:=FindCorrespondingProcParamNode(NewNode);
|
||||
if (NewNode=nil) or (NewNode.StartPos>CursorNode.StartPos) then
|
||||
NewNode:=CursorNode;
|
||||
end;
|
||||
CleanCursorPos:=GetIdentStartPosition(Src,NewNode.StartPos);
|
||||
|
||||
Result:=JumpToCleanPos(CleanCursorPos,CleanCursorPos,CleanCursorPos,
|
||||
NewPos,NewTopLine,false);
|
||||
exit;
|
||||
@ -4122,10 +4129,6 @@ var
|
||||
end;
|
||||
|
||||
function FindDeclarationNode: boolean;
|
||||
const
|
||||
JumpToProcAttr = [phpInUpperCase,phpWithoutClassName,phpWithVarModifiers];
|
||||
var
|
||||
ProcNode: TCodeTreeNode;
|
||||
begin
|
||||
Result:=false;
|
||||
|
||||
@ -4156,31 +4159,13 @@ var
|
||||
|
||||
ctnProcedure:
|
||||
AliasDeclarationNode:=DeclarationTool.FindCorrespondingProcNode(
|
||||
DeclarationNode,JumpToProcAttr);
|
||||
DeclarationNode);
|
||||
ctnProcedureHead:
|
||||
AliasDeclarationNode:=DeclarationTool.FindCorrespondingProcNode(
|
||||
DeclarationNode.Parent,JumpToProcAttr);
|
||||
DeclarationNode.Parent);
|
||||
ctnVarDefinition:
|
||||
if DeclarationNode.HasParentOfType(ctnProcedureHead) then begin
|
||||
// this is a parameter name
|
||||
ProcNode:=DeclarationNode.GetNodeOfType(ctnProcedure);
|
||||
// search alias for parameter
|
||||
ProcNode:=DeclarationTool.FindCorrespondingProcNode(ProcNode,JumpToProcAttr);
|
||||
if ProcNode<>nil then begin
|
||||
DeclarationTool.BuildSubTreeForProcHead(ProcNode);
|
||||
AliasDeclarationNode:=ProcNode;
|
||||
while (AliasDeclarationNode<>nil) do begin
|
||||
if AliasDeclarationNode.Desc
|
||||
in [ctnProcedure,ctnProcedureHead,ctnParameterList]
|
||||
then
|
||||
AliasDeclarationNode:=AliasDeclarationNode.FirstChild
|
||||
else begin
|
||||
if CompareIdentifiers(PChar(Pointer(Identifier)),
|
||||
@DeclarationTool.Src[AliasDeclarationNode.StartPos])=0 then break;
|
||||
AliasDeclarationNode:=AliasDeclarationNode.NextBrother;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
AliasDeclarationNode:=FindCorrespondingProcParamNode(DeclarationNode);
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
@ -96,7 +96,11 @@ type
|
||||
function FindProcNode(StartNode: TCodeTreeNode; const AProcHead: string;
|
||||
Attr: TProcHeadAttributes): TCodeTreeNode;
|
||||
function FindCorrespondingProcNode(ProcNode: TCodeTreeNode;
|
||||
Attr: TProcHeadAttributes): TCodeTreeNode;
|
||||
Attr: TProcHeadAttributes = [phpInUpperCase,phpWithoutClassName,phpWithVarModifiers]
|
||||
): TCodeTreeNode;
|
||||
function FindCorrespondingProcParamNode(ProcParamNode: TCodeTreeNode;
|
||||
Attr: TProcHeadAttributes = [phpInUpperCase,phpWithoutClassName,phpWithVarModifiers]
|
||||
): TCodeTreeNode;
|
||||
function FindProcBody(ProcNode: TCodeTreeNode): TCodeTreeNode;
|
||||
function ProcBodyIsEmpty(ProcNode: TCodeTreeNode): boolean;
|
||||
procedure MoveCursorToFirstProcSpecifier(ProcNode: TCodeTreeNode);
|
||||
@ -661,6 +665,41 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TPascalReaderTool.FindCorrespondingProcParamNode(
|
||||
ProcParamNode: TCodeTreeNode; Attr: TProcHeadAttributes): TCodeTreeNode;
|
||||
var
|
||||
ProcNode: TCodeTreeNode;
|
||||
begin
|
||||
Result:=nil;
|
||||
if ProcParamNode=nil then exit;
|
||||
if (ProcParamNode.Desc=ctnVarDefinition)
|
||||
and (ProcParamNode.Parent.Desc=ctnParameterList)
|
||||
and (ProcParamNode.Parent.Parent.Desc=ctnProcedureHead) then begin
|
||||
// this is a parameter name
|
||||
ProcNode:=ProcParamNode.GetNodeOfType(ctnProcedure);
|
||||
if ProcNode=nil then exit;
|
||||
// search alias for parameter
|
||||
ProcNode:=FindCorrespondingProcNode(ProcNode,Attr);
|
||||
if ProcNode=nil then exit;
|
||||
BuildSubTreeForProcHead(ProcNode);
|
||||
Result:=ProcNode;
|
||||
while (Result<>nil) do begin
|
||||
//debugln(['TPascalReaderTool.FindCorrespondingProcParamNode ',dbgstr(copy(Src,Result.StartPos,20))]);
|
||||
if Result.Desc
|
||||
in [ctnProcedure,ctnProcedureHead,ctnParameterList]
|
||||
then
|
||||
Result:=Result.FirstChild
|
||||
else begin
|
||||
if Result.StartPos<1 then break;
|
||||
if CompareIdentifiers(@Src[ProcParamNode.StartPos],@Src[Result.StartPos])=0
|
||||
then exit;
|
||||
Result:=Result.NextBrother;
|
||||
end;
|
||||
end;
|
||||
Result:=nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TPascalReaderTool.FindProcBody(ProcNode: TCodeTreeNode
|
||||
): TCodeTreeNode;
|
||||
begin
|
||||
|
||||
Loading…
Reference in New Issue
Block a user