changed consistency stops during method renaming to errors

git-svn-id: trunk@5063 -
This commit is contained in:
mattias 2004-01-13 22:34:06 +00:00
parent 5ae2f7b03e
commit a418b3b9fc
4 changed files with 63 additions and 30 deletions

View File

@ -479,7 +479,6 @@ function TEventsCodeTool.RenamePublishedMethod(const UpperClassName,
var ClassNode: TCodeTreeNode; var ClassNode: TCodeTreeNode;
begin begin
BuildTree(false); BuildTree(false);
if not EndOfSourceFound then exit;
ClassNode:=FindClassNodeInInterface(UpperClassName,true,false,true); ClassNode:=FindClassNodeInInterface(UpperClassName,true,false,true);
Result:=RenamePublishedMethod(ClassNode,UpperOldMethodName,NewMethodName, Result:=RenamePublishedMethod(ClassNode,UpperOldMethodName,NewMethodName,
SourceChangeCache); SourceChangeCache);
@ -489,45 +488,64 @@ function TEventsCodeTool.RenamePublishedMethod(ClassNode: TCodeTreeNode;
const UpperOldMethodName, NewMethodName: string; const UpperOldMethodName, NewMethodName: string;
SourceChangeCache: TSourceChangeCache): boolean; SourceChangeCache: TSourceChangeCache): boolean;
// rename published method in class and in procedure itself // rename published method in class and in procedure itself
var ANode, ProcHeadNode: TCodeTreeNode; var ProcNode, ProcHeadNode: TCodeTreeNode;
NameStart, NameEnd: integer; NameStart, NameEnd: integer;
UpperClassName: string; UpperClassName: string;
ProcBodyNode: TCodeTreeNode;
begin begin
Result:=false; Result:=false;
if (ClassNode=nil) or (ClassNode.Desc<>ctnClass) or (UpperOldMethodName='') if (ClassNode=nil) or (ClassNode.Desc<>ctnClass) then
or (NewMethodName='') or (SourceChangeCache=nil) or (Scanner=nil) then RaiseException('Invalid class node');
exit; if (UpperOldMethodName='') then
RaiseException('Invalid UpperOldMethodName="'+UpperOldMethodName+'"');
if (NewMethodName='') then
RaiseException('Invalid NewMethodName="'+NewMethodName+'"');
if (SourceChangeCache=nil) or (Scanner=nil) then
RaiseException('Invalid SourceChangeCache or Scanner');
SourceChangeCache.MainScanner:=Scanner; SourceChangeCache.MainScanner:=Scanner;
// rename in class // rename in class
ANode:=FindIdentifierNodeInClass(ClassNode,@UpperOldMethodName[1]); ProcNode:=FindIdentifierNodeInClass(ClassNode,@UpperOldMethodName[1]);
if (ANode=nil) then begin if (ProcNode=nil) then begin
MoveCursorToNodeStart(ClassNode); MoveCursorToNodeStart(ClassNode);
RaiseExceptionFmt(ctsOldMethodNotFound,[UpperOldMethodName]); RaiseExceptionFmt(ctsOldMethodNotFound,[UpperOldMethodName]);
end; end;
if (ANode.Desc<>ctnProcedure) then begin if (ProcNode.Desc<>ctnProcedure) then begin
MoveCursorToNodeStart(ANode); MoveCursorToNodeStart(ProcNode);
RaiseExceptionFmt(ctsOldMethodNotFound,[UpperOldMethodName]); RaiseExceptionFmt(ctsOldMethodNotFound,[UpperOldMethodName]);
end; end;
ProcHeadNode:=ANode.FirstChild; ProcHeadNode:=ProcNode.FirstChild;
if ProcHeadNode=nil then exit; if ProcHeadNode=nil then begin
MoveCursorToNodeStart(ProcNode);
RaiseException('Invalid proc header');
end;
NameStart:=ProcHeadNode.StartPos; NameStart:=ProcHeadNode.StartPos;
NameEnd:=NameStart; NameEnd:=NameStart;
while (NameEnd<=SrcLen) and (IsIdentChar[UpperSrc[NameEnd]]) do while (NameEnd<=SrcLen) and (IsIdentChar[UpperSrc[NameEnd]]) do
inc(NameEnd); inc(NameEnd);
if not SourceChangeCache.Replace(gtNone,gtNone,NameStart,NameEnd, if not SourceChangeCache.Replace(gtNone,gtNone,NameStart,NameEnd,
NewMethodName) then exit; NewMethodName)
// rename procedure itself -> find implementation node then begin
MoveCursorToNodeStart(ProcHeadNode);
RaiseException('Unable to rename method declaration');
end;
// main goal achieved
Result:=true;
// rename procedure body -> find implementation node
UpperClassName:=ExtractClassName(ClassNode,true); UpperClassName:=ExtractClassName(ClassNode,true);
ANode:=FindMethodNodeInImplementation(UpperClassName,UpperOldMethodName,false); ProcBodyNode:=FindMethodNodeInImplementation(UpperClassName,
if ANode=nil then exit; UpperOldMethodName,false);
ProcHeadNode:=ANode.FirstChild; if (ProcBodyNode<>nil) and (ProcBodyNode<>nil) then begin
if ProcHeadNode=nil then exit; ProcHeadNode:=ProcBodyNode.FirstChild;
MoveCursorToNodeStart(ProcHeadNode); MoveCursorToNodeStart(ProcHeadNode);
ReadNextAtom; // read class name ReadNextAtom; // read class name
ReadNextAtom; // read '.' ReadNextAtom; // read '.'
ReadNextAtom; // read method name ReadNextAtom; // read method name
Result:=SourceChangeCache.Replace(gtNone,gtNone, SourceChangeCache.Replace(gtNone,gtNone,
CurPos.StartPos,CurPos.EndPos,NewMethodName); CurPos.StartPos,CurPos.EndPos,NewMethodName);
end;
Result:=SourceChangeCache.Apply;
end; end;
function TEventsCodeTool.CreatePublishedMethod(const UpperClassName, function TEventsCodeTool.CreatePublishedMethod(const UpperClassName,

View File

@ -26,7 +26,7 @@
<UsageCount Value="23"/> <UsageCount Value="23"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
<CursorPos X="25" Y="21"/> <CursorPos X="13" Y="20"/>
<EditorIndex Value="0"/> <EditorIndex Value="0"/>
<Filename Value="main.pas"/> <Filename Value="main.pas"/>
<ComponentName Value="Form1"/> <ComponentName Value="Form1"/>

View File

@ -9881,7 +9881,8 @@ end;
procedure TMainIDE.OnPropHookRenameMethod(const CurName, NewName: ShortString); procedure TMainIDE.OnPropHookRenameMethod(const CurName, NewName: ShortString);
var ActiveSrcEdit: TSourceEditor; var ActiveSrcEdit: TSourceEditor;
ActiveUnitInfo: TUnitInfo; ActiveUnitInfo: TUnitInfo;
r: boolean; BossResult: boolean;
ErrorMsg: String;
begin begin
if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[ctfSwitchToFormSource]) if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[ctfSwitchToFormSource])
then exit; then exit;
@ -9892,19 +9893,21 @@ begin
FOpenEditorsOnCodeToolChange:=true; FOpenEditorsOnCodeToolChange:=true;
try try
// create published method // create published method
r:=CodeToolBoss.RenamePublishedMethod(ActiveUnitInfo.Source, BossResult:=CodeToolBoss.RenamePublishedMethod(ActiveUnitInfo.Source,
ActiveUnitInfo.Component.ClassName,CurName,NewName); ActiveUnitInfo.Component.ClassName,CurName,NewName);
{$IFDEF IDE_DEBUG} {$IFDEF IDE_DEBUG}
writeln(''); writeln('');
writeln('[TMainIDE.OnPropHookRenameMethod] ************2 ',r); writeln('[TMainIDE.OnPropHookRenameMethod] ************2 ',r);
{$ENDIF} {$ENDIF}
ApplyCodeToolChanges; ApplyCodeToolChanges;
if r then begin if BossResult then begin
FormEditor1.RenameJITMethod(ActiveUnitInfo.Component,CurName,NewName); FormEditor1.RenameJITMethod(ActiveUnitInfo.Component,CurName,NewName);
end else begin end else begin
ErrorMsg:=CodeToolBoss.ErrorMessage;
DoJumpToCodeToolBossError; DoJumpToCodeToolBossError;
raise Exception.Create( raise Exception.Create(
lisUnableToRenameMethodPlzFixTheErrorShownInTheMessag); lisUnableToRenameMethodPlzFixTheErrorShownInTheMessag
+#13#13+lisError+ErrorMsg);
end; end;
finally finally
FOpenEditorsOnCodeToolChange:=false; FOpenEditorsOnCodeToolChange:=false;
@ -10269,6 +10272,9 @@ end.
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.701 2004/01/13 22:34:05 mattias
changed consistency stops during method renaming to errors
Revision 1.700 2004/01/13 16:39:01 mattias Revision 1.700 2004/01/13 16:39:01 mattias
changed consistency stops during var renaming to errors changed consistency stops during var renaming to errors

View File

@ -1285,10 +1285,19 @@ begin
if (ItemIndex<FRows.Count-1) then ItemIndex:=ItemIndex+1; if (ItemIndex<FRows.Count-1) then ItemIndex:=ItemIndex+1;
VK_LEFT: VK_LEFT:
if (ItemIndex>=0) then (ShrinkRow(ItemIndex)); if (FCurrentEdit=nil)
and (ItemIndex>=0) and (Rows[ItemIndex].Expanded) then
ShrinkRow(ItemIndex)
else
Handled:=false;
VK_RIGHT: VK_RIGHT:
if (ItemIndex>=0) then (ExpandRow(ItemIndex)); if (FCurrentEdit=nil)
and (ItemIndex>=0) and (not Rows[ItemIndex].Expanded)
and (paSubProperties in Rows[ItemIndex].Editor.GetAttributes) then
ExpandRow(ItemIndex)
else
Handled:=false;
VK_RETURN: VK_RETURN:
SetRowValue; SetRowValue;