mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-10-25 01:51:53 +02:00
codetools: GetIDEDirectives: implemented filter, needed to fix removing all
git-svn-id: trunk@48335 -
This commit is contained in:
parent
695ac7c9e9
commit
686b04a732
@ -827,10 +827,10 @@ type
|
|||||||
const APropertyPath: string = ''): boolean;
|
const APropertyPath: string = ''): boolean;
|
||||||
|
|
||||||
// IDE % directives
|
// IDE % directives
|
||||||
function GetIDEDirectives(Code: TCodeBuffer;
|
function GetIDEDirectives(Code: TCodeBuffer; DirectiveList: TStrings;
|
||||||
DirectiveList: TStrings): boolean;
|
const Filter: TOnIDEDirectiveFilter = nil): boolean;
|
||||||
function SetIDEDirectives(Code: TCodeBuffer;
|
function SetIDEDirectives(Code: TCodeBuffer; DirectiveList: TStrings;
|
||||||
DirectiveList: TStrings): boolean;
|
const Filter: TOnIDEDirectiveFilter = nil): boolean;
|
||||||
|
|
||||||
// linker jumping
|
// linker jumping
|
||||||
function JumpToLinkerIdentifier(Code: TCodeBuffer;
|
function JumpToLinkerIdentifier(Code: TCodeBuffer;
|
||||||
@ -3800,7 +3800,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TCodeToolManager.GetIDEDirectives(Code: TCodeBuffer;
|
function TCodeToolManager.GetIDEDirectives(Code: TCodeBuffer;
|
||||||
DirectiveList: TStrings): boolean;
|
DirectiveList: TStrings; const Filter: TOnIDEDirectiveFilter): boolean;
|
||||||
begin
|
begin
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
DebugLn('TCodeToolManager.GetIDEDirectives A ',Code.Filename);
|
DebugLn('TCodeToolManager.GetIDEDirectives A ',Code.Filename);
|
||||||
@ -3808,14 +3808,14 @@ begin
|
|||||||
Result:=false;
|
Result:=false;
|
||||||
if not InitCurCodeTool(Code) then exit;
|
if not InitCurCodeTool(Code) then exit;
|
||||||
try
|
try
|
||||||
Result:=FCurCodeTool.GetIDEDirectives(DirectiveList);
|
Result:=FCurCodeTool.GetIDEDirectives(DirectiveList,Filter);
|
||||||
except
|
except
|
||||||
on e: Exception do Result:=HandleException(e);
|
on e: Exception do Result:=HandleException(e);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCodeToolManager.SetIDEDirectives(Code: TCodeBuffer;
|
function TCodeToolManager.SetIDEDirectives(Code: TCodeBuffer;
|
||||||
DirectiveList: TStrings): boolean;
|
DirectiveList: TStrings; const Filter: TOnIDEDirectiveFilter): boolean;
|
||||||
begin
|
begin
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
DebugLn('TCodeToolManager.GetIDEDirectives A ',Code.Filename);
|
DebugLn('TCodeToolManager.GetIDEDirectives A ',Code.Filename);
|
||||||
@ -3823,7 +3823,7 @@ begin
|
|||||||
Result:=false;
|
Result:=false;
|
||||||
if not InitCurCodeTool(Code) then exit;
|
if not InitCurCodeTool(Code) then exit;
|
||||||
try
|
try
|
||||||
Result:=FCurCodeTool.SetIDEDirectives(DirectiveList,SourceChangeCache);
|
Result:=FCurCodeTool.SetIDEDirectives(DirectiveList,SourceChangeCache,Filter);
|
||||||
except
|
except
|
||||||
on e: Exception do Result:=HandleException(e);
|
on e: Exception do Result:=HandleException(e);
|
||||||
end;
|
end;
|
||||||
|
|||||||
@ -57,6 +57,8 @@ uses
|
|||||||
CustomCodeTool, CodeToolsStructs, LazFileUtils;
|
CustomCodeTool, CodeToolsStructs, LazFileUtils;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
TStandardCodeTool = class;
|
||||||
|
|
||||||
TInsertStatementPosDescription = class
|
TInsertStatementPosDescription = class
|
||||||
public
|
public
|
||||||
InsertPos: integer;
|
InsertPos: integer;
|
||||||
@ -72,6 +74,8 @@ type
|
|||||||
const ClassContext, AncestorClassContext: TFindContext;
|
const ClassContext, AncestorClassContext: TFindContext;
|
||||||
LFMNode: TLFMTreeNode;
|
LFMNode: TLFMTreeNode;
|
||||||
const IdentName: string; var IsDefined: boolean) of object;
|
const IdentName: string; var IsDefined: boolean) of object;
|
||||||
|
TOnIDEDirectiveFilter = function(Tool: TStandardCodeTool;
|
||||||
|
StartPos, EndPos: integer): boolean of object; // true = use
|
||||||
|
|
||||||
{ TStandardCodeTool }
|
{ TStandardCodeTool }
|
||||||
|
|
||||||
@ -348,9 +352,11 @@ type
|
|||||||
SourceChangeCache: TSourceChangeCache): boolean;
|
SourceChangeCache: TSourceChangeCache): boolean;
|
||||||
|
|
||||||
// IDE % directives
|
// IDE % directives
|
||||||
function GetIDEDirectives(DirectiveList: TStrings): boolean;
|
function GetIDEDirectives(DirectiveList: TStrings;
|
||||||
|
const Filter: TOnIDEDirectiveFilter = nil): boolean;
|
||||||
function SetIDEDirectives(DirectiveList: TStrings;
|
function SetIDEDirectives(DirectiveList: TStrings;
|
||||||
SourceChangeCache: TSourceChangeCache): boolean;
|
SourceChangeCache: TSourceChangeCache;
|
||||||
|
const Filter: TOnIDEDirectiveFilter = nil): boolean;
|
||||||
|
|
||||||
procedure CalcMemSize(Stats: TCTMemStats); override;
|
procedure CalcMemSize(Stats: TCTMemStats); override;
|
||||||
end;
|
end;
|
||||||
@ -4101,7 +4107,8 @@ begin
|
|||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TStandardCodeTool.GetIDEDirectives(DirectiveList: TStrings): boolean;
|
function TStandardCodeTool.GetIDEDirectives(DirectiveList: TStrings;
|
||||||
|
const Filter: TOnIDEDirectiveFilter): boolean;
|
||||||
var
|
var
|
||||||
StartPos: Integer;
|
StartPos: Integer;
|
||||||
EndPos: Integer;
|
EndPos: Integer;
|
||||||
@ -4114,7 +4121,8 @@ begin
|
|||||||
StartPos:=FindNextIDEDirective(Src,EndPos,Scanner.NestedComments);
|
StartPos:=FindNextIDEDirective(Src,EndPos,Scanner.NestedComments);
|
||||||
if StartPos<1 then break;
|
if StartPos<1 then break;
|
||||||
EndPos:=FindCommentEnd(Src,StartPos,Scanner.NestedComments);
|
EndPos:=FindCommentEnd(Src,StartPos,Scanner.NestedComments);
|
||||||
DirectiveList.Add(copy(Src,StartPos,EndPos-StartPos));
|
if (Filter=nil) or Filter(Self,StartPos,EndPos) then
|
||||||
|
DirectiveList.Add(copy(Src,StartPos,EndPos-StartPos));
|
||||||
if EndPos>SrcLen then break;
|
if EndPos>SrcLen then break;
|
||||||
StartPos:=EndPos;
|
StartPos:=EndPos;
|
||||||
until false;
|
until false;
|
||||||
@ -4122,7 +4130,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TStandardCodeTool.SetIDEDirectives(DirectiveList: TStrings;
|
function TStandardCodeTool.SetIDEDirectives(DirectiveList: TStrings;
|
||||||
SourceChangeCache: TSourceChangeCache): boolean;
|
SourceChangeCache: TSourceChangeCache; const Filter: TOnIDEDirectiveFilter
|
||||||
|
): boolean;
|
||||||
var
|
var
|
||||||
InsertPos: Integer;
|
InsertPos: Integer;
|
||||||
EndPos: Integer;
|
EndPos: Integer;
|
||||||
@ -4137,7 +4146,12 @@ begin
|
|||||||
|
|
||||||
// find first old IDE directive
|
// find first old IDE directive
|
||||||
InsertPos:=FindNextIDEDirective(Src,1,Scanner.NestedComments);
|
InsertPos:=FindNextIDEDirective(Src,1,Scanner.NestedComments);
|
||||||
if InsertPos<1 then InsertPos:=0;
|
if InsertPos>=1 then begin
|
||||||
|
EndPos:=FindCommentEnd(Src,InsertPos,Scanner.NestedComments);
|
||||||
|
if (Filter<>nil) and (not Filter(Self,InsertPos,EndPos)) then
|
||||||
|
InsertPos:=0;
|
||||||
|
end else
|
||||||
|
InsertPos:=0;
|
||||||
|
|
||||||
// remove all old IDE directives
|
// remove all old IDE directives
|
||||||
if InsertPos>=1 then
|
if InsertPos>=1 then
|
||||||
@ -4149,18 +4163,21 @@ begin
|
|||||||
StartPos:=FindNextIDEDirective(Src,EndPos,Scanner.NestedComments);
|
StartPos:=FindNextIDEDirective(Src,EndPos,Scanner.NestedComments);
|
||||||
if StartPos<1 then break;
|
if StartPos<1 then break;
|
||||||
EndPos:=FindCommentEnd(Src,StartPos,Scanner.NestedComments);
|
EndPos:=FindCommentEnd(Src,StartPos,Scanner.NestedComments);
|
||||||
// remove also space in front of directive
|
if (Filter=nil) or Filter(Self,StartPos,EndPos) then begin
|
||||||
while (StartPos>1) and (Src[StartPos-1] in [' ',#9]) do dec(StartPos);
|
// remove also space in front of directive
|
||||||
// remove also space behind directive
|
while (StartPos>1) and (Src[StartPos-1] in [' ',#9]) do dec(StartPos);
|
||||||
while (EndPos<=SrcLen) and (Src[EndPos] in [' ',#9]) do inc(EndPos);
|
// remove also space behind directive
|
||||||
if (EndPos<=SrcLen) and (Src[EndPos] in [#10,#13]) then begin
|
while (EndPos<=SrcLen) and (Src[EndPos] in [' ',#9]) do inc(EndPos);
|
||||||
inc(EndPos);
|
if (EndPos<=SrcLen) and (Src[EndPos] in [#10,#13]) then begin
|
||||||
if (EndPos<=SrcLen) and (Src[EndPos] in [#10,#13])
|
|
||||||
and (Src[EndPos]<>Src[EndPos-1]) then
|
|
||||||
inc(EndPos);
|
inc(EndPos);
|
||||||
|
if (EndPos<=SrcLen) and (Src[EndPos] in [#10,#13])
|
||||||
|
and (Src[EndPos]<>Src[EndPos-1]) then
|
||||||
|
inc(EndPos);
|
||||||
|
end;
|
||||||
|
// remove directive
|
||||||
|
if not SourceChangeCache.Replace(gtNone,gtNone,StartPos,EndPos,'') then
|
||||||
|
exit;
|
||||||
end;
|
end;
|
||||||
// remove directive
|
|
||||||
SourceChangeCache.Replace(gtNone,gtNone,StartPos,EndPos,'');
|
|
||||||
if EndPos>SrcLen then break;
|
if EndPos>SrcLen then break;
|
||||||
StartPos:=EndPos;
|
StartPos:=EndPos;
|
||||||
until false;
|
until false;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user