本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes.STRING_LITERAL属性的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes.STRING_LITERAL属性的具体用法?Java TokenTypes.STRING_LITERAL怎么用?Java TokenTypes.STRING_LITERAL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.puppycrawl.tools.checkstyle.api.TokenTypes
的用法示例。
在下文中一共展示了TokenTypes.STRING_LITERAL属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: containsAllSafeTokens
/**
* Looks for all "safe" Token combinations in the argument
* expression branch.
* @param expr the argument expression
* @return - true if any child matches the set of tokens, false if not
*/
private static boolean containsAllSafeTokens(final DetailAST expr) {
DetailAST arg = expr.getFirstChild();
arg = skipVariableAssign(arg);
boolean argIsNotNull = false;
if (arg.getType() == TokenTypes.PLUS) {
DetailAST child = arg.getFirstChild();
while (child != null
&& !argIsNotNull) {
argIsNotNull = child.getType() == TokenTypes.STRING_LITERAL
|| child.getType() == TokenTypes.IDENT;
child = child.getNextSibling();
}
}
return argIsNotNull
|| !arg.branchContains(TokenTypes.IDENT)
&& !arg.branchContains(TokenTypes.LITERAL_NULL);
}
示例2: getStringExpr
/**
* Returns the literal string expression represented by an AST.
* @param ast an AST node for an EXPR
* @return the Java string represented by the given AST expression
* or empty string if expression is too complex
* @throws IllegalArgumentException if the AST is invalid
*/
private static String getStringExpr(DetailAST ast) {
final DetailAST firstChild = ast.getFirstChild();
String expr = "";
switch (firstChild.getType()) {
case TokenTypes.STRING_LITERAL:
// NOTE: escaped characters are not unescaped
final String quotedText = firstChild.getText();
expr = quotedText.substring(1, quotedText.length() - 1);
break;
case TokenTypes.IDENT:
expr = firstChild.getText();
break;
case TokenTypes.DOT:
expr = firstChild.getLastChild().getText();
break;
default:
// annotations with complex expressions cannot suppress warnings
}
return expr;
}
示例3: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.NUM_DOUBLE,
TokenTypes.NUM_FLOAT,
TokenTypes.NUM_INT,
TokenTypes.NUM_LONG,
TokenTypes.IDENT,
TokenTypes.COMMENT_CONTENT,
TokenTypes.STRING_LITERAL,
TokenTypes.CHAR_LITERAL,
};
}
示例4: visitToken
@Override
public void visitToken(DetailAST ast) {
// no need to check for nulls here, == and != always have two children
final AST firstChild = ast.getFirstChild();
final AST secondChild = firstChild.getNextSibling();
if (firstChild.getType() == TokenTypes.STRING_LITERAL
|| secondChild.getType() == TokenTypes.STRING_LITERAL) {
log(ast.getLineNo(), ast.getColumnNo(),
MSG_KEY, ast.getText());
}
}
示例5: getDefaultTokens
@Override
public int[] getDefaultTokens() {
return new int[] {
TokenTypes.EXPR,
TokenTypes.IDENT,
TokenTypes.NUM_DOUBLE,
TokenTypes.NUM_FLOAT,
TokenTypes.NUM_INT,
TokenTypes.NUM_LONG,
TokenTypes.STRING_LITERAL,
TokenTypes.LITERAL_NULL,
TokenTypes.LITERAL_FALSE,
TokenTypes.LITERAL_TRUE,
TokenTypes.ASSIGN,
TokenTypes.BAND_ASSIGN,
TokenTypes.BOR_ASSIGN,
TokenTypes.BSR_ASSIGN,
TokenTypes.BXOR_ASSIGN,
TokenTypes.DIV_ASSIGN,
TokenTypes.MINUS_ASSIGN,
TokenTypes.MOD_ASSIGN,
TokenTypes.PLUS_ASSIGN,
TokenTypes.SL_ASSIGN,
TokenTypes.SR_ASSIGN,
TokenTypes.STAR_ASSIGN,
TokenTypes.LAMBDA,
};
}
示例6: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.EXPR,
TokenTypes.IDENT,
TokenTypes.NUM_DOUBLE,
TokenTypes.NUM_FLOAT,
TokenTypes.NUM_INT,
TokenTypes.NUM_LONG,
TokenTypes.STRING_LITERAL,
TokenTypes.LITERAL_NULL,
TokenTypes.LITERAL_FALSE,
TokenTypes.LITERAL_TRUE,
TokenTypes.ASSIGN,
TokenTypes.BAND_ASSIGN,
TokenTypes.BOR_ASSIGN,
TokenTypes.BSR_ASSIGN,
TokenTypes.BXOR_ASSIGN,
TokenTypes.DIV_ASSIGN,
TokenTypes.MINUS_ASSIGN,
TokenTypes.MOD_ASSIGN,
TokenTypes.PLUS_ASSIGN,
TokenTypes.SL_ASSIGN,
TokenTypes.SR_ASSIGN,
TokenTypes.STAR_ASSIGN,
TokenTypes.LAMBDA,
};
}
示例7: visitToken
@Override
public void visitToken(DetailAST ast) {
final int type = ast.getType();
final DetailAST parent = ast.getParent();
if (type == TokenTypes.LAMBDA && isLambdaSingleParameterSurrounded(ast)) {
log(ast, MSG_LAMBDA, ast.getText());
}
else if (type != TokenTypes.ASSIGN
|| parent.getType() != TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR) {
final boolean surrounded = isSurrounded(ast);
// An identifier surrounded by parentheses.
if (surrounded && type == TokenTypes.IDENT) {
parentToSkip = ast.getParent();
log(ast, MSG_IDENT, ast.getText());
}
// A literal (numeric or string) surrounded by parentheses.
else if (surrounded && isInTokenList(type, LITERALS)) {
parentToSkip = ast.getParent();
if (type == TokenTypes.STRING_LITERAL) {
log(ast, MSG_STRING,
chopString(ast.getText()));
}
else {
log(ast, MSG_LITERAL, ast.getText());
}
}
// The rhs of an assignment surrounded by parentheses.
else if (isInTokenList(type, ASSIGNMENTS)) {
assignDepth++;
final DetailAST last = ast.getLastChild();
if (last.getType() == TokenTypes.RPAREN) {
log(ast, MSG_ASSIGN);
}
}
}
}
示例8: testGetRequiredTokens
@Test
public void testGetRequiredTokens() {
final AvoidEscapedUnicodeCharactersCheck checkObj =
new AvoidEscapedUnicodeCharactersCheck();
final int[] expected = {
TokenTypes.STRING_LITERAL,
TokenTypes.CHAR_LITERAL,
};
assertArrayEquals("Required tokens differ from expected",
expected, checkObj.getRequiredTokens());
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:11,代码来源:AvoidEscapedUnicodeCharactersCheckTest.java
示例9: testGetAcceptableTokens
@Test
public void testGetAcceptableTokens() {
final AvoidEscapedUnicodeCharactersCheck check = new AvoidEscapedUnicodeCharactersCheck();
final int[] actual = check.getAcceptableTokens();
final int[] expected = {TokenTypes.STRING_LITERAL, TokenTypes.CHAR_LITERAL };
assertArrayEquals("Acceptable tokens differ from expected",
expected, actual);
}
示例10: visitToken
@Override
public void visitToken(final DetailAST ast) {
final DetailAST annotation = getSuppressWarnings(ast);
if (annotation != null) {
final DetailAST warningHolder =
findWarningsHolder(annotation);
final DetailAST token =
warningHolder.findFirstToken(TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR);
DetailAST warning;
if (token == null) {
warning = warningHolder.findFirstToken(TokenTypes.EXPR);
}
else {
// case like '@SuppressWarnings(value = UNUSED)'
warning = token.findFirstToken(TokenTypes.EXPR);
}
//rare case with empty array ex: @SuppressWarnings({})
if (warning == null) {
//check to see if empty warnings are forbidden -- are by default
logMatch(warningHolder.getLineNo(),
warningHolder.getColumnNo(), "");
}
else {
while (warning != null) {
if (warning.getType() == TokenTypes.EXPR) {
final DetailAST fChild = warning.getFirstChild();
switch (fChild.getType()) {
//typical case
case TokenTypes.STRING_LITERAL:
final String warningText =
removeQuotes(warning.getFirstChild().getText());
logMatch(warning.getLineNo(),
warning.getColumnNo(), warningText);
break;
// conditional case
// ex:
// @SuppressWarnings((false) ? (true) ? "unchecked" : "foo" : "unused")
case TokenTypes.QUESTION:
walkConditional(fChild);
break;
// param in constant case
// ex: public static final String UNCHECKED = "unchecked";
// @SuppressWarnings(UNCHECKED)
// or
// @SuppressWarnings(SomeClass.UNCHECKED)
case TokenTypes.IDENT:
case TokenTypes.DOT:
break;
default:
// Known limitation: cases like @SuppressWarnings("un" + "used") or
// @SuppressWarnings((String) "unused") are not properly supported,
// but they should not cause exceptions.
}
}
warning = warning.getNextSibling();
}
}
}
}
示例11: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {TokenTypes.STRING_LITERAL};
}
示例12: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {TokenTypes.STRING_LITERAL, TokenTypes.CHAR_LITERAL};
}
示例13: isStringLiteral
/**
* Checks for calling equals on String literal and
* anon object which cannot be null.
* @param objCalledOn object AST
* @return if it is string literal
*/
private static boolean isStringLiteral(DetailAST objCalledOn) {
return objCalledOn.getType() == TokenTypes.STRING_LITERAL
|| objCalledOn.getType() == TokenTypes.LITERAL_NEW;
}