codetools: added CreatePrivateMethod

git-svn-id: trunk@9478 -
This commit is contained in:
mattias 2006-06-22 18:21:55 +00:00
parent 7a675dec3a
commit 8eb418b76e
2 changed files with 55 additions and 21 deletions

View File

@ -555,7 +555,12 @@ type
function CreatePublishedMethod(Code: TCodeBuffer; const AClassName, function CreatePublishedMethod(Code: TCodeBuffer; const AClassName,
NewMethodName: string; ATypeInfo: PTypeInfo; NewMethodName: string; ATypeInfo: PTypeInfo;
UseTypeInfoForParameters: boolean = false): boolean; UseTypeInfoForParameters: boolean = false): boolean;
// private class parts
function CreatePrivateMethod(Code: TCodeBuffer; const AClassName,
NewMethodName: string; ATypeInfo: PTypeInfo;
UseTypeInfoForParameters: boolean = false): boolean;
// IDE % directives // IDE % directives
function GetIDEDirectives(Code: TCodeBuffer; function GetIDEDirectives(Code: TCodeBuffer;
DirectiveList: TStrings): boolean; DirectiveList: TStrings): boolean;
@ -2521,8 +2526,28 @@ begin
if not Result then exit; if not Result then exit;
try try
SourceChangeCache.Clear; SourceChangeCache.Clear;
Result:=FCurCodeTool.CreatePublishedMethod(UpperCaseStr(AClassName), Result:=FCurCodeTool.CreateMethod(UpperCaseStr(AClassName),
NewMethodName,ATypeInfo,SourceChangeCache,UseTypeInfoForParameters); NewMethodName,ATypeInfo,SourceChangeCache,UseTypeInfoForParameters,
pcsPublished);
except
on e: Exception do Result:=HandleException(e);
end;
end;
function TCodeToolManager.CreatePrivateMethod(Code: TCodeBuffer;
const AClassName, NewMethodName: string; ATypeInfo: PTypeInfo;
UseTypeInfoForParameters: boolean): boolean;
begin
{$IFDEF CTDEBUG}
DebugLn('TCodeToolManager.CreatePrivateMethod A');
{$ENDIF}
Result:=InitCurCodeTool(Code);
if not Result then exit;
try
SourceChangeCache.Clear;
Result:=FCurCodeTool.CreateMethod(UpperCaseStr(AClassName),
NewMethodName,ATypeInfo,SourceChangeCache,UseTypeInfoForParameters,
pcsPrivate);
except except
on e: Exception do Result:=HandleException(e); on e: Exception do Result:=HandleException(e);
end; end;

View File

@ -44,7 +44,7 @@ uses
{$ENDIF} {$ENDIF}
Classes, SysUtils, FileProcs, CodeToolsStrConsts, CodeTree, CodeAtom, Classes, SysUtils, FileProcs, CodeToolsStrConsts, CodeTree, CodeAtom,
PascalParserTool, CodeCompletionTool, KeywordFuncLists, BasicCodeTools, PascalParserTool, CodeCompletionTool, KeywordFuncLists, BasicCodeTools,
LinkScanner, AVL_Tree, TypInfo, LinkScanner, AVL_Tree, TypInfo, CodeToolsStructs,
SourceChanger, FindDeclarationTool, ExtractProcTool; SourceChanger, FindDeclarationTool, ExtractProcTool;
type type
@ -84,14 +84,17 @@ type
function RenamePublishedMethod(ClassNode: TCodeTreeNode; function RenamePublishedMethod(ClassNode: TCodeTreeNode;
const UpperOldMethodName, NewMethodName: string; const UpperOldMethodName, NewMethodName: string;
SourceChangeCache: TSourceChangeCache): boolean; SourceChangeCache: TSourceChangeCache): boolean;
function CreatePublishedMethod(const UpperClassName,
function CreateMethod(const UpperClassName,
AMethodName: string; ATypeInfo: PTypeInfo; AMethodName: string; ATypeInfo: PTypeInfo;
SourceChangeCache: TSourceChangeCache; SourceChangeCache: TSourceChangeCache;
UseTypeInfoForParameters: boolean = false): boolean; UseTypeInfoForParameters: boolean = false;
function CreatePublishedMethod(ClassNode: TCodeTreeNode; Section: TPascalClassSection = pcsPublished): boolean;
function CreateMethod(ClassNode: TCodeTreeNode;
const AMethodName: string; ATypeInfo: PTypeInfo; const AMethodName: string; ATypeInfo: PTypeInfo;
SourceChangeCache: TSourceChangeCache; SourceChangeCache: TSourceChangeCache;
UseTypeInfoForParameters: boolean = false): boolean; UseTypeInfoForParameters: boolean = false;
Section: TPascalClassSection = pcsPublished): boolean;
function CreateExprListFromMethodTypeData(TypeData: PTypeData; function CreateExprListFromMethodTypeData(TypeData: PTypeData;
Params: TFindDeclarationParams): TExprTypeList; Params: TFindDeclarationParams): TExprTypeList;
@ -570,34 +573,36 @@ begin
Result:=SourceChangeCache.Apply; Result:=SourceChangeCache.Apply;
end; end;
function TEventsCodeTool.CreatePublishedMethod(const UpperClassName, function TEventsCodeTool.CreateMethod(const UpperClassName,
AMethodName: string; ATypeInfo: PTypeInfo; AMethodName: string; ATypeInfo: PTypeInfo;
SourceChangeCache: TSourceChangeCache; SourceChangeCache: TSourceChangeCache;
UseTypeInfoForParameters: boolean): boolean; UseTypeInfoForParameters: boolean;
Section: TPascalClassSection): boolean;
var AClassNode: TCodeTreeNode; var AClassNode: TCodeTreeNode;
begin begin
BuildTree(false); BuildTree(false);
if not EndOfSourceFound then exit; if not EndOfSourceFound then exit;
AClassNode:=FindClassNodeInInterface(UpperClassName,true,false,true); AClassNode:=FindClassNodeInInterface(UpperClassName,true,false,true);
Result:=CreatePublishedMethod(AClassNode,AMethodName,ATypeInfo, Result:=CreateMethod(AClassNode,AMethodName,ATypeInfo,
SourceChangeCache,UseTypeInfoForParameters); SourceChangeCache,UseTypeInfoForParameters,Section);
end; end;
function TEventsCodeTool.CreatePublishedMethod(ClassNode: TCodeTreeNode; function TEventsCodeTool.CreateMethod(ClassNode: TCodeTreeNode;
const AMethodName: string; ATypeInfo: PTypeInfo; const AMethodName: string; ATypeInfo: PTypeInfo;
SourceChangeCache: TSourceChangeCache; UseTypeInfoForParameters: boolean SourceChangeCache: TSourceChangeCache; UseTypeInfoForParameters: boolean;
): boolean; Section: TPascalClassSection): boolean;
var var
CleanMethodDefinition, MethodDefinition: string; CleanMethodDefinition, MethodDefinition: string;
FindContext: TFindContext; FindContext: TFindContext;
ATypeData: PTypeData; ATypeData: PTypeData;
NewSection: TNewClassPart;
begin begin
try try
Result:=false; Result:=false;
if (ClassNode=nil) or (ClassNode.Desc<>ctnClass) or (AMethodName='') if (ClassNode=nil) or (ClassNode.Desc<>ctnClass) or (AMethodName='')
or (ATypeInfo=nil) or (SourceChangeCache=nil) or (Scanner=nil) then exit; or (ATypeInfo=nil) or (SourceChangeCache=nil) or (Scanner=nil) then exit;
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
DebugLn('[TEventsCodeTool.CreatePublishedMethod] A AMethodName="',AMethodName,'" in "',MainFilename,'"'); DebugLn('[TEventsCodeTool.CreateMethod] A AMethodName="',AMethodName,'" in "',MainFilename,'"');
{$ENDIF} {$ENDIF}
// initialize class for code completion // initialize class for code completion
CodeCompleteClassNode:=ClassNode; CodeCompleteClassNode:=ClassNode;
@ -619,7 +624,7 @@ begin
end; end;
if not ProcExistsInCodeCompleteClass(CleanMethodDefinition) then begin if not ProcExistsInCodeCompleteClass(CleanMethodDefinition) then begin
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
DebugLn('[TEventsCodeTool.CreatePublishedMethod] insert method definition to class'); DebugLn('[TEventsCodeTool.CreateMethod] insert method definition to class');
{$ENDIF} {$ENDIF}
// insert method definition into class // insert method definition into class
if UseTypeInfoForParameters then begin if UseTypeInfoForParameters then begin
@ -637,13 +642,17 @@ begin
MethodDefinition:=SourceChangeCache.BeautifyCodeOptions. MethodDefinition:=SourceChangeCache.BeautifyCodeOptions.
AddClassAndNameToProc(MethodDefinition, '', AMethodName); AddClassAndNameToProc(MethodDefinition, '', AMethodName);
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
DebugLn('[TEventsCodeTool.CreatePublishedMethod] MethodDefinition="',MethodDefinition,'"'); DebugLn('[TEventsCodeTool.CreateMethod] MethodDefinition="',MethodDefinition,'"');
{$ENDIF} {$ENDIF}
if Section in [pcsPublished,pcsPublic] then
NewSection:=ncpPublishedProcs
else
NewSection:=ncpPrivateProcs;
AddClassInsertion(nil, CleanMethodDefinition, MethodDefinition, AMethodName, AddClassInsertion(nil, CleanMethodDefinition, MethodDefinition, AMethodName,
'', ncpPublishedProcs); '', NewSection);
end; end;
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
DebugLn('[TEventsCodeTool.CreatePublishedMethod] invoke class completion'); DebugLn('[TEventsCodeTool.CreateMethod] invoke class completion');
{$ENDIF} {$ENDIF}
if not InsertAllNewClassParts then if not InsertAllNewClassParts then
RaiseException(ctsErrorDuringInsertingNewClassParts); RaiseException(ctsErrorDuringInsertingNewClassParts);
@ -656,7 +665,7 @@ begin
if not SourceChangeCache.Apply then if not SourceChangeCache.Apply then
RaiseException(ctsUnableToApplyChanges); RaiseException(ctsUnableToApplyChanges);
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
DebugLn('[TEventsCodeTool.CreatePublishedMethod] END'); DebugLn('[TEventsCodeTool.CreateMethod] END');
{$ENDIF} {$ENDIF}
Result:=true; Result:=true;
finally finally