本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes.SINGLE_LINE_COMMENT属性的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes.SINGLE_LINE_COMMENT属性的具体用法?Java TokenTypes.SINGLE_LINE_COMMENT怎么用?Java TokenTypes.SINGLE_LINE_COMMENT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.puppycrawl.tools.checkstyle.api.TokenTypes
的用法示例。
在下文中一共展示了TokenTypes.SINGLE_LINE_COMMENT属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCommentFirstLine
/**
* Gets the first line of comment in catch block. If comment is single-line -
* returns it fully, else if comment is multi-line - returns the first line.
* @param catchAst {@link TokenTypes#LITERAL_CATCH LITERAL_CATCH}
* @return the first line of comment in catch block, "" if no comment was found.
*/
private static String getCommentFirstLine(DetailAST catchAst) {
final DetailAST slistToken = catchAst.getLastChild();
final DetailAST firstElementInBlock = slistToken.getFirstChild();
String commentContent = "";
if (firstElementInBlock.getType() == TokenTypes.SINGLE_LINE_COMMENT) {
commentContent = firstElementInBlock.getFirstChild().getText();
}
else if (firstElementInBlock.getType() == TokenTypes.BLOCK_COMMENT_BEGIN) {
commentContent = firstElementInBlock.getFirstChild().getText();
final String[] lines = commentContent.split(System.getProperty("line.separator"));
for (String line : lines) {
if (!line.isEmpty()) {
commentContent = line;
break;
}
}
}
return commentContent;
}
示例2: isCorrectJavadocPosition
/**
* Checks Javadoc comment it's in right place.
* <p>From Javadoc util documentation:
* "Placement of comments - Documentation comments are recognized only when placed
* immediately before class, interface, constructor, method, field or annotation field
* declarations -- see the class example, method example, and field example.
* Documentation comments placed in the body of a method are ignored."</p>
* <p>If there are many documentation comments per declaration statement,
* only the last one will be recognized.</p>
*
* @param blockComment Block comment AST
* @return true if Javadoc is in right place
* @see <a href="https://docs.oracle.com/javase/8/docs/technotes/tools/unix/javadoc.html">
* Javadoc util documentation</a>
*/
private static boolean isCorrectJavadocPosition(DetailAST blockComment) {
// We must be sure that after this one there are no other documentation comments.
DetailAST sibling = blockComment.getNextSibling();
while (sibling != null) {
if (sibling.getType() == TokenTypes.BLOCK_COMMENT_BEGIN) {
if (isJavadocComment(getBlockCommentContent(sibling))) {
// Found another javadoc comment, so this one should be ignored.
break;
}
sibling = sibling.getNextSibling();
}
else if (sibling.getType() == TokenTypes.SINGLE_LINE_COMMENT) {
sibling = sibling.getNextSibling();
}
else {
// Annotation, declaration or modifier is here. Do not check further.
sibling = null;
}
}
return sibling == null
&& (BlockCommentPosition.isOnType(blockComment)
|| BlockCommentPosition.isOnMember(blockComment));
}
示例3: getDefaultTokens
@Override
public int[] getDefaultTokens() {
return new int[] {
TokenTypes.SINGLE_LINE_COMMENT,
TokenTypes.BLOCK_COMMENT_BEGIN,
};
}
示例4: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.SINGLE_LINE_COMMENT,
TokenTypes.BLOCK_COMMENT_BEGIN,
};
}
示例5: visitToken
@Override
public void visitToken(DetailAST commentAst) {
switch (commentAst.getType()) {
case TokenTypes.SINGLE_LINE_COMMENT:
case TokenTypes.BLOCK_COMMENT_BEGIN:
visitComment(commentAst);
break;
default:
final String exceptionMsg = "Unexpected token type: " + commentAst.getText();
throw new IllegalArgumentException(exceptionMsg);
}
}
示例6: 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;
}
示例7: getMessageKey
/**
* Get a message key depending on a comment type.
* @param comment the comment to process.
* @return a message key.
*/
private static String getMessageKey(DetailAST comment) {
final String msgKey;
if (comment.getType() == TokenTypes.SINGLE_LINE_COMMENT) {
msgKey = MSG_KEY_SINGLE;
}
else {
msgKey = MSG_KEY_BLOCK;
}
return msgKey;
}
示例8: isEmptyCatchBlock
/**
* Checks if catch block is empty or contains only comments.
* @param catchAst {@link TokenTypes#LITERAL_CATCH LITERAL_CATCH}
* @return true if catch block is empty.
*/
private static boolean isEmptyCatchBlock(DetailAST catchAst) {
boolean result = true;
final DetailAST slistToken = catchAst.findFirstToken(TokenTypes.SLIST);
DetailAST catchBlockStmt = slistToken.getFirstChild();
while (catchBlockStmt.getType() != TokenTypes.RCURLY) {
if (catchBlockStmt.getType() != TokenTypes.SINGLE_LINE_COMMENT
&& catchBlockStmt.getType() != TokenTypes.BLOCK_COMMENT_BEGIN) {
result = false;
break;
}
catchBlockStmt = catchBlockStmt.getNextSibling();
}
return result;
}
示例9: getNextSiblingSkipComments
/**
* Get next sibling node skipping any comment nodes.
* @param node current node
* @return next sibling
*/
private static DetailAST getNextSiblingSkipComments(DetailAST node) {
DetailAST result = node.getNextSibling();
while (result.getType() == TokenTypes.SINGLE_LINE_COMMENT
|| result.getType() == TokenTypes.BLOCK_COMMENT_BEGIN) {
result = result.getNextSibling();
}
return result;
}
示例10: getPrevSiblingSkipComments
/**
* Get previous sibling node skipping any comments.
* @param node current node
* @return previous sibling
*/
private static DetailAST getPrevSiblingSkipComments(DetailAST node) {
DetailAST result = node.getPreviousSibling();
while (result != null
&& (result.getType() == TokenTypes.SINGLE_LINE_COMMENT
|| result.getType() == TokenTypes.BLOCK_COMMENT_BEGIN)) {
result = result.getPreviousSibling();
}
return result;
}
示例11: createCommentAstFromToken
/**
* Create comment AST from token. Depending on token type
* SINGLE_LINE_COMMENT or BLOCK_COMMENT_BEGIN is created.
* @param token
* Token object.
* @return DetailAST of comment node.
*/
private static DetailAST createCommentAstFromToken(Token token) {
final DetailAST commentAst;
if (token.getType() == TokenTypes.SINGLE_LINE_COMMENT) {
commentAst = createSlCommentNode(token);
}
else {
commentAst = CommonUtils.createBlockCommentNode(token);
}
return commentAst;
}
示例12: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {TokenTypes.SINGLE_LINE_COMMENT};
}
示例13: 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;
}
示例14: isComment
/**
* Check if token is a comment.
* @param ast ast node
* @return true, if given ast is comment.
*/
private static boolean isComment(DetailAST ast) {
return ast.getType() == TokenTypes.SINGLE_LINE_COMMENT
|| ast.getType() == TokenTypes.BLOCK_COMMENT_BEGIN;
}