Properties editor reporting 'Unused property' for all entries

Hi,

I'm using a properties file to define a bunch of key=value pairs. All keys are used; either in the same file, or in another file in the form of ${key}.

How can I tell IntelliJ to treat ${key} as an usage of 'key' and stop showing the 'Unused property' warning?

I'm using IDEA 13.0 Community edition.

Thanks,
Arvind

8 comments
Comment actions Permalink

Arvind,

I use the Ultimate Edition, but assume this should work the same on both.  

  1. Hover over the yellow lightbulb and click the drop down on it
  2. Next, click on the "expand arrow" to the right of "Remove Property", this will bring up additional options (see screenshot below)

You can choose to:
  • completely disable it,
  • Suppress for a specific property,
  • Suppress for the whole file


If you suppress the property or file, IDEA will put in a special comment (see screenshot below) in the file that is a directive to Inspections.  You need to leave that comment in and you are all set to go.  You can use this with any Inspection.

Let me know if that helps out.  Cheers!

supress_warning_01.png
supress_warning_02.png

0
Comment actions Permalink

Thanks Stuart. I have hundreds of properties, and it's a shared project.

I'd prefer a way to have intellij recognize the way these properties are being used currently: ${key}

Thanks!
Arvind

0
Comment actions Permalink

Hello.

Is there some standard for such references? I've browsed the java API: http://docs.oracle.com/javase/7/docs/api/java/util/Properties.html and find nothing similar.

Thank you,
Alexander.

0
Comment actions Permalink

Hi Alexander, Just simple variable/parameter substitution: http://azkaban.github.io/azkaban2/documents/2.1/jobconf.html for example usage.
${key} is typically found to be an acceptable way to use (and re-use) variables within strings and have them expanded at run-time.


Thanks!

0
Comment actions Permalink

Thank you. If I get it correctly, this is not something widely adopted, but rather a particular tool's innovation. It's Ok, but implementing this would require to preserve other users from unexpected consequences. Typically such problems are solved with creating a custom IDEA plugin purposed to work with specific tool.

If you like, you can create a feature request in our tracker anyway: http://youtrack.jetbrains.com/issues/IDEA

Regards,
Alexander.

0
Comment actions Permalink

Arvind,
I've been wanting to get my hands dirty & dive into the CE source. I checked it out yesterday & have started exploring how to implement a custom plugin. I'll reply to this thread if I'm able to figure it out. It's always easier to learn when you have a purpose. :)
I'd still recommend creating a feature request, per Alexander. I've had success with that path here. If you open RFE, can you add the link to it to this thread?
Cheers!
- Stuart

0
Comment actions Permalink

Hi All,

I have a similar kind of issue and I already wrote my own plugin to cover some specific needs in the company I'm working for.

I already have an own GotoDeclarationHandler that will show the references of a key if I do a CTRL + click 

but I guess that I missed something somewhere as the keys are still greyed out.

 

maybe I did it wrongly ? 


here is the source file of my handler

 

https://github.com/alain57/swissas-dev-tools/blob/master/src/main/java/com/swissas/handler/PropertiesKeyToUsage.java

 

basically what it does : 

it reads a java file that contains the real usages , if it found one it will return the usages of the _Message file.

0
Comment actions Permalink

Hi, I have similar problem. I use ultimate version.

I have common.properties like:

foo=FOO (yellow)

bar=BAR (grey: unused property)

the difference between the two is that foo is used in constructor-arg and bar is used in property:

<bean id="blabla" class="com.example.Moo">
<constructor-arg name="foo" value="${foo}"/>
<property name="bar" value="${bar}"/>
</bean>
0

Please sign in to leave a comment.