codetools: moved CommentCode to TStdCodeTool

git-svn-id: trunk@40815 -
This commit is contained in:
mattias 2013-04-15 09:09:08 +00:00
parent 5ee76dbc83
commit a0f58c4b7d
2 changed files with 52 additions and 50 deletions

View File

@ -235,8 +235,6 @@ type
WithCommentBounds, CaseSensitive, IgnoreSpaces, WithCommentBounds, CaseSensitive, IgnoreSpaces,
CompareOnlyStart: boolean; CompareOnlyStart: boolean;
out CommentStart, CommentEnd: integer): boolean; out CommentStart, CommentEnd: integer): boolean;
function CommentCode(const StartPos, EndPos: integer;
SourceChangeCache: TSourceChangeCache; Apply: boolean): boolean;
function GetPasDocComments(const StartPos: TCodeXYPosition; function GetPasDocComments(const StartPos: TCodeXYPosition;
InvokeBuildTree: boolean; InvokeBuildTree: boolean;
out ListOfPCodeXYPosition: TFPList): boolean; out ListOfPCodeXYPosition: TFPList): boolean;
@ -3045,53 +3043,6 @@ begin
CommentEnd:=FoundEndPos; CommentEnd:=FoundEndPos;
end; end;
function TPascalReaderTool.CommentCode(const StartPos, EndPos: integer;
SourceChangeCache: TSourceChangeCache; Apply: boolean): boolean;
var
i: LongInt;
CurStartPos: LongInt;
CommentNeeded: Boolean;
CurEndPos: LongInt;
begin
if StartPos>=EndPos then
RaiseException('TStandardCodeTool CommentCode');
Result:=false;
// comment with curly brackets {}
i:=StartPos;
CurStartPos:=i;
CurEndPos:=CurStartPos;
CommentNeeded:=false;
repeat
//debugln(['TPascalReaderTool.CommentCode ',dbgstr(Src[i]),' Needed=',CommentNeeded,' ',dbgstr(copy(Src,CurStartPos,CurEndPos-CurStartPos))]);
if (Src[i]='{') or (i>=EndPos) then begin
// the area contains a comment -> comment in front
if CommentNeeded then begin
if not SourceChangeCache.Replace(gtNone,gtNone,
CurStartPos,CurStartPos,'{') then exit;
if not SourceChangeCache.Replace(gtNone,gtNone,
CurEndPos,CurEndPos,'}') then exit;
//DebugLn('Comment "',copy(Src,CurStartPos,i-CurStartPos),'"');
CommentNeeded:=false;
end;
if i>=EndPos then break;
// skip comment
i:=FindCommentEnd(Src,i,Scanner.NestedComments)-1;
end else if not IsSpaceChar[Src[i]] then begin
if not CommentNeeded then begin
CurStartPos:=i;
CommentNeeded:=true;
end;
CurEndPos:=i+1;
end;
inc(i);
until false;
if Apply then
Result:=SourceChangeCache.Apply
else
Result:=true;
end;
function TPascalReaderTool.GetPasDocComments(const StartPos: TCodeXYPosition; function TPascalReaderTool.GetPasDocComments(const StartPos: TCodeXYPosition;
InvokeBuildTree: boolean; out ListOfPCodeXYPosition: TFPList): boolean; InvokeBuildTree: boolean; out ListOfPCodeXYPosition: TFPList): boolean;
var var

View File

@ -233,7 +233,7 @@ type
SourceChangeCache: TSourceChangeCache; SourceChangeCache: TSourceChangeCache;
OnlyIfCursorBlockIndented: boolean; OnlyIfCursorBlockIndented: boolean;
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean; out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
// compiler directives // compiler directives
function GuessMisplacedIfdefEndif(const CursorPos: TCodeXYPosition; function GuessMisplacedIfdefEndif(const CursorPos: TCodeXYPosition;
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean; out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
@ -275,6 +275,10 @@ type
SourceChangeCache: TSourceChangeCache; SourceChangeCache: TSourceChangeCache;
SkipPointWords: boolean = false): boolean; SkipPointWords: boolean = false): boolean;
// comments
function CommentCode(const StartPos, EndPos: integer;
SourceChangeCache: TSourceChangeCache; Apply: boolean): boolean;
// expressions // expressions
function GetStringConstBounds(const CursorPos: TCodeXYPosition; function GetStringConstBounds(const CursorPos: TCodeXYPosition;
out StartPos, EndPos: TCodeXYPosition; out StartPos, EndPos: TCodeXYPosition;
@ -3258,6 +3262,53 @@ begin
end; end;
end; end;
function TStandardCodeTool.CommentCode(const StartPos, EndPos: integer;
SourceChangeCache: TSourceChangeCache; Apply: boolean): boolean;
var
i: LongInt;
CurStartPos: LongInt;
CommentNeeded: Boolean;
CurEndPos: LongInt;
begin
if StartPos>=EndPos then
RaiseException('TStandardCodeTool CommentCode');
Result:=false;
// comment with curly brackets {}
i:=StartPos;
CurStartPos:=i;
CurEndPos:=CurStartPos;
CommentNeeded:=false;
repeat
//debugln(['TPascalReaderTool.CommentCode ',dbgstr(Src[i]),' Needed=',CommentNeeded,' ',dbgstr(copy(Src,CurStartPos,CurEndPos-CurStartPos))]);
if (Src[i]='{') or (i>=EndPos) then begin
// the area contains a comment -> comment in front
if CommentNeeded then begin
if not SourceChangeCache.Replace(gtNone,gtNone,
CurStartPos,CurStartPos,'{') then exit;
if not SourceChangeCache.Replace(gtNone,gtNone,
CurEndPos,CurEndPos,'}') then exit;
//DebugLn('Comment "',copy(Src,CurStartPos,i-CurStartPos),'"');
CommentNeeded:=false;
end;
if i>=EndPos then break;
// skip comment
i:=FindCommentEnd(Src,i,Scanner.NestedComments)-1;
end else if not IsSpaceChar[Src[i]] then begin
if not CommentNeeded then begin
CurStartPos:=i;
CommentNeeded:=true;
end;
CurEndPos:=i+1;
end;
inc(i);
until false;
if Apply then
Result:=SourceChangeCache.Apply
else
Result:=true;
end;
function TStandardCodeTool.GetStringConstBounds( function TStandardCodeTool.GetStringConstBounds(
const CursorPos: TCodeXYPosition; const CursorPos: TCodeXYPosition;
out StartPos, EndPos: TCodeXYPosition; ResolveComments: boolean): boolean; out StartPos, EndPos: TCodeXYPosition; ResolveComments: boolean): boolean;