本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes.COMMENT_CONTENT属性的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes.COMMENT_CONTENT属性的具体用法?Java TokenTypes.COMMENT_CONTENT怎么用?Java TokenTypes.COMMENT_CONTENT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.puppycrawl.tools.checkstyle.api.TokenTypes
的用法示例。
在下文中一共展示了TokenTypes.COMMENT_CONTENT属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertToString
/**
* Converts given AST node to string representation.
* @param ast node to be represented as string
* @return string representation of AST node
*/
private static String convertToString(DetailAST ast) {
final String tokenText;
switch (ast.getType()) {
case TokenTypes.LABELED_STAT:
tokenText = ast.getFirstChild().getText() + ast.getText();
break;
// multiline tokens need to become singlelined
case TokenTypes.COMMENT_CONTENT:
tokenText = JavadocUtils.escapeAllControlChars(ast.getText());
break;
default:
tokenText = ast.getText();
break;
}
return tokenText;
}
示例2: printJavaAndJavadocTree
/**
* Prints full tree (java + comments + javadoc) of the DetailAST.
* @param ast root DetailAST
* @return Full tree
*/
private static String printJavaAndJavadocTree(DetailAST ast) {
final StringBuilder messageBuilder = new StringBuilder(1024);
DetailAST node = ast;
while (node != null) {
messageBuilder.append(getIndentation(node))
.append(getNodeInfo(node))
.append(LINE_SEPARATOR);
if (node.getType() == TokenTypes.COMMENT_CONTENT
&& JavadocUtils.isJavadocComment(node.getParent())) {
final String javadocTree = parseAndPrintJavadocTree(node);
messageBuilder.append(javadocTree);
}
else {
messageBuilder.append(printJavaAndJavadocTree(node.getFirstChild()));
}
node = node.getNextSibling();
}
return messageBuilder.toString();
}
示例3: getChildCount
/**
* Returns the number of children of parent.
* @param parent the node to count children for.
* @return the number of children of the node parent.
*/
public int getChildCount(Object parent) {
final int result;
if (parent instanceof DetailNode) {
result = ((DetailNode) parent).getChildren().length;
}
else {
if (parseMode == ParseMode.JAVA_WITH_JAVADOC_AND_COMMENTS
&& ((AST) parent).getType() == TokenTypes.COMMENT_CONTENT
&& JavadocUtils.isJavadocComment(((DetailAST) parent).getParent())) {
//getChildCount return 0 on COMMENT_CONTENT,
//but we need to attach javadoc tree, that is separate tree
result = 1;
}
else {
result = ((DetailAST) parent).getChildCount();
}
}
return result;
}
示例4: getChildAtDetailAst
/**
* Gets child of DetailAST node at specified index.
* @param parent DetailAST node
* @param index child index
* @return child DetailsAST or DetailNode if child is Javadoc node
* and parseMode is JAVA_WITH_JAVADOC_AND_COMMENTS.
*/
private Object getChildAtDetailAst(DetailAST parent, int index) {
final Object result;
if (parseMode == ParseMode.JAVA_WITH_JAVADOC_AND_COMMENTS
&& parent.getType() == TokenTypes.COMMENT_CONTENT
&& JavadocUtils.isJavadocComment(parent.getParent())) {
result = getJavadocTree(parent.getParent());
}
else {
int currentIndex = 0;
DetailAST child = parent.getFirstChild();
while (currentIndex < index) {
child = child.getNextSibling();
currentIndex++;
}
result = child;
}
return result;
}
示例5: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.NUM_DOUBLE,
TokenTypes.NUM_FLOAT,
TokenTypes.NUM_INT,
TokenTypes.NUM_LONG,
TokenTypes.IDENT,
TokenTypes.COMMENT_CONTENT,
TokenTypes.STRING_LITERAL,
TokenTypes.CHAR_LITERAL,
};
}
示例6: isDistributedExpression
/**
* Checks whether the previous statement of a comment is a method call chain or
* string concatenation statement distributed over two ore more lines.
* @param comment comment to check.
* @return true if the previous statement is a distributed expression.
*/
private boolean isDistributedExpression(DetailAST comment) {
DetailAST previousSibling = comment.getPreviousSibling();
while (previousSibling != null && isComment(previousSibling)) {
previousSibling = previousSibling.getPreviousSibling();
}
boolean isDistributed = false;
if (previousSibling != null) {
if (previousSibling.getType() == TokenTypes.SEMI
&& isOnPreviousLineIgnoringComments(comment, previousSibling)) {
DetailAST currentToken = previousSibling.getPreviousSibling();
while (currentToken.getFirstChild() != null) {
currentToken = currentToken.getFirstChild();
}
if (currentToken.getType() == TokenTypes.COMMENT_CONTENT) {
currentToken = currentToken.getParent();
while (isComment(currentToken)) {
currentToken = currentToken.getNextSibling();
}
}
if (previousSibling.getLineNo() != currentToken.getLineNo()) {
isDistributed = true;
}
}
else {
isDistributed = isStatementWithPossibleCurlies(previousSibling);
}
}
return isDistributed;
}
示例7: isComment
/**
* Whether the ast is a comment.
* @param ast the ast to check.
* @return true if the ast is a comment.
*/
private static boolean isComment(DetailAST ast) {
final int astType = ast.getType();
return astType == TokenTypes.SINGLE_LINE_COMMENT
|| astType == TokenTypes.BLOCK_COMMENT_BEGIN
|| astType == TokenTypes.COMMENT_CONTENT
|| astType == TokenTypes.BLOCK_COMMENT_END;
}
示例8: testGetRequiredTokens
@Test
public void testGetRequiredTokens() {
final TodoCommentCheck checkObj = new TodoCommentCheck();
final int[] expected = {TokenTypes.COMMENT_CONTENT};
assertArrayEquals("Required tokens differs from expected",
expected, checkObj.getRequiredTokens());
}
示例9: testGetAcceptableTokens
@Test
public void testGetAcceptableTokens() {
final int[] expected = {TokenTypes.COMMENT_CONTENT };
final TodoCommentCheck check = new TodoCommentCheck();
final int[] actual = check.getAcceptableTokens();
assertEquals("Amount of acceptable tokens differs from expected",
1, actual.length);
assertArrayEquals("Acceptable tokens differs from expected",
expected, actual);
}
示例10: testGetTokenNameWithGreatestPossibleId
@Test
public void testGetTokenNameWithGreatestPossibleId() {
final Integer id = TokenTypes.COMMENT_CONTENT;
final String tokenName = TokenUtils.getTokenName(id);
assertEquals("Invalid token name", "COMMENT_CONTENT", tokenName);
}
示例11: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {TokenTypes.COMMENT_CONTENT };
}
示例12: isCommentType
/**
* Is argument comment-related type (SINGLE_LINE_COMMENT,
* BLOCK_COMMENT_BEGIN, BLOCK_COMMENT_END, COMMENT_CONTENT).
* @param type
* token type.
* @return true if type is comment-related type.
*/
public static boolean isCommentType(int type) {
return type == TokenTypes.SINGLE_LINE_COMMENT
|| type == TokenTypes.BLOCK_COMMENT_BEGIN
|| type == TokenTypes.BLOCK_COMMENT_END
|| type == TokenTypes.COMMENT_CONTENT;
}