本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.DetailAST.setNextSibling方法的典型用法代码示例。如果您正苦于以下问题:Java DetailAST.setNextSibling方法的具体用法?Java DetailAST.setNextSibling怎么用?Java DetailAST.setNextSibling使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.puppycrawl.tools.checkstyle.api.DetailAST
的用法示例。
在下文中一共展示了DetailAST.setNextSibling方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: 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());
}
示例3: 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"));
}
示例4: 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"));
}
示例5: 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());
}
示例6: 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));
}
示例7: testEmptyJavadocCommentAst
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testEmptyJavadocCommentAst() {
final DetailAST commentBegin = new DetailAST();
commentBegin.setType(TokenTypes.BLOCK_COMMENT_BEGIN);
commentBegin.setText("/*");
final DetailAST javadocCommentContent = new DetailAST();
javadocCommentContent.setType(TokenTypes.COMMENT_CONTENT);
javadocCommentContent.setText("*");
final DetailAST commentEnd = new DetailAST();
commentEnd.setType(TokenTypes.BLOCK_COMMENT_END);
commentEnd.setText("*/");
commentBegin.setFirstChild(javadocCommentContent);
javadocCommentContent.setNextSibling(commentEnd);
final DetailAST commentBeginParent = new DetailAST();
commentBeginParent.setType(TokenTypes.MODIFIERS);
commentBeginParent.setFirstChild(commentBegin);
final DetailAST aJavadocPosition = new DetailAST();
aJavadocPosition.setType(TokenTypes.METHOD_DEF);
aJavadocPosition.setFirstChild(commentBeginParent);
assertTrue("Should return true when empty javadoc comment ast is passed",
JavadocUtils.isJavadocComment(commentBegin));
}
示例8: 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());
}