本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.DetailAST.initialize方法的典型用法代码示例。如果您正苦于以下问题:Java DetailAST.initialize方法的具体用法?Java DetailAST.initialize怎么用?Java DetailAST.initialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.puppycrawl.tools.checkstyle.api.DetailAST
的用法示例。
在下文中一共展示了DetailAST.initialize方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDefaultHooks
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testDefaultHooks() {
final NPathComplexityCheck npathComplexityCheckObj = new NPathComplexityCheck();
final DetailAST ast = new DetailAST();
ast.initialize(new CommonHiddenStreamToken(TokenTypes.INTERFACE_DEF, "interface"));
npathComplexityCheckObj.visitToken(ast);
final SortedSet<LocalizedMessage> messages1 = npathComplexityCheckObj.getMessages();
Assert.assertEquals("No exception messages expected", 0, messages1.size());
npathComplexityCheckObj.leaveToken(ast);
final SortedSet<LocalizedMessage> messages2 = npathComplexityCheckObj.getMessages();
Assert.assertEquals("No exception messages expected", 0, messages2.size());
}
示例2: createBlockCommentNode
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Create block comment from token.
* @param token
* Token object.
* @return DetailAST with BLOCK_COMMENT type.
*/
public static DetailAST createBlockCommentNode(Token token) {
final DetailAST blockComment = new DetailAST();
blockComment.initialize(TokenTypes.BLOCK_COMMENT_BEGIN, BLOCK_MULTIPLE_COMMENT_BEGIN);
// column counting begins from 0
blockComment.setColumnNo(token.getColumn() - 1);
blockComment.setLineNo(token.getLine());
final DetailAST blockCommentContent = new DetailAST();
blockCommentContent.setType(TokenTypes.COMMENT_CONTENT);
// column counting begins from 0
// plus length of '/*'
blockCommentContent.setColumnNo(token.getColumn() - 1 + 2);
blockCommentContent.setLineNo(token.getLine());
blockCommentContent.setText(token.getText());
final DetailAST blockCommentClose = new DetailAST();
blockCommentClose.initialize(TokenTypes.BLOCK_COMMENT_END, BLOCK_MULTIPLE_COMMENT_END);
final Map.Entry<Integer, Integer> linesColumns = countLinesColumns(
token.getText(), token.getLine(), token.getColumn());
blockCommentClose.setLineNo(linesColumns.getKey());
blockCommentClose.setColumnNo(linesColumns.getValue());
blockComment.addChild(blockCommentContent);
blockComment.addChild(blockCommentClose);
return blockComment;
}
示例3: testVisitTokenWithWrongTokenType
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testVisitTokenWithWrongTokenType() {
final ExecutableStatementCountCheck checkObj =
new ExecutableStatementCountCheck();
final DetailAST ast = new DetailAST();
ast.initialize(
new CommonHiddenStreamToken(TokenTypes.ENUM, "ENUM"));
try {
checkObj.visitToken(ast);
fail("exception expected");
}
catch (IllegalStateException ex) {
assertEquals("Invalid exception message", "ENUM[0x-1]", ex.getMessage());
}
}
示例4: testLeaveTokenWithWrongTokenType
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testLeaveTokenWithWrongTokenType() {
final ExecutableStatementCountCheck checkObj =
new ExecutableStatementCountCheck();
final DetailAST ast = new DetailAST();
ast.initialize(
new CommonHiddenStreamToken(TokenTypes.ENUM, "ENUM"));
try {
checkObj.leaveToken(ast);
fail("exception expected");
}
catch (IllegalStateException ex) {
assertEquals("Invalid exception message", "ENUM[0x-1]", ex.getMessage());
}
}
示例5: testWrongToken
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testWrongToken() {
final BooleanExpressionComplexityCheck booleanExpressionComplexityCheckObj =
new BooleanExpressionComplexityCheck();
final DetailAST ast = new DetailAST();
ast.initialize(new CommonHiddenStreamToken(TokenTypes.INTERFACE_DEF, "interface"));
try {
booleanExpressionComplexityCheckObj.visitToken(ast);
fail("exception expected");
}
catch (IllegalArgumentException ex) {
assertEquals("Invalid exception message",
"Unknown type: interface[0x-1]", ex.getMessage());
}
}
示例6: mockAST
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Creates MOCK lexical token and returns AST node for this token.
* @param tokenType type of token
* @param tokenText text of token
* @param tokenFileName file name of token
* @param tokenRow token position in a file (row)
* @param tokenColumn token position in a file (column)
* @return AST node for the token
*/
private static DetailAST mockAST(final int tokenType, final String tokenText,
final String tokenFileName, final int tokenRow, final int tokenColumn) {
final CommonHiddenStreamToken tokenImportSemi = new CommonHiddenStreamToken();
tokenImportSemi.setType(tokenType);
tokenImportSemi.setText(tokenText);
tokenImportSemi.setLine(tokenRow);
tokenImportSemi.setColumn(tokenColumn);
tokenImportSemi.setFilename(tokenFileName);
final DetailAST astSemi = new DetailAST();
astSemi.initialize(tokenImportSemi);
return astSemi;
}
示例7: testWrongToken
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testWrongToken() {
final ClassDataAbstractionCouplingCheck classDataAbstractionCouplingCheckObj =
new ClassDataAbstractionCouplingCheck();
final DetailAST ast = new DetailAST();
ast.initialize(new CommonHiddenStreamToken(TokenTypes.CTOR_DEF, "ctor"));
try {
classDataAbstractionCouplingCheckObj.visitToken(ast);
fail("exception expected");
}
catch (IllegalArgumentException ex) {
assertEquals("Invalid exception message",
"Unknown type: ctor[0x-1]", ex.getMessage());
}
}
示例8: testDefaultSwitch
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testDefaultSwitch() {
final RequireThisCheck check = new RequireThisCheck();
final DetailAST ast = new DetailAST();
ast.initialize(new CommonHiddenStreamToken(TokenTypes.ENUM, "ENUM"));
check.visitToken(ast);
final SortedSet<LocalizedMessage> messages = check.getMessages();
Assert.assertEquals("No exception messages expected", 0, messages.size());
}
示例9: testIllegalStateException
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testIllegalStateException() {
final UncommentedMainCheck check = new UncommentedMainCheck();
final DetailAST ast = new DetailAST();
ast.initialize(new CommonHiddenStreamToken(TokenTypes.CTOR_DEF, "ctor"));
try {
check.visitToken(ast);
Assert.fail("IllegalStateException is expected");
}
catch (IllegalStateException ex) {
assertEquals("Error message is unexpected",
ast.toString(), ex.getMessage());
}
}
示例10: mockAST
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Creates MOCK lexical token and returns AST node for this token.
* @param tokenType type of token
* @param tokenText text of token
* @param tokenFileName file name of token
* @return AST node for the token
*/
private static DetailAST mockAST(final int tokenType, final String tokenText,
final String tokenFileName) {
final CommonHiddenStreamToken tokenImportSemi = new CommonHiddenStreamToken();
tokenImportSemi.setType(tokenType);
tokenImportSemi.setText(tokenText);
tokenImportSemi.setFilename(tokenFileName);
final DetailAST astSemi = new DetailAST();
astSemi.initialize(tokenImportSemi);
return astSemi;
}
示例11: testWrongTokenType
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testWrongTokenType() {
final GenericWhitespaceCheck genericWhitespaceCheckObj = new GenericWhitespaceCheck();
final DetailAST ast = new DetailAST();
ast.initialize(new CommonHiddenStreamToken(TokenTypes.INTERFACE_DEF, "interface"));
try {
genericWhitespaceCheckObj.visitToken(ast);
fail("exception expected");
}
catch (IllegalArgumentException ex) {
assertEquals("Invalid exception message",
"Unknown type interface[0x-1]", ex.getMessage());
}
}
示例12: testWrongTokenType
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testWrongTokenType() {
final VisibilityModifierCheck obj = new VisibilityModifierCheck();
final DetailAST ast = new DetailAST();
ast.initialize(new CommonHiddenStreamToken(TokenTypes.CLASS_DEF, "class"));
try {
obj.visitToken(ast);
fail("exception expected");
}
catch (IllegalArgumentException ex) {
assertEquals("Invalid exception message",
"Unexpected token type: class", ex.getMessage());
}
}
示例13: testWrongTokenType
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testWrongTokenType() {
final ThrowsCountCheck obj = new ThrowsCountCheck();
final DetailAST ast = new DetailAST();
ast.initialize(new CommonHiddenStreamToken(TokenTypes.CLASS_DEF, "class"));
try {
obj.visitToken(ast);
fail("IllegalStateException is expected");
}
catch (IllegalStateException ex) {
assertEquals("Invalid exception message", ast.toString(), ex.getMessage());
}
}
示例14: testWrongTokenType
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testWrongTokenType() {
final MutableExceptionCheck obj = new MutableExceptionCheck();
final DetailAST ast = new DetailAST();
ast.initialize(new CommonHiddenStreamToken(TokenTypes.INTERFACE_DEF, "interface"));
try {
obj.visitToken(ast);
fail("IllegalStateException is expected");
}
catch (IllegalStateException ex) {
//expected
}
}