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


Java DetailAST.setType方法代码示例

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


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

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testParam() {
    final DetailAST ast = new DetailAST();

    final int[] validTypes = {
        TokenTypes.CLASS_DEF,
        TokenTypes.INTERFACE_DEF,
        TokenTypes.METHOD_DEF,
        TokenTypes.CTOR_DEF,
    };
    for (int type: validTypes) {
        ast.setType(type);
        assertTrue("Invalid ast type for current tag: " + ast.getType(),
                JavadocTagInfo.PARAM.isValidOn(ast));
    }

    ast.setType(TokenTypes.LAMBDA);
    assertFalse("Should return false when ast type is invalid for current tag",
            JavadocTagInfo.PARAM.isValidOn(ast));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:21,代码来源:JavadocTagInfoTest.java

示例3: testContainsAnnotationWithComment

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testContainsAnnotationWithComment() {
    final DetailAST astForTest = new DetailAST();
    astForTest.setType(TokenTypes.PACKAGE_DEF);
    final DetailAST child = new DetailAST();
    final DetailAST annotations = new DetailAST();
    final DetailAST annotation = new DetailAST();
    final DetailAST annotationNameHolder = new DetailAST();
    final DetailAST annotationName = new DetailAST();
    final DetailAST comment = new DetailAST();
    annotations.setType(TokenTypes.ANNOTATIONS);
    annotation.setType(TokenTypes.ANNOTATION);
    annotationNameHolder.setType(TokenTypes.AT);
    comment.setType(TokenTypes.BLOCK_COMMENT_BEGIN);
    annotationName.setText("Annotation");

    annotationNameHolder.setNextSibling(annotationName);
    annotation.setFirstChild(comment);
    comment.setNextSibling(annotationNameHolder);
    annotations.setFirstChild(annotation);
    child.setNextSibling(annotations);
    astForTest.setFirstChild(child);

    assertTrue("Annotation should contain " + astForTest,
            AnnotationUtility.containsAnnotation(astForTest, "Annotation"));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:27,代码来源:AnnotationUtilityTest.java

示例4: testParents

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testParents() {
    final DetailAST parent = new DetailAST();
    parent.setType(TokenTypes.STATIC_INIT);
    final DetailAST method = new DetailAST();
    method.setType(TokenTypes.METHOD_DEF);
    parent.setFirstChild(method);
    final DetailAST ctor = new DetailAST();
    ctor.setType(TokenTypes.CTOR_DEF);
    method.setNextSibling(ctor);

    final DeclarationOrderCheck check = new DeclarationOrderCheck();

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

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

    check.visitToken(ctor);
    final SortedSet<LocalizedMessage> messages2 = check.getMessages();

    assertEquals("No exception messages expected", 0, messages2.size());
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:DeclarationOrderCheckTest.java

示例5: testVisitToken

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testVisitToken() {
    final CommentsIndentationCheck check = new CommentsIndentationCheck();
    final DetailAST methodDef = new DetailAST();
    methodDef.setType(TokenTypes.METHOD_DEF);
    methodDef.setText("methodStub");
    try {
        check.visitToken(methodDef);
        Assert.fail("IllegalArgumentException should have been thrown!");
    }
    catch (IllegalArgumentException ex) {
        final String msg = ex.getMessage();
        Assert.assertEquals("Invalid exception message",
                "Unexpected token type: methodStub", msg);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:CommentsIndentationCheckTest.java

示例6: testVersions

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testVersions() {
    final DetailAST ast = new DetailAST();

    final int[] validTypes = {
        TokenTypes.PACKAGE_DEF,
        TokenTypes.CLASS_DEF,
        TokenTypes.INTERFACE_DEF,
        TokenTypes.ENUM_DEF,
        TokenTypes.ANNOTATION_DEF,
    };
    for (int type: validTypes) {
        ast.setType(type);
        assertTrue("Invalid ast type for current tag: " + ast.getType(),
                JavadocTagInfo.VERSION.isValidOn(ast));
    }

    ast.setType(TokenTypes.LAMBDA);
    assertFalse("Should return false when ast type is invalid for current tag",
            JavadocTagInfo.VERSION.isValidOn(ast));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:22,代码来源:JavadocTagInfoTest.java

示例7: testEmptyBlockCommentAst

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testEmptyBlockCommentAst() {
    final DetailAST commentBegin = new DetailAST();
    commentBegin.setType(TokenTypes.BLOCK_COMMENT_BEGIN);
    commentBegin.setText("/*");

    final DetailAST commentContent = new DetailAST();
    commentContent.setType(TokenTypes.COMMENT_CONTENT);
    commentContent.setText("");

    final DetailAST commentEnd = new DetailAST();
    commentEnd.setType(TokenTypes.BLOCK_COMMENT_END);
    commentEnd.setText("*/");

    commentBegin.setFirstChild(commentContent);
    commentContent.setNextSibling(commentEnd);

    assertFalse("Should return false when empty block comment is passed",
            JavadocUtils.isJavadocComment(commentBegin));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:21,代码来源:JavadocUtilsTest.java

示例8: testThrows

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testThrows() {
    final DetailAST ast = new DetailAST();

    final int[] validTypes = {
        TokenTypes.METHOD_DEF,
        TokenTypes.CTOR_DEF,
    };
    for (int type: validTypes) {
        ast.setType(type);
        assertTrue("Invalid ast type for current tag: " + ast.getType(),
                JavadocTagInfo.THROWS.isValidOn(ast));
    }

    ast.setType(TokenTypes.LAMBDA);
    assertFalse("Should return false when ast type is invalid for current tag",
            JavadocTagInfo.THROWS.isValidOn(ast));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:19,代码来源:JavadocTagInfoTest.java

示例9: testAuthor

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testAuthor() {
    final DetailAST ast = new DetailAST();

    final int[] validTypes = {
        TokenTypes.PACKAGE_DEF,
        TokenTypes.CLASS_DEF,
        TokenTypes.INTERFACE_DEF,
        TokenTypes.ENUM_DEF,
        TokenTypes.ANNOTATION_DEF,
    };
    for (int type: validTypes) {
        ast.setType(type);
        assertTrue("Invalid ast type for current tag: " + ast.getType(),
                JavadocTagInfo.AUTHOR.isValidOn(ast));
    }

    ast.setType(TokenTypes.LAMBDA);
    assertFalse("Should return false when ast type is invalid for current tag",
            JavadocTagInfo.AUTHOR.isValidOn(ast));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:22,代码来源:JavadocTagInfoTest.java

示例10: testContainsAnnotation

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testContainsAnnotation() {
    final DetailAST astForTest = new DetailAST();
    astForTest.setType(TokenTypes.PACKAGE_DEF);
    final DetailAST child = new DetailAST();
    final DetailAST annotations = new DetailAST();
    final DetailAST annotation = new DetailAST();
    final DetailAST annotationNameHolder = new DetailAST();
    final DetailAST annotationName = new DetailAST();
    annotations.setType(TokenTypes.ANNOTATIONS);
    annotation.setType(TokenTypes.ANNOTATION);
    annotationNameHolder.setType(TokenTypes.AT);
    annotationName.setText("Annotation");

    annotationNameHolder.setNextSibling(annotationName);
    annotation.setFirstChild(annotationNameHolder);
    annotations.setFirstChild(annotation);
    child.setNextSibling(annotations);
    astForTest.setFirstChild(child);

    assertTrue("Annotation should contain " + astForTest,
            AnnotationUtility.containsAnnotation(astForTest, "Annotation"));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:AnnotationUtilityTest.java

示例11: testStatefulFieldsClearedOnBeginTree

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testStatefulFieldsClearedOnBeginTree() throws Exception {
    final DetailAST ast = new DetailAST();
    ast.setType(TokenTypes.STATIC_INIT);
    final ExecutableStatementCountCheck check = new ExecutableStatementCountCheck();
    Assert.assertTrue("Stateful field is not cleared after beginTree",
            TestUtil.isStatefulFieldClearedDuringBeginTree(check, ast, "contextStack",
                new Predicate<Object>() {
                    @Override
                    public boolean test(Object contextStack) {
                        return ((Collection<Context>) contextStack).isEmpty();
                    }
                }));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:16,代码来源:ExecutableStatementCountCheckTest.java

示例12: testSerialField

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testSerialField() {
    final DetailAST ast = new DetailAST();
    final DetailAST astChild = new DetailAST();
    astChild.setType(TokenTypes.TYPE);
    ast.setFirstChild(astChild);
    final DetailAST astChild2 = new DetailAST();
    astChild2.setType(TokenTypes.ARRAY_DECLARATOR);
    astChild2.setText("ObjectStreamField");
    astChild.setFirstChild(astChild2);

    final int[] validTypes = {
        TokenTypes.VARIABLE_DEF,
    };
    for (int type: validTypes) {
        ast.setType(type);
        assertTrue("Invalid ast type for current tag: " + ast.getType(),
                JavadocTagInfo.SERIAL_FIELD.isValidOn(ast));
    }

    astChild2.setText("1111");
    assertFalse("Should return false when ast type is invalid for current tag",
            JavadocTagInfo.SERIAL_FIELD.isValidOn(ast));

    astChild2.setType(TokenTypes.LITERAL_VOID);
    assertFalse("Should return false when ast type is invalid for current tag",
            JavadocTagInfo.SERIAL_FIELD.isValidOn(ast));

    ast.setType(TokenTypes.LAMBDA);
    assertFalse("Should return false when ast type is invalid for current tag",
            JavadocTagInfo.SERIAL_FIELD.isValidOn(ast));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:33,代码来源:JavadocTagInfoTest.java

示例13: testImproperToken

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testImproperToken() {
    final DetailAST parent = new DetailAST();
    parent.setType(TokenTypes.STATIC_INIT);
    final DetailAST array = new DetailAST();
    array.setType(TokenTypes.ARRAY_INIT);
    parent.setFirstChild(array);

    final DeclarationOrderCheck check = new DeclarationOrderCheck();

    check.visitToken(array);
    final SortedSet<LocalizedMessage> messages = check.getMessages();

    assertEquals("No exception messages expected", 0, messages.size());
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:16,代码来源:DeclarationOrderCheckTest.java

示例14: testImproperToken

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testImproperToken() {
    final FinalClassCheck finalClassCheck = new FinalClassCheck();
    final DetailAST badAst = new DetailAST();
    final int unsupportedTokenByCheck = TokenTypes.EOF;
    badAst.setType(unsupportedTokenByCheck);
    try {
        finalClassCheck.visitToken(badAst);
        Assert.fail("IllegalStateException is expected");
    }
    catch (IllegalStateException ex) {
        // it is OK
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:15,代码来源:FinalClassCheckTest.java

示例15: testImproperToken

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testImproperToken() {
    final IllegalTypeCheck check = new IllegalTypeCheck();

    final DetailAST classDefAst = new DetailAST();
    classDefAst.setType(TokenTypes.CLASS_DEF);

    try {
        check.visitToken(classDefAst);
        Assert.fail("IllegalStateException is expected");
    }
    catch (IllegalStateException ex) {
        // it is OK
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:16,代码来源:IllegalTypeCheckTest.java


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