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

View File

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

View File

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

View File

@ -1285,10 +1285,19 @@ begin
if (ItemIndex<FRows.Count-1) then ItemIndex:=ItemIndex+1;
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:
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:
SetRowValue;