mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-09 06:32:38 +02:00
codetools: code completion: use GetIndentStr of beautifier
git-svn-id: trunk@40814 -
This commit is contained in:
parent
fd4d0497fc
commit
5ee76dbc83
@ -536,6 +536,7 @@ procedure TCodeCompletionCodeTool.AddClassInsertion(
|
|||||||
|
|
||||||
}
|
}
|
||||||
var NewInsert, InsertPos, LastInsertPos: TCodeTreeNodeExtension;
|
var NewInsert, InsertPos, LastInsertPos: TCodeTreeNodeExtension;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
DebugLn('[TCodeCompletionCodeTool.AddClassInsertion] CleanDef="',CleanDef,'" Def="',Def,'" Identifiername="',Identifiername,'" Body="',Body,'"');
|
DebugLn('[TCodeCompletionCodeTool.AddClassInsertion] CleanDef="',CleanDef,'" Def="',Def,'" Identifiername="',Identifiername,'" Body="',Body,'"');
|
||||||
@ -561,7 +562,8 @@ begin
|
|||||||
FirstInsert:=NewInsert;
|
FirstInsert:=NewInsert;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
if ASourceChangeCache.BeautifyCodeOptions.ClassPartInsertPolicy=cpipLast then
|
Beauty:=ASourceChangeCache.BeautifyCodeOptions;
|
||||||
|
if Beauty.ClassPartInsertPolicy=cpipLast then
|
||||||
begin
|
begin
|
||||||
// add as last to inserts
|
// add as last to inserts
|
||||||
InsertPos:=FirstInsert;
|
InsertPos:=FirstInsert;
|
||||||
@ -672,6 +674,7 @@ var
|
|||||||
ProcPosBehind: Integer;
|
ProcPosBehind: Integer;
|
||||||
EmptyLinesInFront: Integer;
|
EmptyLinesInFront: Integer;
|
||||||
EmptyLinesBehind: Integer;
|
EmptyLinesBehind: Integer;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
IsInInterface:=ProcNode.HasParentOfType(ctnInterface);
|
IsInInterface:=ProcNode.HasParentOfType(ctnInterface);
|
||||||
if IsInInterface then begin
|
if IsInInterface then begin
|
||||||
@ -701,8 +704,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
//debugln(['TCodeCompletionCodeTool.FindInsertPositionForForwardProc ',ord(SourceChangeCache.BeautifyCodeOptions.ForwardProcBodyInsertPolicy)]);
|
Beauty:=SourceChangeCache.BeautifyCodeOptions;
|
||||||
if SourceChangeCache.BeautifyCodeOptions.KeepForwardProcOrder then begin
|
//debugln(['TCodeCompletionCodeTool.FindInsertPositionForForwardProc ',ord(Beauty.ForwardProcBodyInsertPolicy)]);
|
||||||
|
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
|
||||||
// in the same order of other forward proc definitions.
|
// in the same order of other forward proc definitions.
|
||||||
ForwardProcNodes:=nil;
|
ForwardProcNodes:=nil;
|
||||||
@ -801,8 +805,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if SourceChangeCache.BeautifyCodeOptions.ForwardProcBodyInsertPolicy
|
if Beauty.ForwardProcBodyInsertPolicy = fpipInFrontOfMethods
|
||||||
= fpipInFrontOfMethods
|
|
||||||
then begin
|
then begin
|
||||||
// Try to insert new proc in front of existing methods
|
// Try to insert new proc in front of existing methods
|
||||||
|
|
||||||
@ -824,8 +827,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
end else if SourceChangeCache.BeautifyCodeOptions.ForwardProcBodyInsertPolicy
|
end else if Beauty.ForwardProcBodyInsertPolicy = fpipBehindMethods
|
||||||
= fpipBehindMethods
|
|
||||||
then begin
|
then begin
|
||||||
// Try to insert new proc behind existing methods
|
// Try to insert new proc behind existing methods
|
||||||
|
|
||||||
@ -999,6 +1001,7 @@ var
|
|||||||
ParentNode: TCodeTreeNode;
|
ParentNode: TCodeTreeNode;
|
||||||
OtherSectionNode: TCodeTreeNode;
|
OtherSectionNode: TCodeTreeNode;
|
||||||
HeaderNode: TCodeTreeNode;
|
HeaderNode: TCodeTreeNode;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if CleanLevelPos<1 then CleanLevelPos:=CleanCursorPos;
|
if CleanLevelPos<1 then CleanLevelPos:=CleanCursorPos;
|
||||||
@ -1007,6 +1010,7 @@ begin
|
|||||||
RaiseException('TCodeCompletionCodeTool.AddLocalVariable Internal Error: '
|
RaiseException('TCodeCompletionCodeTool.AddLocalVariable Internal Error: '
|
||||||
+'CleanPosToCodePos');
|
+'CleanPosToCodePos');
|
||||||
end;
|
end;
|
||||||
|
Beauty:=SourceChangeCache.BeautifyCodeOptions;
|
||||||
|
|
||||||
// find the level and find sections in front
|
// find the level and find sections in front
|
||||||
Node:=Tree.Root;
|
Node:=Tree.Root;
|
||||||
@ -1063,7 +1067,7 @@ begin
|
|||||||
if VarNode<>nil then begin
|
if VarNode<>nil then begin
|
||||||
Indent:=GetLineIndent(Src,VarNode.StartPos);
|
Indent:=GetLineIndent(Src,VarNode.StartPos);
|
||||||
if PositionsInSameLine(Src,VarSectionNode.StartPos,VarNode.StartPos) then
|
if PositionsInSameLine(Src,VarSectionNode.StartPos,VarNode.StartPos) then
|
||||||
inc(Indent,SourceChangeCache.BeautifyCodeOptions.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:=GetLineIndent(Src,VarSectionNode.StartPos);
|
||||||
@ -1108,14 +1112,12 @@ begin
|
|||||||
Indent:=GetLineIndent(Src,InsertPos);
|
Indent:=GetLineIndent(Src,InsertPos);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
InsertTxt:='var'+SourceChangeCache.BeautifyCodeOptions.LineEnd
|
InsertTxt:='var'+Beauty.LineEnd
|
||||||
+GetIndentStr(Indent+SourceChangeCache.BeautifyCodeOptions.Indent)
|
+Beauty.GetIndentStr(Indent+Beauty.Indent)+InsertTxt;
|
||||||
+InsertTxt;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// insert new code
|
// insert new code
|
||||||
InsertTxt:=SourceChangeCache.BeautifyCodeOptions.BeautifyStatement(
|
InsertTxt:=Beauty.BeautifyStatement(InsertTxt,Indent);
|
||||||
InsertTxt,Indent);
|
|
||||||
//DebugLn('TCodeCompletionCodeTool.AddLocalVariable E ',InsertTxt,' ');
|
//DebugLn('TCodeCompletionCodeTool.AddLocalVariable E ',InsertTxt,' ');
|
||||||
SourceChangeCache.Replace(gtNewLine,gtNewLine,InsertPos,InsertPos,InsertTxt);
|
SourceChangeCache.Replace(gtNewLine,gtNewLine,InsertPos,InsertPos,InsertTxt);
|
||||||
|
|
||||||
@ -1182,6 +1184,7 @@ procedure TCodeCompletionCodeTool.AddMethodCompatibleToProcType(
|
|||||||
MethodAttr: TProcHeadAttributes; SourceChangeCache: TSourceChangeCache);
|
MethodAttr: TProcHeadAttributes; SourceChangeCache: TSourceChangeCache);
|
||||||
var
|
var
|
||||||
CleanMethodDefinition: string;
|
CleanMethodDefinition: string;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
MethodDefinition:='';
|
MethodDefinition:='';
|
||||||
MethodAttr:=[];
|
MethodAttr:=[];
|
||||||
@ -1202,13 +1205,13 @@ begin
|
|||||||
CodeCompleteSrcChgCache:=SourceChangeCache;
|
CodeCompleteSrcChgCache:=SourceChangeCache;
|
||||||
|
|
||||||
// insert new published method to class
|
// insert new published method to class
|
||||||
|
Beauty:=SourceChangeCache.BeautifyCodeOptions;
|
||||||
MethodAttr:=[phpWithStart, phpWithoutClassKeyword, phpWithVarModifiers,
|
MethodAttr:=[phpWithStart, phpWithoutClassKeyword, phpWithVarModifiers,
|
||||||
phpWithParameterNames,phpWithDefaultValues,phpWithResultType];
|
phpWithParameterNames,phpWithDefaultValues,phpWithResultType];
|
||||||
MethodDefinition:=TrimCodeSpace(ProcContext.Tool.ExtractProcHead(
|
MethodDefinition:=TrimCodeSpace(ProcContext.Tool.ExtractProcHead(
|
||||||
ProcContext.Node,
|
ProcContext.Node,
|
||||||
MethodAttr+[phpWithoutClassName,phpWithoutName]));
|
MethodAttr+[phpWithoutClassName,phpWithoutName]));
|
||||||
MethodDefinition:=SourceChangeCache.BeautifyCodeOptions.
|
MethodDefinition:=Beauty.AddClassAndNameToProc(MethodDefinition, '', AnEventName);
|
||||||
AddClassAndNameToProc(MethodDefinition, '', AnEventName);
|
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
DebugLn(' CompleteEventAssignment: Add Method To Class...');
|
DebugLn(' CompleteEventAssignment: Add Method To Class...');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -1217,8 +1220,7 @@ begin
|
|||||||
AddClassInsertion(CleanMethodDefinition, MethodDefinition,
|
AddClassInsertion(CleanMethodDefinition, MethodDefinition,
|
||||||
AnEventName, ncpPublishedProcs);
|
AnEventName, ncpPublishedProcs);
|
||||||
end;
|
end;
|
||||||
MethodDefinition:=SourceChangeCache.BeautifyCodeOptions.
|
MethodDefinition:=Beauty.AddClassAndNameToProc(MethodDefinition,
|
||||||
AddClassAndNameToProc(MethodDefinition,
|
|
||||||
ExtractClassName(AClassNode,false,true), AnEventName);
|
ExtractClassName(AClassNode,false,true), AnEventName);
|
||||||
if not InsertAllNewClassParts then
|
if not InsertAllNewClassParts then
|
||||||
RaiseException(ctsErrorDuringInsertingNewClassParts);
|
RaiseException(ctsErrorDuringInsertingNewClassParts);
|
||||||
@ -1239,6 +1241,7 @@ var
|
|||||||
Indent: Integer;
|
Indent: Integer;
|
||||||
InsertPos: Integer;
|
InsertPos: Integer;
|
||||||
NewProc: String;
|
NewProc: String;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
// 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;
|
||||||
@ -1289,6 +1292,8 @@ 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,
|
||||||
@ -1296,12 +1301,11 @@ begin
|
|||||||
MethodDefinition:=TrimCodeSpace(
|
MethodDefinition:=TrimCodeSpace(
|
||||||
ProcContext.Tool.ExtractProcHead(ProcContext.Node,
|
ProcContext.Tool.ExtractProcHead(ProcContext.Node,
|
||||||
MethodAttr+[phpWithoutClassName,phpWithoutName]));
|
MethodAttr+[phpWithoutClassName,phpWithoutName]));
|
||||||
MethodDefinition:=SourceChangeCache.BeautifyCodeOptions.
|
MethodDefinition:=Beauty.AddClassAndNameToProc(MethodDefinition, '', NewProcName);
|
||||||
AddClassAndNameToProc(MethodDefinition, '', NewProcName);
|
|
||||||
debugln(['TCodeCompletionCodeTool.AddProcedureCompatibleToProcType MethodDefinition="',MethodDefinition,'"']);
|
debugln(['TCodeCompletionCodeTool.AddProcedureCompatibleToProcType MethodDefinition="',MethodDefinition,'"']);
|
||||||
|
|
||||||
// create code and insert
|
// create code and insert
|
||||||
NewProc:=SourceChangeCache.BeautifyCodeOptions.BeautifyProc(MethodDefinition,Indent,true);
|
NewProc:=Beauty.BeautifyProc(MethodDefinition,Indent,true);
|
||||||
debugln(['TCodeCompletionCodeTool.AddProcedureCompatibleToProcType NewProc="',NewProc,'"']);
|
debugln(['TCodeCompletionCodeTool.AddProcedureCompatibleToProcType NewProc="',NewProc,'"']);
|
||||||
if not SourceChangeCache.Replace(gtEmptyLine,gtEmptyLine,InsertPos,InsertPos,NewProc)
|
if not SourceChangeCache.Replace(gtEmptyLine,gtEmptyLine,InsertPos,InsertPos,NewProc)
|
||||||
then
|
then
|
||||||
@ -1440,6 +1444,7 @@ var
|
|||||||
ProcCode: String;
|
ProcCode: String;
|
||||||
Indent: integer;
|
Indent: integer;
|
||||||
InsertPos: integer;
|
InsertPos: integer;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
Result:=true;
|
Result:=true;
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
@ -1493,6 +1498,7 @@ begin
|
|||||||
Indent,InsertPos);
|
Indent,InsertPos);
|
||||||
|
|
||||||
// build nice procs
|
// build nice procs
|
||||||
|
Beauty:=SourceChangeCache.BeautifyCodeOptions;
|
||||||
CurProcNode:=StartProcNode;
|
CurProcNode:=StartProcNode;
|
||||||
repeat
|
repeat
|
||||||
ProcCode:=ExtractProcHead(CurProcNode,[phpWithStart,
|
ProcCode:=ExtractProcHead(CurProcNode,[phpWithStart,
|
||||||
@ -1509,8 +1515,7 @@ begin
|
|||||||
CurPos.EndPos,CurPos.EndPos,';') then
|
CurPos.EndPos,CurPos.EndPos,';') then
|
||||||
RaiseException('CompleteForwardProcs: unable to insert semicolon');
|
RaiseException('CompleteForwardProcs: unable to insert semicolon');
|
||||||
end;
|
end;
|
||||||
ProcCode:=SourceChangeCache.BeautifyCodeOptions.BeautifyProc(ProcCode,
|
ProcCode:=Beauty.BeautifyProc(ProcCode,Indent,true);
|
||||||
Indent,true);
|
|
||||||
if not SourceChangeCache.Replace(gtEmptyLine,gtEmptyLine,
|
if not SourceChangeCache.Replace(gtEmptyLine,gtEmptyLine,
|
||||||
InsertPos,InsertPos,ProcCode) then
|
InsertPos,InsertPos,ProcCode) then
|
||||||
RaiseException('CompleteForwardProcs: unable to insert new proc body');
|
RaiseException('CompleteForwardProcs: unable to insert new proc body');
|
||||||
@ -2383,6 +2388,7 @@ var
|
|||||||
FromPos: Integer;
|
FromPos: Integer;
|
||||||
EndPos: Integer;
|
EndPos: Integer;
|
||||||
Indent: Integer;
|
Indent: Integer;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
|
|
||||||
@ -2410,6 +2416,7 @@ begin
|
|||||||
//DebugLn(['CompleteMethod CurClassName=',CurClassName]);
|
//DebugLn(['CompleteMethod CurClassName=',CurClassName]);
|
||||||
CodeCompleteClassNode:=FindClassNodeInUnit(CurClassName,true,false,false,true);
|
CodeCompleteClassNode:=FindClassNodeInUnit(CurClassName,true,false,false,true);
|
||||||
|
|
||||||
|
Beauty:=SourceChangeCache.BeautifyCodeOptions;
|
||||||
ClassProcs:=nil;
|
ClassProcs:=nil;
|
||||||
ProcBodyNodes:=nil;
|
ProcBodyNodes:=nil;
|
||||||
try
|
try
|
||||||
@ -2467,7 +2474,7 @@ begin
|
|||||||
FromPos:=DefProcNode.StartPos;
|
FromPos:=DefProcNode.StartPos;
|
||||||
EndPos:=DefProcNode.EndPos;
|
EndPos:=DefProcNode.EndPos;
|
||||||
SourceChangeCache.MainScanner:=Scanner;
|
SourceChangeCache.MainScanner:=Scanner;
|
||||||
NewProcCode:=SourceChangeCache.BeautifyCodeOptions.BeautifyStatement(
|
NewProcCode:=Beauty.BeautifyStatement(
|
||||||
NewProcCode,Indent,[bcfDoNotIndentFirstLine]);
|
NewProcCode,Indent,[bcfDoNotIndentFirstLine]);
|
||||||
{$IFDEF VerboseCompleteMethod}
|
{$IFDEF VerboseCompleteMethod}
|
||||||
debugln('TCodeCompletionCodeTool.CompleteMethodByBody final NewProcCode:');
|
debugln('TCodeCompletionCodeTool.CompleteMethodByBody final NewProcCode:');
|
||||||
@ -2709,9 +2716,12 @@ const
|
|||||||
var
|
var
|
||||||
le: String;
|
le: String;
|
||||||
ProcName: String;
|
ProcName: String;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
|
|
||||||
|
Beauty:=SourceChangeCache.BeautifyCodeOptions;
|
||||||
|
|
||||||
// create param list
|
// create param list
|
||||||
ProcCode:=CreateParamListFromStatement(CursorNode,BracketOpenPos,CleanProcHead);
|
ProcCode:=CreateParamListFromStatement(CursorNode,BracketOpenPos,CleanProcHead);
|
||||||
if ProcCode<>'' then begin
|
if ProcCode<>'' then begin
|
||||||
@ -2732,13 +2742,13 @@ const
|
|||||||
CleanProcHead:=CleanProcHead+';';
|
CleanProcHead:=CleanProcHead+';';
|
||||||
|
|
||||||
// append begin..end
|
// append begin..end
|
||||||
le:=SourceChangeCache.BeautifyCodeOptions.LineEnd;
|
le:=Beauty.LineEnd;
|
||||||
ProcCode:=ProcCode+le
|
ProcCode:=ProcCode+le
|
||||||
+'begin'+le
|
+'begin'+le
|
||||||
+le
|
+le
|
||||||
+'end;';
|
+'end;';
|
||||||
|
|
||||||
ProcCode:=SourceChangeCache.BeautifyCodeOptions.BeautifyStatement(ProcCode,Indent);
|
ProcCode:=Beauty.BeautifyStatement(ProcCode,Indent);
|
||||||
|
|
||||||
DebugLn(['TCodeCompletionCodeTool.CompleteProcByCall ',ProcCode]);
|
DebugLn(['TCodeCompletionCodeTool.CompleteProcByCall ',ProcCode]);
|
||||||
Result:=true;
|
Result:=true;
|
||||||
@ -3777,12 +3787,14 @@ var
|
|||||||
FromPos: LongInt;
|
FromPos: LongInt;
|
||||||
ToPos: LongInt;
|
ToPos: LongInt;
|
||||||
NewSrc: String;
|
NewSrc: String;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if SourceChangeCache=nil then exit;
|
if SourceChangeCache=nil then exit;
|
||||||
if (TreeOfCodeTreeNodeExt=nil) or (TreeOfCodeTreeNodeExt.Count=0) then
|
if (TreeOfCodeTreeNodeExt=nil) or (TreeOfCodeTreeNodeExt.Count=0) then
|
||||||
exit(true);
|
exit(true);
|
||||||
SourceChangeCache.MainScanner:=Scanner;
|
SourceChangeCache.MainScanner:=Scanner;
|
||||||
|
Beauty:=SourceChangeCache.BeautifyCodeOptions;
|
||||||
|
|
||||||
AVLNode:=TreeOfCodeTreeNodeExt.FindLowest;
|
AVLNode:=TreeOfCodeTreeNodeExt.FindLowest;
|
||||||
while AVLNode<>nil do begin
|
while AVLNode<>nil do begin
|
||||||
@ -3809,7 +3821,7 @@ begin
|
|||||||
FromPos:=DefNode.StartPos;
|
FromPos:=DefNode.StartPos;
|
||||||
ToPos:=DefNode.EndPos;
|
ToPos:=DefNode.EndPos;
|
||||||
if Src[ToPos]=';' then inc(ToPos);// add semicolon
|
if Src[ToPos]=';' then inc(ToPos);// add semicolon
|
||||||
NewSrc:=GetIndentStr(SourceChangeCache.BeautifyCodeOptions.Indent)
|
NewSrc:=Beauty.GetIndentStr(Beauty.Indent)
|
||||||
+ExtractProcName(DefNode,[])+' = '+Expr+';';
|
+ExtractProcName(DefNode,[])+' = '+Expr+';';
|
||||||
SourceChangeCache.Replace(gtNone,gtNone,FromPos,ToPos,NewSrc);
|
SourceChangeCache.Replace(gtNone,gtNone,FromPos,ToPos,NewSrc);
|
||||||
// add 'const' keyword
|
// add 'const' keyword
|
||||||
@ -4026,12 +4038,14 @@ var
|
|||||||
FromPos: LongInt;
|
FromPos: LongInt;
|
||||||
ToPos: LongInt;
|
ToPos: LongInt;
|
||||||
NewSrc: String;
|
NewSrc: String;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if SourceChangeCache=nil then exit;
|
if SourceChangeCache=nil then exit;
|
||||||
if (TreeOfCodeTreeNodeExt=nil) or (TreeOfCodeTreeNodeExt.Count=0) then
|
if (TreeOfCodeTreeNodeExt=nil) or (TreeOfCodeTreeNodeExt.Count=0) then
|
||||||
exit(true);
|
exit(true);
|
||||||
SourceChangeCache.MainScanner:=Scanner;
|
SourceChangeCache.MainScanner:=Scanner;
|
||||||
|
Beauty:=SourceChangeCache.BeautifyCodeOptions;
|
||||||
|
|
||||||
AVLNode:=TreeOfCodeTreeNodeExt.FindLowest;
|
AVLNode:=TreeOfCodeTreeNodeExt.FindLowest;
|
||||||
while AVLNode<>nil do begin
|
while AVLNode<>nil do begin
|
||||||
@ -4058,7 +4072,7 @@ begin
|
|||||||
FromPos:=DefNode.StartPos;
|
FromPos:=DefNode.StartPos;
|
||||||
ToPos:=DefNode.EndPos;
|
ToPos:=DefNode.EndPos;
|
||||||
if Src[ToPos]=';' then inc(ToPos);// add semicolon
|
if Src[ToPos]=';' then inc(ToPos);// add semicolon
|
||||||
NewSrc:=GetIndentStr(SourceChangeCache.BeautifyCodeOptions.Indent)
|
NewSrc:=Beauty.GetIndentStr(Beauty.Indent)
|
||||||
+ExtractProcName(DefNode,[])+' = '+Expr+';';
|
+ExtractProcName(DefNode,[])+' = '+Expr+';';
|
||||||
SourceChangeCache.Replace(gtNone,gtNone,FromPos,ToPos,NewSrc);
|
SourceChangeCache.Replace(gtNone,gtNone,FromPos,ToPos,NewSrc);
|
||||||
// add 'type' keyword
|
// add 'type' keyword
|
||||||
@ -4133,7 +4147,8 @@ var
|
|||||||
if MoveNode then begin
|
if MoveNode then begin
|
||||||
FromPos:=FindLineEndOrCodeInFrontOfPosition(Node.StartPos);
|
FromPos:=FindLineEndOrCodeInFrontOfPosition(Node.StartPos);
|
||||||
ToPos:=FindLineEndOrCodeAfterPosition(Node.EndPos);
|
ToPos:=FindLineEndOrCodeAfterPosition(Node.EndPos);
|
||||||
NodeSrc:=GetIndentStr(Indent)+Trim(copy(Src,FromPos,ToPos-FromPos));
|
NodeSrc:=SourceChangeCache.BeautifyCodeOptions.GetIndentStr(Indent)
|
||||||
|
+Trim(copy(Src,FromPos,ToPos-FromPos));
|
||||||
// remove
|
// remove
|
||||||
if (Node.PriorBrother=nil)
|
if (Node.PriorBrother=nil)
|
||||||
and (Node.Parent<>nil) and (Node.Parent.Desc in AllDefinitionSections)
|
and (Node.Parent<>nil) and (Node.Parent.Desc in AllDefinitionSections)
|
||||||
@ -4318,16 +4333,16 @@ function TCodeCompletionCodeTool.FixForwardDefinitions(
|
|||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CreateTypeSectionForCircle(CircleOfGraphNodes: TFPList;
|
function CreateTypeSectionForCircle(CycleOfGraphNodes: TFPList;
|
||||||
var Definitions: TAVLTree; var Graph: TCodeGraph): boolean;
|
var Definitions: TAVLTree; var Graph: TCodeGraph): boolean;
|
||||||
// CircleOfGraphNodes is a list of TCodeGraphNode that should be moved
|
// CycleOfGraphNodes is a list of TCodeGraphNode that should be moved
|
||||||
// to a new type section
|
// to a new type section
|
||||||
|
|
||||||
function IndexOfNode(Node: TCodeTreeNode): integer;
|
function IndexOfNode(Node: TCodeTreeNode): integer;
|
||||||
begin
|
begin
|
||||||
Result:=CircleOfGraphNodes.Count-1;
|
Result:=CycleOfGraphNodes.Count-1;
|
||||||
while (Result>=0)
|
while (Result>=0)
|
||||||
and (TCodeGraphNode(CircleOfGraphNodes[Result]).Node<>Node) do
|
and (TCodeGraphNode(CycleOfGraphNodes[Result]).Node<>Node) do
|
||||||
dec(Result);
|
dec(Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -4341,17 +4356,18 @@ function TCodeCompletionCodeTool.FixForwardDefinitions(
|
|||||||
Indent: LongInt;
|
Indent: LongInt;
|
||||||
FromPos: LongInt;
|
FromPos: LongInt;
|
||||||
ToPos: LongInt;
|
ToPos: LongInt;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
// check if whole type sections are moved and combine them
|
// check if whole type sections are moved and combine them
|
||||||
i:=CircleOfGraphNodes.Count-1;
|
i:=CycleOfGraphNodes.Count-1;
|
||||||
while i>=0 do begin
|
while i>=0 do begin
|
||||||
GraphNode:=TCodeGraphNode(CircleOfGraphNodes[i]);
|
GraphNode:=TCodeGraphNode(CycleOfGraphNodes[i]);
|
||||||
Node:=GraphNode.Node;
|
Node:=GraphNode.Node;
|
||||||
if Node.Parent.Desc=ctnTypeSection then begin
|
if Node.Parent.Desc=ctnTypeSection then begin
|
||||||
if IndexOfNode(Node.Parent)>=0 then begin
|
if IndexOfNode(Node.Parent)>=0 then begin
|
||||||
// the whole type section of this type will be moved
|
// the whole type section of this type will be moved
|
||||||
// => remove this type
|
// => remove this type
|
||||||
CircleOfGraphNodes.Delete(i);
|
CycleOfGraphNodes.Delete(i);
|
||||||
end else begin
|
end else begin
|
||||||
// check if all types of this type section will be moved
|
// check if all types of this type section will be moved
|
||||||
Node:=Node.Parent.FirstChild;
|
Node:=Node.Parent.FirstChild;
|
||||||
@ -4360,8 +4376,8 @@ function TCodeCompletionCodeTool.FixForwardDefinitions(
|
|||||||
if Node=nil then begin
|
if Node=nil then begin
|
||||||
// all types of this type section will be moved
|
// all types of this type section will be moved
|
||||||
// => remove the type and add the type section instead
|
// => remove the type and add the type section instead
|
||||||
CircleOfGraphNodes.Delete(i);
|
CycleOfGraphNodes.Delete(i);
|
||||||
CircleOfGraphNodes.Add(Graph.AddGraphNode(GraphNode.Node.Parent));
|
CycleOfGraphNodes.Add(Graph.AddGraphNode(GraphNode.Node.Parent));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -4369,21 +4385,22 @@ function TCodeCompletionCodeTool.FixForwardDefinitions(
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// create new type section
|
// create new type section
|
||||||
|
Beauty:=SourceChangeCache.BeautifyCodeOptions;
|
||||||
// Note: InsertPos must be outside the types and type sections which are moved
|
// Note: InsertPos must be outside the types and type sections which are moved
|
||||||
GraphNode:=TCodeGraphNode(CircleOfGraphNodes[0]);
|
GraphNode:=TCodeGraphNode(CycleOfGraphNodes[0]);
|
||||||
Node:=GraphNode.Node;
|
Node:=GraphNode.Node;
|
||||||
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:=GetLineIndent(Src,Node.StartPos);
|
||||||
SourceChangeCache.Replace(gtEmptyLine,gtNewLine,InsertPos,InsertPos,
|
SourceChangeCache.Replace(gtEmptyLine,gtNewLine,InsertPos,InsertPos,
|
||||||
GetIndentStr(Indent)+'type');
|
Beauty.GetIndentStr(Indent)+'type');
|
||||||
inc(Indent,SourceChangeCache.BeautifyCodeOptions.Indent);
|
inc(Indent,Beauty.Indent);
|
||||||
// move the types
|
// move the types
|
||||||
for i:=0 to CircleOfGraphNodes.Count-1 do begin
|
for i:=0 to CycleOfGraphNodes.Count-1 do begin
|
||||||
GraphNode:=TCodeGraphNode(CircleOfGraphNodes[i]);
|
GraphNode:=TCodeGraphNode(CycleOfGraphNodes[i]);
|
||||||
Node:=GraphNode.Node;
|
Node:=GraphNode.Node;
|
||||||
if i=CircleOfGraphNodes.Count-1 then
|
if i=CycleOfGraphNodes.Count-1 then
|
||||||
EndGap:=gtEmptyLine
|
EndGap:=gtEmptyLine
|
||||||
else
|
else
|
||||||
EndGap:=gtNewLine;
|
EndGap:=gtNewLine;
|
||||||
@ -4397,7 +4414,7 @@ function TCodeCompletionCodeTool.FixForwardDefinitions(
|
|||||||
if Node.FirstChild<>nil then begin
|
if Node.FirstChild<>nil then begin
|
||||||
FromPos:=FindLineEndOrCodeInFrontOfPosition(Node.FirstChild.StartPos);
|
FromPos:=FindLineEndOrCodeInFrontOfPosition(Node.FirstChild.StartPos);
|
||||||
ToPos:=FindLineEndOrCodeAfterPosition(Node.LastChild.EndPos);
|
ToPos:=FindLineEndOrCodeAfterPosition(Node.LastChild.EndPos);
|
||||||
NewTxt:=GetIndentStr(Indent)+ExtractCode(FromPos,ToPos,[phpWithComments]);
|
NewTxt:=Beauty.GetIndentStr(Indent)+ExtractCode(FromPos,ToPos,[phpWithComments]);
|
||||||
DebugLn(['CreateTypeSectionForCircle Adding types: ',NewTxt]);
|
DebugLn(['CreateTypeSectionForCircle Adding types: ',NewTxt]);
|
||||||
SourceChangeCache.Replace(gtNewLine,EndGap,InsertPos,InsertPos,NewTxt);
|
SourceChangeCache.Replace(gtNewLine,EndGap,InsertPos,InsertPos,NewTxt);
|
||||||
end;
|
end;
|
||||||
@ -4408,7 +4425,7 @@ function TCodeCompletionCodeTool.FixForwardDefinitions(
|
|||||||
DebugLn(['CreateTypeSectionForCircle Removing node: ',ExtractCode(FromPos,ToPos,[])]);
|
DebugLn(['CreateTypeSectionForCircle Removing node: ',ExtractCode(FromPos,ToPos,[])]);
|
||||||
SourceChangeCache.Replace(gtNone,gtNone,FromPos,ToPos,'');
|
SourceChangeCache.Replace(gtNone,gtNone,FromPos,ToPos,'');
|
||||||
// add type to new type section
|
// add type to new type section
|
||||||
NewTxt:=GetIndentStr(Indent)+ExtractNode(Node,[phpWithComments]);
|
NewTxt:=Beauty.GetIndentStr(Indent)+ExtractNode(Node,[phpWithComments]);
|
||||||
DebugLn(['CreateTypeSectionForCircle Adding type: ',NewTxt]);
|
DebugLn(['CreateTypeSectionForCircle Adding type: ',NewTxt]);
|
||||||
SourceChangeCache.Replace(gtNewLine,EndGap,InsertPos,InsertPos,NewTxt);
|
SourceChangeCache.Replace(gtNewLine,EndGap,InsertPos,InsertPos,NewTxt);
|
||||||
end else
|
end else
|
||||||
@ -4613,6 +4630,7 @@ function TCodeCompletionCodeTool.FixForwardDefinitions(
|
|||||||
DestSection: TCodeTreeNodeDesc;
|
DestSection: TCodeTreeNodeDesc;
|
||||||
NewTxt: String;
|
NewTxt: String;
|
||||||
DestNodeInFront: TCodeTreeNode;
|
DestNodeInFront: TCodeTreeNode;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
AVLNode:=TreeOfNodeMoveEdges.FindLowest;
|
AVLNode:=TreeOfNodeMoveEdges.FindLowest;
|
||||||
@ -4620,6 +4638,7 @@ function TCodeCompletionCodeTool.FixForwardDefinitions(
|
|||||||
LastInsertAtSamePos:=false;
|
LastInsertAtSamePos:=false;
|
||||||
DestNode:=nil;
|
DestNode:=nil;
|
||||||
DestSection:=ctnNone;
|
DestSection:=ctnNone;
|
||||||
|
Beauty:=SourceChangeCache.BeautifyCodeOptions;
|
||||||
// process every move
|
// process every move
|
||||||
while AVLNode<>nil do begin
|
while AVLNode<>nil do begin
|
||||||
CurMove:=TNodeMoveEdge(AVLNode.Data);
|
CurMove:=TNodeMoveEdge(AVLNode.Data);
|
||||||
@ -4797,7 +4816,7 @@ function TCodeCompletionCodeTool.FixForwardDefinitions(
|
|||||||
InsertPos,InsertPos,NewTxt)
|
InsertPos,InsertPos,NewTxt)
|
||||||
then
|
then
|
||||||
exit;
|
exit;
|
||||||
Indent:=SourceChangeCache.BeautifyCodeOptions.Indent;
|
Indent:=Beauty.Indent;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -4817,7 +4836,7 @@ function TCodeCompletionCodeTool.FixForwardDefinitions(
|
|||||||
ToPos:=FindLineEndOrCodeAfterPosition(Node.EndPos);
|
ToPos:=FindLineEndOrCodeAfterPosition(Node.EndPos);
|
||||||
NewTxt:=ExtractCode(FromPos,ToPos,[phpWithComments]);
|
NewTxt:=ExtractCode(FromPos,ToPos,[phpWithComments]);
|
||||||
end;
|
end;
|
||||||
NewTxt:=GetIndentStr(Indent)+NewTxt;
|
NewTxt:=Beauty.GetIndentStr(Indent)+NewTxt;
|
||||||
DebugLn(['MoveNodes insert "',NewTxt,'"']);
|
DebugLn(['MoveNodes insert "',NewTxt,'"']);
|
||||||
if not SourceChangeCache.Replace(gtNewLine,gtNewLine,InsertPos,InsertPos,
|
if not SourceChangeCache.Replace(gtNewLine,gtNewLine,InsertPos,InsertPos,
|
||||||
NewTxt) then exit;
|
NewTxt) then exit;
|
||||||
@ -5691,12 +5710,14 @@ var
|
|||||||
IndentStep: LongInt;
|
IndentStep: LongInt;
|
||||||
SrcVar: String;
|
SrcVar: String;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
NewPos:=CleanCodeXYPosition;
|
NewPos:=CleanCodeXYPosition;
|
||||||
NewTopLine:=-1;
|
NewTopLine:=-1;
|
||||||
if ClassNode=nil then exit;
|
if ClassNode=nil then exit;
|
||||||
if (ParamName='') or (ParamType='') then exit;
|
if (ParamName='') or (ParamType='') then exit;
|
||||||
|
Beauty:=SourceChanger.BeautifyCodeOptions;
|
||||||
aClassName:=ExtractClassName(ClassNode,false);
|
aClassName:=ExtractClassName(ClassNode,false);
|
||||||
CleanDef:=ProcName+'('+ParamType+');';
|
CleanDef:=ProcName+'('+ParamType+');';
|
||||||
Def:='procedure '+ProcName+'('+ParamName+':'+ParamType+');';
|
Def:='procedure '+ProcName+'('+ParamName+':'+ParamType+');';
|
||||||
@ -5720,7 +5741,7 @@ begin
|
|||||||
SrcVar:='aSource';
|
SrcVar:='aSource';
|
||||||
end;
|
end;
|
||||||
ProcBody:=ProcBody+'var'+e
|
ProcBody:=ProcBody+'var'+e
|
||||||
+GetIndentStr(Indent+IndentStep)+SrcVar+':'+aClassName+';'+e;
|
+Beauty.GetIndentStr(Indent+IndentStep)+SrcVar+':'+aClassName+';'+e;
|
||||||
end;
|
end;
|
||||||
ProcBody:=ProcBody+'begin'+e;
|
ProcBody:=ProcBody+'begin'+e;
|
||||||
inc(Indent,IndentStep);
|
inc(Indent,IndentStep);
|
||||||
@ -5728,15 +5749,15 @@ begin
|
|||||||
// call inherited
|
// call inherited
|
||||||
if CallInherited and (not CallInheritedOnlyInElse) then
|
if CallInherited and (not CallInheritedOnlyInElse) then
|
||||||
ProcBody:=ProcBody
|
ProcBody:=ProcBody
|
||||||
+GetIndentStr(Indent)+'inherited '+ProcName+'('+ParamName+');'+e;
|
+Beauty.GetIndentStr(Indent)+'inherited '+ProcName+'('+ParamName+');'+e;
|
||||||
|
|
||||||
if not SameType then begin
|
if not SameType then begin
|
||||||
// add a parameter check to the new procedure
|
// add a parameter check to the new procedure
|
||||||
ProcBody:=ProcBody
|
ProcBody:=ProcBody
|
||||||
+GetIndentStr(Indent)+'if '+ParamName+' is '+aClassName+' then'+e
|
+Beauty.GetIndentStr(Indent)+'if '+ParamName+' is '+aClassName+' then'+e
|
||||||
+GetIndentStr(Indent)+'begin'+e;
|
+Beauty.GetIndentStr(Indent)+'begin'+e;
|
||||||
inc(Indent,IndentStep);
|
inc(Indent,IndentStep);
|
||||||
ProcBody:=ProcBody+GetIndentStr(Indent)+SrcVar+':='+aClassName+'('+ParamName+');'+e;
|
ProcBody:=ProcBody+Beauty.GetIndentStr(Indent)+SrcVar+':='+aClassName+'('+ParamName+');'+e;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// add assignments
|
// add assignments
|
||||||
@ -5744,7 +5765,7 @@ begin
|
|||||||
for i:=0 to MemberNodeExts.Count-1 do begin
|
for i:=0 to MemberNodeExts.Count-1 do begin
|
||||||
NodeExt:=TCodeTreeNodeExtension(MemberNodeExts[i]);
|
NodeExt:=TCodeTreeNodeExtension(MemberNodeExts[i]);
|
||||||
// add assignment
|
// add assignment
|
||||||
ProcBody:=ProcBody+GetIndentStr(Indent)+NodeExt.Txt+':='+SrcVar+'.'+NodeExt.Txt+';'+e;
|
ProcBody:=ProcBody+Beauty.GetIndentStr(Indent)+NodeExt.Txt+':='+SrcVar+'.'+NodeExt.Txt+';'+e;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -5752,10 +5773,10 @@ begin
|
|||||||
// close if block
|
// close if block
|
||||||
dec(Indent,IndentStep);
|
dec(Indent,IndentStep);
|
||||||
if CallInherited and CallInheritedOnlyInElse then begin
|
if CallInherited and CallInheritedOnlyInElse then begin
|
||||||
ProcBody:=ProcBody+GetIndentStr(Indent)+'end else'+e
|
ProcBody:=ProcBody+Beauty.GetIndentStr(Indent)+'end else'+e
|
||||||
+GetIndentStr(Indent+IndentStep)+'inherited '+ProcName+'('+ParamName+');'+e;
|
+Beauty.GetIndentStr(Indent+IndentStep)+'inherited '+ProcName+'('+ParamName+');'+e;
|
||||||
end else begin
|
end else begin
|
||||||
ProcBody:=ProcBody+GetIndentStr(Indent)+'end;'+e
|
ProcBody:=ProcBody+Beauty.GetIndentStr(Indent)+'end;'+e
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
// close procedure body
|
// close procedure body
|
||||||
@ -6035,6 +6056,7 @@ var
|
|||||||
Indent: Integer;
|
Indent: Integer;
|
||||||
Node: TCodeTreeNode;
|
Node: TCodeTreeNode;
|
||||||
NeedSection: Boolean;
|
NeedSection: Boolean;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
@ -6047,6 +6069,7 @@ begin
|
|||||||
Indent:=0;
|
Indent:=0;
|
||||||
FrontGap:=gtNewLine;
|
FrontGap:=gtNewLine;
|
||||||
AfterGap:=gtNewLine;
|
AfterGap:=gtNewLine;
|
||||||
|
Beauty:=SourceChangeCache.BeautifyCodeOptions;
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
debugln(['TCodeCompletionCodeTool.DeclareVariableAt CursorNode=',CursorNode.DescAsString]);
|
debugln(['TCodeCompletionCodeTool.DeclareVariableAt CursorNode=',CursorNode.DescAsString]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -6073,8 +6096,7 @@ begin
|
|||||||
if CursorNode.FirstChild<>nil then
|
if CursorNode.FirstChild<>nil then
|
||||||
Indent:=GetLineIndent(Src,CursorNode.FirstChild.StartPos)
|
Indent:=GetLineIndent(Src,CursorNode.FirstChild.StartPos)
|
||||||
else
|
else
|
||||||
Indent:=GetLineIndent(Src,CursorNode.StartPos)
|
Indent:=GetLineIndent(Src,CursorNode.StartPos)+Beauty.Indent;
|
||||||
+SourceChangeCache.BeautifyCodeOptions.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
|
||||||
@ -6094,8 +6116,7 @@ begin
|
|||||||
if Node.LastChild<>nil then
|
if Node.LastChild<>nil then
|
||||||
Indent:=GetLineIndent(Src,Node.LastChild.StartPos)
|
Indent:=GetLineIndent(Src,Node.LastChild.StartPos)
|
||||||
else
|
else
|
||||||
Indent:=GetLineIndent(Src,Node.StartPos)
|
Indent:=GetLineIndent(Src,Node.StartPos)+Beauty.Indent;
|
||||||
+SourceChangeCache.BeautifyCodeOptions.Indent;
|
|
||||||
end else begin
|
end else begin
|
||||||
// start a new var section
|
// start a new var section
|
||||||
NeedSection:=true;
|
NeedSection:=true;
|
||||||
@ -6111,9 +6132,9 @@ begin
|
|||||||
NeedSection:=true;
|
NeedSection:=true;
|
||||||
end;
|
end;
|
||||||
if NeedSection then
|
if NeedSection then
|
||||||
NewCode:='var'+SourceChangeCache.BeautifyCodeOptions.LineEnd
|
NewCode:='var'+Beauty.LineEnd
|
||||||
+GetIndentStr(SourceChangeCache.BeautifyCodeOptions.Indent)+NewCode;
|
+Beauty.GetIndentStr(Beauty.Indent)+NewCode;
|
||||||
NewCode:=SourceChangeCache.BeautifyCodeOptions.BeautifyStatement(NewCode,
|
NewCode:=Beauty.BeautifyStatement(NewCode,
|
||||||
Indent,[bcfIndentExistingLineBreaks]);
|
Indent,[bcfIndentExistingLineBreaks]);
|
||||||
|
|
||||||
SourceChangeCache.BeginUpdate;
|
SourceChangeCache.BeginUpdate;
|
||||||
@ -6728,10 +6749,10 @@ var
|
|||||||
+'('+SetPropertyVariablename+':'+PropType+');'
|
+'('+SetPropertyVariablename+':'+PropType+');'
|
||||||
+BeautifyCodeOpts.LineEnd
|
+BeautifyCodeOpts.LineEnd
|
||||||
+'begin'+BeautifyCodeOpts.LineEnd
|
+'begin'+BeautifyCodeOpts.LineEnd
|
||||||
+GetIndentStr(BeautifyCodeOpts.Indent)
|
+BeautifyCodeOpts.GetIndentStr(BeautifyCodeOpts.Indent)
|
||||||
+'if '+VariableName+'='+SetPropertyVariablename+' then Exit;'
|
+'if '+VariableName+'='+SetPropertyVariablename+' then Exit;'
|
||||||
+BeautifyCodeOpts.LineEnd
|
+BeautifyCodeOpts.LineEnd
|
||||||
+GetIndentStr(BeautifyCodeOpts.Indent)
|
+BeautifyCodeOpts.GetIndentStr(BeautifyCodeOpts.Indent)
|
||||||
+VariableName+':='+SetPropertyVariablename+';'
|
+VariableName+':='+SetPropertyVariablename+';'
|
||||||
+BeautifyCodeOpts.LineEnd
|
+BeautifyCodeOpts.LineEnd
|
||||||
+'end;';
|
+'end;';
|
||||||
@ -6890,9 +6911,11 @@ var ANodeExt: TCodeTreeNodeExtension;
|
|||||||
CurCode: string;
|
CurCode: string;
|
||||||
IsVariable, InsertBehind: boolean;
|
IsVariable, InsertBehind: boolean;
|
||||||
Visibility: TPascalClassSection;
|
Visibility: TPascalClassSection;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
ANodeExt:=FirstInsert;
|
ANodeExt:=FirstInsert;
|
||||||
Visibility:=NewClassPartVisibility[PartType];
|
Visibility:=NewClassPartVisibility[PartType];
|
||||||
|
Beauty:=ASourceChangeCache.BeautifyCodeOptions;
|
||||||
// insert all nodes of specific type
|
// insert all nodes of specific type
|
||||||
while ANodeExt<>nil do begin
|
while ANodeExt<>nil do begin
|
||||||
IsVariable:=NodeExtIsVariable(ANodeExt);
|
IsVariable:=NodeExtIsVariable(ANodeExt);
|
||||||
@ -6939,8 +6962,7 @@ begin
|
|||||||
if ClassSectionNode=nil then begin
|
if ClassSectionNode=nil then begin
|
||||||
// there is no existing class section node
|
// there is no existing class section node
|
||||||
// -> insert in the new one
|
// -> insert in the new one
|
||||||
Indent:=NewClassSectionIndent[Visibility]
|
Indent:=NewClassSectionIndent[Visibility]+Beauty.Indent;
|
||||||
+ASourceChangeCache.BeautifyCodeOptions.Indent;
|
|
||||||
InsertPos:=NewClassSectionInsertPos[Visibility];
|
InsertPos:=NewClassSectionInsertPos[Visibility];
|
||||||
if InsertPos<1 then
|
if InsertPos<1 then
|
||||||
raise Exception.Create('TCodeCompletionCodeTool.InsertNewClassParts inconsistency: missing section: please create a bug report');
|
raise Exception.Create('TCodeCompletionCodeTool.InsertNewClassParts inconsistency: missing section: please create a bug report');
|
||||||
@ -6968,7 +6990,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// find a nice position between similar siblings
|
// find a nice position between similar siblings
|
||||||
case ASourceChangeCache.BeautifyCodeOptions.ClassPartInsertPolicy of
|
case Beauty.ClassPartInsertPolicy of
|
||||||
|
|
||||||
cpipAlphabetically:
|
cpipAlphabetically:
|
||||||
begin
|
begin
|
||||||
@ -7018,7 +7040,7 @@ begin
|
|||||||
break;
|
break;
|
||||||
end else begin
|
end else begin
|
||||||
// the insertion is a method
|
// the insertion is a method
|
||||||
if (not ASourceChangeCache.BeautifyCodeOptions.MixMethodsAndProperties)
|
if (not Beauty.MixMethodsAndProperties)
|
||||||
and (ANode.Desc=ctnProperty) then
|
and (ANode.Desc=ctnProperty) then
|
||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
@ -7062,8 +7084,7 @@ 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)
|
Indent:=GetLineIndent(Src,ClassSectionNode.StartPos)+Beauty.Indent;
|
||||||
+ASourceChangeCache.BeautifyCodeOptions.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)
|
||||||
@ -7071,10 +7092,10 @@ 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:=GetLineIndent(Src,ClassSectionNode.NextBrother.StartPos)
|
||||||
+ASourceChangeCache.BeautifyCodeOptions.Indent
|
+Beauty.Indent
|
||||||
else
|
else
|
||||||
Indent:=GetLineIndent(Src,ClassSectionNode.Parent.StartPos)
|
Indent:=GetLineIndent(Src,ClassSectionNode.Parent.StartPos)
|
||||||
+ASourceChangeCache.BeautifyCodeOptions.Indent;
|
+Beauty.Indent;
|
||||||
end else if (ClassSectionNode.Desc in AllClassBaseSections)
|
end else if (ClassSectionNode.Desc in AllClassBaseSections)
|
||||||
then begin
|
then begin
|
||||||
// skip keyword
|
// skip keyword
|
||||||
@ -7102,17 +7123,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
CurCode:=ANodeExt.ExtTxt1;
|
CurCode:=ANodeExt.ExtTxt1;
|
||||||
CurCode:=ASourceChangeCache.BeautifyCodeOptions.BeautifyStatement(
|
CurCode:=Beauty.BeautifyStatement(CurCode,Indent);
|
||||||
CurCode,Indent);
|
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
DebugLn('TCodeCompletionCodeTool.InsertNewClassParts:');
|
DebugLn('TCodeCompletionCodeTool.InsertNewClassParts:');
|
||||||
DebugLn(CurCode);
|
DebugLn(CurCode);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
ASourceChangeCache.Replace(gtNewLine,gtNewLine,InsertPos,InsertPos,
|
ASourceChangeCache.Replace(gtNewLine,gtNewLine,InsertPos,InsertPos,
|
||||||
CurCode);
|
CurCode);
|
||||||
if (not IsVariable)
|
if (not IsVariable) and (Beauty.MethodInsertPolicy=mipClassOrder) then
|
||||||
and (ASourceChangeCache.BeautifyCodeOptions.MethodInsertPolicy
|
|
||||||
=mipClassOrder) then
|
|
||||||
begin
|
begin
|
||||||
// this was a new method definition and the body should be added in
|
// this was a new method definition and the body should be added in
|
||||||
// Class Order
|
// Class Order
|
||||||
@ -7128,6 +7146,7 @@ function TCodeCompletionCodeTool.InsertAllNewClassParts: boolean;
|
|||||||
var
|
var
|
||||||
NewSectionKeyWordNeeded: boolean;
|
NewSectionKeyWordNeeded: boolean;
|
||||||
NewSection: TPascalClassSection;
|
NewSection: TPascalClassSection;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
|
|
||||||
function GetTopMostPositionNode(Visibility: TPascalClassSection
|
function GetTopMostPositionNode(Visibility: TPascalClassSection
|
||||||
): TCodeTreeNode;
|
): TCodeTreeNode;
|
||||||
@ -7176,6 +7195,7 @@ var
|
|||||||
ANode: TCodeTreeNode;
|
ANode: TCodeTreeNode;
|
||||||
FirstVisibilitySection: TCodeTreeNode;
|
FirstVisibilitySection: TCodeTreeNode;
|
||||||
NewCode: String;
|
NewCode: String;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
NewClassSectionInsertPos[Visibility]:=-1;
|
NewClassSectionInsertPos[Visibility]:=-1;
|
||||||
NewClassSectionIndent[Visibility]:=0;
|
NewClassSectionIndent[Visibility]:=0;
|
||||||
@ -7212,6 +7232,7 @@ var
|
|||||||
the first published section. But if a variable is already
|
the first published section. But if a variable is already
|
||||||
needed in the first published section, then the new section
|
needed in the first published section, then the new section
|
||||||
must be inserted in front of all }
|
must be inserted in front of all }
|
||||||
|
Beauty:=ASourceChangeCache.BeautifyCodeOptions;
|
||||||
FirstVisibilitySection:=GetFirstVisibilitySectionNode;
|
FirstVisibilitySection:=GetFirstVisibilitySectionNode;
|
||||||
if (TopMostPositionNode<>nil)
|
if (TopMostPositionNode<>nil)
|
||||||
and (FirstVisibilitySection<>nil)
|
and (FirstVisibilitySection<>nil)
|
||||||
@ -7257,11 +7278,11 @@ var
|
|||||||
NewClassSectionInsertPos[Visibility]:=ANode.EndPos;
|
NewClassSectionInsertPos[Visibility]:=ANode.EndPos;
|
||||||
end;
|
end;
|
||||||
SectionKeyWord:=PascalClassSectionKeywords[Visibility];
|
SectionKeyWord:=PascalClassSectionKeywords[Visibility];
|
||||||
NewCode:=ASourceChangeCache.BeautifyCodeOptions.BeautifyKeyWord(SectionKeyWord);
|
NewCode:=Beauty.BeautifyKeyWord(SectionKeyWord);
|
||||||
ASourceChangeCache.Replace(gtNewLine,gtNewLine,
|
ASourceChangeCache.Replace(gtNewLine,gtNewLine,
|
||||||
NewClassSectionInsertPos[Visibility],
|
NewClassSectionInsertPos[Visibility],
|
||||||
NewClassSectionInsertPos[Visibility],
|
NewClassSectionInsertPos[Visibility],
|
||||||
GetIndentStr(NewClassSectionIndent[Visibility])+NewCode);
|
Beauty.GetIndentStr(NewClassSectionIndent[Visibility])+NewCode);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -7275,6 +7296,8 @@ begin
|
|||||||
Result:=true;
|
Result:=true;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
Beauty:=ASourceChangeCache.BeautifyCodeOptions;
|
||||||
|
|
||||||
NewSectionKeyWordNeeded:=false;// 'published'/'public' keyword after first private section needed
|
NewSectionKeyWordNeeded:=false;// 'published'/'public' keyword after first private section needed
|
||||||
if CodeCompleteClassNode.Desc = ctnClass then
|
if CodeCompleteClassNode.Desc = ctnClass then
|
||||||
NewSection := pcsPublished
|
NewSection := pcsPublished
|
||||||
@ -7293,8 +7316,8 @@ begin
|
|||||||
ASourceChangeCache.Replace(gtNewLine,gtNewLine,
|
ASourceChangeCache.Replace(gtNewLine,gtNewLine,
|
||||||
NewClassSectionInsertPos[NewSection],
|
NewClassSectionInsertPos[NewSection],
|
||||||
NewClassSectionInsertPos[NewSection],
|
NewClassSectionInsertPos[NewSection],
|
||||||
GetIndentStr(NewClassSectionIndent[NewSection])+
|
Beauty.GetIndentStr(NewClassSectionIndent[NewSection])+
|
||||||
ASourceChangeCache.BeautifyCodeOptions.BeautifyKeyWord(PascalClassSectionKeywords[NewSection]));
|
Beauty.BeautifyKeyWord(PascalClassSectionKeywords[NewSection]));
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
AddClassSection(pcsPublic);
|
AddClassSection(pcsPublic);
|
||||||
@ -7305,8 +7328,8 @@ begin
|
|||||||
ASourceChangeCache.Replace(gtNewLine,gtNewLine,
|
ASourceChangeCache.Replace(gtNewLine,gtNewLine,
|
||||||
NewClassSectionInsertPos[NewSection],
|
NewClassSectionInsertPos[NewSection],
|
||||||
NewClassSectionInsertPos[NewSection],
|
NewClassSectionInsertPos[NewSection],
|
||||||
GetIndentStr(NewClassSectionIndent[NewSection])+
|
Beauty.GetIndentStr(NewClassSectionIndent[NewSection])+
|
||||||
ASourceChangeCache.BeautifyCodeOptions.BeautifyKeyWord(PascalClassSectionKeywords[NewSection]));
|
Beauty.BeautifyKeyWord(PascalClassSectionKeywords[NewSection]));
|
||||||
end;
|
end;
|
||||||
InsertNewClassParts(ncpPublishedVars);
|
InsertNewClassParts(ncpPublishedVars);
|
||||||
InsertNewClassParts(ncpPublishedProcs);
|
InsertNewClassParts(ncpPublishedProcs);
|
||||||
@ -7322,9 +7345,11 @@ var
|
|||||||
InsertPos: LongInt;
|
InsertPos: LongInt;
|
||||||
Indent: LongInt;
|
Indent: LongInt;
|
||||||
StartPos, CommentStart, CommentEnd: TCodeXYPosition;
|
StartPos, CommentStart, CommentEnd: TCodeXYPosition;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
Result:=true;
|
Result:=true;
|
||||||
if not ASourceChangeCache.BeautifyCodeOptions.ClassHeaderComments then exit;
|
Beauty:=ASourceChangeCache.BeautifyCodeOptions;
|
||||||
|
if not Beauty.ClassHeaderComments then exit;
|
||||||
// check if there is already a comment in front of the class
|
// check if there is already a comment in front of the class
|
||||||
|
|
||||||
// find the start of the class (the position in front of the class name)
|
// find the start of the class (the position in front of the class name)
|
||||||
@ -7351,7 +7376,7 @@ begin
|
|||||||
// insert comment in front
|
// insert comment in front
|
||||||
InsertPos:=ClassIdentifierNode.StartPos;
|
InsertPos:=ClassIdentifierNode.StartPos;
|
||||||
Indent:=GetLineIndent(Src,InsertPos);
|
Indent:=GetLineIndent(Src,InsertPos);
|
||||||
Code:=GetIndentStr(Indent)+'{ '+Code+' }';
|
Code:=Beauty.GetIndentStr(Indent)+'{ '+Code+' }';
|
||||||
ASourceChangeCache.Replace(gtEmptyLine,gtEmptyLine,
|
ASourceChangeCache.Replace(gtEmptyLine,gtEmptyLine,
|
||||||
InsertPos,InsertPos,Code);
|
InsertPos,InsertPos,Code);
|
||||||
end;
|
end;
|
||||||
@ -7503,11 +7528,13 @@ procedure TCodeCompletionCodeTool.AddNewPropertyAccessMethodsToClassProcs(
|
|||||||
ClassProcs: TAVLTree; const TheClassName: string);
|
ClassProcs: TAVLTree; const TheClassName: string);
|
||||||
var ANodeExt: TCodeTreeNodeExtension;
|
var ANodeExt: TCodeTreeNodeExtension;
|
||||||
NewNodeExt: TCodeTreeNodeExtension;
|
NewNodeExt: TCodeTreeNodeExtension;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
DebugLn('[TCodeCompletionCodeTool.AddNewPropertyAccessMethodsToClassProcs]');
|
DebugLn('[TCodeCompletionCodeTool.AddNewPropertyAccessMethodsToClassProcs]');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
// add new property access methods to ClassProcs
|
// add new property access methods to ClassProcs
|
||||||
|
Beauty:=ASourceChangeCache.BeautifyCodeOptions;
|
||||||
ANodeExt:=FirstInsert;
|
ANodeExt:=FirstInsert;
|
||||||
while ANodeExt<>nil do begin
|
while ANodeExt<>nil do begin
|
||||||
if not NodeExtIsVariable(ANodeExt) then begin
|
if not NodeExtIsVariable(ANodeExt) then begin
|
||||||
@ -7515,7 +7542,7 @@ begin
|
|||||||
NewNodeExt:=TCodeTreeNodeExtension.Create;
|
NewNodeExt:=TCodeTreeNodeExtension.Create;
|
||||||
with NewNodeExt do begin
|
with NewNodeExt do begin
|
||||||
Txt:=UpperCaseStr(TheClassName)+'.'+ANodeExt.Txt; // Name+ParamTypeList
|
Txt:=UpperCaseStr(TheClassName)+'.'+ANodeExt.Txt; // Name+ParamTypeList
|
||||||
ExtTxt1:=ASourceChangeCache.BeautifyCodeOptions.AddClassAndNameToProc(
|
ExtTxt1:=Beauty.AddClassAndNameToProc(
|
||||||
ANodeExt.ExtTxt1,TheClassName,''); // complete proc head code
|
ANodeExt.ExtTxt1,TheClassName,''); // complete proc head code
|
||||||
ExtTxt3:=ANodeExt.ExtTxt3;
|
ExtTxt3:=ANodeExt.ExtTxt3;
|
||||||
Position:=ANodeExt.Position;
|
Position:=ANodeExt.Position;
|
||||||
@ -7590,7 +7617,7 @@ begin
|
|||||||
if NodeIsFunction(ProcNode) then
|
if NodeIsFunction(ProcNode) then
|
||||||
ProcCall:=Beauty.BeautifyIdentifier('Result')+':='+ProcCall;
|
ProcCall:=Beauty.BeautifyIdentifier('Result')+':='+ProcCall;
|
||||||
ProcCode:=ProcCode+Beauty.LineEnd+'begin'+Beauty.LineEnd
|
ProcCode:=ProcCode+Beauty.LineEnd+'begin'+Beauty.LineEnd
|
||||||
+GetIndentStr(Beauty.Indent)+ProcCall+Beauty.LineEnd+'end;';
|
+Beauty.GetIndentStr(Beauty.Indent)+ProcCall+Beauty.LineEnd+'end;';
|
||||||
ProcCode:=Beauty.BeautifyProc(ProcCode,Indent,false);
|
ProcCode:=Beauty.BeautifyProc(ProcCode,Indent,false);
|
||||||
ANodeExt.ExtTxt3:=ProcCode;
|
ANodeExt.ExtTxt3:=ProcCode;
|
||||||
end;
|
end;
|
||||||
@ -7617,10 +7644,12 @@ var
|
|||||||
OldProcCode: String;
|
OldProcCode: String;
|
||||||
Bodies: TFPList;
|
Bodies: TFPList;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
begin
|
begin
|
||||||
Result:=true;
|
Result:=true;
|
||||||
ProcsCopied:=false;
|
ProcsCopied:=false;
|
||||||
Bodies:=nil;
|
Bodies:=nil;
|
||||||
|
Beauty:=ASourceChangeCache.BeautifyCodeOptions;
|
||||||
try
|
try
|
||||||
// create a mapping in ClassProcs Data to ProcBodyNodes
|
// create a mapping in ClassProcs Data to ProcBodyNodes
|
||||||
GuessMethodDefBodyMapping(ClassProcs,ProcBodyNodes);
|
GuessMethodDefBodyMapping(ClassProcs,ProcBodyNodes);
|
||||||
@ -7643,8 +7672,7 @@ begin
|
|||||||
InsertPos:=BodyNodeExt.Node.StartPos;
|
InsertPos:=BodyNodeExt.Node.StartPos;
|
||||||
InsertEndPos:=BodyProcHeadNode.EndPos;
|
InsertEndPos:=BodyProcHeadNode.EndPos;
|
||||||
Indent:=GetLineIndent(Src,InsertPos);
|
Indent:=GetLineIndent(Src,InsertPos);
|
||||||
NewProcCode:=ASourceChangeCache.BeautifyCodeOptions.BeautifyProc(
|
NewProcCode:=Beauty.BeautifyProc(NewProcCode,Indent,false);
|
||||||
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
|
||||||
// update body
|
// update body
|
||||||
@ -7898,6 +7926,7 @@ const
|
|||||||
phpWithParameterNames,phpWithResultType,phpWithCallingSpecs];
|
phpWithParameterNames,phpWithResultType,phpWithCallingSpecs];
|
||||||
var
|
var
|
||||||
TheClassName: string;
|
TheClassName: string;
|
||||||
|
Beauty: TBeautifyCodeOptions;
|
||||||
|
|
||||||
procedure InsertProcBody(ANodeExt: TCodeTreeNodeExtension;
|
procedure InsertProcBody(ANodeExt: TCodeTreeNodeExtension;
|
||||||
InsertPos, Indent: integer);
|
InsertPos, Indent: integer);
|
||||||
@ -7907,13 +7936,11 @@ var
|
|||||||
ProcCode:=ANodeExt.ExtTxt3
|
ProcCode:=ANodeExt.ExtTxt3
|
||||||
else
|
else
|
||||||
ProcCode:=ANodeExt.ExtTxt1;
|
ProcCode:=ANodeExt.ExtTxt1;
|
||||||
ProcCode:=ASourceChangeCache.BeautifyCodeOptions.AddClassAndNameToProc(
|
ProcCode:=Beauty.AddClassAndNameToProc(ProcCode,TheClassName,'');
|
||||||
ProcCode,TheClassName,'');
|
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
DebugLn('CreateMissingProcBodies InsertProcBody ',TheClassName,' "',ProcCode,'"');
|
DebugLn('CreateMissingProcBodies InsertProcBody ',TheClassName,' "',ProcCode,'"');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
ProcCode:=ASourceChangeCache.BeautifyCodeOptions.BeautifyProc(
|
ProcCode:=Beauty.BeautifyProc(ProcCode,Indent,ANodeExt.ExtTxt3='');
|
||||||
ProcCode,Indent,ANodeExt.ExtTxt3='');
|
|
||||||
ASourceChangeCache.Replace(gtEmptyLine,gtEmptyLine,InsertPos,InsertPos,ProcCode);
|
ASourceChangeCache.Replace(gtEmptyLine,gtEmptyLine,InsertPos,InsertPos,ProcCode);
|
||||||
if FJumpToProcName='' then begin
|
if FJumpToProcName='' then begin
|
||||||
// remember one proc body to jump to after the completion
|
// remember one proc body to jump to after the completion
|
||||||
@ -7939,8 +7966,7 @@ var
|
|||||||
ANode:=TheNodeExt.Node;
|
ANode:=TheNodeExt.Node;
|
||||||
if (ANode<>nil) and (ANode.Desc=ctnProcedure) then begin
|
if (ANode<>nil) and (ANode.Desc=ctnProcedure) then begin
|
||||||
ProcCode:=ExtractProcHead(ANode,ProcAttrDefToBody);
|
ProcCode:=ExtractProcHead(ANode,ProcAttrDefToBody);
|
||||||
TheNodeExt.ExtTxt3:=ASourceChangeCache.BeautifyCodeOptions.BeautifyProc(
|
TheNodeExt.ExtTxt3:=Beauty.BeautifyProc(ProcCode,Indent,true);
|
||||||
ProcCode,Indent,true);
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -8062,7 +8088,7 @@ var
|
|||||||
// class is not in interface section
|
// class is not in interface section
|
||||||
StartSearchProc:=CodeCompleteClassNode.GetTopMostNodeOfType(ctnTypeSection);
|
StartSearchProc:=CodeCompleteClassNode.GetTopMostNodeOfType(ctnTypeSection);
|
||||||
end;
|
end;
|
||||||
case ASourceChangeCache.BeautifyCodeOptions.ForwardProcBodyInsertPolicy of
|
case Beauty.ForwardProcBodyInsertPolicy of
|
||||||
fpipInFrontOfMethods:
|
fpipInFrontOfMethods:
|
||||||
begin
|
begin
|
||||||
// Try to insert new proc in front of existing methods
|
// Try to insert new proc in front of existing methods
|
||||||
@ -8130,7 +8156,7 @@ var
|
|||||||
begin
|
begin
|
||||||
// insert class comment
|
// insert class comment
|
||||||
if ClassProcs.Count=0 then exit;
|
if ClassProcs.Count=0 then exit;
|
||||||
if not ASourceChangeCache.BeautifyCodeOptions.ClassImplementationComments
|
if not Beauty.ClassImplementationComments
|
||||||
then
|
then
|
||||||
exit;
|
exit;
|
||||||
// find the start of the class (the position in front of the class name)
|
// find the start of the class (the position in front of the class name)
|
||||||
@ -8139,7 +8165,7 @@ var
|
|||||||
// comment already exists
|
// comment already exists
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
ClassStartComment:=GetIndentStr(Indent)
|
ClassStartComment:=Beauty.GetIndentStr(Indent)
|
||||||
+'{ '+ExtractClassName(CodeCompleteClassNode,false)+' }';
|
+'{ '+ExtractClassName(CodeCompleteClassNode,false)+' }';
|
||||||
ASourceChangeCache.Replace(gtEmptyLine,gtEmptyLine,InsertPos,InsertPos,
|
ASourceChangeCache.Replace(gtEmptyLine,gtEmptyLine,InsertPos,InsertPos,
|
||||||
ClassStartComment);
|
ClassStartComment);
|
||||||
@ -8162,7 +8188,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
Result:=false;
|
Result:=false;
|
||||||
MethodInsertPolicy:=ASourceChangeCache.BeautifyCodeOptions.MethodInsertPolicy;
|
Beauty:=ASourceChangeCache.BeautifyCodeOptions;
|
||||||
|
MethodInsertPolicy:=Beauty.MethodInsertPolicy;
|
||||||
// gather existing class proc bodies
|
// gather existing class proc bodies
|
||||||
ClassProcs:=nil;
|
ClassProcs:=nil;
|
||||||
ProcBodyNodes:=nil;
|
ProcBodyNodes:=nil;
|
||||||
@ -8662,7 +8689,7 @@ begin
|
|||||||
phpWithResultType,phpWithCallingSpecs]);
|
phpWithResultType,phpWithCallingSpecs]);
|
||||||
ProcCode:=ProcCode+Beautifier.LineEnd
|
ProcCode:=ProcCode+Beautifier.LineEnd
|
||||||
+'begin'+Beautifier.LineEnd
|
+'begin'+Beautifier.LineEnd
|
||||||
+GetIndentStr(Beautifier.Indent)+Beautifier.LineEnd
|
+Beautifier.GetIndentStr(Beautifier.Indent)+Beautifier.LineEnd
|
||||||
+'end;';
|
+'end;';
|
||||||
|
|
||||||
// add method data
|
// add method data
|
||||||
|
@ -165,6 +165,7 @@ type
|
|||||||
|
|
||||||
NestedComments: boolean;
|
NestedComments: boolean;
|
||||||
|
|
||||||
|
function GetIndentStr(TheIndent: integer): string; inline;
|
||||||
procedure SetupWordPolicyExceptions(ws: TStrings);
|
procedure SetupWordPolicyExceptions(ws: TStrings);
|
||||||
function BeautifyProc(const AProcCode: string; IndentSize: integer;
|
function BeautifyProc(const AProcCode: string; IndentSize: integer;
|
||||||
AddBeginEnd: boolean): string;
|
AddBeginEnd: boolean): string;
|
||||||
@ -1225,6 +1226,12 @@ end;
|
|||||||
|
|
||||||
{ TBeautifyCodeOptions }
|
{ TBeautifyCodeOptions }
|
||||||
|
|
||||||
|
// inline
|
||||||
|
function TBeautifyCodeOptions.GetIndentStr(TheIndent: integer): string;
|
||||||
|
begin
|
||||||
|
Result:=BasicCodeTools.GetIndentStr(TheIndent,UseTabWidth);
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TBeautifyCodeOptions.Create;
|
constructor TBeautifyCodeOptions.Create;
|
||||||
begin
|
begin
|
||||||
LineLength:=80;
|
LineLength:=80;
|
||||||
|
Loading…
Reference in New Issue
Block a user