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


Java DetailAST.getPreviousSibling方法代码示例

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


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

示例1: logCommaViolation

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Logs a trailing array comma violation if one exists.
 *
 * @param ast the array init
 * {@link TokenTypes#ANNOTATION_ARRAY_INIT ANNOTATION_ARRAY_INIT}.
 */
private void logCommaViolation(final DetailAST ast) {
    final DetailAST rCurly = ast.findFirstToken(TokenTypes.RCURLY);

    //comma can be null if array is empty
    final DetailAST comma = rCurly.getPreviousSibling();

    if (trailingArrayComma == TrailingArrayComma.ALWAYS
        && (comma == null || comma.getType() != TokenTypes.COMMA)) {
        log(rCurly.getLineNo(),
            rCurly.getColumnNo(), MSG_KEY_ANNOTATION_TRAILING_COMMA_MISSING);
    }
    else if (trailingArrayComma == TrailingArrayComma.NEVER
        && comma != null && comma.getType() == TokenTypes.COMMA) {
        log(comma.getLineNo(),
            comma.getColumnNo(), MSG_KEY_ANNOTATION_TRAILING_COMMA_PRESENT);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:AnnotationUseStyleCheck.java

示例2: isVariableDefCountable

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks if a variable definition is countable.
 *
 * @param ast the AST
 * @return true if the variable definition is countable, false otherwise
 */
private static boolean isVariableDefCountable(DetailAST ast) {
    boolean countable = false;

    //count variable definitions only if they are direct child to a slist or
    // object block
    final int parentType = ast.getParent().getType();

    if (parentType == TokenTypes.SLIST
        || parentType == TokenTypes.OBJBLOCK) {
        final DetailAST prevSibling = ast.getPreviousSibling();

        //is countable if no previous sibling is found or
        //the sibling is no COMMA.
        //This is done because multiple assignment on one line are counted
        // as 1
        countable = prevSibling == null
                || prevSibling.getType() != TokenTypes.COMMA;
    }

    return countable;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:28,代码来源:JavaNCSSCheck.java

示例3: getDistributedPreviousStatement

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Returns the first token of the distributed previous statement of comment.
 * @param comment comment to check.
 * @return the first token of the distributed previous statement of comment.
 */
private static DetailAST getDistributedPreviousStatement(DetailAST comment) {
    DetailAST currentToken = comment.getPreviousSibling();
    while (isComment(currentToken)) {
        currentToken = currentToken.getPreviousSibling();
    }
    final DetailAST previousStatement;
    if (currentToken.getType() == TokenTypes.SEMI) {
        currentToken = currentToken.getPreviousSibling();
        while (currentToken.getFirstChild() != null) {
            currentToken = currentToken.getFirstChild();
        }
        previousStatement = currentToken;
    }
    else {
        previousStatement = currentToken;
    }
    return previousStatement;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:CommentsIndentationCheck.java

示例4: getFieldWithoutThis

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Returns the frame where the field is declared, if the given field is used without
 * 'this', and null otherwise.
 * @param ast field definition ast token.
 * @param parentType type of the parent.
 * @return the frame where the field is declared, if the given field is used without
 *         'this' and null otherwise.
 */
private AbstractFrame getFieldWithoutThis(DetailAST ast, int parentType) {
    final boolean importOrPackage = ScopeUtils.getSurroundingScope(ast) == null;
    final boolean methodNameInMethodCall = parentType == TokenTypes.DOT
            && ast.getPreviousSibling() != null;
    final boolean typeName = parentType == TokenTypes.TYPE
            || parentType == TokenTypes.LITERAL_NEW;
    AbstractFrame frame = null;

    if (!importOrPackage
            && !methodNameInMethodCall
            && !typeName
            && !isDeclarationToken(parentType)
            && !isLambdaParameter(ast)) {
        final AbstractFrame fieldFrame = findClassFrame(ast, false);

        if (fieldFrame != null && ((ClassFrame) fieldFrame).hasInstanceMember(ast)) {
            frame = getClassFrameWhereViolationIsFound(ast);
        }
    }
    return frame;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:30,代码来源:RequireThisCheck.java

示例5: checkIfSemicolonIsInDifferentLineThanPrevious

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks if given semicolon is in different line than previous.
 * @param ast semicolon to check
 */
private void checkIfSemicolonIsInDifferentLineThanPrevious(DetailAST ast) {
    DetailAST currentStatement = ast;
    final boolean hasResourcesPrevSibling =
            currentStatement.getPreviousSibling() != null
                    && currentStatement.getPreviousSibling().getType() == TokenTypes.RESOURCES;
    if (!hasResourcesPrevSibling && isMultilineStatement(currentStatement)) {
        currentStatement = ast.getPreviousSibling();
    }
    if (isInLambda) {
        int countOfSemiInCurrentLambda = countOfSemiInLambda.pop();
        countOfSemiInCurrentLambda++;
        countOfSemiInLambda.push(countOfSemiInCurrentLambda);
        if (!inForHeader && countOfSemiInCurrentLambda > 1
                && isOnTheSameLine(currentStatement,
                lastStatementEnd, forStatementEnd,
                lambdaStatementEnd)) {
            log(ast, MSG_KEY);
        }
    }
    else if (!inForHeader && isOnTheSameLine(currentStatement, lastStatementEnd,
            forStatementEnd, lambdaStatementEnd)) {
        log(ast, MSG_KEY);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:29,代码来源:OneStatementPerLineCheck.java

示例6: isDistributedExpression

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks whether the previous statement of a comment is a method call chain or
 * string concatenation statement distributed over two ore more lines.
 * @param comment comment to check.
 * @return true if the previous statement is a distributed expression.
 */
private boolean isDistributedExpression(DetailAST comment) {
    DetailAST previousSibling = comment.getPreviousSibling();
    while (previousSibling != null && isComment(previousSibling)) {
        previousSibling = previousSibling.getPreviousSibling();
    }
    boolean isDistributed = false;
    if (previousSibling != null) {
        if (previousSibling.getType() == TokenTypes.SEMI
                && isOnPreviousLineIgnoringComments(comment, previousSibling)) {
            DetailAST currentToken = previousSibling.getPreviousSibling();
            while (currentToken.getFirstChild() != null) {
                currentToken = currentToken.getFirstChild();
            }
            if (currentToken.getType() == TokenTypes.COMMENT_CONTENT) {
                currentToken = currentToken.getParent();
                while (isComment(currentToken)) {
                    currentToken = currentToken.getNextSibling();
                }
            }
            if (previousSibling.getLineNo() != currentToken.getLineNo()) {
                isDistributed = true;
            }
        }
        else {
            isDistributed = isStatementWithPossibleCurlies(previousSibling);
        }
    }
    return isDistributed;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:36,代码来源:CommentsIndentationCheck.java

示例7: isPartOfDoubleBraceInitializerForPreviousToken

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Check if given ast is part of double brace initializer and if it
 * should omit checking if previous token is separated by whitespace.
 * @param ast ast to check
 * @return true if it should omit checking for previous token, false otherwise
 */
private static boolean isPartOfDoubleBraceInitializerForPreviousToken(DetailAST ast) {
    final boolean initializerBeginsAfterClassBegins = ast.getType() == TokenTypes.SLIST
            && ast.getParent().getType() == TokenTypes.INSTANCE_INIT;
    final boolean classEndsAfterInitializerEnds = ast.getType() == TokenTypes.RCURLY
            && ast.getPreviousSibling() != null
            && ast.getPreviousSibling().getType() == TokenTypes.INSTANCE_INIT;
    return initializerBeginsAfterClassBegins || classEndsAfterInitializerEnds;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:15,代码来源:WhitespaceAroundCheck.java

示例8: getPrevStatementWhenCommentIsUnderCase

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Gets previous statement for comment which is placed immediately under case.
 * @param parentStatement comment's parent statement.
 * @return comment's previous statement or null if previous statement is absent.
 */
private static DetailAST getPrevStatementWhenCommentIsUnderCase(DetailAST parentStatement) {
    DetailAST prevStmt = null;
    final DetailAST prevBlock = parentStatement.getPreviousSibling();
    if (prevBlock.getLastChild() != null) {
        DetailAST blockBody = prevBlock.getLastChild().getLastChild();
        if (blockBody.getType() == TokenTypes.SEMI) {
            blockBody = blockBody.getPreviousSibling();
        }
        if (blockBody.getType() == TokenTypes.EXPR) {
            if (isUsingOfObjectReferenceToInvokeMethod(blockBody)) {
                prevStmt = findStartTokenOfMethodCallChain(blockBody);
            }
            else {
                prevStmt = blockBody.getFirstChild().getFirstChild();
            }
        }
        else {
            if (blockBody.getType() == TokenTypes.SLIST) {
                prevStmt = blockBody.getParent().getParent();
            }
            else {
                prevStmt = blockBody;
            }
        }
        if (isComment(prevStmt)) {
            prevStmt = prevStmt.getNextSibling();
        }
    }
    return prevStmt;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:36,代码来源:CommentsIndentationCheck.java

示例9: isObjectValid

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Check whether the object equals method is called on is not a String literal
 * and not too complex.
 * @param objCalledOn the object equals method is called on ast.
 * @return true if the object is valid.
 */
private static boolean isObjectValid(DetailAST objCalledOn) {
    boolean result = true;
    final DetailAST previousSibling = objCalledOn.getPreviousSibling();
    if (previousSibling != null
            && previousSibling.getType() == TokenTypes.DOT) {
        result = false;
    }
    if (isStringLiteral(objCalledOn)) {
        result = false;
    }
    return result;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:19,代码来源:EqualsAvoidNullCheck.java

示例10: hasAtLeastOneSiblingWithSameTokenType

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks if the given ast element has unique {@code TokenTypes} among siblings.
 * @param ast {@code DetailAST} ast element
 * @return if the given ast element has unique {@code TokenTypes} among siblings
 */
private static boolean hasAtLeastOneSiblingWithSameTokenType(DetailAST ast) {
    boolean result = false;
    if (ast.getParent() == null) {
        DetailAST prev = ast.getPreviousSibling();
        while (prev != null) {
            if (prev.getType() == ast.getType()) {
                result = true;
                break;
            }
            prev = prev.getPreviousSibling();
        }
        if (!result) {
            DetailAST next = ast.getNextSibling();
            while (next != null) {
                if (next.getType() == ast.getType()) {
                    result = true;
                    break;
                }
                next = next.getNextSibling();
            }
        }
    }
    else {
        result = ast.getParent().getChildCount(ast.getType()) > 1;
    }
    return result;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:33,代码来源:XpathQueryGenerator.java

示例11: isPrecededByJavadoc

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Check if token is preceded by javadoc comment.
 * @param token token for check.
 * @return true, if token is preceded by javadoc comment.
 */
private static boolean isPrecededByJavadoc(DetailAST token) {
    boolean result = false;
    final DetailAST previous = token.getPreviousSibling();
    if (previous.getType() == TokenTypes.BLOCK_COMMENT_BEGIN
            && JavadocUtils.isJavadocComment(previous.getFirstChild().getText())) {
        result = true;
    }
    return result;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:15,代码来源:EmptyLineSeparatorCheck.java

示例12: isInEmptyForInitializerOrCondition

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks that semicolon is in empty for initializer or condition.
 * @param semicolonAst DetailAST of semicolon.
 * @return true if semicolon is in empty for initializer or condition.
 */
private static boolean isInEmptyForInitializerOrCondition(DetailAST semicolonAst) {
    boolean result = false;
    if (semicolonAst.getType() == TokenTypes.SEMI) {
        final DetailAST sibling = semicolonAst.getPreviousSibling();
        if (sibling != null
                && (sibling.getType() == TokenTypes.FOR_INIT
                        || sibling.getType() == TokenTypes.FOR_CONDITION)
                && sibling.getChildCount() == 0) {
            result = true;
        }
    }
    return result;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:19,代码来源:NoWhitespaceBeforeCheck.java

示例13: getFirstAnnotationOnSameLine

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Returns first annotation on same line.
 * @param annotation
 *            last annotation on the line
 * @return first annotation on same line.
 */
private static DetailAST getFirstAnnotationOnSameLine(DetailAST annotation) {
    DetailAST previousAnnotation = annotation;
    final int lastAnnotationLineNumber = previousAnnotation.getLineNo();
    while (previousAnnotation.getPreviousSibling() != null
            && previousAnnotation.getPreviousSibling().getLineNo()
                == lastAnnotationLineNumber) {

        previousAnnotation = previousAnnotation.getPreviousSibling();
    }
    return previousAnnotation;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:18,代码来源:LeftCurlyCheck.java

示例14: isMultilineStatement

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks whether statement is multiline.
 * @param ast token for the current statement.
 * @return true if one statement is distributed over two or more lines.
 */
private static boolean isMultilineStatement(DetailAST ast) {
    final boolean multiline;
    if (ast.getPreviousSibling() == null) {
        multiline = false;
    }
    else {
        final DetailAST prevSibling = ast.getPreviousSibling();
        multiline = prevSibling.getLineNo() != ast.getLineNo()
                && ast.getParent() != null;
    }
    return multiline;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:18,代码来源:OneStatementPerLineCheck.java

示例15: getClassFrameWhereViolationIsFound

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Returns the class frame where violation is found (where the field is used without 'this')
 * or null otherwise.
 * @param ast IDENT ast to check.
 * @return the class frame where violation is found or null otherwise.
 * @noinspection IfStatementWithIdenticalBranches
 */
// [email protected][CyclomaticComplexity] Method already invokes too many methods that fully explain
// a logic, additional abstraction will not make logic/algorithm more readable.
private AbstractFrame getClassFrameWhereViolationIsFound(DetailAST ast) {
    AbstractFrame frameWhereViolationIsFound = null;
    final AbstractFrame variableDeclarationFrame = findFrame(ast, false);
    final FrameType variableDeclarationFrameType = variableDeclarationFrame.getType();
    final DetailAST prevSibling = ast.getPreviousSibling();
    if (variableDeclarationFrameType == FrameType.CLASS_FRAME
            && !validateOnlyOverlapping
            && prevSibling == null
            && canBeReferencedFromStaticContext(ast)) {
        frameWhereViolationIsFound = variableDeclarationFrame;
    }
    else if (variableDeclarationFrameType == FrameType.METHOD_FRAME) {
        if (isOverlappingByArgument(ast)) {
            if (!isUserDefinedArrangementOfThis(variableDeclarationFrame, ast)
                    && !isReturnedVariable(variableDeclarationFrame, ast)
                    && canBeReferencedFromStaticContext(ast)
                    && canAssignValueToClassField(ast)) {
                frameWhereViolationIsFound = findFrame(ast, true);
            }
        }
        else if (!validateOnlyOverlapping
                 && prevSibling == null
                 && isAssignToken(ast.getParent().getType())
                 && !isUserDefinedArrangementOfThis(variableDeclarationFrame, ast)
                 && canBeReferencedFromStaticContext(ast)
                 && canAssignValueToClassField(ast)) {
            frameWhereViolationIsFound = findFrame(ast, true);

        }
    }
    else if (variableDeclarationFrameType == FrameType.CTOR_FRAME
             && isOverlappingByArgument(ast)
             && !isUserDefinedArrangementOfThis(variableDeclarationFrame, ast)) {
        frameWhereViolationIsFound = findFrame(ast, true);
    }
    else if (variableDeclarationFrameType == FrameType.BLOCK_FRAME
                && isOverlappingByLocalVariable(ast)
                && canAssignValueToClassField(ast)
                && !isUserDefinedArrangementOfThis(variableDeclarationFrame, ast)
                && !isReturnedVariable(variableDeclarationFrame, ast)
                && canBeReferencedFromStaticContext(ast)) {
        frameWhereViolationIsFound = findFrame(ast, true);
    }
    return frameWhereViolationIsFound;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:55,代码来源:RequireThisCheck.java


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