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


Java DetailAST.getLineNo方法代码示例

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


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

示例1: visitToken

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
    if (ast.getType() == TokenTypes.PACKAGE_DEF) {
        if (customImportOrderRules.contains(SAME_PACKAGE_RULE_GROUP)) {
            samePackageDomainsRegExp = createSamePackageRegexp(
                    samePackageMatchingDepth, ast);
        }
    }
    else {
        final String importFullPath = getFullImportIdent(ast);
        final int lineNo = ast.getLineNo();
        final boolean isStatic = ast.getType() == TokenTypes.STATIC_IMPORT;
        importToGroupList.add(new ImportDetails(importFullPath,
                lineNo, getImportGroup(isStatic, importFullPath),
                isStatic));
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:18,代码来源:CustomImportOrderCheck.java

示例2: isOnPreviousLineIgnoringComments

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks whether the checked statement is on the previous line ignoring empty lines
 * and lines which contain only comments.
 * @param currentStatement current statement.
 * @param checkedStatement checked statement.
 * @return true if checked statement is on the line which is previous to current statement
 *     ignoring empty lines and lines which contain only comments.
 */
private boolean isOnPreviousLineIgnoringComments(DetailAST currentStatement,
                                                 DetailAST checkedStatement) {
    DetailAST nextToken = getNextToken(checkedStatement);
    int distanceAim = 1;
    if (nextToken != null && isComment(nextToken)) {
        distanceAim += countEmptyLines(checkedStatement, currentStatement);
    }

    while (nextToken != null && nextToken != currentStatement && isComment(nextToken)) {
        if (nextToken.getType() == TokenTypes.BLOCK_COMMENT_BEGIN) {
            distanceAim += nextToken.getLastChild().getLineNo() - nextToken.getLineNo();
        }
        distanceAim++;
        nextToken = nextToken.getNextSibling();
    }
    return currentStatement.getLineNo() - checkedStatement.getLineNo() == distanceAim;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:26,代码来源:CommentsIndentationCheck.java

示例3: getEmptyLines

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Get list of empty lines.
 * @param ast the ast to check.
 * @return list of line numbers for empty lines.
 */
private List<Integer> getEmptyLines(DetailAST ast) {
    final DetailAST lastToken = ast.getLastChild().getLastChild();
    int lastTokenLineNo = 0;
    if (lastToken != null) {
        // -1 as count starts from 0
        // -2 as last token line cannot be empty, because it is a RCURLY
        lastTokenLineNo = lastToken.getLineNo() - 2;
    }
    final List<Integer> emptyLines = new ArrayList<Integer>();
    final FileContents fileContents = getFileContents();

    for (int lineNo = ast.getLineNo(); lineNo <= lastTokenLineNo; lineNo++) {
        if (fileContents.lineIsBlank(lineNo)) {
            emptyLines.add(lineNo);
        }
    }
    return emptyLines;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:EmptyLineSeparatorCheck.java

示例4: checkTopLevelToken

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
protected void checkTopLevelToken() {
    // check if else is nested with rcurly of if:
    //
    //  } else ...

    final DetailAST ifAST = getMainAst().getParent();
    final DetailAST slist = ifAST.findFirstToken(TokenTypes.SLIST);
    if (slist == null) {
        super.checkTopLevelToken();
    }
    else {
        final DetailAST lcurly = slist.getLastChild();
        // indentation checked as part of LITERAL IF check
        if (lcurly.getLineNo() != getMainAst().getLineNo()) {
            super.checkTopLevelToken();
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:20,代码来源:ElseHandler.java

示例5: visitToken

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
    final DetailAST typeAST = ast.getParent();
    if (typeAST.getType() == TokenTypes.TYPE
            // Do not check method's return type.
            // We have no alternatives here.
            && typeAST.getParent().getType() != TokenTypes.METHOD_DEF) {
        final DetailAST variableAST = typeAST.getNextSibling();
        if (variableAST != null) {
            final boolean isJavaStyle =
                variableAST.getLineNo() > ast.getLineNo()
                || variableAST.getColumnNo() - ast.getColumnNo() > -1;

            if (isJavaStyle != javaStyle) {
                log(ast.getLineNo(), ast.getColumnNo(), MSG_KEY);
            }
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:20,代码来源:ArrayTypeStyleCheck.java

示例6: handleCommentAtTheEndOfTheCodeBlock

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Handles a comment which is placed at the end of non empty code block.
 * Note, if single line comment is placed at the end of non empty block the comment should have
 * the same indentation level as the previous statement. For example:
 * <p>
 * {@code
 *    if (a == true) {
 *        int b = 1;
 *        // comment
 *    }
 * }
 * </p>
 * @param prevStmt previous statement.
 * @param comment comment to check.
 * @param nextStmt next statement.
 */
private void handleCommentAtTheEndOfTheCodeBlock(DetailAST prevStmt, DetailAST comment,
                                                 DetailAST nextStmt) {
    if (prevStmt != null) {
        if (prevStmt.getType() == TokenTypes.LITERAL_CASE
                || prevStmt.getType() == TokenTypes.CASE_GROUP
                || prevStmt.getType() == TokenTypes.LITERAL_DEFAULT) {
            if (comment.getColumnNo() < nextStmt.getColumnNo()) {
                log(comment.getLineNo(), getMessageKey(comment), nextStmt.getLineNo(),
                    comment.getColumnNo(), nextStmt.getColumnNo());
            }
        }
        else if (isCommentForMultiblock(nextStmt)) {
            if (!areSameLevelIndented(comment, prevStmt, nextStmt)) {
                logMultilineIndentation(prevStmt, comment, nextStmt);
            }
        }
        else if (!areSameLevelIndented(comment, prevStmt, prevStmt)) {
            final int prevStmtLineNo = prevStmt.getLineNo();
            log(comment.getLineNo(), getMessageKey(comment), prevStmtLineNo,
                    comment.getColumnNo(), getLineStart(prevStmtLineNo));
        }
    }

}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:41,代码来源:CommentsIndentationCheck.java

示例7: processPackage

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Process Package.
 * @param ast token
 * @param nextToken next token
 */
private void processPackage(DetailAST ast, DetailAST nextToken) {
    if (ast.getLineNo() > 1 && !hasEmptyLineBefore(ast)) {
        if (getFileContents().getFileName().endsWith("package-info.java")) {
            if (ast.getFirstChild().getChildCount() == 0 && !isPrecededByJavadoc(ast)) {
                log(ast.getLineNo(), MSG_SHOULD_BE_SEPARATED, ast.getText());
            }
        }
        else {
            log(ast.getLineNo(), MSG_SHOULD_BE_SEPARATED, ast.getText());
        }
    }
    if (!hasEmptyLineAfter(ast)) {
        log(nextToken.getLineNo(), MSG_SHOULD_BE_SEPARATED, nextToken.getText());
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:21,代码来源:EmptyLineSeparatorCheck.java

示例8: postProcessLiteralNew

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Processes one of the collected "new" tokens when walking tree
 * has finished.
 * @param newTokenAst the "new" token.
 */
private void postProcessLiteralNew(DetailAST newTokenAst) {
    final DetailAST typeNameAst = newTokenAst.getFirstChild();
    final AST nameSibling = typeNameAst.getNextSibling();
    if (nameSibling.getType() != TokenTypes.ARRAY_DECLARATOR) {
        // ast != "new Boolean[]"
        final FullIdent typeIdent = FullIdent.createFullIdent(typeNameAst);
        final String typeName = typeIdent.getText();
        final String fqClassName = getIllegalInstantiation(typeName);
        if (fqClassName != null) {
            final int lineNo = newTokenAst.getLineNo();
            final int colNo = newTokenAst.getColumnNo();
            log(lineNo, colNo, MSG_KEY, fqClassName);
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:21,代码来源:IllegalInstantiationCheck.java

示例9: visitToken

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
    final DetailAST parent = ast.getParent();
    //we do not want to check colon for cases and defaults
    if (ast.getType() != TokenTypes.COLON
            || parent.getType() != TokenTypes.LITERAL_DEFAULT
                && parent.getType() != TokenTypes.LITERAL_CASE) {
        final String text = ast.getText();
        final int colNo = ast.getColumnNo();
        final int lineNo = ast.getLineNo();
        final String currentLine = getLine(lineNo - 1);

        // Check if rest of line is whitespace, and not just the operator
        // by itself. This last bit is to handle the operator on a line by
        // itself.
        if (option == WrapOption.NL
                && !text.equals(currentLine.trim())
                && CommonUtils.isBlank(currentLine.substring(colNo + text.length()))) {
            log(lineNo, colNo, MSG_LINE_NEW, text);
        }
        else if (option == WrapOption.EOL
                && CommonUtils.hasWhitespaceBefore(colNo - 1, currentLine)) {
            log(lineNo, colNo, MSG_LINE_PREVIOUS, text);
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:27,代码来源:OperatorWrapCheck.java

示例10: initialize

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * initialized this node with input node
 * @param aAST the node to initialize from. Must be a
 * <code>DetailAST</code> object.
 */
public void initialize(AST aAST)
{
    if (aAST != null) {
        super.initialize(aAST);
        final DetailAST detailAST = (DetailAST) aAST;
        setDetailNode(detailAST);
        _column = detailAST.getColumnNo() + 1;
        _line = detailAST.getLineNo();
    } 
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:16,代码来源:SymTabAST.java

示例11: finishTree

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void finishTree(DetailAST ast) {
    if (!defined) {
        int lineNumber = DEFAULT_LINE_NUMBER;
        if (ast != null) {
            lineNumber = ast.getLineNo();
        }
        log(lineNumber, MSG_KEY_MISSING);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:11,代码来源:PackageDeclarationCheck.java

示例12: visitToken

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
    DetailAST nextNode = ast.getNextSibling();

    if (nextNode != null) {
        final boolean isCommaSeparated = nextNode.getType() == TokenTypes.COMMA;

        if (isCommaSeparated
            || nextNode.getType() == TokenTypes.SEMI) {
            nextNode = nextNode.getNextSibling();
        }

        if (nextNode != null
                && nextNode.getType() == TokenTypes.VARIABLE_DEF) {
            final DetailAST firstNode = CheckUtils.getFirstNode(ast);
            if (isCommaSeparated) {
                // Check if the multiple variable declarations are in a
                // for loop initializer. If they are, then no warning
                // should be displayed. Declaring multiple variables in
                // a for loop initializer is a good way to minimize
                // variable scope. Refer Feature Request Id - 2895985
                // for more details
                if (ast.getParent().getType() != TokenTypes.FOR_INIT) {
                    log(firstNode, MSG_MULTIPLE_COMMA);
                }
            }
            else {
                final DetailAST lastNode = getLastNode(ast);
                final DetailAST firstNextNode = CheckUtils.getFirstNode(nextNode);

                if (firstNextNode.getLineNo() == lastNode.getLineNo()) {
                    log(firstNode, MSG_MULTIPLE);
                }
            }
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:38,代码来源:MultipleVariableDeclarationsCheck.java

示例13: visitToken

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST arrayInit) {
    final DetailAST rcurly = arrayInit.findFirstToken(TokenTypes.RCURLY);
    final DetailAST previousSibling = rcurly.getPreviousSibling();

    if (arrayInit.getLineNo() != rcurly.getLineNo()
            && arrayInit.getChildCount() != 1
            && rcurly.getLineNo() != previousSibling.getLineNo()
            && arrayInit.getLineNo() != previousSibling.getLineNo()
            && previousSibling.getType() != TokenTypes.COMMA) {
        log(rcurly.getLineNo(), MSG_KEY);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:14,代码来源:ArrayTrailingCommaCheck.java

示例14: isSingleLineBlock

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks whether block has a single-line format.
 * @param details for validation.
 * @return true if block has single-line format.
 */
private static boolean isSingleLineBlock(Details details) {
    final DetailAST rcurly = details.rcurly;
    final DetailAST lcurly = details.lcurly;
    final DetailAST nextToken = details.nextToken;
    return rcurly.getLineNo() == lcurly.getLineNo()
        && rcurly.getLineNo() != nextToken.getLineNo();
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:13,代码来源:RightCurlyCheck.java

示例15: hasText

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks if SLIST token contains any text.
 * @param slistAST a {@code DetailAST} value
 * @return whether the SLIST token contains any text.
 */
private boolean hasText(final DetailAST slistAST) {
    final DetailAST rightCurly = slistAST.findFirstToken(TokenTypes.RCURLY);
    final DetailAST rcurlyAST;

    if (rightCurly == null) {
        rcurlyAST = slistAST.getParent().findFirstToken(TokenTypes.RCURLY);
    }
    else {
        rcurlyAST = rightCurly;
    }
    final int slistLineNo = slistAST.getLineNo();
    final int slistColNo = slistAST.getColumnNo();
    final int rcurlyLineNo = rcurlyAST.getLineNo();
    final int rcurlyColNo = rcurlyAST.getColumnNo();
    final String[] lines = getLines();
    boolean returnValue = false;
    if (slistLineNo == rcurlyLineNo) {
        // Handle braces on the same line
        final String txt = lines[slistLineNo - 1]
                .substring(slistColNo + 1, rcurlyColNo);
        if (!CommonUtils.isBlank(txt)) {
            returnValue = true;
        }
    }
    else {
        final String firstLine = lines[slistLineNo - 1].substring(slistColNo + 1);
        final String lastLine = lines[rcurlyLineNo - 1].substring(0, rcurlyColNo);
        // check if all lines are also only whitespace
        returnValue = !(CommonUtils.isBlank(firstLine) && CommonUtils.isBlank(lastLine))
                || !checkIsAllLinesAreWhitespace(lines, slistLineNo, rcurlyLineNo);
    }
    return returnValue;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:39,代码来源:EmptyBlockCheck.java


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