mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-22 02:39:23 +02:00
codetools: find protected members in class helpers, bug #28810, patch from Ondrej
git-svn-id: trunk@50115 -
This commit is contained in:
parent
ea4449e888
commit
3b84c9a585
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -1012,6 +1012,7 @@ components/codetools/tests/fpctests/tchlp52.pp svneol=native#text/plain
|
|||||||
components/codetools/tests/fpctests/tchlp53.pp svneol=native#text/plain
|
components/codetools/tests/fpctests/tchlp53.pp svneol=native#text/plain
|
||||||
components/codetools/tests/fpctests/tchlp6.pp svneol=native#text/plain
|
components/codetools/tests/fpctests/tchlp6.pp svneol=native#text/plain
|
||||||
components/codetools/tests/fpctests/tchlp7.pp svneol=native#text/plain
|
components/codetools/tests/fpctests/tchlp7.pp svneol=native#text/plain
|
||||||
|
components/codetools/tests/fpctests/uchlp12.pp svneol=native#text/plain
|
||||||
components/codetools/tests/laztests/README.txt svneol=native#text/plain
|
components/codetools/tests/laztests/README.txt svneol=native#text/plain
|
||||||
components/codetools/tests/laztests/bug28861_unit1.pas svneol=native#text/plain
|
components/codetools/tests/laztests/bug28861_unit1.pas svneol=native#text/plain
|
||||||
components/codetools/tests/laztests/bug28861_unit2.pas svneol=native#text/plain
|
components/codetools/tests/laztests/bug28861_unit2.pas svneol=native#text/plain
|
||||||
|
@ -893,9 +893,9 @@ type
|
|||||||
|
|
||||||
// ancestors
|
// ancestors
|
||||||
function FindClassAndAncestors(ClassNode: TCodeTreeNode;
|
function FindClassAndAncestors(ClassNode: TCodeTreeNode;
|
||||||
out ListOfPFindContext: TFPList; ExceptionOnNotFound: boolean
|
var ListOfPFindContext: TFPList; ExceptionOnNotFound: boolean
|
||||||
): boolean; // without interfaces, recursive
|
): boolean; // without interfaces, recursive
|
||||||
function FindContextClassAndAncestors(const CursorPos: TCodeXYPosition;
|
function FindContextClassAndAncestorsAndExtendedClassOfHelper(const CursorPos: TCodeXYPosition;
|
||||||
var ListOfPFindContext: TFPList): boolean; // without interfaces
|
var ListOfPFindContext: TFPList): boolean; // without interfaces
|
||||||
function FindAncestorOfClass(ClassNode: TCodeTreeNode;
|
function FindAncestorOfClass(ClassNode: TCodeTreeNode;
|
||||||
Params: TFindDeclarationParams; FindClassContext: boolean): boolean; // returns false for TObject, IInterface, IUnknown
|
Params: TFindDeclarationParams; FindClassContext: boolean): boolean; // returns false for TObject, IInterface, IUnknown
|
||||||
@ -4950,7 +4950,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TFindDeclarationTool.FindClassAndAncestors(ClassNode: TCodeTreeNode;
|
function TFindDeclarationTool.FindClassAndAncestors(ClassNode: TCodeTreeNode;
|
||||||
out ListOfPFindContext: TFPList; ExceptionOnNotFound: boolean): boolean;
|
var ListOfPFindContext: TFPList; ExceptionOnNotFound: boolean): boolean;
|
||||||
var
|
var
|
||||||
Params: TFindDeclarationParams;
|
Params: TFindDeclarationParams;
|
||||||
|
|
||||||
@ -4979,7 +4979,6 @@ var
|
|||||||
begin
|
begin
|
||||||
{$IFDEF CheckNodeTool}CheckNodeTool(ClassNode);{$ENDIF}
|
{$IFDEF CheckNodeTool}CheckNodeTool(ClassNode);{$ENDIF}
|
||||||
Result:=false;
|
Result:=false;
|
||||||
ListOfPFindContext:=nil;
|
|
||||||
if (ClassNode=nil) or (not (ClassNode.Desc in AllClasses))
|
if (ClassNode=nil) or (not (ClassNode.Desc in AllClasses))
|
||||||
or (ClassNode.Parent=nil)
|
or (ClassNode.Parent=nil)
|
||||||
or (not (ClassNode.Parent.Desc in [ctnTypeDefinition,ctnGenericType])) then
|
or (not (ClassNode.Parent.Desc in [ctnTypeDefinition,ctnGenericType])) then
|
||||||
@ -5076,14 +5075,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TFindDeclarationTool.FindContextClassAndAncestors(
|
function TFindDeclarationTool.FindContextClassAndAncestorsAndExtendedClassOfHelper
|
||||||
const CursorPos: TCodeXYPosition; var ListOfPFindContext: TFPList
|
(const CursorPos: TCodeXYPosition; var ListOfPFindContext: TFPList): boolean;
|
||||||
): boolean;
|
|
||||||
// returns a list of nodes of AllClasses (ctnClass, ...)
|
// returns a list of nodes of AllClasses (ctnClass, ...)
|
||||||
var
|
var
|
||||||
CleanCursorPos: integer;
|
CleanCursorPos: integer;
|
||||||
ANode: TCodeTreeNode;
|
ANode: TCodeTreeNode;
|
||||||
ClassNode: TCodeTreeNode;
|
ClassNode: TCodeTreeNode;
|
||||||
|
ExtendedClassExpr: TExpressionType;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
ListOfPFindContext:=nil;
|
ListOfPFindContext:=nil;
|
||||||
@ -5107,6 +5106,15 @@ begin
|
|||||||
if not FindClassAndAncestors(ClassNode,ListOfPFindContext,true)
|
if not FindClassAndAncestors(ClassNode,ListOfPFindContext,true)
|
||||||
then exit;
|
then exit;
|
||||||
|
|
||||||
|
//find extended class node
|
||||||
|
ExtendedClassExpr := FindExtendedExprOfHelper(ClassNode);
|
||||||
|
if ((ExtendedClassExpr.Desc=xtContext) and (ExtendedClassExpr.Context.Tool<>nil) and
|
||||||
|
(ExtendedClassExpr.Context.Node<>nil) and (ExtendedClassExpr.Context.Node.Desc=ctnClass)) then
|
||||||
|
begin
|
||||||
|
if not ExtendedClassExpr.Context.Tool.FindClassAndAncestors(ExtendedClassExpr.Context.Node,ListOfPFindContext,true)
|
||||||
|
then exit;
|
||||||
|
end;
|
||||||
|
|
||||||
//debugln('TFindDeclarationTool.FindContextClassAndAncestors List: ',ListOfPFindContextToStr(ListOfPFindContext));
|
//debugln('TFindDeclarationTool.FindContextClassAndAncestors List: ',ListOfPFindContextToStr(ListOfPFindContext));
|
||||||
|
|
||||||
finally
|
finally
|
||||||
|
@ -355,7 +355,7 @@ type
|
|||||||
FBeautifier: TBeautifyCodeOptions;
|
FBeautifier: TBeautifyCodeOptions;
|
||||||
FLastGatheredIdentParent: TCodeTreeNode;
|
FLastGatheredIdentParent: TCodeTreeNode;
|
||||||
FLastGatheredIdentLevel: integer;
|
FLastGatheredIdentLevel: integer;
|
||||||
FICTClassAndAncestors: TFPList;// list of PCodeXYPosition
|
FICTClassAndAncestorsAndExtClassOfHelper: TFPList;// list of PCodeXYPosition
|
||||||
FIDCTFoundPublicProperties: TAVLTree;// tree of PChar (pointing to the
|
FIDCTFoundPublicProperties: TAVLTree;// tree of PChar (pointing to the
|
||||||
// property names in source)
|
// property names in source)
|
||||||
FIDTFoundMethods: TAVLTree;// tree of TCodeTreeNodeExtension Txt=clean text
|
FIDTFoundMethods: TAVLTree;// tree of TCodeTreeNodeExtension Txt=clean text
|
||||||
@ -1009,7 +1009,7 @@ var
|
|||||||
FoundClassContext: TFindContext;
|
FoundClassContext: TFindContext;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if FICTClassAndAncestors<>nil then begin
|
if (FICTClassAndAncestorsAndExtClassOfHelper<>nil) then begin
|
||||||
// start of the identifier completion is in a method or class
|
// start of the identifier completion is in a method or class
|
||||||
// => all protected ancestor classes are allowed as well.
|
// => all protected ancestor classes are allowed as well.
|
||||||
CurClassNode:=FoundContext.Node;
|
CurClassNode:=FoundContext.Node;
|
||||||
@ -1018,8 +1018,8 @@ var
|
|||||||
CurClassNode:=CurClassNode.Parent;
|
CurClassNode:=CurClassNode.Parent;
|
||||||
if CurClassNode=nil then exit;
|
if CurClassNode=nil then exit;
|
||||||
FoundClassContext:=CreateFindContext(Params.NewCodeTool,CurClassNode);
|
FoundClassContext:=CreateFindContext(Params.NewCodeTool,CurClassNode);
|
||||||
if IndexOfFindContext(FICTClassAndAncestors,@FoundClassContext)>=0 then begin
|
if IndexOfFindContext(FICTClassAndAncestorsAndExtClassOfHelper,@FoundClassContext)>=0 then begin
|
||||||
// this class node is the class or one of the ancestors of the class
|
// this class node is the class or one of the ancestors of the class or extended class of the helper+ancestors
|
||||||
// of the start context of the identifier completion
|
// of the start context of the identifier completion
|
||||||
exit(true);
|
exit(true);
|
||||||
end;
|
end;
|
||||||
@ -2576,7 +2576,9 @@ begin
|
|||||||
GatherContext := ExprType.Context;
|
GatherContext := ExprType.Context;
|
||||||
// find class and ancestors if existing (needed for protected identifiers)
|
// find class and ancestors if existing (needed for protected identifiers)
|
||||||
if GatherContext.Tool = Self then
|
if GatherContext.Tool = Self then
|
||||||
FindContextClassAndAncestors(IdentStartXY, FICTClassAndAncestors);
|
begin
|
||||||
|
FindContextClassAndAncestorsAndExtendedClassOfHelper(IdentStartXY, FICTClassAndAncestorsAndExtClassOfHelper);
|
||||||
|
end;
|
||||||
|
|
||||||
CursorContext:=CreateFindContext(Self,CursorNode);
|
CursorContext:=CreateFindContext(Self,CursorNode);
|
||||||
GatherContextKeywords(CursorContext,IdentStartPos,Beautifier);
|
GatherContextKeywords(CursorContext,IdentStartPos,Beautifier);
|
||||||
@ -2756,7 +2758,7 @@ begin
|
|||||||
|
|
||||||
Result:=true;
|
Result:=true;
|
||||||
finally
|
finally
|
||||||
FreeListOfPFindContext(FICTClassAndAncestors);
|
FreeListOfPFindContext(FICTClassAndAncestorsAndExtClassOfHelper);
|
||||||
FreeAndNil(FIDCTFoundPublicProperties);
|
FreeAndNil(FIDCTFoundPublicProperties);
|
||||||
Params.Free;
|
Params.Free;
|
||||||
ClearIgnoreErrorAfter;
|
ClearIgnoreErrorAfter;
|
||||||
@ -2959,7 +2961,7 @@ begin
|
|||||||
if IdentEndPos=0 then ;
|
if IdentEndPos=0 then ;
|
||||||
|
|
||||||
// find class and ancestors if existing (needed for protected identifiers)
|
// find class and ancestors if existing (needed for protected identifiers)
|
||||||
FindContextClassAndAncestors(CursorPos,FICTClassAndAncestors);
|
FindContextClassAndAncestorsAndExtendedClassOfHelper(CursorPos,FICTClassAndAncestorsAndExtClassOfHelper);
|
||||||
|
|
||||||
if CursorNode<>nil then begin
|
if CursorNode<>nil then begin
|
||||||
if not CheckContextIsParameter(Result) then begin
|
if not CheckContextIsParameter(Result) then begin
|
||||||
@ -2981,7 +2983,7 @@ begin
|
|||||||
end else begin
|
end else begin
|
||||||
FreeAndNil(CurrentIdentifierContexts);
|
FreeAndNil(CurrentIdentifierContexts);
|
||||||
end;
|
end;
|
||||||
FreeListOfPFindContext(FICTClassAndAncestors);
|
FreeListOfPFindContext(FICTClassAndAncestorsAndExtClassOfHelper);
|
||||||
FreeAndNil(FIDCTFoundPublicProperties);
|
FreeAndNil(FIDCTFoundPublicProperties);
|
||||||
Params.Free;
|
Params.Free;
|
||||||
ClearIgnoreErrorAfter;
|
ClearIgnoreErrorAfter;
|
||||||
@ -3324,9 +3326,9 @@ var
|
|||||||
m: PtrUint;
|
m: PtrUint;
|
||||||
begin
|
begin
|
||||||
inherited CalcMemSize(Stats);
|
inherited CalcMemSize(Stats);
|
||||||
if FICTClassAndAncestors<>nil then
|
if FICTClassAndAncestorsAndExtClassOfHelper<>nil then
|
||||||
Stats.Add('TIdentCompletionTool.ClassAndAncestors',
|
Stats.Add('TIdentCompletionTool.ClassAndAncestorsAndExtClassOfHelper',
|
||||||
FICTClassAndAncestors.Count*(SizeOf(TAVLTreeNode)+SizeOf(TCodeXYPosition)));
|
FICTClassAndAncestorsAndExtClassOfHelper.Count*(SizeOf(TAVLTreeNode)+SizeOf(TCodeXYPosition)));
|
||||||
if FIDCTFoundPublicProperties<>nil then
|
if FIDCTFoundPublicProperties<>nil then
|
||||||
Stats.Add('TIdentCompletionTool.FoundPublicProperties',
|
Stats.Add('TIdentCompletionTool.FoundPublicProperties',
|
||||||
FIDCTFoundPublicProperties.Count*SizeOf(TAVLTreeNode));
|
FIDCTFoundPublicProperties.Count*SizeOf(TAVLTreeNode));
|
||||||
|
@ -18,7 +18,7 @@ type
|
|||||||
|
|
||||||
function TTestHelper.AccessTest: Integer;
|
function TTestHelper.AccessTest: Integer;
|
||||||
begin
|
begin
|
||||||
Result := Test3;
|
Result := Test3{declaration:uchlp12.TTest.test3};
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -18,7 +18,7 @@ type
|
|||||||
|
|
||||||
function TTestHelper.AccessTest: Integer;
|
function TTestHelper.AccessTest: Integer;
|
||||||
begin
|
begin
|
||||||
Result := Test4;
|
Result := Test4{declaration:uchlp12.TTest.test4};
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
36
components/codetools/tests/fpctests/uchlp12.pp
Normal file
36
components/codetools/tests/fpctests/uchlp12.pp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
unit uchlp12;
|
||||||
|
|
||||||
|
{$ifdef fpc}
|
||||||
|
{$mode delphi}
|
||||||
|
{$endif}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
type
|
||||||
|
{$M+}
|
||||||
|
TTest = class
|
||||||
|
private
|
||||||
|
function GetTest6: Integer;
|
||||||
|
strict private
|
||||||
|
Test1: Integer;
|
||||||
|
private
|
||||||
|
Test2: Integer;
|
||||||
|
strict protected
|
||||||
|
Test3: Integer;
|
||||||
|
protected
|
||||||
|
Test4: Integer;
|
||||||
|
public
|
||||||
|
Test5: Integer;
|
||||||
|
published
|
||||||
|
property Test6: Integer read GetTest6;
|
||||||
|
end;
|
||||||
|
{$M-}
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
function TTest.GetTest6: Integer;
|
||||||
|
begin
|
||||||
|
Result := 0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
Loading…
Reference in New Issue
Block a user