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


Java DetailAST.setColumnNo方法代码示例

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


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

示例1: createBlockCommentNode

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Create block comment from string content.
 * @param content comment content.
 * @return DetailAST block comment
 */
public static DetailAST createBlockCommentNode(String content) {
    final DetailAST blockCommentBegin = new DetailAST();
    blockCommentBegin.setType(TokenTypes.BLOCK_COMMENT_BEGIN);
    blockCommentBegin.setText(BLOCK_MULTIPLE_COMMENT_BEGIN);
    blockCommentBegin.setLineNo(0);
    blockCommentBegin.setColumnNo(-JAVADOC_START.length());

    final DetailAST commentContent = new DetailAST();
    commentContent.setType(TokenTypes.COMMENT_CONTENT);
    commentContent.setText("*" + content);
    commentContent.setLineNo(0);
    // javadoc should starts at 0 column, so COMMENT_CONTENT node
    // that contains javadoc identifier has -1 column
    commentContent.setColumnNo(-1);

    final DetailAST blockCommentEnd = new DetailAST();
    blockCommentEnd.setType(TokenTypes.BLOCK_COMMENT_END);
    blockCommentEnd.setText(BLOCK_MULTIPLE_COMMENT_END);

    blockCommentBegin.setFirstChild(commentContent);
    commentContent.setNextSibling(blockCommentEnd);
    return blockCommentBegin;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:29,代码来源:CommonUtils.java

示例2: createSlCommentNode

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Create single-line comment from token.
 * @param token
 *        Token object.
 * @return DetailAST with SINGLE_LINE_COMMENT type.
 */
private static DetailAST createSlCommentNode(Token token) {
    final DetailAST slComment = new DetailAST();
    slComment.setType(TokenTypes.SINGLE_LINE_COMMENT);
    slComment.setText("//");

    // column counting begins from 0
    slComment.setColumnNo(token.getColumn() - 1);
    slComment.setLineNo(token.getLine());

    final DetailAST slCommentContent = new DetailAST();
    slCommentContent.setType(TokenTypes.COMMENT_CONTENT);

    // column counting begins from 0
    // plus length of '//'
    slCommentContent.setColumnNo(token.getColumn() - 1 + 2);
    slCommentContent.setLineNo(token.getLine());
    slCommentContent.setText(token.getText());

    slComment.addChild(slCommentContent);
    return slComment;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:28,代码来源:TreeWalker.java

示例3: testGetAnnotationValuesWrongArg

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testGetAnnotationValuesWrongArg() throws Exception {
    final SuppressWarningsHolder holder = new SuppressWarningsHolder();
    final Method getAllAnnotationValues = holder.getClass()
            .getDeclaredMethod("getAnnotationValues", DetailAST.class);
    getAllAnnotationValues.setAccessible(true);

    final DetailAST methodDef = new DetailAST();
    methodDef.setType(TokenTypes.METHOD_DEF);
    methodDef.setText("Method Def");
    methodDef.setLineNo(0);
    methodDef.setColumnNo(0);

    try {
        getAllAnnotationValues.invoke(holder, methodDef);
        fail("Exception expected");
    }
    catch (InvocationTargetException ex) {
        assertTrue("Error type is unexpected",
                ex.getCause() instanceof IllegalArgumentException);
        assertEquals("Error message is unexpected",
                "Expression or annotation array"
                + " initializer AST expected: Method Def[0x0]", ex.getCause().getMessage());
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:26,代码来源:SuppressWarningsHolderTest.java

示例4: testTokenEndIsAfterSameLineColumn

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * This must be a reflection test as it is too difficult to hit normally and
 * the responsible code can't be removed without failing tests.
 * TokenEnd is only used for processingTokenEnd and it is only set during visitConditional
 * and visitUnitaryOperator. For it to be the same line/column, it must be the exact same
 * token or a token who has the same line/column as it's child and we visit. We never
 * visit the same token twice and we are only visiting on very specific tokens.
 * The line can't be removed or reworked as other tests fail, and regression shows us no
 * use cases to create a UT for.
 * @throws Exception if there is an error.
 */
@Test
public void testTokenEndIsAfterSameLineColumn() throws Exception {
    final NPathComplexityCheck check = new NPathComplexityCheck();
    final Object tokenEnd = TestUtil.getClassDeclaredField(NPathComplexityCheck.class,
            "processingTokenEnd").get(check);
    final DetailAST token = new DetailAST();
    token.setLineNo(0);
    token.setColumnNo(0);

    Assert.assertTrue("isAfter must be true for same line/column",
            (Boolean) TestUtil.getClassDeclaredMethod(tokenEnd.getClass(), "isAfter")
                .invoke(tokenEnd, token));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:25,代码来源:NPathComplexityCheckTest.java

示例5: testGetAllAnnotationValuesWrongArg

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testGetAllAnnotationValuesWrongArg() throws Exception {
    final SuppressWarningsHolder holder = new SuppressWarningsHolder();
    final Method getAllAnnotationValues = holder.getClass()
            .getDeclaredMethod("getAllAnnotationValues", DetailAST.class);
    getAllAnnotationValues.setAccessible(true);

    final DetailAST methodDef = new DetailAST();
    methodDef.setType(TokenTypes.METHOD_DEF);
    methodDef.setText("Method Def");
    methodDef.setLineNo(0);
    methodDef.setColumnNo(0);

    final DetailAST lparen = new DetailAST();
    lparen.setType(TokenTypes.LPAREN);

    final DetailAST parent = new DetailAST();
    parent.addChild(lparen);
    parent.addChild(methodDef);

    try {
        getAllAnnotationValues.invoke(holder, parent);
        fail("Exception expected");
    }
    catch (InvocationTargetException ex) {
        assertTrue("Error type is unexpected",
                ex.getCause() instanceof IllegalArgumentException);
        assertEquals("Error message is unexpected",
                "Unexpected AST: Method Def[0x0]", ex.getCause().getMessage());
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:32,代码来源:SuppressWarningsHolderTest.java

示例6: testGetAnnotationTargetWrongArg

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testGetAnnotationTargetWrongArg() throws Exception {
    final SuppressWarningsHolder holder = new SuppressWarningsHolder();
    final Method getAnnotationTarget = holder.getClass()
            .getDeclaredMethod("getAnnotationTarget", DetailAST.class);
    getAnnotationTarget.setAccessible(true);

    final DetailAST methodDef = new DetailAST();
    methodDef.setType(TokenTypes.METHOD_DEF);
    methodDef.setText("Method Def");

    final DetailAST parent = new DetailAST();
    parent.setType(TokenTypes.ASSIGN);
    parent.setText("Parent ast");
    parent.addChild(methodDef);
    parent.setLineNo(0);
    parent.setColumnNo(0);

    try {
        getAnnotationTarget.invoke(holder, methodDef);
        fail("Exception expected");
    }
    catch (InvocationTargetException ex) {
        assertTrue("Error type is unexpected",
                ex.getCause() instanceof IllegalArgumentException);
        assertEquals("Error message is unexpected",
                "Unexpected container AST: Parent ast[0x0]", ex.getCause().getMessage());
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:30,代码来源:SuppressWarningsHolderTest.java

示例7: testGetFirstNode1

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testGetFirstNode1() {
    final DetailAST child = new DetailAST();
    child.setLineNo(5);
    child.setColumnNo(6);

    final DetailAST root = new DetailAST();
    root.setLineNo(5);
    root.setColumnNo(6);

    root.addChild(child);

    assertEquals("Unexpected node", root, CheckUtils.getFirstNode(root));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:15,代码来源:CheckUtilsTest.java

示例8: testGetFirstNode2

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testGetFirstNode2() {
    final DetailAST child = new DetailAST();
    child.setLineNo(6);
    child.setColumnNo(5);

    final DetailAST root = new DetailAST();
    root.setLineNo(5);
    root.setColumnNo(6);

    root.addChild(child);

    assertEquals("Unexpected node", root, CheckUtils.getFirstNode(root));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:15,代码来源:CheckUtilsTest.java

示例9: testNullClassLoader

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testNullClassLoader() throws Exception {
    final DetailAST exprAst = new DetailAST();
    exprAst.setType(TokenTypes.EXPR);

    final DetailAST newAst = new DetailAST();
    newAst.setType(TokenTypes.LITERAL_NEW);
    newAst.setLineNo(1);
    newAst.setColumnNo(1);

    final DetailAST identAst = new DetailAST();
    identAst.setType(TokenTypes.IDENT);
    identAst.setText("Boolean");

    final DetailAST lparenAst = new DetailAST();
    lparenAst.setType(TokenTypes.LPAREN);

    final DetailAST elistAst = new DetailAST();
    elistAst.setType(TokenTypes.ELIST);

    final DetailAST rparenAst = new DetailAST();
    rparenAst.setType(TokenTypes.RPAREN);

    exprAst.addChild(newAst);
    newAst.addChild(identAst);
    identAst.setNextSibling(lparenAst);
    lparenAst.setNextSibling(elistAst);
    elistAst.setNextSibling(rparenAst);

    final IllegalInstantiationCheck check = new IllegalInstantiationCheck();
    final File inputFile = new File(getNonCompilablePath("InputIllegalInstantiationLang.java"));
    check.setFileContents(new FileContents(new FileText(inputFile,
            StandardCharsets.UTF_8.name())));
    check.configure(createModuleConfig(IllegalInstantiationCheck.class));
    check.setClasses("java.lang.Boolean");

    check.visitToken(newAst);
    final SortedSet<LocalizedMessage> messages1 = check.getMessages();

    Assert.assertEquals("No exception messages expected", 0, messages1.size());

    check.finishTree(newAst);
    final SortedSet<LocalizedMessage> messages2 = check.getMessages();

    final LocalizedMessage addExceptionMessage = new LocalizedMessage(0,
            "com.puppycrawl.tools.checkstyle.checks.coding.messages", "instantiation.avoid",
            new String[] {"java.lang.Boolean"}, null,
            getClass(), null);
    Assert.assertEquals("Invalid exception message",
            addExceptionMessage.getMessage(),
        messages2.first().getMessage());
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:53,代码来源:IllegalInstantiationCheckTest.java

示例10: createAst

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
private static DetailAST createAst(int line, int column) {
    final DetailAST ast = new DetailAST();
    ast.setLineNo(line);
    ast.setColumnNo(column);
    return ast;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:7,代码来源:TreeWalkerTest.java


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