diff --git a/components/codetools/examples/methodjumping.pas b/components/codetools/examples/methodjumping.pas index 03bb787fa5..f892a0d191 100644 --- a/components/codetools/examples/methodjumping.pas +++ b/components/codetools/examples/methodjumping.pas @@ -32,17 +32,17 @@ var NewCode: TCodeBuffer; NewX, NewY, NewTopLine: integer; RevertableJump: boolean; - Tool: TCustomCodeTool; + //Tool: TCustomCodeTool; begin ExpandedFilename:=ExpandFileName('tgeneric2.pp'); CodeBuf:=CodeToolBoss.LoadFile(ExpandedFilename,true,false); - if CodeToolBoss.JumpToMethod(CodeBuf,10,8,NewCode,NewX,NewY,NewTopLine, + if CodeToolBoss.JumpToMethod(CodeBuf,3,15,NewCode,NewX,NewY,NewTopLine, RevertableJump) then writeln(NewCode.Filename,' ',NewX,',',NewY,' TopLine=',NewTopLine,' RevertableJump=',RevertableJump) else writeln('Method body not found.'); - Tool:=CodeToolBoss.FindCodeToolForSource(CodeBuf); - Tool.WriteDebugTreeReport; + //Tool:=CodeToolBoss.FindCodeToolForSource(CodeBuf); + //Tool.WriteDebugTreeReport; end. diff --git a/components/codetools/methodjumptool.pas b/components/codetools/methodjumptool.pas index 0fc440f8c0..00362d4cd9 100644 --- a/components/codetools/methodjumptool.pas +++ b/components/codetools/methodjumptool.pas @@ -271,9 +271,10 @@ const ProcNode: TCodeTreeNode; begin Result:=false; + if SearchForProcNode=nil then exit; SearchedProcHead:=ExtractProcHead(SearchForProcNode,SearchForProcAttr); {$IFDEF CTDEBUG} - DebugLn('TMethodJumpingCodeTool.FindJumpPoint.FindBestProcNode Searching ',dbgs(ProcNode<>nil),' "',SearchedProcHead,'"'); + DebugLn('TMethodJumpingCodeTool.FindJumpPoint.FindBestProcNode Searching ',SearchForProcNode.DescAsString,' "',SearchedProcHead,'" ',ProcHeadAttributesToStr(SearchForProcAttr)); {$ENDIF} if SearchedProcHead='' then exit; ProcNode:=FindProcNode(StartNode,SearchedProcHead,SearchInProcAttr); @@ -353,10 +354,7 @@ begin DebugLn('TMethodJumpingCodeTool.FindJumpPoint E ',dbgs(CleanCursorPos),', |',copy(Src,CleanCursorPos,8)); {$ENDIF} BuildSubTreeForClass(ClassNode); - TypeSectionNode:=ClassNode.Parent; - if (TypeSectionNode<>nil) and (TypeSectionNode.Parent<>nil) - and (TypeSectionNode.Parent.Desc=ctnTypeSection) then - TypeSectionNode:=TypeSectionNode.Parent; + TypeSectionNode:=ClassNode.GetNodeOfType(ctnTypeSection); // search the method node under the cursor CursorNode:=FindDeepestNodeAtPos(CleanCursorPos,true). GetNodeOfType(ctnProcedure); diff --git a/components/codetools/pascalreadertool.pas b/components/codetools/pascalreadertool.pas index a015a4838c..bf1e551f2e 100644 --- a/components/codetools/pascalreadertool.pas +++ b/components/codetools/pascalreadertool.pas @@ -326,7 +326,7 @@ end; function TPascalReaderTool.ExtractProcHead(ProcNode: TCodeTreeNode; Attr: TProcHeadAttributes): string; var - GrandPaNode: TCodeTreeNode; + TypeDefNode: TCodeTreeNode; TheClassName, s: string; HasClassName, IsProcType: boolean; IsProcedure: Boolean; @@ -344,13 +344,17 @@ begin exit; IsProcType:=(ProcNode.Desc=ctnProcedureType); if (phpAddClassname in Attr) then begin - GrandPaNode:=ProcNode.Parent; - if GrandPaNode=nil then exit; - GrandPaNode:=GrandPaNode.Parent; - if (GrandPaNode=nil) or (GrandPaNode.Desc<>ctnClass) then exit; - GrandPaNode:=GrandPaNode.Parent; - if GrandPaNode.Desc<>ctnTypeDefinition then exit; - MoveCursorToCleanPos(GrandPaNode.StartPos); + TypeDefNode:=ProcNode.Parent; + if TypeDefNode=nil then exit; + TypeDefNode:=TypeDefNode.Parent; + if (TypeDefNode=nil) or (TypeDefNode.Desc<>ctnClass) then exit; + TypeDefNode:=TypeDefNode.Parent; + if TypeDefNode.Desc=ctnGenericType then begin + TypeDefNode:=TypeDefNode.Parent; + if TypeDefNode=nil then exit; + end; + if TypeDefNode.Desc<>ctnTypeDefinition then exit; + MoveCursorToCleanPos(TypeDefNode.StartPos); ReadNextAtom; if not AtomIsIdentifier(false) then exit; TheClassName:=GetAtom; @@ -365,7 +369,6 @@ begin ExtractNextAtom((phpWithStart in Attr) and not (phpWithoutClassKeyword in Attr),Attr); IsProcedure:=UpAtomIs('PROCEDURE'); - IsProcedure:=UpAtomIs('PROCEDURE'); IsFunction:=(not IsProcedure) and UpAtomIs('FUNCTION'); IsOperator:=(not IsProcedure) and (not IsFunction) and UpAtomIs('OPERATOR'); if IsProcedure or IsFunction or IsOperator @@ -1056,6 +1059,8 @@ begin if Result<>nil then exit; end else if ANode.Desc=ctnTypeDefinition then begin CurClassNode:=ANode.FirstChild; + if (CurClassNode<>nil) and (CurClassNode.Desc=ctnGenericType) then + CurClassNode:=CurClassNode.FirstChild; if (CurClassNode<>nil) and (CurClassNode.Desc=ctnClass) then begin if (not (IgnoreForwards and ((CurClassNode.SubDesc and ctnsForwardDeclaration)>0)))