本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes.QUESTION属性的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes.QUESTION属性的具体用法?Java TokenTypes.QUESTION怎么用?Java TokenTypes.QUESTION使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.puppycrawl.tools.checkstyle.api.TokenTypes
的用法示例。
在下文中一共展示了TokenTypes.QUESTION属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDefaultTokens
@Override
public int[] getDefaultTokens() {
return new int[] {
TokenTypes.CTOR_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.INSTANCE_INIT,
TokenTypes.STATIC_INIT,
TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_FOR,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_SWITCH,
TokenTypes.LITERAL_CASE,
TokenTypes.LITERAL_CATCH,
TokenTypes.QUESTION,
TokenTypes.LAND,
TokenTypes.LOR,
};
}
示例2: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.CTOR_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.INSTANCE_INIT,
TokenTypes.STATIC_INIT,
TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_FOR,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_SWITCH,
TokenTypes.LITERAL_CASE,
TokenTypes.LITERAL_CATCH,
TokenTypes.QUESTION,
TokenTypes.LAND,
TokenTypes.LOR,
};
}
示例3: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {
TokenTypes.CTOR_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.STATIC_INIT,
TokenTypes.INSTANCE_INIT,
TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_FOR,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_ELSE,
TokenTypes.LITERAL_SWITCH,
TokenTypes.CASE_GROUP,
TokenTypes.LITERAL_TRY,
TokenTypes.LITERAL_CATCH,
TokenTypes.QUESTION,
TokenTypes.LITERAL_RETURN,
TokenTypes.LITERAL_DEFAULT,
};
}
示例4: countConditionalOperators
/**
* Calculates number of conditional operators, including inline ternary operator, for a token.
* @param ast inspected token.
* @return number of conditional operators.
* @see <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.23">
* Java Language Specification, §15.23</a>
* @see <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.24">
* Java Language Specification, §15.24</a>
* @see <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.25">
* Java Language Specification, §15.25</a>
*/
private static int countConditionalOperators(DetailAST ast) {
int number = 0;
for (DetailAST child = ast.getFirstChild(); child != null;
child = child.getNextSibling()) {
final int type = child.getType();
if (type == TokenTypes.LOR || type == TokenTypes.LAND) {
number++;
}
else if (type == TokenTypes.QUESTION) {
number += 2;
}
number += countConditionalOperators(child);
}
return number;
}
示例5: makeAcceptableTokens
/**
* Returns array of acceptable tokens.
* @return acceptableTokens.
*/
private static int[] makeAcceptableTokens() {
return new int[] {TokenTypes.ANNOTATION,
TokenTypes.ANNOTATION_FIELD_DEF,
TokenTypes.CTOR_CALL,
TokenTypes.CTOR_DEF,
TokenTypes.DOT,
TokenTypes.ENUM_CONSTANT_DEF,
TokenTypes.EXPR,
TokenTypes.LITERAL_CATCH,
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_FOR,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_NEW,
TokenTypes.LITERAL_SWITCH,
TokenTypes.LITERAL_SYNCHRONIZED,
TokenTypes.LITERAL_WHILE,
TokenTypes.METHOD_CALL,
TokenTypes.METHOD_DEF,
TokenTypes.QUESTION,
TokenTypes.RESOURCE_SPECIFICATION,
TokenTypes.SUPER_CTOR_CALL,
TokenTypes.LAMBDA,
};
}
示例6: testGetAcceptableTokens
@Test
public void testGetAcceptableTokens() {
final CyclomaticComplexityCheck cyclomaticComplexityCheckObj =
new CyclomaticComplexityCheck();
final int[] actual = cyclomaticComplexityCheckObj.getAcceptableTokens();
final int[] expected = {
TokenTypes.CTOR_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.INSTANCE_INIT,
TokenTypes.STATIC_INIT,
TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_FOR,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_SWITCH,
TokenTypes.LITERAL_CASE,
TokenTypes.LITERAL_CATCH,
TokenTypes.QUESTION,
TokenTypes.LAND,
TokenTypes.LOR,
};
Assert.assertArrayEquals("Invalid acceptable tokens", expected, actual);
}
示例7: testGetAcceptableTokens
@Test
public void testGetAcceptableTokens() {
final NPathComplexityCheck npathComplexityCheckObj = new NPathComplexityCheck();
final int[] actual = npathComplexityCheckObj.getAcceptableTokens();
final int[] expected = {
TokenTypes.CTOR_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.STATIC_INIT,
TokenTypes.INSTANCE_INIT,
TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_FOR,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_ELSE,
TokenTypes.LITERAL_SWITCH,
TokenTypes.CASE_GROUP,
TokenTypes.LITERAL_TRY,
TokenTypes.LITERAL_CATCH,
TokenTypes.QUESTION,
TokenTypes.LITERAL_RETURN,
TokenTypes.LITERAL_DEFAULT,
};
Assert.assertNotNull("Acceptable tokens should not be null", actual);
Assert.assertArrayEquals("Invalid acceptable tokens", expected, actual);
}
示例8: testGetRequiredTokens
@Test
public void testGetRequiredTokens() {
final NPathComplexityCheck npathComplexityCheckObj = new NPathComplexityCheck();
final int[] actual = npathComplexityCheckObj.getRequiredTokens();
final int[] expected = {
TokenTypes.CTOR_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.STATIC_INIT,
TokenTypes.INSTANCE_INIT,
TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_FOR,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_ELSE,
TokenTypes.LITERAL_SWITCH,
TokenTypes.CASE_GROUP,
TokenTypes.LITERAL_TRY,
TokenTypes.LITERAL_CATCH,
TokenTypes.QUESTION,
TokenTypes.LITERAL_RETURN,
TokenTypes.LITERAL_DEFAULT,
};
Assert.assertNotNull("Required tokens should not be null", actual);
Assert.assertArrayEquals("Invalid required tokens", expected, actual);
}
示例9: walkConditional
/**
* Recursively walks a conditional expression checking the left
* and right sides, checking for matches and
* logging violations.
*
* @param cond a Conditional type
* {@link TokenTypes#QUESTION QUESTION}
*/
private void walkConditional(final DetailAST cond) {
if (cond.getType() == TokenTypes.QUESTION) {
walkConditional(getCondLeft(cond));
walkConditional(getCondRight(cond));
}
else {
final String warningText =
removeQuotes(cond.getText());
logMatch(cond.getLineNo(), cond.getColumnNo(), warningText);
}
}
示例10: leaveToken
@Override
public void leaveToken(DetailAST ast) {
switch (ast.getType()) {
case TokenTypes.LITERAL_WHILE:
case TokenTypes.LITERAL_DO:
case TokenTypes.LITERAL_FOR:
case TokenTypes.LITERAL_IF:
case TokenTypes.LITERAL_SWITCH:
leaveConditional();
break;
case TokenTypes.LITERAL_TRY:
leaveMultiplyingConditional();
break;
case TokenTypes.LITERAL_RETURN:
case TokenTypes.QUESTION:
leaveUnitaryOperator();
break;
case TokenTypes.LITERAL_CATCH:
leaveAddingConditional();
break;
case TokenTypes.LITERAL_DEFAULT:
leaveBranch();
break;
case TokenTypes.LITERAL_ELSE:
case TokenTypes.CASE_GROUP:
leaveBranch();
branchVisited = false;
break;
case TokenTypes.CTOR_DEF:
case TokenTypes.METHOD_DEF:
case TokenTypes.INSTANCE_INIT:
case TokenTypes.STATIC_INIT:
leaveMethodDef(ast);
break;
default:
break;
}
}
示例11: getDefaultTokens
@Override
public int[] getDefaultTokens() {
return new int[] {
TokenTypes.QUESTION, // '?'
TokenTypes.COLON, // ':' (not reported for a case)
TokenTypes.EQUAL, // "=="
TokenTypes.NOT_EQUAL, // "!="
TokenTypes.DIV, // '/'
TokenTypes.PLUS, //' +' (unary plus is UNARY_PLUS)
TokenTypes.MINUS, // '-' (unary minus is UNARY_MINUS)
TokenTypes.STAR, // '*'
TokenTypes.MOD, // '%'
TokenTypes.SR, // ">>"
TokenTypes.BSR, // ">>>"
TokenTypes.GE, // ">="
TokenTypes.GT, // ">"
TokenTypes.SL, // "<<"
TokenTypes.LE, // "<="
TokenTypes.LT, // '<'
TokenTypes.BXOR, // '^'
TokenTypes.BOR, // '|'
TokenTypes.LOR, // "||"
TokenTypes.BAND, // '&'
TokenTypes.LAND, // "&&"
TokenTypes.TYPE_EXTENSION_AND,
TokenTypes.LITERAL_INSTANCEOF,
};
}
示例12: visitToken
@Override
public void visitToken(DetailAST ast) {
switch (ast.getType()) {
case TokenTypes.METHOD_CALL:
processLeft(ast);
processRight(ast.findFirstToken(TokenTypes.RPAREN));
break;
case TokenTypes.DOT:
case TokenTypes.EXPR:
case TokenTypes.QUESTION:
processExpression(ast);
break;
case TokenTypes.LITERAL_FOR:
visitLiteralFor(ast);
break;
case TokenTypes.ANNOTATION:
case TokenTypes.ENUM_CONSTANT_DEF:
case TokenTypes.LITERAL_NEW:
case TokenTypes.LITERAL_SYNCHRONIZED:
case TokenTypes.LAMBDA:
visitTokenWithOptionalParentheses(ast);
break;
case TokenTypes.RESOURCE_SPECIFICATION:
visitResourceSpecification(ast);
break;
default:
processLeft(ast.findFirstToken(TokenTypes.LPAREN));
processRight(ast.findFirstToken(TokenTypes.RPAREN));
}
}
示例13: 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();
}
}
}
}
示例14: visitToken
@Override
public void visitToken(DetailAST ast) {
switch (ast.getType()) {
case TokenTypes.LITERAL_IF:
case TokenTypes.LITERAL_SWITCH:
case TokenTypes.LITERAL_WHILE:
case TokenTypes.LITERAL_DO:
case TokenTypes.LITERAL_FOR:
visitConditional(ast, 1);
break;
case TokenTypes.QUESTION:
visitUnitaryOperator(ast, 2);
break;
case TokenTypes.LITERAL_RETURN:
visitUnitaryOperator(ast, 0);
break;
case TokenTypes.CASE_GROUP:
final int caseNumber = countCaseTokens(ast);
branchVisited = true;
pushValue(caseNumber);
break;
case TokenTypes.LITERAL_ELSE:
branchVisited = true;
if (currentRangeValue.equals(BigInteger.ZERO)) {
currentRangeValue = BigInteger.ONE;
}
pushValue(0);
break;
case TokenTypes.LITERAL_TRY:
case TokenTypes.LITERAL_CATCH:
case TokenTypes.LITERAL_DEFAULT:
pushValue(1);
break;
case TokenTypes.CTOR_DEF:
case TokenTypes.METHOD_DEF:
case TokenTypes.INSTANCE_INIT:
case TokenTypes.STATIC_INIT:
pushValue(0);
break;
default:
break;
}
}
示例15: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {TokenTypes.QUESTION};
}