Structural search question Follow
I'm trying to create a structural search that will detect badly declared
logger variables. Here's what I have so far:
class $Class1$ {
static org.apache.log4j.Logger $logger$ = Logger.getLogger($Class2$.class);
}
This finds all declarations of log4j loggers in my project. However I only
want to detect cases where $Class1$ != $Class2$. Is this possible?
Regards,
Chris
Please sign in to leave a comment.
It will be possible in next eap build of IDEA 8, just specify groovy
script constraint for the second variable, like Class1 != Class2
Chris Miller wrote:
--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"
Ah very timely and great news! Thanks, I look forward to putting this to
the test.
>> I'm trying to create a structural search that will detect badly
>> declared logger variables. Here's what I have so far:
>>
>> class $Class1$ {
>> static org.apache.log4j.Logger $logger$ =
>> Logger.getLogger($Class2$.class);
>> }
>> This finds all declarations of log4j loggers in my project. However I
>> only want to detect cases where $Class1$ != $Class2$. Is this
>> possible?
>>
>> Regards,
>> Chris
I will be making an inspection out of this.
Bas
Chris Miller wrote:
That would be great Bas, thanks. My plan was to make my own custom structural
search inspection anyway, but if you're willing to add this as a first class
one (possibly with a quick fix too?) then it would be fantastic. I guess
to do it properly would require support for java.util.logging, commons logging
and sl4j/logback too.
Cheers,
Chris
>> I'm trying to create a structural search that will detect badly
>> declared logger variables. Here's what I have so far:
>>
>> class $Class1$ {
>> static org.apache.log4j.Logger $logger$ =
>> Logger.getLogger($Class2$.class);
>> }
>> This finds all declarations of log4j loggers in my project. However I
>> only want to detect cases where $Class1$ != $Class2$. Is this
>> possible?
>>
>> Regards,
>> Chris
Look for the "Logger initialized with foreign class" inspection in the next Diana EAP build. It has a quick fix and the Logger class and factory method are configurable. As far as I know the java.util.logging.Logger has no way to create a logger from a class literal, do you have any suggestions how the inspection work there?
Bas
Oh good point regarding java.util.logging - I hadn't given it enough thought.
I guess there's nothing that needs doing there.