codetools: code completion: use GetLineIndent of beautifier

git-svn-id: trunk@40821 -
This commit is contained in:
mattias 2013-04-15 10:07:23 +00:00
parent f1b6abfac5
commit f47d8f4577
2 changed files with 60 additions and 56 deletions

View File

@ -651,10 +651,12 @@ end;
procedure TCodeCompletionCodeTool.FindInsertPositionForForwardProc( procedure TCodeCompletionCodeTool.FindInsertPositionForForwardProc(
SourceChangeCache: TSourceChangeCache; ProcNode: TCodeTreeNode; var Indent, SourceChangeCache: TSourceChangeCache; ProcNode: TCodeTreeNode; var Indent,
InsertPos: integer); InsertPos: integer);
var
Beauty: TBeautifyCodeOptions;
procedure SetIndentAndInsertPos(Node: TCodeTreeNode; Behind: boolean); procedure SetIndentAndInsertPos(Node: TCodeTreeNode; Behind: boolean);
begin begin
Indent:=GetLineIndent(Src,Node.StartPos); Indent:=Beauty.GetLineIndent(Src,Node.StartPos);
if Behind then if Behind then
InsertPos:=FindLineEndOrCodeAfterPosition(Node.EndPos) InsertPos:=FindLineEndOrCodeAfterPosition(Node.EndPos)
else else
@ -674,8 +676,8 @@ var
ProcPosBehind: Integer; ProcPosBehind: Integer;
EmptyLinesInFront: Integer; EmptyLinesInFront: Integer;
EmptyLinesBehind: Integer; EmptyLinesBehind: Integer;
Beauty: TBeautifyCodeOptions;
begin begin
Beauty:=SourceChangeCache.BeautifyCodeOptions;
IsInInterface:=ProcNode.HasParentOfType(ctnInterface); IsInInterface:=ProcNode.HasParentOfType(ctnInterface);
if IsInInterface then begin if IsInInterface then begin
// forward proc in interface // forward proc in interface
@ -688,7 +690,7 @@ begin
end else begin end else begin
// implementation is empty // implementation is empty
// -> add it as first body // -> add it as first body
Indent:=GetLineIndent(Src,StartSearchProc.StartPos); Indent:=Beauty.GetLineIndent(Src,StartSearchProc.StartPos);
InsertPos:=StartSearchProc.StartPos+length('implementation'); InsertPos:=StartSearchProc.StartPos+length('implementation');
exit; exit;
end; end;
@ -704,7 +706,6 @@ begin
end; end;
end; end;
Beauty:=SourceChangeCache.BeautifyCodeOptions;
//debugln(['TCodeCompletionCodeTool.FindInsertPositionForForwardProc ',ord(Beauty.ForwardProcBodyInsertPolicy)]); //debugln(['TCodeCompletionCodeTool.FindInsertPositionForForwardProc ',ord(Beauty.ForwardProcBodyInsertPolicy)]);
if Beauty.KeepForwardProcOrder then begin if Beauty.KeepForwardProcOrder then begin
// KeepForwardProcOrder: gather all procs and try to insert the new body // KeepForwardProcOrder: gather all procs and try to insert the new body
@ -819,7 +820,7 @@ begin
if NearestProcNode.PriorBrother<>nil then if NearestProcNode.PriorBrother<>nil then
SetIndentAndInsertPos(NearestProcNode.PriorBrother,true) SetIndentAndInsertPos(NearestProcNode.PriorBrother,true)
else begin else begin
Indent:=GetLineIndent(Src,NearestProcNode.StartPos); Indent:=Beauty.GetLineIndent(Src,NearestProcNode.StartPos);
InsertPos:=NearestProcNode.Parent.StartPos; InsertPos:=NearestProcNode.Parent.StartPos;
while (InsertPos<=NearestProcNode.StartPos) while (InsertPos<=NearestProcNode.StartPos)
and (not IsSpaceChar[Src[InsertPos]]) do and (not IsSpaceChar[Src[InsertPos]]) do
@ -860,13 +861,15 @@ procedure TCodeCompletionCodeTool.FindInsertPositionForProcInterface(
var Indent, InsertPos: integer; SourceChangeCache: TSourceChangeCache); var Indent, InsertPos: integer; SourceChangeCache: TSourceChangeCache);
var var
InsertNode: TCodeTreeNode; InsertNode: TCodeTreeNode;
Beauty: TBeautifyCodeOptions;
begin begin
Beauty:=SourceChangeCache.BeautifyCodeOptions;
InsertNode:=FindInterfaceNode; InsertNode:=FindInterfaceNode;
if InsertNode<>nil then begin if InsertNode<>nil then begin
// there is an interface // there is an interface
// -> append at end of interface // -> append at end of interface
InsertPos:=FindLineEndOrCodeInFrontOfPosition(InsertNode.EndPos,true); InsertPos:=FindLineEndOrCodeInFrontOfPosition(InsertNode.EndPos,true);
Indent:=GetLineIndent(Src,InsertNode.EndPos); Indent:=Beauty.GetLineIndent(Src,InsertNode.EndPos);
end; end;
if InsertPos<1 then begin if InsertPos<1 then begin
// there is no interface // there is no interface
@ -876,13 +879,13 @@ begin
InsertNode:=InsertNode.NextBrother; InsertNode:=InsertNode.NextBrother;
if InsertNode<>nil then begin if InsertNode<>nil then begin
InsertPos:=FindLineEndOrCodeInFrontOfPosition(InsertNode.StartPos,true); InsertPos:=FindLineEndOrCodeInFrontOfPosition(InsertNode.StartPos,true);
Indent:=GetLineIndent(Src,InsertPos); Indent:=Beauty.GetLineIndent(Src,InsertPos);
end; end;
end; end;
if InsertPos<1 then begin if InsertPos<1 then begin
InsertNode:=FindFirstSectionChild; InsertNode:=FindFirstSectionChild;
if InsertNode<>nil then begin if InsertNode<>nil then begin
Indent:=GetLineIndent(Src,InsertNode.StartPos); Indent:=Beauty.GetLineIndent(Src,InsertNode.StartPos);
if InsertNode.Desc=ctnUsesSection then if InsertNode.Desc=ctnUsesSection then
// insert behind uses section // insert behind uses section
InsertPos:=FindLineEndOrCodeAfterPosition(InsertNode.EndPos) InsertPos:=FindLineEndOrCodeAfterPosition(InsertNode.EndPos)
@ -893,7 +896,7 @@ begin
// insert in interface or somewhere at start // insert in interface or somewhere at start
InsertNode:=Tree.Root; InsertNode:=Tree.Root;
InsertPos:=FindLineEndOrCodeInFrontOfPosition(InsertNode.EndPos,true); InsertPos:=FindLineEndOrCodeInFrontOfPosition(InsertNode.EndPos,true);
Indent:=GetLineIndent(Src,InsertNode.EndPos); Indent:=Beauty.GetLineIndent(Src,InsertNode.EndPos);
end; end;
end; end;
end; end;
@ -1065,12 +1068,12 @@ begin
//debugln(['TCodeCompletionCodeTool.AddLocalVariable insert into existing var section']); //debugln(['TCodeCompletionCodeTool.AddLocalVariable insert into existing var section']);
VarNode:=VarSectionNode.LastChild; VarNode:=VarSectionNode.LastChild;
if VarNode<>nil then begin if VarNode<>nil then begin
Indent:=GetLineIndent(Src,VarNode.StartPos); Indent:=Beauty.GetLineIndent(Src,VarNode.StartPos);
if PositionsInSameLine(Src,VarSectionNode.StartPos,VarNode.StartPos) then if PositionsInSameLine(Src,VarSectionNode.StartPos,VarNode.StartPos) then
inc(Indent,Beauty.Indent); inc(Indent,Beauty.Indent);
InsertPos:=FindLineEndOrCodeAfterPosition(VarNode.EndPos); InsertPos:=FindLineEndOrCodeAfterPosition(VarNode.EndPos);
end else begin end else begin
Indent:=GetLineIndent(Src,VarSectionNode.StartPos); Indent:=Beauty.GetLineIndent(Src,VarSectionNode.StartPos);
MoveCursorToNodeStart(VarSectionNode); MoveCursorToNodeStart(VarSectionNode);
ReadNextAtom; ReadNextAtom;
InsertPos:=CurPos.EndPos; InsertPos:=CurPos.EndPos;
@ -1083,7 +1086,7 @@ begin
// => put the var section below // => put the var section below
//debugln(['TCodeCompletionCodeTool.AddLocalVariable start a new var section below '+OtherSectionNode.DescAsString]); //debugln(['TCodeCompletionCodeTool.AddLocalVariable start a new var section below '+OtherSectionNode.DescAsString]);
InsertPos:=OtherSectionNode.EndPos; InsertPos:=OtherSectionNode.EndPos;
Indent:=GetLineIndent(Src,OtherSectionNode.StartPos); Indent:=Beauty.GetLineIndent(Src,OtherSectionNode.StartPos);
end else begin end else begin
// there is no var/type/const section in front // there is no var/type/const section in front
if (ParentNode.Desc=ctnProcedure) and (HeaderNode=nil) then if (ParentNode.Desc=ctnProcedure) and (HeaderNode=nil) then
@ -1097,19 +1100,19 @@ begin
// add the var section directly in front of the begin // add the var section directly in front of the begin
//debugln(['TCodeCompletionCodeTool.AddLocalVariable start a new var section in front of begin block']); //debugln(['TCodeCompletionCodeTool.AddLocalVariable start a new var section in front of begin block']);
InsertPos:=CursorNode.StartPos; InsertPos:=CursorNode.StartPos;
Indent:=GetLineIndent(Src,InsertPos); Indent:=Beauty.GetLineIndent(Src,InsertPos);
end else if HeaderNode<>nil then begin end else if HeaderNode<>nil then begin
// put the var section below the header // put the var section below the header
//debugln(['TCodeCompletionCodeTool.AddLocalVariable start a new var section below '+HeaderNode.DescAsString]); //debugln(['TCodeCompletionCodeTool.AddLocalVariable start a new var section below '+HeaderNode.DescAsString]);
InsertPos:=HeaderNode.EndPos; InsertPos:=HeaderNode.EndPos;
Indent:=GetLineIndent(Src,InsertPos); Indent:=Beauty.GetLineIndent(Src,InsertPos);
end else begin end else begin
// insert behind section keyword // insert behind section keyword
//debugln(['TCodeCompletionCodeTool.AddLocalVariable start a new var section at start of '+ParentNode.DescAsString]); //debugln(['TCodeCompletionCodeTool.AddLocalVariable start a new var section at start of '+ParentNode.DescAsString]);
MoveCursorToNodeStart(ParentNode); MoveCursorToNodeStart(ParentNode);
ReadNextAtom; ReadNextAtom;
InsertPos:=CurPos.EndPos; InsertPos:=CurPos.EndPos;
Indent:=GetLineIndent(Src,InsertPos); Indent:=Beauty.GetLineIndent(Src,InsertPos);
end; end;
end; end;
InsertTxt:='var'+Beauty.LineEnd InsertTxt:='var'+Beauty.LineEnd
@ -1243,6 +1246,7 @@ var
NewProc: String; NewProc: String;
Beauty: TBeautifyCodeOptions; Beauty: TBeautifyCodeOptions;
begin begin
Beauty:=SourceChangeCache.BeautifyCodeOptions;
// find a nice insert position in front of methods and CursorNode // find a nice insert position in front of methods and CursorNode
StartNode:=FindImplementationNode; StartNode:=FindImplementationNode;
if (StartNode=nil) and (Tree.Root.Desc<>ctnUnit) then if (StartNode=nil) and (Tree.Root.Desc<>ctnUnit) then
@ -1262,13 +1266,13 @@ begin
end; end;
if InFrontOfNode<>nil then begin if InFrontOfNode<>nil then begin
// insert in front // insert in front
Indent:=GetLineIndent(Src,InFrontOfNode.StartPos); Indent:=Beauty.GetLineIndent(Src,InFrontOfNode.StartPos);
InsertPos:=FindLineEndOrCodeInFrontOfPosition(InFrontOfNode.StartPos); InsertPos:=FindLineEndOrCodeInFrontOfPosition(InFrontOfNode.StartPos);
end else begin end else begin
Node:=FindMainUsesSection(false); Node:=FindMainUsesSection(false);
if Node<>nil then begin if Node<>nil then begin
// insert behind uses section // insert behind uses section
Indent:=GetLineIndent(Src,Node.StartPos); Indent:=Beauty.GetLineIndent(Src,Node.StartPos);
InsertPos:=FindLineEndOrCodeAfterPosition(Node.EndPos); InsertPos:=FindLineEndOrCodeAfterPosition(Node.EndPos);
end else begin end else begin
// insert at start // insert at start
@ -1280,10 +1284,10 @@ begin
if Node<>nil then begin if Node<>nil then begin
// insert in front of second node // insert in front of second node
InsertPos:=Node.StartPos; InsertPos:=Node.StartPos;
Indent:=GetLineIndent(Src,InsertPos); Indent:=Beauty.GetLineIndent(Src,InsertPos);
end else if StartNode.Desc=ctnImplementation then begin end else if StartNode.Desc=ctnImplementation then begin
// empty implementation => insert at start // empty implementation => insert at start
Indent:=GetLineIndent(Src,StartNode.StartPos); Indent:=Beauty.GetLineIndent(Src,StartNode.StartPos);
InsertPos:=StartNode.StartPos+length('implementation'); InsertPos:=StartNode.StartPos+length('implementation');
end else begin end else begin
// empty program // empty program
@ -1292,8 +1296,6 @@ begin
end; end;
end; end;
Beauty:=SourceChangeCache.BeautifyCodeOptions;
// extract method param list, result type and modifiers // extract method param list, result type and modifiers
MethodAttr:=[phpWithStart, phpWithoutClassKeyword, phpWithVarModifiers, MethodAttr:=[phpWithStart, phpWithoutClassKeyword, phpWithVarModifiers,
phpWithParameterNames,phpWithDefaultValues,phpWithResultType, phpWithParameterNames,phpWithDefaultValues,phpWithResultType,
@ -2470,7 +2472,7 @@ begin
+'CleanPosToCodePos'); +'CleanPosToCodePos');
end; end;
Indent:=GetLineIndent(Src,DefProcNode.StartPos); Indent:=Beauty.GetLineIndent(Src,DefProcNode.StartPos);
FromPos:=DefProcNode.StartPos; FromPos:=DefProcNode.StartPos;
EndPos:=DefProcNode.EndPos; EndPos:=DefProcNode.EndPos;
SourceChangeCache.MainScanner:=Scanner; SourceChangeCache.MainScanner:=Scanner;
@ -2812,6 +2814,7 @@ var
FuncType: String; FuncType: String;
CleanProcHead: string; CleanProcHead: string;
NewProcPath: TStringList; NewProcPath: TStringList;
Beauty: TBeautifyCodeOptions;
begin begin
Result:=false; Result:=false;
if not CheckProcSyntax(BeginNode,ProcNameAtom,BracketOpenPos,BracketClosePos) if not CheckProcSyntax(BeginNode,ProcNameAtom,BracketOpenPos,BracketClosePos)
@ -2819,6 +2822,7 @@ begin
CheckWholeUnitParsed(CursorNode,BeginNode); CheckWholeUnitParsed(CursorNode,BeginNode);
Beauty:=SourceChangeCache.BeautifyCodeOptions;
Params:=TFindDeclarationParams.Create; Params:=TFindDeclarationParams.Create;
ExprList:=nil; ExprList:=nil;
ActivateGlobalWriteLock; ActivateGlobalWriteLock;
@ -2846,12 +2850,12 @@ begin
// this is a normal proc or sub proc // this is a normal proc or sub proc
// insert new proc in front // insert new proc in front
InsertPos:=FindLineEndOrCodeInFrontOfPosition(ProcNode.StartPos); InsertPos:=FindLineEndOrCodeInFrontOfPosition(ProcNode.StartPos);
Indent:=GetLineIndent(Src,ProcNode.StartPos); Indent:=Beauty.GetLineIndent(Src,ProcNode.StartPos);
end else begin end else begin
// this is a begin..end without proc (e.g. program or unit code) // this is a begin..end without proc (e.g. program or unit code)
// insert new proc in front // insert new proc in front
InsertPos:=FindLineEndOrCodeInFrontOfPosition(BeginNode.StartPos); InsertPos:=FindLineEndOrCodeInFrontOfPosition(BeginNode.StartPos);
Indent:=GetLineIndent(Src,BeginNode.StartPos); Indent:=Beauty.GetLineIndent(Src,BeginNode.StartPos);
end; end;
end; end;
end else begin end else begin
@ -4228,7 +4232,7 @@ var
GraphNode:=TCodeGraphNode(ListOfGraphNodes[i]); GraphNode:=TCodeGraphNode(ListOfGraphNodes[i]);
if GraphNode.Flags=0 then begin if GraphNode.Flags=0 then begin
InsertPos:=FindLineEndOrCodeInFrontOfPosition(GraphNode.Node.StartPos); InsertPos:=FindLineEndOrCodeInFrontOfPosition(GraphNode.Node.StartPos);
Indent:=GetLineIndent(Src,GraphNode.Node.StartPos); Indent:=Beauty.GetLineIndent(Src,GraphNode.Node.StartPos);
if not ApplyNodeMove(GraphNode,false,InsertPos,Indent) then exit; if not ApplyNodeMove(GraphNode,false,InsertPos,Indent) then exit;
end; end;
end; end;
@ -4393,7 +4397,7 @@ function TCodeCompletionCodeTool.FixForwardDefinitions(
if Node.Parent.Desc=ctnTypeSection then if Node.Parent.Desc=ctnTypeSection then
Node:=Node.Parent; Node:=Node.Parent;
InsertPos:=FindLineEndOrCodeInFrontOfPosition(Node.StartPos); InsertPos:=FindLineEndOrCodeInFrontOfPosition(Node.StartPos);
Indent:=GetLineIndent(Src,Node.StartPos); Indent:=Beauty.GetLineIndent(Src,Node.StartPos);
SourceChangeCache.Replace(gtEmptyLine,gtNewLine,InsertPos,InsertPos, SourceChangeCache.Replace(gtEmptyLine,gtNewLine,InsertPos,InsertPos,
Beauty.GetIndentStr(Indent)+'type'); Beauty.GetIndentStr(Indent)+'type');
inc(Indent,Beauty.Indent); inc(Indent,Beauty.Indent);
@ -4794,7 +4798,7 @@ function TCodeCompletionCodeTool.FixForwardDefinitions(
//DebugLn(['MoveNodes destination is not in a section']); //DebugLn(['MoveNodes destination is not in a section']);
end; end;
InsertPos:=FindLineEndOrCodeAfterPosition(DestNode.StartPos); InsertPos:=FindLineEndOrCodeAfterPosition(DestNode.StartPos);
Indent:=GetLineIndent(Src,DestNode.StartPos); Indent:=Beauty.GetLineIndent(Src,DestNode.StartPos);
//DebugLn(['MoveNodes DestNode=',GetRedefinitionNodeText(DestNode),':',DestNode.DescAsString,' DestSection=',NodeDescToStr(DestSection)]); //DebugLn(['MoveNodes DestNode=',GetRedefinitionNodeText(DestNode),':',DestNode.DescAsString,' DestSection=',NodeDescToStr(DestSection)]);
end; end;
@ -6080,7 +6084,7 @@ begin
// insert in front of another var // insert in front of another var
CursorNode:=GetFirstGroupVarNode(CursorNode); CursorNode:=GetFirstGroupVarNode(CursorNode);
InsertPos:=CursorNode.StartPos; InsertPos:=CursorNode.StartPos;
Indent:=GetLineIndent(Src,InsertPos); Indent:=Beauty.GetLineIndent(Src,InsertPos);
end else if CursorNode.Desc in (AllClassBaseSections end else if CursorNode.Desc in (AllClassBaseSections
+[ctnVarSection,ctnRecordType,ctnClassClassVar]) +[ctnVarSection,ctnRecordType,ctnClassClassVar])
then begin then begin
@ -6095,9 +6099,9 @@ begin
InsertPos:=CurPos.EndPos; InsertPos:=CurPos.EndPos;
end; end;
if CursorNode.FirstChild<>nil then if CursorNode.FirstChild<>nil then
Indent:=GetLineIndent(Src,CursorNode.FirstChild.StartPos) Indent:=Beauty.GetLineIndent(Src,CursorNode.FirstChild.StartPos)
else else
Indent:=GetLineIndent(Src,CursorNode.StartPos)+Beauty.Indent; Indent:=Beauty.GetLineIndent(Src,CursorNode.StartPos)+Beauty.Indent;
end else if CursorNode.Desc in [ctnProcedure,ctnInterface,ctnImplementation, end else if CursorNode.Desc in [ctnProcedure,ctnInterface,ctnImplementation,
ctnProgram,ctnLibrary,ctnPackage] ctnProgram,ctnLibrary,ctnPackage]
then begin then begin
@ -6115,18 +6119,18 @@ begin
if (Node<>nil) and (Node.Desc=ctnVarSection) then begin if (Node<>nil) and (Node.Desc=ctnVarSection) then begin
// append to a var section // append to a var section
if Node.LastChild<>nil then if Node.LastChild<>nil then
Indent:=GetLineIndent(Src,Node.LastChild.StartPos) Indent:=Beauty.GetLineIndent(Src,Node.LastChild.StartPos)
else else
Indent:=GetLineIndent(Src,Node.StartPos)+Beauty.Indent; Indent:=Beauty.GetLineIndent(Src,Node.StartPos)+Beauty.Indent;
end else begin end else begin
// start a new var section // start a new var section
NeedSection:=true; NeedSection:=true;
if Node<>nil then if Node<>nil then
Indent:=GetLineIndent(Src,Node.StartPos) Indent:=Beauty.GetLineIndent(Src,Node.StartPos)
else if CursorNode.FirstChild<>nil then else if CursorNode.FirstChild<>nil then
Indent:=GetLineIndent(Src,CursorNode.FirstChild.StartPos) Indent:=Beauty.GetLineIndent(Src,CursorNode.FirstChild.StartPos)
else else
Indent:=GetLineIndent(Src,CursorNode.StartPos); Indent:=Beauty.GetLineIndent(Src,CursorNode.StartPos);
end; end;
end else begin end else begin
// default: add the variable at cursor // default: add the variable at cursor
@ -7074,7 +7078,7 @@ begin
InsertBehind:=false; InsertBehind:=false;
end; end;
Indent:=GetLineIndent(Src,InsertNode.StartPos); Indent:=Beauty.GetLineIndent(Src,InsertNode.StartPos);
if InsertBehind then begin if InsertBehind then begin
// insert behind InsertNode // insert behind InsertNode
InsertPos:=FindLineEndOrCodeAfterPosition(InsertNode.EndPos); InsertPos:=FindLineEndOrCodeAfterPosition(InsertNode.EndPos);
@ -7085,17 +7089,17 @@ begin
end else begin end else begin
// insert as first variable/proc // insert as first variable/proc
//debugln(['TCodeCompletionCodeTool.InsertNewClassParts insert as first var: ',ClassSectionNode.DescAsString,' ',dbgstr(copy(Src,ClassSectionNode.StartPos,ClassSectionNode.EndPos-ClassSectionNode.StartPos))]); //debugln(['TCodeCompletionCodeTool.InsertNewClassParts insert as first var: ',ClassSectionNode.DescAsString,' ',dbgstr(copy(Src,ClassSectionNode.StartPos,ClassSectionNode.EndPos-ClassSectionNode.StartPos))]);
Indent:=GetLineIndent(Src,ClassSectionNode.StartPos)+Beauty.Indent; Indent:=Beauty.GetLineIndent(Src,ClassSectionNode.StartPos)+Beauty.Indent;
InsertPos:=ClassSectionNode.StartPos; InsertPos:=ClassSectionNode.StartPos;
if (ClassSectionNode.Desc=ctnClassPublished) if (ClassSectionNode.Desc=ctnClassPublished)
and (CompareIdentifiers(@Src[ClassSectionNode.StartPos],'published')<>0) and (CompareIdentifiers(@Src[ClassSectionNode.StartPos],'published')<>0)
then begin then begin
// the first published section has no keyword // the first published section has no keyword
if ClassSectionNode.NextBrother<>nil then if ClassSectionNode.NextBrother<>nil then
Indent:=GetLineIndent(Src,ClassSectionNode.NextBrother.StartPos) Indent:=Beauty.GetLineIndent(Src,ClassSectionNode.NextBrother.StartPos)
+Beauty.Indent +Beauty.Indent
else else
Indent:=GetLineIndent(Src,ClassSectionNode.Parent.StartPos) Indent:=Beauty.GetLineIndent(Src,ClassSectionNode.Parent.StartPos)
+Beauty.Indent; +Beauty.Indent;
end else if (ClassSectionNode.Desc in AllClassBaseSections) end else if (ClassSectionNode.Desc in AllClassBaseSections)
then begin then begin
@ -7243,7 +7247,7 @@ var
// topmost node is in the first section // topmost node is in the first section
// -> insert the new section as the first section // -> insert the new section as the first section
ANode:=FirstVisibilitySection; ANode:=FirstVisibilitySection;
NewClassSectionIndent[Visibility]:=GetLineIndent(Src,ANode.StartPos); NewClassSectionIndent[Visibility]:=Beauty.GetLineIndent(Src,ANode.StartPos);
if (ANode.FirstChild<>nil) and (ANode.FirstChild.Desc<>ctnClassGUID) if (ANode.FirstChild<>nil) and (ANode.FirstChild.Desc<>ctnClassGUID)
then then
NewClassSectionInsertPos[Visibility]:=ANode.StartPos NewClassSectionInsertPos[Visibility]:=ANode.StartPos
@ -7275,7 +7279,7 @@ var
// default: insert new section behind first published section // default: insert new section behind first published section
ANode:=FirstVisibilitySection; ANode:=FirstVisibilitySection;
end; end;
NewClassSectionIndent[Visibility]:=GetLineIndent(Src,ANode.StartPos); NewClassSectionIndent[Visibility]:=Beauty.GetLineIndent(Src,ANode.StartPos);
NewClassSectionInsertPos[Visibility]:=ANode.EndPos; NewClassSectionInsertPos[Visibility]:=ANode.EndPos;
end; end;
SectionKeyWord:=PascalClassSectionKeywords[Visibility]; SectionKeyWord:=PascalClassSectionKeywords[Visibility];
@ -7376,7 +7380,7 @@ begin
// insert comment in front // insert comment in front
InsertPos:=ClassIdentifierNode.StartPos; InsertPos:=ClassIdentifierNode.StartPos;
Indent:=GetLineIndent(Src,InsertPos); Indent:=Beauty.GetLineIndent(Src,InsertPos);
Code:=Beauty.GetIndentStr(Indent)+'{ '+Code+' }'; Code:=Beauty.GetIndentStr(Indent)+'{ '+Code+' }';
ASourceChangeCache.Replace(gtEmptyLine,gtEmptyLine, ASourceChangeCache.Replace(gtEmptyLine,gtEmptyLine,
InsertPos,InsertPos,Code); InsertPos,InsertPos,Code);
@ -7672,7 +7676,7 @@ begin
BodyProcHeadNode:=BodyNodeExt.Node.FirstChild; BodyProcHeadNode:=BodyNodeExt.Node.FirstChild;
InsertPos:=BodyNodeExt.Node.StartPos; InsertPos:=BodyNodeExt.Node.StartPos;
InsertEndPos:=BodyProcHeadNode.EndPos; InsertEndPos:=BodyProcHeadNode.EndPos;
Indent:=GetLineIndent(Src,InsertPos); Indent:=Beauty.GetLineIndent(Src,InsertPos);
NewProcCode:=Beauty.BeautifyProc(NewProcCode,Indent,false); NewProcCode:=Beauty.BeautifyProc(NewProcCode,Indent,false);
OldProcCode:=ExtractProcHead(BodyNodeExt.Node,ProcAttrCopyDefToBody); OldProcCode:=ExtractProcHead(BodyNodeExt.Node,ProcAttrCopyDefToBody);
if CompareTextIgnoringSpace(NewProcCode,OldProcCode,true)<>0 then begin if CompareTextIgnoringSpace(NewProcCode,OldProcCode,true)<>0 then begin
@ -8042,7 +8046,7 @@ var
procedure SetIndentAndInsertPos(Node: TCodeTreeNode; Behind: boolean); procedure SetIndentAndInsertPos(Node: TCodeTreeNode; Behind: boolean);
begin begin
Indent:=GetLineIndent(Src,Node.StartPos); Indent:=Beauty.GetLineIndent(Src,Node.StartPos);
if Behind then if Behind then
InsertPos:=FindLineEndOrCodeAfterPosition(Node.EndPos) InsertPos:=FindLineEndOrCodeAfterPosition(Node.EndPos)
else else
@ -8066,7 +8070,7 @@ var
if ImplementationNode=nil then begin if ImplementationNode=nil then begin
// create implementation section // create implementation section
InsertPos:=UnitInterfaceNode.EndPos; InsertPos:=UnitInterfaceNode.EndPos;
Indent:=GetLineIndent(Src,UnitInterfaceNode.StartPos); Indent:=Beauty.GetLineIndent(Src,UnitInterfaceNode.StartPos);
if not CodeCompleteSrcChgCache.Replace(gtNewLine,gtNewLine,InsertPos,InsertPos, if not CodeCompleteSrcChgCache.Replace(gtNewLine,gtNewLine,InsertPos,InsertPos,
CodeCompleteSrcChgCache.BeautifyCodeOptions.BeautifyKeyWord('implementation')) CodeCompleteSrcChgCache.BeautifyCodeOptions.BeautifyKeyWord('implementation'))
then begin then begin
@ -8077,7 +8081,7 @@ var
end else if (ImplementationNode.FirstChild=nil) end else if (ImplementationNode.FirstChild=nil)
or (ImplementationNode.FirstChild.Desc=ctnBeginBlock) then begin or (ImplementationNode.FirstChild.Desc=ctnBeginBlock) then begin
// implementation is empty // implementation is empty
Indent:=GetLineIndent(Src,ImplementationNode.StartPos); Indent:=Beauty.GetLineIndent(Src,ImplementationNode.StartPos);
if ImplementationNode.FirstChild<>nil then if ImplementationNode.FirstChild<>nil then
InsertPos:=ImplementationNode.FirstChild.StartPos InsertPos:=ImplementationNode.FirstChild.StartPos
else else
@ -8102,7 +8106,7 @@ var
if NearestProcNode<>nil then begin if NearestProcNode<>nil then begin
// the comments in front of the first method probably belong to the class // the comments in front of the first method probably belong to the class
// Therefore insert behind the node in front of the first method // Therefore insert behind the node in front of the first method
Indent:=GetLineIndent(Src,NearestProcNode.StartPos); Indent:=Beauty.GetLineIndent(Src,NearestProcNode.StartPos);
if NearestProcNode.PriorBrother<>nil then begin if NearestProcNode.PriorBrother<>nil then begin
InsertPos:=FindLineEndOrCodeAfterPosition(NearestProcNode.PriorBrother.EndPos); InsertPos:=FindLineEndOrCodeAfterPosition(NearestProcNode.PriorBrother.EndPos);
end else begin end else begin
@ -8305,7 +8309,7 @@ begin
{$ENDIF} {$ENDIF}
// set default insert position // set default insert position
Indent:=GetLineIndent(Src,LastExistingProcBody.StartPos); Indent:=Beauty.GetLineIndent(Src,LastExistingProcBody.StartPos);
InsertPos:=FindLineEndOrCodeAfterPosition(LastExistingProcBody.EndPos); InsertPos:=FindLineEndOrCodeAfterPosition(LastExistingProcBody.EndPos);
// check for all defined class methods (MissingNode), if there is a body // check for all defined class methods (MissingNode), if there is a body
@ -8333,7 +8337,7 @@ begin
end; end;
ANodeExt2:=TCodeTreeNodeExtension(ExistingNode.Data); ANodeExt2:=TCodeTreeNodeExtension(ExistingNode.Data);
ANode:=ANodeExt2.Node; ANode:=ANodeExt2.Node;
Indent:=GetLineIndent(Src,ANode.StartPos); Indent:=Beauty.GetLineIndent(Src,ANode.StartPos);
if cmp>0 then begin if cmp>0 then begin
// insert behind ExistingNode // insert behind ExistingNode
InsertPos:=FindLineEndOrCodeAfterPosition(ANode.EndPos); InsertPos:=FindLineEndOrCodeAfterPosition(ANode.EndPos);
@ -8369,14 +8373,14 @@ begin
ANodeExt2:=TCodeTreeNodeExtension(NearestAVLNode.Data); ANodeExt2:=TCodeTreeNodeExtension(NearestAVLNode.Data);
// see above (note 1) for ANodeExt2.Data // see above (note 1) for ANodeExt2.Data
ANode:=TCodeTreeNodeExtension(ANodeExt2.Data).Node; ANode:=TCodeTreeNodeExtension(ANodeExt2.Data).Node;
Indent:=GetLineIndent(Src,ANode.StartPos); Indent:=Beauty.GetLineIndent(Src,ANode.StartPos);
InsertPos:=FindLineEndOrCodeAfterPosition(ANode.EndPos); InsertPos:=FindLineEndOrCodeAfterPosition(ANode.EndPos);
end else if NextAVLNode<>nil then begin end else if NextAVLNode<>nil then begin
// there is a NextAVLNode behind -> insert in front of body // there is a NextAVLNode behind -> insert in front of body
ANodeExt2:=TCodeTreeNodeExtension(NextAVLNode.Data); ANodeExt2:=TCodeTreeNodeExtension(NextAVLNode.Data);
// see above (note 1) for ANodeExt2.Data // see above (note 1) for ANodeExt2.Data
ANode:=TCodeTreeNodeExtension(ANodeExt2.Data).Node; ANode:=TCodeTreeNodeExtension(ANodeExt2.Data).Node;
Indent:=GetLineIndent(Src,ANode.StartPos); Indent:=Beauty.GetLineIndent(Src,ANode.StartPos);
InsertPos:=FindLineEndOrCodeInFrontOfPosition(ANode.StartPos); InsertPos:=FindLineEndOrCodeInFrontOfPosition(ANode.StartPos);
end; end;
end; end;

View File

@ -302,7 +302,7 @@ var
{$IFDEF CTDebug} {$IFDEF CTDebug}
DebugLn('TExtractProcTool.ReplaceSelectionWithCall A'); DebugLn('TExtractProcTool.ReplaceSelectionWithCall A');
{$ENDIF} {$ENDIF}
Indent:=GetLineIndent(Src,BlockStartPos); Indent:=Beauty.GetLineIndent(Src,BlockStartPos);
ParamListCode:=''; ParamListCode:='';
// gather all variables, that are used in the selection and in the rest of // gather all variables, that are used in the selection and in the rest of
// the old proc (in front or behind). These are the parameters for the new proc. // the old proc (in front or behind). These are the parameters for the new proc.
@ -750,14 +750,14 @@ var
while BeginNode.Desc<>ctnBeginBlock do while BeginNode.Desc<>ctnBeginBlock do
BeginNode:=BeginNode.PriorBrother; BeginNode:=BeginNode.PriorBrother;
InsertPos:=BeginNode.StartPos; InsertPos:=BeginNode.StartPos;
Indent:=GetLineIndent(Src,InsertPos)+Beauty.Indent; Indent:=Beauty.GetLineIndent(Src,InsertPos)+Beauty.Indent;
end; end;
eptSubProcedureSameLvl: eptSubProcedureSameLvl:
begin begin
// -> insert in front of old proc // -> insert in front of old proc
InsertPos:=FindLineEndOrCodeInFrontOfPosition(MainBlockNode.StartPos); InsertPos:=FindLineEndOrCodeInFrontOfPosition(MainBlockNode.StartPos);
Indent:=GetLineIndent(Src,MainBlockNode.StartPos); Indent:=Beauty.GetLineIndent(Src,MainBlockNode.StartPos);
end; end;
eptProcedure,eptProcedureWithInterface: eptProcedure,eptProcedureWithInterface:
@ -778,7 +778,7 @@ var
InsertNode:=InsertNode.PriorBrother; InsertNode:=InsertNode.PriorBrother;
end; end;
// -> insert in front of top level proc // -> insert in front of top level proc
Indent:=GetLineIndent(Src,InsertNode.StartPos); Indent:=Beauty.GetLineIndent(Src,InsertNode.StartPos);
if InsertNode.PriorBrother<>nil then begin if InsertNode.PriorBrother<>nil then begin
InsertPos:=FindLineEndOrCodeAfterPosition( InsertPos:=FindLineEndOrCodeAfterPosition(
InsertNode.PriorBrother.EndPos); InsertNode.PriorBrother.EndPos);
@ -795,7 +795,7 @@ var
begin begin
// set default values // set default values
InsertPos:=FindLineEndOrCodeInFrontOfPosition(MainBlockNode.StartPos); InsertPos:=FindLineEndOrCodeInFrontOfPosition(MainBlockNode.StartPos);
Indent:=GetLineIndent(Src,MainBlockNode.StartPos); Indent:=Beauty.GetLineIndent(Src,MainBlockNode.StartPos);
end; end;
else else