fixed jumping to renamed procs

git-svn-id: trunk@3158 -
This commit is contained in:
mattias 2002-08-18 16:50:07 +00:00
parent 7f229dadde
commit 125edc1935

View File

@ -104,6 +104,10 @@ type
SourceChangeCache: TSourceChangeCache): boolean; SourceChangeCache: TSourceChangeCache): boolean;
procedure AdjustCursor(OldCodePos: TCodePosition; OldTopLine: integer; procedure AdjustCursor(OldCodePos: TCodePosition; OldTopLine: integer;
var NewPos: TCodeXYPosition; var NewTopLine: integer); var NewPos: TCodeXYPosition; var NewTopLine: integer);
function CompleteLocalVariableAssignment(CleanCursorPos,
OldTopLine: integer; CursorNode: TCodeTreeNode;
var NewPos: TCodeXYPosition; var NewTopLine: integer;
SourceChangeCache: TSourceChangeCache): boolean;
protected protected
property CodeCompleteClassNode: TCodeTreeNode property CodeCompleteClassNode: TCodeTreeNode
read ClassNode write SetCodeCompleteClassNode; read ClassNode write SetCodeCompleteClassNode;
@ -593,6 +597,76 @@ begin
//writeln('TCodeCompletionCodeTool.AdjustCursor END NewPos: Line=',NewPos.Y,' Col=',NewPos.X,' NewTopLine=',NewTopLine); //writeln('TCodeCompletionCodeTool.AdjustCursor END NewPos: Line=',NewPos.Y,' Col=',NewPos.X,' NewTopLine=',NewTopLine);
end; end;
function TCodeCompletionCodeTool.CompleteLocalVariableAssignment(
CleanCursorPos, OldTopLine: integer;
CursorNode: TCodeTreeNode;
var NewPos: TCodeXYPosition; var NewTopLine: integer;
SourceChangeCache: TSourceChangeCache): boolean;
var
VarNameAtom, AssignmentOperator, TermAtom: TAtomPosition;
NewType: string;
Params: TFindDeclarationParams;
begin
Result:=false;
{$IFDEF CTDEBUG}
writeln(' CompleteLocalVariableAssignment: A');
{$ENDIF}
if not ((CursorNode.Desc=ctnBeginBlock)
or CursorNode.HasParentOfType(ctnBeginBlock)) then exit;
if CursorNode.Desc=ctnBeginBlock then
BuildSubTreeForBeginBlock(CursorNode);
CursorNode:=FindDeepestNodeAtPos(CleanCursorPos,true);
{$IFDEF CTDEBUG}
writeln(' CompleteLocalVariableAssignment: B CheckLocalVarAssignmentSyntax ...');
{$ENDIF}
// check assignment syntax
if not CheckLocalVarAssignmentSyntax(CleanCursorPos,
VarNameAtom,AssignmentOperator,TermAtom)
then
exit;
// search variable
ActivateGlobalWriteLock;
Params:=TFindDeclarationParams.Create;
try
{$IFDEF CTDEBUG}
writeln(' CompleteLocalVariableAssignment: check if variable is already defined ...');
{$ENDIF}
// check if identifier exists
Result:=IdentifierIsDefined(VarNameAtom,CursorNode,Params);
if Result then begin
MoveCursorToCleanPos(VarNameAtom.StartPos);
ReadNextAtom;
RaiseExceptionFmt(ctsIdentifierAlreadyDefined,[GetAtom]);
end;
{$IFDEF CTDEBUG}
writeln(' CompleteLocalVariableAssignment: Find type of term... ');
{$ENDIF}
// find type of term
NewType:=FindTermTypeAsString(TermAtom,CursorNode,Params);
if NewType='' then
RaiseException('CompleteLocalVariableAssignment Internal error: NewType=""');
finally
Params.Free;
DeactivateGlobalWriteLock;
end;
// all needed parameters found
Result:=true;
// add local variable
if not AddLocalVariable(CleanCursorPos, OldTopLine,
GetAtom(VarNameAtom), NewType,
NewPos, NewTopLine, SourceChangeCache)
then
RaiseException('CompleteLocalVariableAssignment Internal error: AddLocalVariable');
end;
function TCodeCompletionCodeTool.AddPublishedVariable(const UpperClassName, function TCodeCompletionCodeTool.AddPublishedVariable(const UpperClassName,
VarName, VarType: string; SourceChangeCache: TSourceChangeCache): boolean; VarName, VarType: string; SourceChangeCache: TSourceChangeCache): boolean;
begin begin
@ -2012,7 +2086,7 @@ var CleanCursorPos, Indent, insertPos: integer;
Result:=FindJumpPoint(CursorPos,NewPos,NewTopLine,RevertableJump); Result:=FindJumpPoint(CursorPos,NewPos,NewTopLine,RevertableJump);
end; end;
function IsEventAssignment: boolean; function CompleteEventAssignment: boolean;
var SearchedClassName: string; var SearchedClassName: string;
{ examples: { examples:
Button1.OnClick:=| Button1.OnClick:=|
@ -2179,7 +2253,7 @@ var CleanCursorPos, Indent, insertPos: integer;
Result:=false; Result:=false;
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
writeln(' IsEventAssignment: Extract method param list...'); writeln(' CompleteEventAssignment: Extract method param list...');
{$ENDIF} {$ENDIF}
// extract method param list and result type // extract method param list and result type
CleanMethodDefinition:=UpperCaseStr(AnEventName) CleanMethodDefinition:=UpperCaseStr(AnEventName)
@ -2187,7 +2261,7 @@ var CleanCursorPos, Indent, insertPos: integer;
[phpWithoutClassName, phpWithoutName, phpInUpperCase]); [phpWithoutClassName, phpWithoutName, phpInUpperCase]);
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
writeln(' IsEventAssignment: Initializing CodeCompletion...'); writeln(' CompleteEventAssignment: Initializing CodeCompletion...');
{$ENDIF} {$ENDIF}
// initialize class for code completion // initialize class for code completion
CodeCompleteClassNode:=AClassNode; CodeCompleteClassNode:=AClassNode;
@ -2202,7 +2276,7 @@ var CleanCursorPos, Indent, insertPos: integer;
MethodDefinition:=SourceChangeCache.BeautifyCodeOptions. MethodDefinition:=SourceChangeCache.BeautifyCodeOptions.
AddClassAndNameToProc(MethodDefinition, '', AnEventName); AddClassAndNameToProc(MethodDefinition, '', AnEventName);
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
writeln(' IsEventAssignment: Add Method To Class...'); writeln(' CompleteEventAssignment: Add Method To Class...');
{$ENDIF} {$ENDIF}
if not ProcExistsInCodeCompleteClass(CleanMethodDefinition) then begin if not ProcExistsInCodeCompleteClass(CleanMethodDefinition) then begin
// insert method definition into class // insert method definition into class
@ -2220,7 +2294,7 @@ var CleanCursorPos, Indent, insertPos: integer;
RaiseException(ctsErrorDuringCreationOfNewProcBodies); RaiseException(ctsErrorDuringCreationOfNewProcBodies);
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
writeln(' IsEventAssignment: Changing right side of assignment...'); writeln(' CompleteEventAssignment: Changing right side of assignment...');
{$ENDIF} {$ENDIF}
// add new event name as right value of assignment // add new event name as right value of assignment
// add address operator @ if needed or user provided it himself // add address operator @ if needed or user provided it himself
@ -2243,7 +2317,7 @@ var CleanCursorPos, Indent, insertPos: integer;
RValue); RValue);
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
writeln(' IsEventAssignment: Applying changes...'); writeln(' CompleteEventAssignment: Applying changes...');
{$ENDIF} {$ENDIF}
// apply the changes // apply the changes
if not SourceChangeCache.Apply then if not SourceChangeCache.Apply then
@ -2251,7 +2325,7 @@ var CleanCursorPos, Indent, insertPos: integer;
Result:=true; Result:=true;
end; end;
// function IsEventAssignment: boolean // function CompleteEventAssignment: boolean
var var
UserEventAtom, PropertyAtom: TAtomPosition; UserEventAtom, PropertyAtom: TAtomPosition;
AssignmentOperator, AddrOperatorPos, SemicolonPos: integer; AssignmentOperator, AddrOperatorPos, SemicolonPos: integer;
@ -2263,7 +2337,7 @@ var CleanCursorPos, Indent, insertPos: integer;
Result:=false; Result:=false;
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
writeln(' IsEventAssignment: CheckEventAssignmentSyntax...'); writeln(' CompleteEventAssignment: CheckEventAssignmentSyntax...');
{$ENDIF} {$ENDIF}
// check assigment syntax // check assigment syntax
if not CheckEventAssignmentSyntax(PropertyAtom, AssignmentOperator, if not CheckEventAssignmentSyntax(PropertyAtom, AssignmentOperator,
@ -2272,7 +2346,7 @@ var CleanCursorPos, Indent, insertPos: integer;
exit; exit;
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
writeln(' IsEventAssignment: find class of method...'); writeln(' CompleteEventAssignment: find class of method...');
{$ENDIF} {$ENDIF}
if not FindClassAndProcNode then exit; if not FindClassAndProcNode then exit;
@ -2280,7 +2354,7 @@ var CleanCursorPos, Indent, insertPos: integer;
Params:=TFindDeclarationParams.Create; Params:=TFindDeclarationParams.Create;
try try
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
writeln(' IsEventAssignment: FindEventTypeAtCursor...'); writeln(' CompleteEventAssignment: FindEventTypeAtCursor...');
{$ENDIF} {$ENDIF}
// check if identifier is event property and build // check if identifier is event property and build
Result:=FindEventTypeAtCursor(PropertyAtom,PropertyContext,ProcContext, Result:=FindEventTypeAtCursor(PropertyAtom,PropertyContext,ProcContext,
@ -2288,7 +2362,7 @@ var CleanCursorPos, Indent, insertPos: integer;
if not Result then exit; if not Result then exit;
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
writeln(' IsEventAssignment: CreateEventFullName... UserEventAtom.StartPos=',UserEventAtom.StartPos); writeln(' CompleteEventAssignment: CreateEventFullName... UserEventAtom.StartPos=',UserEventAtom.StartPos);
{$ENDIF} {$ENDIF}
// create a nice event name // create a nice event name
FullEventName:=CreateEventFullName(UserEventAtom,PropertyAtom); FullEventName:=CreateEventFullName(UserEventAtom,PropertyAtom);
@ -2304,84 +2378,19 @@ var CleanCursorPos, Indent, insertPos: integer;
AssignmentOperator,AddrOperatorPos,SemicolonPos,UserEventAtom, AssignmentOperator,AddrOperatorPos,SemicolonPos,UserEventAtom,
AMethodDefinition, AMethodAttr) AMethodDefinition, AMethodAttr)
then then
RaiseException('IsEventAssignment Internal Error 1'); RaiseException('CompleteEventAssignment Internal Error 1');
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
writeln(' IsEventAssignment: jumping to new method body...'); writeln(' CompleteEventAssignment: jumping to new method body...');
{$ENDIF} {$ENDIF}
// jump to new method body // jump to new method body
if not JumpToMethod(AMethodDefinition,AMethodAttr,NewPos,NewTopLine,false) if not JumpToMethod(AMethodDefinition,AMethodAttr,NewPos,NewTopLine,false)
then then
RaiseException('IsEventAssignment Internal Error 2'); RaiseException('CompleteEventAssignment Internal Error 2');
CompleteCode:=true; CompleteCode:=true;
end; end;
function IsLocalVariableAssignment: boolean;
var
VarNameAtom, AssignmentOperator, TermAtom: TAtomPosition;
NewType: string;
Params: TFindDeclarationParams;
begin
Result:=false;
{$IFDEF CTDEBUG}
writeln(' IsLocalVariableAssignment: A');
{$ENDIF}
if not ((CursorNode.Desc=ctnBeginBlock)
or CursorNode.HasParentOfType(ctnBeginBlock)) then exit;
if CursorNode.Desc=ctnBeginBlock then
BuildSubTreeForBeginBlock(CursorNode);
CursorNode:=FindDeepestNodeAtPos(CleanCursorPos,true);
{$IFDEF CTDEBUG}
writeln(' IsLocalVariableAssignment: B CheckLocalVarAssignmentSyntax ...');
{$ENDIF}
// check assignment syntax
if not CheckLocalVarAssignmentSyntax(CleanCursorPos,
VarNameAtom,AssignmentOperator,TermAtom)
then
exit;
// search variable
ActivateGlobalWriteLock;
Params:=TFindDeclarationParams.Create;
try
{$IFDEF CTDEBUG}
writeln(' IsLocalVariableAssignment: check if variable is already defined ...');
{$ENDIF}
// check if identifier exists
Result:=IdentifierIsDefined(VarNameAtom,CursorNode,Params);
if Result then begin
MoveCursorToCleanPos(VarNameAtom.StartPos);
ReadNextAtom;
RaiseExceptionFmt(ctsIdentifierAlreadyDefined,[GetAtom]);
end;
{$IFDEF CTDEBUG}
writeln(' IsLocalVariableAssignment: Find type of term... ');
{$ENDIF}
// find type of term
NewType:=FindTermTypeAsString(TermAtom,CursorNode,Params);
if NewType='' then
RaiseException('IsLocalVariableAssignment Internal error: NewType=""');
finally
Params.Free;
DeactivateGlobalWriteLock;
end;
// all needed parameters found
Result:=true;
// add local variable
if not AddLocalVariable(CleanCursorPos, OldTopLine,
GetAtom(VarNameAtom), NewType,
NewPos, NewTopLine, SourceChangeCache)
then
RaiseException('IsLocalVariableAssignment Internal error: AddLocalVariable');
end;
// function CompleteCode(CursorPos: TCodeXYPosition; // function CompleteCode(CursorPos: TCodeXYPosition;
// var NewPos: TCodeXYPosition; var NewTopLine: integer; // var NewPos: TCodeXYPosition; var NewTopLine: integer;
// SourceChangeCache: TSourceChangeCache): boolean; // SourceChangeCache: TSourceChangeCache): boolean;
@ -2426,11 +2435,12 @@ begin
end; end;
// test if Event assignment // test if Event assignment
Result:=IsEventAssignment; Result:=CompleteEventAssignment;
if Result then exit; if Result then exit;
// test if Local variable assignment // test if Local variable assignment
Result:=IsLocalVariableAssignment; Result:=CompleteLocalVariableAssignment(CleanCursorPos,OldTopLine,CursorNode,
NewPos,NewTopLine,SourceChangeCache);
if Result then exit; if Result then exit;
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}