codetools: added ExtractOperand

git-svn-id: trunk@21937 -
This commit is contained in:
mattias 2009-10-01 10:41:33 +00:00
parent 580cd00451
commit 406489f03e
3 changed files with 48 additions and 3 deletions

View File

@ -463,6 +463,8 @@ type
ResolveComments: boolean): boolean;
function ReplaceCode(Code: TCodeBuffer; StartX, StartY: integer;
EndX, EndY: integer; const NewCode: string): boolean;
function ExtractOperand(Code: TCodeBuffer; X,Y: integer;
out Operand: string; WithAsOperator: boolean): boolean;
// code completion = auto class completion, auto forward proc completion,
// local var assignment completion, event assignment completion
@ -2537,6 +2539,27 @@ begin
end;
end;
function TCodeToolManager.ExtractOperand(Code: TCodeBuffer; X, Y: integer; out
Operand: string; WithAsOperator: boolean): boolean;
var
CursorPos: TCodeXYPosition;
begin
Result:=false;
{$IFDEF CTDEBUG}
DebugLn('TCodeToolManager.ExtractOperand A ',Code.Filename);
{$ENDIF}
Operand:='';
if not InitCurCodeTool(Code) then exit;
CursorPos.X:=X;
CursorPos.Y:=Y;
CursorPos.Code:=Code;
try
Result:=FCurCodeTool.ExtractOperand(CursorPos,Operand,WithAsOperator);
except
on e: Exception do HandleException(e);
end;
end;
function TCodeToolManager.GuessMisplacedIfdefEndif(Code: TCodeBuffer; X,Y: integer;
var NewCode: TCodeBuffer;
var NewX, NewY, NewTopLine: integer): boolean;

View File

@ -4067,9 +4067,10 @@ begin
// some space/comments were skipped
// -> check if a space must be inserted
if AddAtom
and ((phpCommentsToSpace in Attr)
or ((CurPos.StartPos<=SrcLen) and (IsIdentStartChar[Src[CurPos.StartPos]])
and ExtractStreamEndIsIdentChar))
and ( ((phpCommentsToSpace in Attr) and (CurPos.StartPos>LastAtomEndPos))
or ((CurPos.StartPos<=SrcLen) and (IsIdentStartChar[Src[CurPos.StartPos]])
and ExtractStreamEndIsIdentChar)
)
then begin
ExtractMemStream.Write(space,1);
LastStreamPos:=ExtractMemStream.Position;

View File

@ -255,6 +255,8 @@ type
out StartInStringConst, EndInStringConst: boolean): boolean;
function GetStringConstAsFormatString(StartPos, EndPos: integer;
out FormatStringConstant, FormatParameters: string): boolean;
function ExtractOperand(const CursorPos: TCodeXYPosition;
out Operand: string; WithAsOperator: boolean): boolean;
// resource strings
function GatherResourceStringSections(const CursorPos: TCodeXYPosition;
@ -3493,6 +3495,25 @@ begin
if EndInStringConstant then ;
end;
function TStandardCodeTool.ExtractOperand(const CursorPos: TCodeXYPosition; out
Operand: string; WithAsOperator: boolean): boolean;
var
CleanPos: integer;
StartPos: LongInt;
EndPos: LongInt;
Node: TCodeTreeNode;
begin
Result:=false;
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanPos,[]);
Node:=FindDeepestNodeAtPos(CleanPos,true);
StartPos:=FindStartOfTerm(CleanPos,NodeTermInType(Node));
if StartPos<1 then exit;
EndPos:=FindEndOfTerm(CleanPos,false,WithAsOperator);
if EndPos<1 then exit;
Operand:=ExtractCode(StartPos,EndPos,[phpCommentsToSpace]);
Result:=true;
end;
function TStandardCodeTool.GatherResourceStringSections(
const CursorPos: TCodeXYPosition; PositionList: TCodeXYPositions): boolean;