Equality custom check

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Equality custom check

amir650
This post has NOT been accepted by the mailing list yet.

Hi,

  Is it possible for me to write an equality check check that determines if the comparison involves a variable that implements some interface (including any in its ancestry)?  Example:

interface A  {
}

abstract class B implements A {
}

class C extends B {

}

..

C c1 = new C1();
C c2 = new C2();

if( c1 == c2 ) //NAUGHTY, catch me if you can!

 
Reply | Threaded
Open this post in threaded view
|

Re: Equality custom check

amir650
This post has NOT been accepted by the mailing list yet.
Here's what I have so far

import antlr.collections.AST;

import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;


public final class MyEqualsCheck
        extends Check {

    @Override
    public int[] getDefaultTokens() {
        return new int[] { TokenTypes.EQUAL, TokenTypes.NOT_EQUAL };
    }

    /**
     * Right before we visit the AST, we're allowed to do initialization and setup
     * here.
     */
    @Override
    public void beginTree(final DetailAST aRootAST) {
    }

    /**
     * Each token that we defined above is visited here.
     */
    @Override
    public void visitToken(final DetailAST ast) {

        final AST lValue = ast.getFirstChild();
        final AST rValue = lValue.getNextSibling();

    }

}