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


Java DetailAST.getText方法代码示例

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


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

示例1: 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

示例2: isEqualsMethod

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Tests whether a method definition AST defines an equals covariant.
 * @param ast the method definition AST to test.
 *     Precondition: ast is a TokenTypes.METHOD_DEF node.
 * @return true if ast defines an equals covariant.
 */
public static boolean isEqualsMethod(DetailAST ast) {
    boolean equalsMethod = false;

    if (ast.getType() == TokenTypes.METHOD_DEF) {
        final DetailAST modifiers = ast.findFirstToken(TokenTypes.MODIFIERS);
        final boolean staticOrAbstract =
                modifiers.findFirstToken(TokenTypes.LITERAL_STATIC) != null
                || modifiers.findFirstToken(TokenTypes.ABSTRACT) != null;

        if (!staticOrAbstract) {
            final DetailAST nameNode = ast.findFirstToken(TokenTypes.IDENT);
            final String name = nameNode.getText();

            if ("equals".equals(name)) {
                // one parameter?
                final DetailAST paramsNode = ast.findFirstToken(TokenTypes.PARAMETERS);
                equalsMethod = paramsNode.getChildCount() == 1;
            }
        }
    }
    return equalsMethod;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:29,代码来源:CheckUtils.java

示例3: isStringFieldOrVariable

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Whether the field or the variable is of String type.
 * @param objCalledOn the field or the variable to check.
 * @return true if the field or the variable is of String type.
 */
private boolean isStringFieldOrVariable(DetailAST objCalledOn) {
    boolean result = false;
    final String name = objCalledOn.getText();
    FieldFrame frame = currentFrame;
    while (frame != null) {
        final DetailAST field = frame.findField(name);
        if (field != null
                && (frame.isClassOrEnumOrEnumConstDef()
                        || checkLineNo(field, objCalledOn))) {
            result = STRING.equals(getFieldType(field));
            break;
        }
        frame = frame.getParent();
    }
    return result;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:22,代码来源:EqualsAvoidNullCheck.java

示例4: processVariable

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Process a variable token.
 * Check whether a local variable or parameter shadows a field.
 * Store a field for later comparison with local variables and parameters.
 * @param ast the variable token.
 */
private void processVariable(DetailAST ast) {
    if (!ScopeUtils.isInInterfaceOrAnnotationBlock(ast)
        && !CheckUtils.isReceiverParameter(ast)
        && (ScopeUtils.isLocalVariableDef(ast)
            || ast.getType() == TokenTypes.PARAMETER_DEF)) {
        // local variable or parameter. Does it shadow a field?
        final DetailAST nameAST = ast.findFirstToken(TokenTypes.IDENT);
        final String name = nameAST.getText();

        if ((frame.containsStaticField(name) || isInstanceField(ast, name))
                && !isMatchingRegexp(name)
                && !isIgnoredParam(ast, name)) {
            log(nameAST, MSG_KEY, name);
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:23,代码来源:HiddenFieldCheck.java

示例5: isOverridingMethod

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Determines whether an AST is a method definition for this check,
 * with 0 parameters.
 * @param ast the method definition AST.
 * @return true if the method of ast is a method for this check.
 */
private boolean isOverridingMethod(DetailAST ast) {
    boolean overridingMethod = false;

    if (ast.getType() == TokenTypes.METHOD_DEF
            && !ScopeUtils.isInInterfaceOrAnnotationBlock(ast)) {
        final DetailAST nameAST = ast.findFirstToken(TokenTypes.IDENT);
        final String name = nameAST.getText();
        final DetailAST modifiersAST = ast.findFirstToken(TokenTypes.MODIFIERS);

        if (getMethodName().equals(name)
                && modifiersAST.findFirstToken(TokenTypes.LITERAL_NATIVE) == null) {
            final DetailAST params = ast.findFirstToken(TokenTypes.PARAMETERS);
            overridingMethod = params.getChildCount() == 0;
        }
    }
    return overridingMethod;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:AbstractSuperCheck.java

示例6: reportMagicNumber

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Reports aAST as a magic number, includes unary operators as needed.
 * @param ast the AST node that contains the number to report
 */
private void reportMagicNumber(DetailAST ast) {
    String text = ast.getText();
    final DetailAST parent = ast.getParent();
    DetailAST reportAST = ast;
    if (parent.getType() == TokenTypes.UNARY_MINUS) {
        reportAST = parent;
        text = "-" + text;
    }
    else if (parent.getType() == TokenTypes.UNARY_PLUS) {
        reportAST = parent;
        text = "+" + text;
    }
    log(reportAST.getLineNo(),
            reportAST.getColumnNo(),
            MSG_KEY,
            text);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:22,代码来源:MagicNumberCheck.java

示例7: visitToken

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST aAST) {
    final DetailAST mid = aAST.findFirstToken(TokenTypes.IDENT);
    final String name = mid.getText();

    if ("finalize".equals(name)) {

        final DetailAST params = aAST.findFirstToken(TokenTypes.PARAMETERS);
        final boolean hasEmptyParamList =
            params.findFirstToken(TokenTypes.PARAMETER_DEF) == null;

        if (hasEmptyParamList) {
            log(aAST.getLineNo(), MSG_KEY);
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:NoFinalizerCheck.java

示例8: visitToken

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST aAST) {
    final DetailAST mid = aAST.findFirstToken(TokenTypes.IDENT);
    final String name = mid.getText();

    if ("clone".equals(name)) {

        final DetailAST params = aAST.findFirstToken(TokenTypes.PARAMETERS);
        final boolean hasEmptyParamList =
            params.findFirstToken(TokenTypes.PARAMETER_DEF) == null;

        if (hasEmptyParamList) {
            log(aAST.getLineNo(), MSG_KEY);
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:NoCloneCheck.java

示例9: visitClassDef

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * If not inner class then change current class name.
 * @param classDef node for class definition
 */
private void visitClassDef(DetailAST classDef) {
    // we are not use inner classes because they can not
    // have static methods
    if (classDepth == 0) {
        final DetailAST ident = classDef.findFirstToken(TokenTypes.IDENT);
        currentClass = packageName.getText() + "." + ident.getText();
        classDepth++;
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:14,代码来源:UncommentedMainCheck.java

示例10: getAnnotationName

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Returns the name of the given annotation.
 * @param annotation annotation node.
 * @return annotation name.
 */
private static String getAnnotationName(DetailAST annotation) {
    DetailAST identNode = annotation.findFirstToken(TokenTypes.IDENT);
    if (identNode == null) {
        identNode = annotation.findFirstToken(TokenTypes.DOT).getLastChild();
    }
    return identNode.getText();
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:13,代码来源:AnnotationOnSameLineCheck.java

示例11: visitToken

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
    final String text = ast.getText();
    if (regexp.matcher(text).find()) {
        String customMessage = message;
        if (customMessage.isEmpty()) {
            customMessage = MSG_KEY;
        }
        log(
            ast.getLineNo(),
            ast.getColumnNo(),
            customMessage,
            format);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:16,代码来源:IllegalTokenTextCheck.java

示例12: visitToken

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST commentAst) {
    switch (commentAst.getType()) {
        case TokenTypes.SINGLE_LINE_COMMENT:
        case TokenTypes.BLOCK_COMMENT_BEGIN:
            visitComment(commentAst);
            break;
        default:
            final String exceptionMsg = "Unexpected token type: " + commentAst.getText();
            throw new IllegalArgumentException(exceptionMsg);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:13,代码来源:CommentsIndentationCheck.java

示例13: processLambda

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Process a lambda token.
 * Checks whether a lambda parameter shadows a field.
 * Note, that when parameter of lambda expression is untyped,
 * ANTLR parses the parameter as an identifier.
 * @param ast the lambda token.
 */
private void processLambda(DetailAST ast) {
    final DetailAST firstChild = ast.getFirstChild();
    if (firstChild.getType() == TokenTypes.IDENT) {
        final String untypedLambdaParameterName = firstChild.getText();
        if (frame.containsStaticField(untypedLambdaParameterName)
            || isInstanceField(firstChild, untypedLambdaParameterName)) {
            log(firstChild, MSG_KEY, untypedLambdaParameterName);
        }
    }
    else {
        // Type of lambda parameter is not omitted.
        processVariable(ast);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:22,代码来源:HiddenFieldCheck.java

示例14: getIdentifier

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Returns the Java identifier represented by an AST.
 * @param ast an AST node for an IDENT or DOT
 * @return the Java identifier represented by the given AST subtree
 * @throws IllegalArgumentException if the AST is invalid
 */
private static String getIdentifier(DetailAST ast) {
    if (ast == null) {
        throw new IllegalArgumentException("Identifier AST expected, but get null.");
    }
    final String identifier;
    if (ast.getType() == TokenTypes.IDENT) {
        identifier = ast.getText();
    }
    else {
        identifier = getIdentifier(ast.getFirstChild()) + "."
            + getIdentifier(ast.getLastChild());
    }
    return identifier;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:21,代码来源:SuppressWarningsHolder.java

示例15: visitVariableDef

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks access modifier of given variable.
 * If it is not proper according to Check - puts violation on it.
 * @param variableDef variable to check.
 */
private void visitVariableDef(DetailAST variableDef) {
    final boolean inInterfaceOrAnnotationBlock =
            ScopeUtils.isInInterfaceOrAnnotationBlock(variableDef);

    if (!inInterfaceOrAnnotationBlock && !hasIgnoreAnnotation(variableDef)) {
        final DetailAST varNameAST = variableDef.findFirstToken(TokenTypes.TYPE)
            .getNextSibling();
        final String varName = varNameAST.getText();
        if (!hasProperAccessModifier(variableDef, varName)) {
            log(varNameAST.getLineNo(), varNameAST.getColumnNo(),
                    MSG_KEY, varName);
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:20,代码来源:VisibilityModifierCheck.java


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