IntelliJ 12 complains "cannot resolve symbol" with Groovy Markup Builder

In my project I'm using groovy markup builder to create html content. for exampe


        builder.table {
            tr {
              td("Data1")
              td("Data2")
            }
       }

IntelliJ inspector now complains that he cannot resolve the symbols table, tr and td. This wasn't a big issue until using the new
darcula theme. Now all those unresolved symbols are marked red in the text and even worse they clutters the problems bar at
the right side of the editor window.

Does anyone know how to tell the inspector to ignore that unroesolved symbols?

Thanks a lot
Holger

7 comments
Comment actions Permalink

Place your cursor on the reported error. Type Alt+Enter.In the popup, arrow down to one of the suggested fixes and open the side menu via the right arrow key. In there you can select to suppress the inspection (for the statement, the method, or the class, You can also select to edit the inspection. That will open the inspection configuration dialog, also accessible via File > Settings > Inspections in the Project Settings section. (the advantage of opening via the popup is it takes you right to that specific inspection.)
.

0
Comment actions Permalink

This issue affects me as well when my Groovy code makes references that IntelliJ can't resolve (for example, referencing a valid property of an object when the type is declared as Object).

I don't think suppressing the inspection is the right solution. Regardless, when I type Alt+Enter, I don't see any way to navigate to an inspection configuration dialog, and if I search the inspections in the settings dialog for "cannot resolve symbol", "can't resolve", "resolve", "symbol", etc. I don't see such an inspection for Groovy to configure.

What really concerns me is that it seems like the behavior of the inspections in the right-hand gutter is different depending on the theme I'm using. When using "Alloy. Default Theme" and editing a Groovy file, references that resolve in "Cannot resolve symbol" are merely underlined in the editor and don't result in anything in the inspections gutter/column/navigator (?) on the right-hand side of the editor, not even a warning. When using "Darcula", the references in the editor are highlighted with a red font rather than a less alarming underline, and there are red indicators in the inspections gutter/column/navigator.



Attachment(s):
actions.png
darcula.png
alloy.png
0
Comment actions Permalink

You can use the right-key to open the dialog. There you can specify for which scope you want do
disable inspection. Intellij will then write some annotation depending on your selection.

0
Comment actions Permalink

mhurne wrote:

I don't think suppressing the inspection is the right solution.

I agree. Suppressing an inspection should only be done in rare cases. I do not know Groovy that well (it's on the list to learn), so I cannot comment on what project change is needed to eliminate the errors you are getting. Hopefully a Groovy user can jump in and provide that answer.

mhurne wrote:

Regardless, when I type Alt+Enter, I don't see any way to navigate to an inspection configuration dialog, and if I search the inspections in the settings dialog for "cannot resolve symbol", "can't resolve", "resolve", "symbol", etc. I don't see such an inspection for Groovy to configure.

As Holger mentions, use the right arrow key (or the mouse to click on the arrow) to open the side menu. So the key sequence is:

  1. Alt+Enter
  2. Down Arrow to one of the quick fixes
  3. Right Arrow
  4. Down Arrow as needed
  5. Enter


screenshot.png

mhurne wrote:

What really concerns me is that it seems like the behavior of the inspections in the right-hand gutter is different depending on the theme I'm using. When using "Alloy. Default Theme" and editing a Groovy file, references that resolve in "Cannot resolve symbol" are merely underlined in the editor and don't result in anything in the inspections gutter/column/navigator (?) on the right-hand side of the editor, not even a warning. When using "Dracula", the references in the editor are highlighted with a red font rather than a less alarming underline, and there are red indicators in the inspections gutter/column/navigator.

The way warnings and errors show is configured in the editor's Color & Fonts settings (File > settings > IDE Settings > Editor > Colors & Fonts > General). You can also get to the settings within the Inspections settings by clicking the ellipsis (…) button next to the severity setting, and then clicking the "Edit Settings|Colors & Fonts" button.

In the Colors and Fonts general section, you can specify the style for warnings and errors. (The different Inspection levels are listed towards the bottom of the example text.) You can set:

  1. the font color
  2. the background color (if any)
  3. any effects (underscored, wavy underscored, strikeout, etc.)
  4. if there is an Error Stripe Marker and if so, its color.

The new Dracula Look & Feel (and possible others) will change the Fonts Scheme being used. (This obviously is necessary with Dracula since the default Color & Fonts schema uses black text.) So it appears that there may be some inconsistencies in how warning and errors are shown between those Color&Font schemas.

Also as a note, for inspections, you can specify the Severity level (info, warning, weak warning, typo, etc) for an inspection. You can even add a custom level.


I hope that helps.

0
Comment actions Permalink

I agree. Suppressing an inspection should only be done in rare cases. I do not know Groovy that well (it's on the list to learn), so I cannot comment on what project change is needed to eliminate the errors you are getting. Hopefully a Groovy user can jump in and provide that answer.



Thanks; they aren't truly errors from a Groovy perspective. Due to Groovy's support for dynamic types/methods/etc., it is often perfectly valid at runtime to call methods, access fields, etc. that the IDE has no way of verifying actually exist. I think the Alloy theme gets it right by only calling out "unresolved symbols" by underlining them in the editor and not displaying any error stripe markers.

As Holger mentions, use the right arrow key (or the mouse to click on the arrow) to open the side menu. So the key sequence is:
  1. Alt+Enter
  2. Down Arrow to one of the quick fixes
  3. Right Arrow
  4. Down Arrow as needed
  5. Enter


I see it now, thanks. Apparently the inspection in question is called 'GrUnresolvedAccess', so to suppress it one can use:
//noinspection GrUnresolvedAccess


I won't be using that, however, since code that triggers this inspection is very common in Groovy programs. I think suppressing inspections is appropriate in many situations, but this usually isn't one of those situations (it sounds like you agree, Mark).

The way warnings and errors show is configured in the editor's Color & Fonts settings (File > settings > IDE Settings > Editor > Colors & Fonts > General). You can also get to the settings within the Inspections settings by clicking the ellipsis (…) button next to the severity setting, and then clicking the "Edit Settings|Colors & Fonts" button.

In the Colors and Fonts general section, you can specify the style for warnings and errors. (The different Inspection levels are listed towards the bottom of the example text.) You can set:

  1. the font color
  2. the background color (if any)
  3. any effects (underscored, wavy underscored, strikeout, etc.)
  4. if there is an Error Stripe Marker and if so, its color.


Excellent, this is what I was looking for! Under 'Editor -> Colors & Fonts -> Groovy', I found 'Unresolved reference access' in the list of items and the default was a Foreground color of red and an Error Stripe Mark of red. I'm going to disable the Error Stripe Mark altogether, and will likely change the Foreground color and add an underline (I haven't decided on that yet, I'll need to play around with it a bit).

When using the 'Alloy Default' theme, the styling for 'Unresolved reference access' in Groovy is a Foreground color of black, no Error Stripe Mark, and a dark gray Underscored effect. So why is the default in Darcula to show an Error Stripe Mark while it isn't in the default theme? I think that *not* showing an Error Stripe Mark for 'Unresolved reference access' in Groovy should be the default behavior of the Darcula theme (and all other themes for that matter).

Obviously regardless of the default, I now know how to configure this to my liking.

Thanks for your help!
1
Comment actions Permalink

I ended up going with not overriding the default Foreground color and a white Underscored effect for 'Unresolved reference access' in Groovy when using Darcula. You can see what that looks like in the attached image (the 'foo' in 'bar.foo' is the relevant part of the code). And as you can see, I disabled the Error Stripe Mark.



Attachment(s):
darcula-improved.png
0
Comment actions Permalink

Huzzah! The default styling in the Darcula theme has already been considered a bug by JetBrains and will be changed to something more reasonable in version 12.0.1: http://youtrack.jetbrains.com/issue/IDEA-96521

0

Please sign in to leave a comment.