当前位置: 首页>>代码示例>>Java>>正文


Java DetailAST.branchContains方法代码示例

本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.DetailAST.branchContains方法的典型用法代码示例。如果您正苦于以下问题:Java DetailAST.branchContains方法的具体用法?Java DetailAST.branchContains怎么用?Java DetailAST.branchContains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.puppycrawl.tools.checkstyle.api.DetailAST的用法示例。


在下文中一共展示了DetailAST.branchContains方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkCheckClosingParens

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * 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);
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:25,代码来源:AnnotationUseStyleCheck.java

示例2: containsAllSafeTokens

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:26,代码来源:EqualsAvoidNullCheck.java

示例3: processExpression

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * 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();
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:25,代码来源:ParenPadCheck.java

示例4: isToStringMethod

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Determines if an AST is a valid toString method implementation.
 *
 * @param ast the AST to check
 * @return true if the {code ast} is a toString method.
 */
public static Boolean isToStringMethod(DetailAST ast) {
  DetailAST modifiers = ast.getFirstChild();
  AST type = ast.findFirstToken(TokenTypes.TYPE);
  AST methodName = ast.findFirstToken(TokenTypes.IDENT);
  DetailAST parameters = ast.findFirstToken(TokenTypes.PARAMETERS);

  return CommonUtil.getSimpleAndFullNames(ClassUtil.STRING_CLASS_NAME_BY_PACKAGE)
                   .contains(type.getFirstChild().getText())
         && TO_STRING_METHOD_NAME.equals(methodName.getText())
         && modifiers.branchContains(TokenTypes.LITERAL_PUBLIC)
         && !modifiers.branchContains(TokenTypes.LITERAL_STATIC)
         && parameters.getFirstChild() == null
         && (ast.branchContains(TokenTypes.SLIST)
             || modifiers.branchContains(TokenTypes.LITERAL_NATIVE));
}
 
开发者ID:startupheroes,项目名称:startupheroes-checkstyle,代码行数:22,代码来源:MethodUtil.java

示例5: hasBody

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Determines whether an AST is a method definition with a body, or is
 * a constructor definition.
 * @param aAST the AST to check.
 * @return if AST has a body.
 */
private boolean hasBody(DetailAST aAST)
{
    if (aAST.getType() == TokenTypes.METHOD_DEF) {
        return aAST.branchContains(TokenTypes.SLIST);
    }
    else if (aAST.getType() == TokenTypes.CTOR_DEF) {
        return true;
    }
    return false;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:17,代码来源:UnusedParameterCheck.java

示例6: isLocal

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks if a given method is local, i.e. either static or private.
 * @param aAST method def for check
 * @return true if a given method is iether static or private.
 */
private boolean isLocal(DetailAST aAST)
{
    if (aAST.getType() == TokenTypes.METHOD_DEF) {
        final DetailAST modifiers =
            aAST.findFirstToken(TokenTypes.MODIFIERS);
        return (modifiers == null)
            || modifiers.branchContains(TokenTypes.LITERAL_STATIC)
            || modifiers.branchContains(TokenTypes.LITERAL_PRIVATE);
    }
    return true;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:17,代码来源:UnusedParameterCheck.java

示例7: checkExpandedStyle

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks for expanded style type violations.
 *
 * @param annotation the annotation token
 */
private void checkExpandedStyle(final DetailAST annotation) {
    final int valuePairCount =
        annotation.getChildCount(TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR);

    if (valuePairCount == 0
        && annotation.branchContains(TokenTypes.EXPR)) {
        log(annotation.getLineNo(), MSG_KEY_ANNOTATION_INCORRECT_STYLE,
            ElementStyle.EXPANDED);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:16,代码来源:AnnotationUseStyleCheck.java

示例8: getSimpleName

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * @return simple name(last name after last DOT if exists)
 */
public static String getSimpleName(DetailAST ast) {
  DetailAST identifier = ast.findFirstToken(TokenTypes.IDENT);
  if (isNull(identifier) && ast.branchContains(TokenTypes.DOT)) {
    DetailAST dotAst = ast.findFirstToken(TokenTypes.DOT);
    identifier = dotAst.findFirstToken(TokenTypes.IDENT);
  }
  return identifier.getText();
}
 
开发者ID:startupheroes,项目名称:startupheroes-checkstyle,代码行数:12,代码来源:CommonUtil.java

示例9: isEqualsMethod

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Determines if an AST is a valid Equals method implementation.
 *
 * @param ast the AST to check
 * @return true if the {code ast} is a Equals method.
 */
public static Boolean isEqualsMethod(DetailAST ast) {
  DetailAST modifiers = ast.getFirstChild();
  DetailAST parameters = ast.findFirstToken(TokenTypes.PARAMETERS);

  return CheckUtils.isEqualsMethod(ast)
         && modifiers.branchContains(TokenTypes.LITERAL_PUBLIC)
         && isObjectParam(parameters.getFirstChild())
         && (ast.branchContains(TokenTypes.SLIST)
             || modifiers.branchContains(TokenTypes.LITERAL_NATIVE));
}
 
开发者ID:startupheroes,项目名称:startupheroes-checkstyle,代码行数:17,代码来源:MethodUtil.java

示例10: isHashCodeMethod

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Determines if an AST is a valid HashCode method implementation.
 *
 * @param ast the AST to check
 * @return true if the {code ast} is a HashCode method.
 */
public static Boolean isHashCodeMethod(DetailAST ast) {
  DetailAST modifiers = ast.getFirstChild();
  AST type = ast.findFirstToken(TokenTypes.TYPE);
  AST methodName = ast.findFirstToken(TokenTypes.IDENT);
  DetailAST parameters = ast.findFirstToken(TokenTypes.PARAMETERS);

  return type.getFirstChild().getType() == TokenTypes.LITERAL_INT
         && HASH_CODE_METHOD_NAME.equals(methodName.getText())
         && modifiers.branchContains(TokenTypes.LITERAL_PUBLIC)
         && !modifiers.branchContains(TokenTypes.LITERAL_STATIC)
         && parameters.getFirstChild() == null
         && (ast.branchContains(TokenTypes.SLIST)
             || modifiers.branchContains(TokenTypes.LITERAL_NATIVE));
}
 
开发者ID:startupheroes,项目名称:startupheroes-checkstyle,代码行数:21,代码来源:MethodUtil.java

示例11: hasJavadocComment

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks whether a method has a javadoc comment.
 * @param methodDef method definition token.
 * @return true if a method has a javadoc comment.
 */
private static boolean hasJavadocComment(DetailAST methodDef) {
    final DetailAST modifiers = methodDef.findFirstToken(TokenTypes.MODIFIERS);
    return modifiers.branchContains(TokenTypes.BLOCK_COMMENT_BEGIN);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:10,代码来源:DesignForExtensionCheck.java


注:本文中的com.puppycrawl.tools.checkstyle.api.DetailAST.branchContains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。