QualInsight / qualinsight-plugins-sonarqube-smell

Code Smells plugin for SonarQube and companion Java library
GNU Lesser General Public License v3.0
47 stars 13 forks source link

Why analyzing Sources and not compiled class files? #14

Closed TurinTuramba closed 9 years ago

TurinTuramba commented 9 years ago

Hi,

after a total not working plugin in Sonar. I investigated my setup in deepth and regconized that !WTF plugin investigates the source files and not the class files (because of the annotations I expected this). The problem in my case was a concatenation for the message field, e.g.

@WTF(minutes = 10, reason = "Anti-pattern" + " blabla", type = WTFType.ANTI_PATTERN)

this resulted in a class cast exception in WTFCheck

Caused by: java.lang.ClassCastException: org.sonar.java.model.expression.BinaryExpressionTreeImpl cannot be cast to org.sonar.plugins.java.api.tree.LiteralTree
    at com.qualinsight.plugins.sonarqube.wtf.internal.check.WTFCheck.handleWTFAnnotation(WTFCheck.java:97)
    at com.qualinsight.plugins.sonarqube.wtf.internal.check.WTFCheck.visitNode(WTFCheck.java:79)
    at org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:89)
    at org.sonar.java.ast.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:115)
    at org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:91)

I am wondering why You decided to analyse the source code rather than the class files, because the informations about the annotations will be compiled to the class file and could be examined there.

Just an idea.

Regards Roland

pawlakm commented 9 years ago

Dear Roland,

Thanks for your feedback. Indeed BinaryExpressionTrees are not handled yet, I'll create an issue to fix this.

Back to your question, the goal of the plugin is to annotate the source in order to inform developers of code smells and make them able to discuss these smells during code reviews / sprint plannings. This information is not needed nor wanted at runtime, nor in compiled classes (no other issue raised by SQ is compiled into your project's bytecode).

Therefor and as documented, the annotation's retention type that was chosen is SOURCE. As the plugin is meant to be simple, and the annotation is meant to document the code, I see no good reason to change this approach.

Kind regards,

Michel

pawlakm commented 9 years ago

The bug you reported is now fixed (see #15) and will be released with milestone 1.0.3.

Added the following test cases :

    public static final String CONSTANT1 = "Anti-";

    public static final String CONSTANT2 = "pattern";

    public static final String CONSTANT3 = "Anti-pattern";

    // Noncompliant @+1 {{Anti-pattern}}
    @WTF(minutes = 10, reason = "Anti-pattern", type = WTFType.ANTI_PATTERN)
    public void method() {
    }

    // Noncompliant @+1 {{Anti-pattern}}
    @WTF(minutes = 10, reason = "Anti-" + "pattern", type = WTFType.ANTI_PATTERN)
    public void method2() {
    }

    // Noncompliant @+1 {{Anti-pattern}}
    @WTF(minutes = 10, reason = "Anti" + "-" + "pattern", type = WTFType.ANTI_PATTERN)
    public void method2() {
    }

    // Noncompliant @+1 {{Anti-pattern}}
    @WTF(minutes = 10, reason = CONSTANT1 + "pattern", type = WTFType.ANTI_PATTERN)
    public void method4() {
    }

    // Noncompliant @+1 {{Anti-pattern}}
    @WTF(minutes = 10, reason = "Anti-" + CONSTANT2, type = WTFType.ANTI_PATTERN)
    public void method3() {
    }

    // Noncompliant @+1 {{Anti-pattern}}
    @WTF(minutes = 10, reason = CONSTANT1 + CONSTANT2, type = WTFType.ANTI_PATTERN)
    public void method5() {
    }

    // Noncompliant @+1 {{Anti-pattern}}
    @WTF(minutes = 10, reason = CONSTANT3, type = WTFType.ANTI_PATTERN)
    public void method6() {
    }

Regards,

Michel

TurinTuramba commented 9 years ago

Hi Michel,

Thanks for Your fast answer. Your are absolutely right I missed the RetentionPolicy.SOURCE and expected the CLASS policy.

And again thank you for this fix.

Do You have an estimation of the release date for the upcoming v.1.0.3?

Regards Roland

pawlakm commented 9 years ago

Hi Roland,

You're welcome. I released 1.0.3 last night so you can start using it right after having read this email :-)

Best Regards,

Michel

Le 16 sept. 2015 à 08:38, TurinTuramba notifications@github.com a écrit :

Hi Michel,

Thanks for Your fast answer. Your are absolutely right I missed the RetentionPolicy.SOURCE and expected the CLASS policy.

And again thank you for this fix.

Do You have an estimation of the release date for the upcoming v.1.0.3?

Regards Roland

— Reply to this email directly or view it on GitHub.

pawlakm commented 9 years ago

Closing issue.