mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 18:39:10 +02:00
IDE: added quickfix for An inherited method is hidden, add overload or reintroduce
git-svn-id: trunk@57915 -
This commit is contained in:
parent
0aeaf2facf
commit
995f971392
@ -41,6 +41,8 @@ type
|
|||||||
protected
|
protected
|
||||||
fMsg: TFPList; // list of TMessageLine
|
fMsg: TFPList; // list of TMessageLine
|
||||||
fItems: TObjectList; // list of TMsgQuickFix
|
fItems: TObjectList; // list of TMsgQuickFix
|
||||||
|
FCurrentSender: TObject;
|
||||||
|
FCurrentCommand: TIDEMenuCommand;
|
||||||
public
|
public
|
||||||
constructor Create(aOwner: TComponent); override;
|
constructor Create(aOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -52,6 +54,8 @@ type
|
|||||||
property Lines[Index: integer]: TMessageLine read GetLines;
|
property Lines[Index: integer]: TMessageLine read GetLines;
|
||||||
function AddMenuItem(Fix: TMsgQuickFix; Msg: TMessageLine; aCaption: string;
|
function AddMenuItem(Fix: TMsgQuickFix; Msg: TMessageLine; aCaption: string;
|
||||||
aTag: PtrInt = 0): TIDEMenuCommand; virtual; abstract;
|
aTag: PtrInt = 0): TIDEMenuCommand; virtual; abstract;
|
||||||
|
property CurrentSender: TObject read FCurrentSender;
|
||||||
|
property CurrentCommand: TIDEMenuCommand read FCurrentCommand;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
|
@ -157,6 +157,15 @@ type
|
|||||||
procedure QuickFix({%H-}Fixes: TMsgQuickFixes; Msg: TMessageLine); override;
|
procedure QuickFix({%H-}Fixes: TMsgQuickFixes; Msg: TMessageLine); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TQuickFixInheritedMethodIsHidden_AddModifier - add proc modifier 'overload' or 'reintroduce' }
|
||||||
|
|
||||||
|
TQuickFixInheritedMethodIsHidden_AddModifier = class(TMsgQuickFix)
|
||||||
|
//blaunit.pas(23,15) Warning: (3057) An inherited method is hidden by "DoIt(LongInt);"
|
||||||
|
function IsApplicable(Msg: TMessageLine; out MsgID: integer): boolean;
|
||||||
|
procedure CreateMenuItems(Fixes: TMsgQuickFixes); override;
|
||||||
|
procedure QuickFix({%H-}Fixes: TMsgQuickFixes; Msg: TMessageLine); override;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TIDEQuickFixes }
|
{ TIDEQuickFixes }
|
||||||
|
|
||||||
TIDEQuickFixes = class(TMsgQuickFixes)
|
TIDEQuickFixes = class(TMsgQuickFixes)
|
||||||
@ -282,6 +291,88 @@ begin
|
|||||||
and (CompareIdentifiers(PChar(CurIdentifier),PChar(Identifier))=0);
|
and (CompareIdentifiers(PChar(CurIdentifier),PChar(Identifier))=0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TQuickFixInheritedMethodIsHidden_AddModifier }
|
||||||
|
|
||||||
|
function TQuickFixInheritedMethodIsHidden_AddModifier.IsApplicable(
|
||||||
|
Msg: TMessageLine; out MsgID: integer): boolean;
|
||||||
|
var
|
||||||
|
Value1, Value2: string;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
MsgID:=0;
|
||||||
|
if (not Msg.HasSourcePosition) then exit;
|
||||||
|
if IDEFPCParser.MsgLineIsId(Msg,3057,Value1,Value2) then begin
|
||||||
|
// An inherited method is hidden by "$1;"
|
||||||
|
MsgID:=3057;
|
||||||
|
Result:=true
|
||||||
|
end
|
||||||
|
else if IDEPas2jsParser.MsgLineIsId(Msg,3021,Value1,Value2) then begin
|
||||||
|
// function hides identifier at "$1". Use overload or reintroduce
|
||||||
|
MsgID:=3021;
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TQuickFixInheritedMethodIsHidden_AddModifier.CreateMenuItems(
|
||||||
|
Fixes: TMsgQuickFixes);
|
||||||
|
var
|
||||||
|
i, MsgID: Integer;
|
||||||
|
Msg: TMessageLine;
|
||||||
|
aCaption: String;
|
||||||
|
begin
|
||||||
|
for i:=0 to Fixes.LineCount-1 do begin
|
||||||
|
Msg:=Fixes.Lines[i];
|
||||||
|
if not IsApplicable(Msg,MsgID) then continue;
|
||||||
|
aCaption:=lisAddModifierOverload;
|
||||||
|
Fixes.AddMenuItem(Self,Msg,aCaption,1);
|
||||||
|
aCaption:=lisAddModifierReintroduce;
|
||||||
|
Fixes.AddMenuItem(Self,Msg,aCaption,2);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TQuickFixInheritedMethodIsHidden_AddModifier.QuickFix(
|
||||||
|
Fixes: TMsgQuickFixes; Msg: TMessageLine);
|
||||||
|
var
|
||||||
|
MsgID: integer;
|
||||||
|
Code: TCodeBuffer;
|
||||||
|
OldChange: Boolean;
|
||||||
|
aModifier: String;
|
||||||
|
begin
|
||||||
|
if not IsApplicable(Msg,MsgID) then begin
|
||||||
|
debugln(['TQuickFixInheritedMethodIsHidden_AddOverload.QuickFix invalid message ',Msg.Msg]);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if not LazarusIDE.BeginCodeTools then begin
|
||||||
|
DebugLn(['TQuickFixInheritedMethodIsHidden_AddOverload failed because IDE busy']);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Code:=CodeToolBoss.LoadFile(Msg.GetFullFilename,true,false);
|
||||||
|
if Code=nil then exit;
|
||||||
|
|
||||||
|
OldChange:=LazarusIDE.OpenEditorsOnCodeToolChange;
|
||||||
|
LazarusIDE.OpenEditorsOnCodeToolChange:=true;
|
||||||
|
try
|
||||||
|
if Fixes.CurrentCommand.Tag=2 then
|
||||||
|
aModifier:='reintroduce'
|
||||||
|
else
|
||||||
|
aModifier:='overload';
|
||||||
|
|
||||||
|
if not CodeToolBoss.AddProcModifier(Code,Msg.Column,Msg.Line,aModifier) then
|
||||||
|
begin
|
||||||
|
DebugLn(['TQuickFixInheritedMethodIsHidden_AddOverload AddProcModifier failed']);
|
||||||
|
LazarusIDE.DoJumpToCodeToolBossError;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// success
|
||||||
|
Msg.MarkFixed;
|
||||||
|
finally
|
||||||
|
LazarusIDE.OpenEditorsOnCodeToolChange:=OldChange;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TQuickFix_HideWithCompilerDirective }
|
{ TQuickFix_HideWithCompilerDirective }
|
||||||
|
|
||||||
function TQuickFix_HideWithCompilerDirective.IsApplicable(Msg: TMessageLine;
|
function TQuickFix_HideWithCompilerDirective.IsApplicable(Msg: TMessageLine;
|
||||||
@ -1083,6 +1174,8 @@ begin
|
|||||||
Cmd:=Sender as TIDEMenuCommand;
|
Cmd:=Sender as TIDEMenuCommand;
|
||||||
Info:=TMenuItemInfo(fMenuItemToInfo[Cmd]);
|
Info:=TMenuItemInfo(fMenuItemToInfo[Cmd]);
|
||||||
if Info=nil then exit;
|
if Info=nil then exit;
|
||||||
|
FCurrentSender:=Sender;
|
||||||
|
FCurrentCommand:=Cmd;
|
||||||
try
|
try
|
||||||
Info.Fix.QuickFix(Self,Info.Msg);
|
Info.Fix.QuickFix(Self,Info.Msg);
|
||||||
finally
|
finally
|
||||||
@ -1096,6 +1189,8 @@ begin
|
|||||||
for i:=0 to ListsMsgLines.Count-1 do
|
for i:=0 to ListsMsgLines.Count-1 do
|
||||||
TMessageLines(ListsMsgLines[i]).ApplyFixedMarks;
|
TMessageLines(ListsMsgLines[i]).ApplyFixedMarks;
|
||||||
finally
|
finally
|
||||||
|
FCurrentSender:=nil;
|
||||||
|
FCurrentCommand:=nil;
|
||||||
ListsMsgLines.Free;
|
ListsMsgLines.Free;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1116,6 +1211,7 @@ begin
|
|||||||
IDEQuickFixes.RegisterQuickFix(TQuickFixUnitNotFound_Remove.Create);
|
IDEQuickFixes.RegisterQuickFix(TQuickFixUnitNotFound_Remove.Create);
|
||||||
IDEQuickFixes.RegisterQuickFix(TQuickFixClassWithAbstractMethods.Create);
|
IDEQuickFixes.RegisterQuickFix(TQuickFixClassWithAbstractMethods.Create);
|
||||||
IDEQuickFixes.RegisterQuickFix(TQuickFixSrcPathOfPkgContains_OpenPkg.Create);
|
IDEQuickFixes.RegisterQuickFix(TQuickFixSrcPathOfPkgContains_OpenPkg.Create);
|
||||||
|
IDEQuickFixes.RegisterQuickFix(TQuickFixInheritedMethodIsHidden_AddModifier.Create);
|
||||||
|
|
||||||
// add as last (no fix, just hide message)
|
// add as last (no fix, just hide message)
|
||||||
IDEQuickFixes.RegisterQuickFix(TQuickFix_HideWithIDEDirective.Create);
|
IDEQuickFixes.RegisterQuickFix(TQuickFix_HideWithIDEDirective.Create);
|
||||||
|
@ -6394,6 +6394,8 @@ resourcestring
|
|||||||
lisPositionOutsideOfSource = '%s (position outside of source)';
|
lisPositionOutsideOfSource = '%s (position outside of source)';
|
||||||
lisHideMessageByInsertingWarnOffToUnit = 'Hide message by inserting {$warn %'
|
lisHideMessageByInsertingWarnOffToUnit = 'Hide message by inserting {$warn %'
|
||||||
+'s off} to unit "%s"';
|
+'s off} to unit "%s"';
|
||||||
|
lisAddModifierOverload = 'Add modifier "overload"';
|
||||||
|
lisAddModifierReintroduce = 'Add modifier "reintroduce"';
|
||||||
lisHideWithProjectOptionVm = 'Hide with project option (-vm%s)';
|
lisHideWithProjectOptionVm = 'Hide with project option (-vm%s)';
|
||||||
lisHideWithPackageOptionVm = 'Hide with package option (-vm%s)';
|
lisHideWithPackageOptionVm = 'Hide with package option (-vm%s)';
|
||||||
lisRemoveLocalVariable3 = 'Remove local variable "%s"';
|
lisRemoveLocalVariable3 = 'Remove local variable "%s"';
|
||||||
|
Loading…
Reference in New Issue
Block a user