Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
package com.wealthfront.test.check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
public class NoLabelStatementCheck extends AbstractCheck {
@Override
public int[] getRequiredTokens() {
return getDefaultTokens();
}
@Override
public int[] getDefaultTokens() {
return getAcceptableTokens();
}
@Override
public int[] getAcceptableTokens() {
return new int[] { TokenTypes.LABELED_STAT };
}
@Override
public void visitToken(DetailAST ast) {
switch (ast.getType()) {
case TokenTypes.LABELED_STAT: {
visitLabelledStatement(ast);
break;
}
default: {
final String exceptionMsg = "Unexpected token type: " + ast.getText();
throw new IllegalArgumentException(exceptionMsg);
}
}
}
protected void visitLabelledStatement(DetailAST ast) {
log(ast.getLineNo(), ast.getColumnNo(), String.format("Labeled statement is not allowed"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment