static method being called using an instance...

If I call a static method using an instance e.g.


instead of


IntelliJ reports this as syntax error in the editor window but hilites it with a yellow line in the gutter. I understand this is not a good thing to do, but can we get an option to downgrade this to a warning rather than error in the editor window?

15 comments
Comment actions Permalink

You can disable the error in IDE Options->Completion->"Show static members
after instance qualifier".

can we get an option to downgrade this to a warning rather than

error in the editor window?

You can post a feature request for this if you really want it.


0
Comment actions Permalink

under IDE Options->Errors there is already an options. You can set it as a warning, error or none at all.

Come on you should know to look there ;)

0
Comment actions Permalink

It's alrready a warning (that's why it shown yellow on the right gutter
bar)! What did you mean?

--
Valentin Kipiatkov
JetBrains, Inc
http://www.intellij.com
"Develop with pleasure!"

"Vinay Moharil" <vmohar98@yahoo.com> wrote in message
news:24375103.1053727854761.JavaMail.jrun@is.intellij.net...

If I call a static method using an instance e.g.

>

class.staticMethod()]]>
instead of

>

IntelliJ reports this as syntax error in the editor window but hilites it

with a yellow line in the gutter. I understand this is not a good thing to
do, but can we get an option to downgrade this to a warning rather than
error in the editor window?


0
Comment actions Permalink

I think I understand what he talks about and I agree. Apart from the yellow line in the gutter, the whole expression is underlined with a red wavy line which makes it look like an error instead of a warning. The other warnings I've seen has more discrete visual signals, such as an import line or a variable declaration being gray instead of the normal black color.

0
Comment actions Permalink

Well but how should the warnings be shown? What color (or other text
attributes) would you suggest?

--
Valentin Kipiatkov
JetBrains, Inc
http://www.intellij.com
"Develop with pleasure!"

"Daniel Bratell" <jiveadmin@jetbrains.com> wrote in message
news:25085881.1053798301227.JavaMail.jrun@is.intellij.net...

I think I understand what he talks about and I agree. Apart from the

yellow line in the gutter, the whole expression is underlined with a red
wavy line which makes it look like an error instead of a warning. The other
warnings I've seen has more discrete visual signals, such as an import line
or a variable declaration being gray instead of the normal black color.
>


0
Comment actions Permalink

Maybe like obsolete imports? BTW, silly assignments (as an opposite) are
errors and should be shown in red.

Tom

0
Comment actions Permalink

1. Obsolete imports-like highlighting (light grey) will make developer think that there is something unused in the expression. I
think it is confusing.
On the other hand, underlining using yellow color, traditionally associated with warning in IDEA, is too bleach.
2. Why do you think silly assignments (something like void f(int i) { i = i; }) are errors ? I think it is just (relatively)
harmless typos which don't make code uncompilable.


--
regards,
Alexey Kudravtsev.
JetBrains, Inc
http://www.intellij.com
"Develop with pleasure!"


"Thomas Singer" <thomas.singer@noregnisspam.de> wrote in message news:oprpps9gr0mxlxr0@news.intellij.net...

Maybe like obsolete imports? BTW, silly assignments (as an opposite) are
errors and should be shown in red.

>

Tom



0
Comment actions Permalink

1. Obsolete imports-like highlighting (light grey)
will make developer think that there is something
unused in the expression. I
think it is confusing.
On the other hand, underlining using yellow color,
traditionally associated with warning in IDEA, is
too bleach.


You may use darker tint for warning underwave. RGB(192,192,0) looks fine on my screen. It would be really useful to visually distinguish potentially redundant code (unused imports, parameters, locals, members, redundant casts, etc.) from potentially erroneous code (static method call via instance, silly assignment).

2. Why do you think silly assignments (something like
void f(int i) { i = i; }) are errors ? I think it is
just (relatively)
harmless typos which don't make code uncompilable.


Silly assignments are not necessarily errors, but they are almost always a clear warning sign. In the code sample above, I would think that it was indended to be {this.i = i;}. Anyway, I'd suggest to add a new highlighting option for warnings and leave error highlighting for real errors (the ones that make the code uncompilable).

0
Comment actions Permalink

On the other hand, underlining using yellow color,
traditionally associated with warning in IDEA, is
too bleach.


Orange?

0
Comment actions Permalink

I've tried orange, but it's barely distinguishable from red error color. "Dark" yellow looks better IMHO.

0
Comment actions Permalink

for my 2 pennies, i like it just the way it is. Most of the time on my team when someone calls a static method from an instance variable they think it's non-static which usually produces a bug

0
Comment actions Permalink

If I understand the original post correctly, the author was frustrated to find that the editor highlighted code as error, while the gutter displayed a warning mark. The point is that there should be no discrepancy between the editor and the gutter. Whether it's an error or a warning, should be set up on "IDE Settings > Errors" page. If the majority of IDEA users think that "static method call via instance" is an error (I also tend to think so), it should be set up to be shown as error by default.

0
Comment actions Permalink

I agree with the frustration (more so confusion to see yellow line in the gutter and red wavy line in the editor)part. I also agree that this is bad coding and needs to be treated in the editor by something more harsh than standard unused code coloring.

However, I think, since the JVM and the specs do allow such code, it should not be treated as error till the language decides to do so. It should be brought to the programmer's attention but should be allowed (something less drastic than syntax error coloring) since the language allows it.

0
Comment actions Permalink

I've created an SCR, where I tried to formulate some thoughts arised in this discussion:
"Editor: two levels of warnings (different severity)"
http://www.intellij.net/tracker/idea/viewSCR?publicId=12720

As always, everyone is welcome to comment and criticise.

0
Comment actions Permalink

And yet one more request, inspired by the discussion of the previous one (#12720):

"Configurable color for the gutter marks"
http://www.intellij.net/tracker/idea/viewSCR?publicId=12944

0

Please sign in to leave a comment.