0
我想用Checkstyle編寫一個Check來確定給定的類是否擴展了其他類,以及是否存在任何'=='的用法。有人能幫我理解我需要做什麼嗎?Checkstyle class check
這是我到目前爲止有:
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 DetailAST lValue = ast.getFirstChild();
final DetailAST rValue = lValue.getNextSibling();
//is it possible to determine if lValue and rValue implement a given interface directly or indirectly?
}
private DetailAST getLowestParent(final DetailAST aAST) {
DetailAST lowestParent = aAST;
while ((lowestParent.getParent() != null)) {
lowestParent = lowestParent.getParent();
}
return lowestParent;
}
}
嗨馬特 - 感謝您的回覆。你可以發佈一段代碼,說明如何找出一個類是否在其祖先的任何地方實現了一個接口? –