@Override public void visitToken(DetailAST ast) { final String text = ast.getText(); if (format.matcher(text).find()) { String customMessage = message; if (customMessage.isEmpty()) { customMessage = MSG_KEY; } log( ast, customMessage, formatString); } }
/** * Set whether or not the match is case sensitive. * @param caseInsensitive true if the match is case insensitive. */ public void setIgnoreCase(boolean caseInsensitive) { ignoreCase = caseInsensitive; updateRegexp(); }
@Test public void testTokensNotNull() { final IllegalTokenTextCheck check = new IllegalTokenTextCheck(); Assert.assertNotNull("Acceptable tokens should not be null", check.getAcceptableTokens()); Assert.assertNotNull("Default tokens should not be null", check.getDefaultTokens()); Assert.assertNotNull("Required tokens should not be null", check.getRequiredTokens()); Assert.assertTrue("Comments are also TokenType token", check.isCommentNodesRequired()); }
@Test public void testOrderOfProperties() throws Exception { // pure class must be used as configuration doesn't guarantee order of // attributes final IllegalTokenTextCheck check = new IllegalTokenTextCheck(); check.setFormat("test"); check.setIgnoreCase(true); final Pattern actual = (Pattern) TestUtil.getClassDeclaredField( IllegalTokenTextCheck.class, "format").get(check); Assert.assertEquals("should match", Pattern.CASE_INSENSITIVE, actual.flags()); Assert.assertEquals("should match", "test", actual.pattern()); }
@Test public void testAcceptableTokensMakeSense() { final int expectedTokenTypesTotalNumber = 169; Assert.assertEquals("Total number of TokenTypes has changed, acceptable tokens in" + " IllegalTokenTextCheck need to be reconsidered.", expectedTokenTypesTotalNumber, TokenUtil.getTokenTypesTotalNumber()); final IllegalTokenTextCheck check = new IllegalTokenTextCheck(); final int[] allowedTokens = check.getAcceptableTokens(); final List<Integer> tokenTypesWithMutableText = Arrays.asList( TokenTypes.NUM_DOUBLE, TokenTypes.NUM_FLOAT, TokenTypes.NUM_INT, TokenTypes.NUM_LONG, TokenTypes.IDENT, TokenTypes.COMMENT_CONTENT, TokenTypes.STRING_LITERAL, TokenTypes.CHAR_LITERAL ); for (int tokenType : allowedTokens) { Assert.assertTrue(TokenUtil.getTokenName(tokenType) + " should not be allowed" + " in this check as its text is a constant (IllegalTokenCheck should be used for" + " such cases).", tokenTypesWithMutableText.contains(tokenType)); } }
/** * Set the format to the specified regular expression. * @param format a {@code String} value * @throws org.apache.commons.beanutils.ConversionException unable to parse format */ public void setFormat(String format) { formatString = format; updateRegexp(); }
@Override public void visitToken(DetailAST ast) { final String text = ast.getText(); if (format.matcher(text).find()) { String customMessage = message; if (customMessage.isEmpty()) { customMessage = MSG_KEY; } log( ast, customMessage, formatString); } }
/** * Set the format to the specified regular expression. * @param format a {@code String} value * @throws org.apache.commons.beanutils.ConversionException unable to parse format */ public void setFormat(String format) { formatString = format; updateRegexp(); }
/** * Set whether or not the match is case sensitive. * @param caseInsensitive true if the match is case insensitive. */ public void setIgnoreCase(boolean caseInsensitive) { ignoreCase = caseInsensitive; updateRegexp(); }