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


Java DetailAST.setText方法代码示例

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


在下文中一共展示了DetailAST.setText方法的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: 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: 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

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

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

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

示例7: testFindFirstTokenByPredicate

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testFindFirstTokenByPredicate() {
    final DetailAST astForTest = new DetailAST();
    final DetailAST child = new DetailAST();
    final DetailAST firstSibling = new DetailAST();
    final DetailAST secondSibling = new DetailAST();
    final DetailAST thirdSibling = new DetailAST();
    firstSibling.setText("first");
    secondSibling.setText("second");
    thirdSibling.setText("third");
    secondSibling.setNextSibling(thirdSibling);
    firstSibling.setNextSibling(secondSibling);
    child.setNextSibling(firstSibling);
    astForTest.setFirstChild(child);
    final Optional<DetailAST> result = TokenUtils.findFirstTokenByPredicate(astForTest,
        new Predicate<DetailAST>() {
            @Override
            public boolean test(DetailAST ast) {
                return "second".equals(ast.getText());
            }
        });

    assertEquals("Invalid second sibling", secondSibling, result.get());
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:25,代码来源:TokenUtilsTest.java

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

示例9: testUnusedMethod

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testUnusedMethod() throws Exception {
    final DetailAST ident = new DetailAST();
    ident.setText("testName");

    final Class<?> cls = Class.forName(RequireThisCheck.class.getName() + "$CatchFrame");
    final Constructor<?> constructor = cls.getDeclaredConstructors()[0];
    constructor.setAccessible(true);
    final Object o = constructor.newInstance(null, ident);

    Assert.assertEquals("expected ident token", ident,
            TestUtil.getClassDeclaredMethod(cls, "getFrameNameIdent").invoke(o));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:14,代码来源:RequireThisCheckTest.java

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

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

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

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

    final String[] validNames = {
        "writeObject",
        "readObject",
        "writeExternal",
        "readExternal",
        "writeReplace",
        "readResolve",
    };
    for (String name: validNames) {
        astChild.setText(name);
        assertTrue("Invalid ast type for current tag: " + ast.getType(),
                JavadocTagInfo.SERIAL_DATA.isValidOn(ast));
    }

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

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

示例14: getNodeWithParentScope

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
private static DetailAST getNodeWithParentScope(int literal, String scope,
                                                int parentTokenType) {
    final DetailAST ast = getNode(parentTokenType, TokenTypes.MODIFIERS, literal);
    ast.setText(scope);
    final DetailAST ast2 = getNode(TokenTypes.OBJBLOCK);
    ast.getParent().getParent().addChild(ast2);
    return ast;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:9,代码来源:ScopeUtilsTest.java

示例15: testElseWithCurly

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testElseWithCurly() {
    final DetailAST ast = new DetailAST();
    ast.setType(TokenTypes.ASSIGN);
    ast.setText("ASSIGN");
    assertFalse("Invalid elseIf check result 'ASSIGN' is not 'else if'",
            CheckUtils.isElseIf(ast));

    final DetailAST parentAst = new DetailAST();
    parentAst.setType(TokenTypes.LCURLY);
    parentAst.setText("LCURLY");

    final DetailAST ifAst = new DetailAST();
    ifAst.setType(TokenTypes.LITERAL_IF);
    ifAst.setText("IF");
    parentAst.addChild(ifAst);

    assertFalse("Invalid elseIf check result: 'IF' is not 'else if'",
            CheckUtils.isElseIf(ifAst));

    final DetailAST parentAst2 = new DetailAST();
    parentAst2.setType(TokenTypes.SLIST);
    parentAst2.setText("SLIST");

    parentAst2.addChild(ifAst);

    assertFalse("Invalid elseIf check result: 'SLIST' is not 'else if'",
            CheckUtils.isElseIf(ifAst));

    final DetailAST elseAst = new DetailAST();
    elseAst.setType(TokenTypes.LITERAL_ELSE);

    elseAst.setFirstChild(ifAst);
    assertTrue("Invalid elseIf check result", CheckUtils.isElseIf(ifAst));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:36,代码来源:CheckUtilsTest.java


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