Skip to content

Instantly share code, notes, and snippets.

@leeym
Created October 26, 2016 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leeym/6f50d9749c06abfcbec4232225f7c0ed to your computer and use it in GitHub Desktop.
Save leeym/6f50d9749c06abfcbec4232225f7c0ed to your computer and use it in GitHub Desktop.
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