本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes.RPAREN属性的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes.RPAREN属性的具体用法?Java TokenTypes.RPAREN怎么用?Java TokenTypes.RPAREN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.puppycrawl.tools.checkstyle.api.TokenTypes
的用法示例。
在下文中一共展示了TokenTypes.RPAREN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processIf
/**
* process the given SymTabAST as an if block
*
* @param tree the SymTabAST to process
* @return <code>void</code>
* @see #makeBlock(SymTabAST)
* @see #walkTree(SymTabAST, boolean)
* @see #processElse(SymTabAST)
*/
public void processIf(SymTabAST tree) {
BlockDef block = makeBlock(tree);
SymTabAST expr = tree.findFirstToken(TokenTypes.EXPR);
SymTabAST ifBranch = (SymTabAST)expr.getNextSibling();
// handle Checkstyle grammar
if (ifBranch.getType() == TokenTypes.RPAREN) {
ifBranch = (SymTabAST) ifBranch.getNextSibling();
}
SymTabAST elseBranch = (SymTabAST)ifBranch.getNextSibling();
// handle Checkstyle grammar
if ((elseBranch != null) && (elseBranch.getType() == TokenTypes.SEMI)) {
elseBranch = (SymTabAST) elseBranch.getNextSibling();
}
if ((elseBranch != null) && (elseBranch.getType() == TokenTypes.LITERAL_ELSE)) {
elseBranch = (SymTabAST) elseBranch.getFirstChild();
}
symbolTable.pushScope( block );
walkTree(expr, false);
walkTree(ifBranch, false);
symbolTable.popScope();
processElse(elseBranch);
}
示例2: checkCheckClosingParens
/**
* Checks to see if the closing parenthesis are present if required or
* prohibited.
*
* @param ast the annotation token
*/
private void checkCheckClosingParens(final DetailAST ast) {
if (closingParens != ClosingParens.IGNORE) {
final DetailAST paren = ast.getLastChild();
final boolean parenExists = paren.getType() == TokenTypes.RPAREN;
if (closingParens == ClosingParens.ALWAYS
&& !parenExists) {
log(ast.getLineNo(), MSG_KEY_ANNOTATION_PARENS_MISSING);
}
else if (closingParens == ClosingParens.NEVER
&& parenExists
&& !ast.branchContains(TokenTypes.EXPR)
&& !ast.branchContains(TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR)
&& !ast.branchContains(TokenTypes.ANNOTATION_ARRAY_INIT)) {
log(ast.getLineNo(), MSG_KEY_ANNOTATION_PARENS_PRESENT);
}
}
}
示例3: getDetailsForLambda
/**
* Collects validation details for Lambdas.
* @param ast a {@code DetailAST} value
* @return an object containing all details to make a validation
*/
private static Details getDetailsForLambda(DetailAST ast) {
final DetailAST lcurly = ast.findFirstToken(TokenTypes.SLIST);
boolean shouldCheckLastRcurly = false;
DetailAST nextToken = getNextToken(ast);
if (nextToken.getType() != TokenTypes.RPAREN
&& nextToken.getType() != TokenTypes.COMMA) {
shouldCheckLastRcurly = true;
nextToken = getNextToken(nextToken);
}
DetailAST rcurly = null;
if (lcurly != null) {
rcurly = lcurly.getLastChild();
}
return new Details(lcurly, rcurly, nextToken, shouldCheckLastRcurly);
}
示例4: processExpression
/**
* Checks parens inside {@link TokenTypes#EXPR}, {@link TokenTypes#QUESTION}
* and {@link TokenTypes#METHOD_CALL}.
* @param ast the token to check.
*/
private void processExpression(DetailAST ast) {
if (ast.branchContains(TokenTypes.LPAREN)) {
DetailAST childAst = ast.getFirstChild();
while (childAst != null) {
if (childAst.getType() == TokenTypes.LPAREN) {
processLeft(childAst);
}
else if (childAst.getType() == TokenTypes.RPAREN && !isInTypecast(childAst)) {
processRight(childAst);
}
else if (!isAcceptableToken(childAst)) {
//Traverse all subtree tokens which will never be configured
//to be launched in visitToken()
processExpression(childAst);
}
childAst = childAst.getNextSibling();
}
}
}
示例5: handleWhileAndSynchronized
/**
* processes a while loop and resolves references in it
*
* @param block the <code>BlockDef</code> to process
*/
private void handleWhileAndSynchronized(BlockDef block) {
SymTabAST node = block.getTreeNode();
SymTabAST condition =
(node.findFirstToken(TokenTypes.EXPR));
SymTabAST slist = (SymTabAST) (condition.getNextSibling());
// handle Checkstyle grammar
if (slist.getType() == TokenTypes.RPAREN) {
slist = (SymTabAST) slist.getNextSibling();
}
resolveExpression(condition, block, null, true);
handleSList(slist, block);
}
示例6: resolveQuestion
private IClass resolveQuestion(
SymTabAST question,
Scope location,
IClass context,
boolean referencePhase) {
SymTabAST test = (SymTabAST) question.getFirstChild();
while (test.getType() == TokenTypes.LPAREN) {
test = (SymTabAST) test.getNextSibling();
}
SymTabAST leftBranch = (SymTabAST) test.getNextSibling();
while (leftBranch.getType() == TokenTypes.RPAREN) {
leftBranch = (SymTabAST) leftBranch.getNextSibling();
}
SymTabAST rightBranch = (SymTabAST) leftBranch.getNextSibling();
while (rightBranch.getType() != TokenTypes.COLON) {
rightBranch = (SymTabAST) rightBranch.getNextSibling();
}
rightBranch = (SymTabAST) rightBranch.getNextSibling();
resolveExpression(test, location, context, referencePhase);
IClass leftClass =
resolveExpression(leftBranch, location, context, referencePhase);
IClass rightClass =
resolveExpression(rightBranch, location, context, referencePhase);
return moreGeneral(leftClass, rightClass);
}
示例7: findRightSibling
/**
* Finds the right sibling of the left child of a binary operator,
* skipping parentheses.
* @param aLeftChild the left child of a binary operator.
* @return the node of the right sibling.
*/
private SymTabAST findRightSibling(SymTabAST aLeftChild) {
SymTabAST rightChild = (SymTabAST) (aLeftChild.getNextSibling());
// handle Checkstyle grammar
while ((rightChild != null)
&& (rightChild.getType() == TokenTypes.RPAREN))
{
rightChild = (SymTabAST) rightChild.getNextSibling();
}
return rightChild;
}
示例8: processFor
/**
* process the given SymTabAST as a for block
*
* @param tree the SymTabAST to process
* @return <code>void</code>
* @see #makeBlock(SymTabAST)
* @see #walkTree(SymTabAST, boolean)
*/
public void processFor(SymTabAST tree) {
BlockDef block = makeBlock(tree);
symbolTable.pushScope( block );
SymTabAST body;
SymTabAST forEach = tree.findFirstToken(TokenTypes.FOR_EACH_CLAUSE);
if (forEach != null) {
walkTree(forEach, false);
body = (SymTabAST)forEach.getNextSibling();
}
else {
walkTree(tree.findFirstToken(TokenTypes.FOR_INIT), false);
walkTree(tree.findFirstToken(TokenTypes.FOR_CONDITION), false);
SymTabAST forIter = tree.findFirstToken(TokenTypes.FOR_ITERATOR);
walkTree(forIter, false);
body = (SymTabAST)forIter.getNextSibling();
}
//handle Checkstyle grammar
if (body.getType() == TokenTypes.RPAREN) {
body = (SymTabAST) body.getNextSibling();
}
walkTree(body, false);
symbolTable.popScope();
}
示例9: visitConditional
/**
* Visits if, while, do-while, for and switch tokens - all of them have expression in
* parentheses which is used for calculation.
* @param ast visited token.
* @param basicBranchingFactor default number of branches added.
*/
private void visitConditional(DetailAST ast, int basicBranchingFactor) {
int expressionValue = basicBranchingFactor;
DetailAST bracketed;
for (bracketed = ast.findFirstToken(TokenTypes.LPAREN).getNextSibling();
bracketed.getType() != TokenTypes.RPAREN;
bracketed = bracketed.getNextSibling()) {
expressionValue += countConditionalOperators(bracketed);
}
processingTokenEnd.setToken(bracketed);
pushValue(expressionValue);
}
示例10: isVariableInOperatorExpr
/**
* Checks if variable is in operator declaration. For instance:
* <pre>
* boolean b = true;
* if (b) {...}
* </pre>
* Variable 'b' is in declaration of operator IF.
* @param operator
* Ast node which represents operator.
* @param variable
* Variable which is checked for content in operator.
* @return true if operator contains variable in its declaration, otherwise
* - false.
*/
private static boolean isVariableInOperatorExpr(
DetailAST operator, DetailAST variable) {
boolean isVarInOperatorDeclaration = false;
final DetailAST openingBracket =
operator.findFirstToken(TokenTypes.LPAREN);
// Get EXPR between brackets
DetailAST exprBetweenBrackets = openingBracket.getNextSibling();
// Look if variable is in operator expression
while (exprBetweenBrackets.getType() != TokenTypes.RPAREN) {
if (isChild(exprBetweenBrackets, variable)) {
isVarInOperatorDeclaration = true;
break;
}
exprBetweenBrackets = exprBetweenBrackets.getNextSibling();
}
// Variable may be met in ELSE declaration
// So, check variable usage in these declarations.
if (!isVarInOperatorDeclaration && operator.getType() == TokenTypes.LITERAL_IF) {
final DetailAST elseBlock = operator.getLastChild();
if (elseBlock.getType() == TokenTypes.LITERAL_ELSE) {
// Get IF followed by ELSE
final DetailAST firstNodeInsideElseBlock = elseBlock.getFirstChild();
if (firstNodeInsideElseBlock.getType() == TokenTypes.LITERAL_IF) {
isVarInOperatorDeclaration =
isVariableInOperatorExpr(firstNodeInsideElseBlock, variable);
}
}
}
return isVarInOperatorDeclaration;
}
示例11: 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);
}
}
}
}
示例12: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.DOT,
TokenTypes.COMMA,
TokenTypes.SEMI,
TokenTypes.ELLIPSIS,
TokenTypes.AT,
TokenTypes.LPAREN,
TokenTypes.RPAREN,
TokenTypes.ARRAY_DECLARATOR,
TokenTypes.RBRACK,
TokenTypes.METHOD_REF,
};
}
示例13: getAllAnnotationValues
/**
* Get all annotation values.
* @param ast annotation token
* @return list values
*/
private static List<String> getAllAnnotationValues(DetailAST ast) {
// get values of annotation
List<String> values = null;
final DetailAST lparenAST = ast.findFirstToken(TokenTypes.LPAREN);
if (lparenAST != null) {
final DetailAST nextAST = lparenAST.getNextSibling();
final int nextType = nextAST.getType();
switch (nextType) {
case TokenTypes.EXPR:
case TokenTypes.ANNOTATION_ARRAY_INIT:
values = getAnnotationValues(nextAST);
break;
case TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR:
// expected children: IDENT ASSIGN ( EXPR |
// ANNOTATION_ARRAY_INIT )
values = getAnnotationValues(getNthChild(nextAST, 2));
break;
case TokenTypes.RPAREN:
// no value present (not valid Java)
break;
default:
// unknown annotation value type (new syntax?)
throw new IllegalArgumentException("Unexpected AST: " + nextAST);
}
}
return values;
}
示例14: testGetAcceptableTokens
@Test
public void testGetAcceptableTokens() {
final TypecastParenPadCheck typecastParenPadCheckObj = new TypecastParenPadCheck();
final int[] actual = typecastParenPadCheckObj.getAcceptableTokens();
final int[] expected = {
TokenTypes.RPAREN,
TokenTypes.TYPECAST,
};
Assert.assertArrayEquals("Invalid acceptable tokens", expected, actual);
}
示例15: handleFor
/**
* processes a for loop and resolves references in it
*
* @param block the <code>BlockDef</code> to process
*/
private void handleFor(BlockDef block) {
SymTabAST node = block.getTreeNode();
SymTabAST body;
SymTabAST forEach = node.findFirstToken(TokenTypes.FOR_EACH_CLAUSE);
if (forEach == null) {
SymTabAST init = node.findFirstToken(TokenTypes.FOR_INIT);
// only need to handle the elist case. if the init node is a variable
// definition, the variable def will be handled later on in the resolution
if (init.getFirstChild() != null) {
if (init.getFirstChild().getType() == TokenTypes.ELIST) {
resolveExpression(
(SymTabAST) (init.getFirstChild()),
block,
null,
true);
}
}
SymTabAST cond = node.findFirstToken(TokenTypes.FOR_CONDITION);
if (cond.getFirstChild() != null) {
resolveExpression(
(SymTabAST) (cond.getFirstChild()),
block,
null,
true);
}
SymTabAST iterator = node.findFirstToken(TokenTypes.FOR_ITERATOR);
if (iterator.getFirstChild() != null) {
resolveExpression(
(SymTabAST) (iterator.getFirstChild()),
block,
null,
true);
}
body = (SymTabAST) (iterator.getNextSibling());
}
else {
resolveExpression(
(forEach.findFirstToken(TokenTypes.EXPR)),
block,
null,
true);
body = (SymTabAST) (forEach.getNextSibling());
}
//could be an SLIST, EXPR or an EMPTY_STAT
if (body.getType() == TokenTypes.RPAREN) {
body = (SymTabAST) body.getNextSibling();
}
if (body.getType() == TokenTypes.SLIST) {
handleSList(body, block);
}
else {
resolveExpression(body, block, null, true);
}
}