Structural search question

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


6 comments
Comment actions Permalink

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:

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


--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

Ah very timely and great news! Thanks, I look forward to putting this to
the test.

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:

>> 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


0
Comment actions Permalink

I will be making an inspection out of this.

Bas

Chris Miller wrote:

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

0
Comment actions Permalink

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 will be making an inspection out of this.

Bas

Chris Miller wrote:

>> 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


0
Comment actions Permalink

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

0
Comment actions Permalink

Oh good point regarding java.util.logging - I hadn't given it enough thought.
I guess there's nothing that needs doing there.

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



0

Please sign in to leave a comment.