mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-28 20:49:16 +02:00
codetools: class completion: adding the first method body using the options for procs
git-svn-id: trunk@28320 -
This commit is contained in:
parent
508c4988a6
commit
ab2f7d54a5
@ -6633,70 +6633,68 @@ var
|
||||
// -> insert at the end of the implementation section
|
||||
if ImplementationNode=nil then
|
||||
RaiseException(ctsImplementationNodeNotFound);
|
||||
Indent:=GetLineIndent(Src,ImplementationNode.StartPos);
|
||||
if (ImplementationNode.LastChild=nil)
|
||||
or (ImplementationNode.LastChild.Desc<>ctnBeginBlock) then
|
||||
if (ImplementationNode.FirstChild=nil)
|
||||
or (ImplementationNode.FirstChild.Desc=ctnBeginBlock) then begin
|
||||
Indent:=GetLineIndent(Src,ImplementationNode.StartPos);
|
||||
InsertPos:=ImplementationNode.EndPos
|
||||
else begin
|
||||
InsertPos:=FindLineEndOrCodeInFrontOfPosition(
|
||||
ImplementationNode.LastChild.StartPos);
|
||||
end;
|
||||
StartSearchProc:=ImplementationNode.FirstChild;
|
||||
end else begin
|
||||
// class is not in interface section
|
||||
StartSearchProc:=CodeCompleteClassNode;
|
||||
while StartSearchProc.Desc<>ctnTypeSection do
|
||||
StartSearchProc:=StartSearchProc.Parent;
|
||||
case ASourceChangeCache.BeautifyCodeOptions.ForwardProcBodyInsertPolicy of
|
||||
fpipInFrontOfMethods:
|
||||
begin
|
||||
// Try to insert new proc in front of existing methods
|
||||
|
||||
// find first method
|
||||
NearestProcNode:=StartSearchProc;
|
||||
while (NearestProcNode<>nil) and (not NodeIsMethodBody(NearestProcNode)) do
|
||||
NearestProcNode:=NearestProcNode.NextBrother;
|
||||
if NearestProcNode<>nil then begin
|
||||
// the comments in front of the first method probably belong to the class
|
||||
// Therefore insert behind the node in front of the first method
|
||||
Indent:=GetLineIndent(Src,NearestProcNode.StartPos);
|
||||
if NearestProcNode.PriorBrother<>nil then begin
|
||||
InsertPos:=FindLineEndOrCodeAfterPosition(NearestProcNode.PriorBrother.EndPos);
|
||||
end else begin
|
||||
InsertPos:=NearestProcNode.Parent.StartPos;
|
||||
while (InsertPos<=NearestProcNode.StartPos)
|
||||
and (not IsSpaceChar[Src[InsertPos]]) do
|
||||
inc(InsertPos);
|
||||
end;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
fpipBehindMethods:
|
||||
begin
|
||||
// Try to insert new proc behind existing methods
|
||||
|
||||
// find last method (go to last brother and search backwards)
|
||||
NearestProcNode:=StartSearchProc.Parent.LastChild;
|
||||
while (NearestProcNode<>nil) and (not NodeIsMethodBody(NearestProcNode)) do
|
||||
NearestProcNode:=NearestProcNode.PriorBrother;
|
||||
if NearestProcNode<>nil then begin
|
||||
SetIndentAndInsertPos(NearestProcNode,true);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
// Default position: Insert behind last node
|
||||
NearestProcNode:=StartSearchProc.Parent.LastChild;
|
||||
if NearestProcNode<>nil then begin
|
||||
Indent:=0;
|
||||
InsertPos:=FindLineEndOrCodeAfterPosition(NearestProcNode.EndPos);
|
||||
SetIndentAndInsertPos(NearestProcNode,true);
|
||||
exit;
|
||||
end;
|
||||
|
||||
RaiseException('TCodeCompletionCodeTool.CreateMissingProcBodies.FindInsertPointForNewClass '
|
||||
+' Internal Error: no insert position found');
|
||||
end;
|
||||
case ASourceChangeCache.BeautifyCodeOptions.ForwardProcBodyInsertPolicy of
|
||||
fpipInFrontOfMethods:
|
||||
begin
|
||||
// Try to insert new proc in front of existing methods
|
||||
|
||||
// find first method
|
||||
NearestProcNode:=StartSearchProc;
|
||||
while (NearestProcNode<>nil) and (not NodeIsMethodBody(NearestProcNode)) do
|
||||
NearestProcNode:=NearestProcNode.NextBrother;
|
||||
if NearestProcNode<>nil then begin
|
||||
// the comments in front of the first method probably belong to the class
|
||||
// Therefore insert behind the node in front of the first method
|
||||
Indent:=GetLineIndent(Src,NearestProcNode.StartPos);
|
||||
if NearestProcNode.PriorBrother<>nil then begin
|
||||
InsertPos:=FindLineEndOrCodeAfterPosition(NearestProcNode.PriorBrother.EndPos);
|
||||
end else begin
|
||||
InsertPos:=NearestProcNode.Parent.StartPos;
|
||||
while (InsertPos<=NearestProcNode.StartPos)
|
||||
and (not IsSpaceChar[Src[InsertPos]]) do
|
||||
inc(InsertPos);
|
||||
end;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
fpipBehindMethods:
|
||||
begin
|
||||
// Try to insert new proc behind existing methods
|
||||
|
||||
// find last method (go to last brother and search backwards)
|
||||
NearestProcNode:=StartSearchProc.Parent.LastChild;
|
||||
while (NearestProcNode<>nil) and (not NodeIsMethodBody(NearestProcNode)) do
|
||||
NearestProcNode:=NearestProcNode.PriorBrother;
|
||||
if NearestProcNode<>nil then begin
|
||||
SetIndentAndInsertPos(NearestProcNode,true);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
// Default position: Insert behind last node
|
||||
NearestProcNode:=StartSearchProc.Parent.LastChild;
|
||||
if NearestProcNode<>nil then begin
|
||||
Indent:=0;
|
||||
InsertPos:=FindLineEndOrCodeAfterPosition(NearestProcNode.EndPos);
|
||||
SetIndentAndInsertPos(NearestProcNode,true);
|
||||
exit;
|
||||
end;
|
||||
|
||||
RaiseException('TCodeCompletionCodeTool.CreateMissingProcBodies.FindInsertPointForNewClass '
|
||||
+' Internal Error: no insert position found');
|
||||
end;
|
||||
|
||||
procedure InsertClassMethodsComment(InsertPos, Indent: integer);
|
||||
|
Loading…
Reference in New Issue
Block a user