toString plugin highlights entire class when toString method is not implemented

This should highlight the class name instead of the entire class. It
makes other inspections totally unusable.

6 comments
Comment actions Permalink

It's one of the 3 hightlight types you have for inspections at that time.

I read somewhere that JetBrains would add more types in the EAP builds.

I haven't checked if they got such a highlight for just the class name.

I also got a few bugs to sort for the new builds. But I'm without internet at home so it could take a while before a new version is released.

0
Comment actions Permalink

Highlighting the class name instead of the entire class should be pretty
easy. I think a tiny change to your ClassHasNotStringMethodInspection
should be enough. In the line:

ProblemDescriptor problem = im.createProblemDescriptor(clazz, "Class
does not overwrite toString() method", fix,
ProblemHighlightType.GENERIC_ERROR_OR_WARNING);

replace "clazz" by "clazz.getNameIdentifier()" and the inspection will
highlight the name of the class. Note that I have not tested this, but
I'm pretty sure it will work.

Bas


Claus Ibsen wrote:

It's one of the 3 hightlight types you have for inspections at that
time.

I read somewhere that JetBrains would add more types in the EAP
builds.

I haven't checked if they got such a highlight for just the class
name.

I also got a few bugs to sort for the new builds. But I'm without
internet at home so it could take a while before a new version is
released.

0
Comment actions Permalink

Thanks Bas I'll try it this weekend and let you know how it went.

0
Comment actions Permalink

Make sure to test the identifier for null, or you'll NPE on anonymous inner classes (which have no name identifier).

--Dave Griffith

0
Comment actions Permalink

I just released v3.16 that has this fixed.

0
Comment actions Permalink

Hi Bas

It worked like a charm. However anonymous classes isn't inspected as I skip all classes that doesn't have a name. So the null check is not needed.

I can't see a use case where a toString() is needed for anonymous classes.

0

Please sign in to leave a comment.