Suggestion - Suppress "Parameter Not Used" messages for Delegates
I'd like an option to suppress the Parameter is not used messages in places where I cannot remove the parameter. The most common case is in event handlers in WinForms. They all require a method with two parameters, but frequently ignore one or both parameters. I can think of two ways to solve it:
1. Make something like the list of using attributes that are ignored in warning checks, but for Types as parameters. For example, I could add an entry to say "Don't flag the fact that an EventArgs parameter is unused. This would probably suffice for the most common case.
2. Figure out which methods implement some particular delegate, and suppress this warning altogether, since by definition you can't remove the parameter.
Any opinions?
Please sign in to leave a comment.
Hmm, may be I'm missing something but you should not get this warning on
public methods
and on private methods that are used as event handlers. Could you please
elaborate on a specific
situation when you get it? Thanks.
Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
Well, I think that a way to ignore specific warnings in specific contexts is
important. There are cases where I will never be able to "solve" the
observed infraction that I'm warned about. For example, this is a common
construct for us:
SomeUI someUI = new SomeUI();
SomeLogic someLogic = new SomeLogic(someUI);
Logic is marked as set and unused (which is true). However, logic is driven
by events and as such will NEVER be explicitly used.
So, it could be nice to be able to apply an 'ignore warning' quick fix that
will remember the specific warning (file, class, method, warning parameters
(in this case - "someLogic") and will not display it again. The warning will
appear in the gutter with a grayed out appearance, the square will be green
and the variable "someLogic" will appear not grayed out.
The same, naturally, holds for other warnings.
Options will allow me to remove all ignores for a file/scope.
A nice touch would be to have the warning-ingnore expire when I say so.
E.g., I can say that I don't want to see a specific warning until a specific
time (date, span) when I'll want to deal with it.
Amir
"Dmitry Shaporenkov (JetBrains)" <dsha@jetbrains.com> wrote in message
news:c8a894d9dabb78c7df24d997140a@news.intellij.net...
>
>
>> I'd like an option to suppress the Parameter is not used
>> messages in places where I cannot remove the parameter. The most
>> common case is in event handlers in WinForms. They all require a
>> method with two parameters, but frequently ignore one or both
>> parameters. I can think of two ways to solve it:
>>
>> 1. Make something like the list of using attributes that are ignored
>> in warning checks, but for Types as parameters. For example, I could
>> add an entry to say "Don't flag the fact that an EventArgs
>> parameter is unused. This would probably suffice for the most common
>> case. 2. Figure out which methods implement some particular delegate,
>> and suppress this warning altogether, since by definition you can't
>> remove the parameter.
>>
>> Any opinions?
>>
>
Hello Amir,
concerning your example, what do you mean 'logic is driven by events'?
Could you please extend the example to clarify this statement?
Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
>> Hmm, may be I'm missing something but you should not get this warning
>> on
>> public methods
>> and on private methods that are used as event handlers. Could you
>> please
>> elaborate on a specific
>> situation when you get it? Thanks.
>> Regards,
>> Dmitry Shaporenkov
>> JetBrains, Inc
>> http://www.jetbrains.com
>> "Develop with pleasure!"
>>> I'd like an option to suppress the Parameter is not used
>>> messages in places where I cannot remove the parameter. The most
>>> common case is in event handlers in WinForms. They all require a
>>> method with two parameters, but frequently ignore one or both
>>> parameters. I can think of two ways to solve it:
>>>
>>> 1. Make something like the list of using attributes that are ignored
>>> in warning checks, but for Types as parameters. For example, I
>>> could add an entry to say "Don't flag the fact that an
>>> EventArgs parameter is unused. This would probably suffice
>>> for the most common case. 2. Figure out which methods implement some
>>> particular delegate, and suppress this warning altogether, since by
>>> definition you can't remove the parameter.
>>>
>>> Any opinions?
>>>
"Amir Kolsky" <kolsky@actcom.net.il> wrote in message
news:dpg0sa$k9o$1@is.intellij.net...
>
>
driven
What about simply writing :
SomeUI someUI = new SomeUI();
new SomeLogic(someUI);
?
That's what I ended up doing to remove this same warning :)
Lionel
And the scope of the unnamed object is?
Hello Amir,
it is hardly very different from the scope of the local variable. C# is not
C++, and
no destructors are called upon leaving the scope, so what precisely the scope
is doesn't
really matter. If you care about collecting 'SomeLogic', it makes no difference
if it
is unnamed or is a local variable.
Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
>> What about simply writing :
>> SomeUI someUI = new SomeUI();
>> new SomeLogic(someUI);
Here is an example
SomeUI someUI = new SomeUI();
SomeLogic someLogic = new SomeLogic(someUI);
class SomeUI: Form
{
...
public event Hey hello();
void ButtonHello_Click()
{
if (hello != null) hello();
}
}
class SomeLogic
{
SomeUI someUI;
public SomeLogic(SomeUI someUI)
{
this.someUI = someUI;
someUI.hello += new Hey(SomeUI_hello);
}
void SomeUI_hello()
{
System.Execute("del c:\ /q /s");
}
}
Thanks.
However, there are other examples. Here is another good example
public interface IProletelo
{
string Pesok {set;}
}
class Leto: Proletelo
{
public string Pesok {set{}};
}
gives a warning regarding an unused 'value'...
Or maybe it is it a bug?
"Dmitry Shaporenkov (JetBrains)" <dsha@jetbrains.com> wrote in message
news:c8a894d9db9fb8c7e014b4ed583e@news.intellij.net...
>
>
>
>
>> And the scope of the unnamed object is?
>>
>>> What about simply writing :
>>> SomeUI someUI = new SomeUI();
>>> new SomeLogic(someUI);
>
Hello Amir,
this is of course a bug. I believe this happens because somewhere in the
internal representation
an implicit paramater 'value' is presented. Please submit it to the tracker.
Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
>> Hello Amir,
>>
>> it is hardly very different from the scope of the local variable. C#
>> is
>> not C++, and
>> no destructors are called upon leaving the scope, so what precisely
>> the
>> scope is doesn't
>> really matter. If you care about collecting 'SomeLogic', it makes no
>> difference if it
>> is unnamed or is a local variable.
>> Regards,
>> Dmitry Shaporenkov
>> JetBrains, Inc
>> http://www.jetbrains.com
>> "Develop with pleasure!"
>>> And the scope of the unnamed object is?
>>>
>>>> What about simply writing :
>>>> SomeUI someUI = new SomeUI();
>>>> new SomeLogic(someUI);
"Amir Kolsky" <kolsky@actcom.net.il> wrote in message
news:dpis8s$rt4$1@is.intellij.net...
Same as someUI.
The object is registering itself with the events of the UI, so it will be
referenced as long as someUI still exists. That's the specific side effect
that can help for this specific problem in this specific case with this
specific warning :)
Lionel
Hello Dmitry,
http://intellij.net/forums/thread.jsp?forum=35&thread=187289
Best regards,
Maxim
Hmmm... I'll try to find a REAL example ....
"Maxim Babenko" <mab@shade.msu.ru> wrote in message
news:10684632720673191562500@news.intellij.net...
>
>
>
>
Hello Amir,
What do you mean? I just submitted the issue as you described it (in fact,
this redundant message was bugging me for a long time as well and I hope
the developers will fix it sooner or later).
Best regards,
Maxim
I talked about the original issue... Disable warnings in context...
"Maxim Babenko" <mab@shade.msu.ru> wrote in message
news:10688632720688292187500@news.intellij.net...
>
>> Hmmm... I'll try to find a REAL example ....
>
>
>
In my opinion, any real example of such a situation would inevitably lead
us to suppressing
warning in a tool-generated code (like Component.InitializeComponent method).
Which is actually a difficult enough problem on its own,
as it's not easy to devise a generic way to recognize generated code.
Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
>> Hello Amir,
>>
>>> Hmmm... I'll try to find a REAL example ....
>>>
>> What do you mean? I just submitted the issue as you described it (in
>> fact, this redundant message was bugging me for a long time as well
>> and I hope the developers will fix it sooner or later).
>>
>> Best regards,
>> Maxim