codetools: remove empty methods: implemented returning list of removed definitions

git-svn-id: trunk@14986 -
This commit is contained in:
mattias 2008-04-26 19:18:57 +00:00
parent 816226e560
commit 5e41e48a30
4 changed files with 35 additions and 11 deletions

View File

@ -253,7 +253,9 @@ type
function RemoveEmptyMethods(CursorPos: TCodeXYPosition; function RemoveEmptyMethods(CursorPos: TCodeXYPosition;
const Sections: TPascalClassSections; const Sections: TPascalClassSections;
SourceChangeCache: TSourceChangeCache; SourceChangeCache: TSourceChangeCache;
out AllRemoved: boolean): boolean; out AllRemoved: boolean;
const Attr: TProcHeadAttributes;
out RemovedProcHeads: TStrings): boolean;
// custom class completion // custom class completion
function InitClassCompletion(const UpperClassName: string; function InitClassCompletion(const UpperClassName: string;
@ -4141,7 +4143,8 @@ end;
function TCodeCompletionCodeTool.RemoveEmptyMethods(CursorPos: TCodeXYPosition; function TCodeCompletionCodeTool.RemoveEmptyMethods(CursorPos: TCodeXYPosition;
const Sections: TPascalClassSections; SourceChangeCache: TSourceChangeCache; const Sections: TPascalClassSections; SourceChangeCache: TSourceChangeCache;
out AllRemoved: boolean): boolean; out AllRemoved: boolean;
const Attr: TProcHeadAttributes; out RemovedProcHeads: TStrings): boolean;
var var
ProcBodyNodes: TAVLTree; ProcBodyNodes: TAVLTree;
AVLNode: TAVLTreeNode; AVLNode: TAVLTreeNode;
@ -4157,9 +4160,11 @@ var
CommentStartPos: integer; CommentStartPos: integer;
ProcDefNodes: TAVLTree; ProcDefNodes: TAVLTree;
NextAVLNode: TAVLTreeNode; NextAVLNode: TAVLTreeNode;
ProcHead: String;
begin begin
Result:=false; Result:=false;
AllRemoved:=false; AllRemoved:=false;
RemovedProcHeads:=nil;
if (SourceChangeCache=nil) or (Scanner=nil) then exit; if (SourceChangeCache=nil) or (Scanner=nil) then exit;
SourceChangeCache.MainScanner:=Scanner; SourceChangeCache.MainScanner:=Scanner;
ProcBodyNodes:=TAVLTree.Create(@CompareCodeTreeNodeExt); ProcBodyNodes:=TAVLTree.Create(@CompareCodeTreeNodeExt);
@ -4219,6 +4224,10 @@ begin
NodeExt.Position:=NodeExt.Node.StartPos; NodeExt.Position:=NodeExt.Node.StartPos;
if (NodeExt.Node<>nil) and (ProcDefNodes.Find(NodeExt)=nil) then begin if (NodeExt.Node<>nil) and (ProcDefNodes.Find(NodeExt)=nil) then begin
ProcDefNodes.Add(NodeExt); ProcDefNodes.Add(NodeExt);
if RemovedProcHeads=nil then
RemovedProcHeads:=TStringList.Create;
ProcHead:=ExtractProcHead(NodeExt.Node,Attr);
RemovedProcHeads.Add(ProcHead);
end else begin end else begin
NodeExt.Free; NodeExt.Free;
end; end;

View File

@ -478,7 +478,9 @@ type
out AllEmpty: boolean): boolean; out AllEmpty: boolean): boolean;
function RemoveEmptyMethods(Code: TCodeBuffer; X,Y: integer; function RemoveEmptyMethods(Code: TCodeBuffer; X,Y: integer;
const Sections: TPascalClassSections; const Sections: TPascalClassSections;
out AllRemoved: boolean): boolean; out AllRemoved: boolean;
const Attr: TProcHeadAttributes;
out RemovedProcHeads: TStrings): boolean;
// custom class completion // custom class completion
function InitClassCompletion(Code: TCodeBuffer; function InitClassCompletion(Code: TCodeBuffer;
@ -3342,7 +3344,8 @@ begin
end; end;
function TCodeToolManager.RemoveEmptyMethods(Code: TCodeBuffer; X,Y: integer; function TCodeToolManager.RemoveEmptyMethods(Code: TCodeBuffer; X,Y: integer;
const Sections: TPascalClassSections; out AllRemoved: boolean): boolean; const Sections: TPascalClassSections; out AllRemoved: boolean;
const Attr: TProcHeadAttributes; out RemovedProcHeads: TStrings): boolean;
var var
CursorPos: TCodeXYPosition; CursorPos: TCodeXYPosition;
begin begin
@ -3356,7 +3359,7 @@ begin
CursorPos.Code:=Code; CursorPos.Code:=Code;
try try
Result:=FCurCodeTool.RemoveEmptyMethods(CursorPos,Sections, Result:=FCurCodeTool.RemoveEmptyMethods(CursorPos,Sections,
SourceChangeCache,AllRemoved); SourceChangeCache,AllRemoved,Attr,RemovedProcHeads);
except except
on e: Exception do Result:=HandleException(e); on e: Exception do Result:=HandleException(e);
end; end;

View File

@ -30,7 +30,8 @@ program RemoveEmptyMethods;
uses uses
Classes, SysUtils, CodeCache, CodeToolManager, DefineTemplates, Classes, SysUtils, CodeCache, CodeToolManager, DefineTemplates,
CodeAtom, CodeToolsConfig, CodeToolsStructs, EmptyMethods1; CodeAtom, CodeToolsConfig, CodeToolsStructs, PascalParserTool,
EmptyMethods1;
const const
ConfigFilename = 'codetools.config'; ConfigFilename = 'codetools.config';
@ -44,6 +45,7 @@ var
P: PCodeXYPosition; P: PCodeXYPosition;
All: boolean; All: boolean;
Sections: TPascalClassSections; Sections: TPascalClassSections;
RemovedProcHeads: TStrings;
begin begin
if (ParamCount>=1) and (Paramcount<>3) then begin if (ParamCount>=1) and (Paramcount<>3) then begin
writeln('Usage:'); writeln('Usage:');
@ -79,15 +81,18 @@ begin
P:=PCodeXYPosition(ListOfPCodeXYPosition[i]); P:=PCodeXYPosition(ListOfPCodeXYPosition[i]);
writeln(i,' ',DbgsCXY(P^)); writeln(i,' ',DbgsCXY(P^));
end; end;
if CodeToolBoss.RemoveEmptyMethods(Code,X,Y,Sections,All) if CodeToolBoss.RemoveEmptyMethods(Code,X,Y,Sections,All,[],RemovedProcHeads)
then begin then begin
writeln('Empty methods removed:'); writeln('Empty methods removed:');
if RemovedProcHeads<>nil then
writeln(RemovedProcHeads.Text);
writeln('========================='); writeln('=========================');
writeln(Code.Source); writeln(Code.Source);
writeln('========================='); writeln('=========================');
end else begin end else begin
writeln('RemoveEmptyMethods failed: ',CodeToolBoss.ErrorMessage); writeln('RemoveEmptyMethods failed: ',CodeToolBoss.ErrorMessage);
end; end;
RemovedProcHeads.Free;
end else begin end else begin
writeln('FindEmptyMethods failed: ',CodeToolBoss.ErrorMessage); writeln('FindEmptyMethods failed: ',CodeToolBoss.ErrorMessage);
end; end;

View File

@ -159,12 +159,19 @@ end;
procedure TEmptyMethodsDialog.OKButtonClick(Sender: TObject); procedure TEmptyMethodsDialog.OKButtonClick(Sender: TObject);
var var
AllEmpty: boolean; AllEmpty: boolean;
RemovedProcHeads: TStrings;
begin begin
DebugLn(['TEmptyMethodsDialog.OKButtonClick ']); DebugLn(['TEmptyMethodsDialog.OKButtonClick ']);
if (not CodeToolBoss.RemoveEmptyMethods(Code,Caret.X,Caret.Y,Sections,AllEmpty)) RemovedProcHeads:=nil;
then begin try
DebugLn(['TEmptyMethodsDialog.OKButtonClick failed']); if (not CodeToolBoss.RemoveEmptyMethods(Code,Caret.X,Caret.Y,Sections,
exit; AllEmpty,[],RemovedProcHeads))
then begin
DebugLn(['TEmptyMethodsDialog.OKButtonClick failed']);
exit;
end;
finally
RemovedProcHeads.Free;
end; end;
ModalResult:=mrOk; ModalResult:=mrOk;
end; end;