本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.DetailAST.getChildCount方法的典型用法代码示例。如果您正苦于以下问题:Java DetailAST.getChildCount方法的具体用法?Java DetailAST.getChildCount怎么用?Java DetailAST.getChildCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.puppycrawl.tools.checkstyle.api.DetailAST
的用法示例。
在下文中一共展示了DetailAST.getChildCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkCompactStyle
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Checks for compact style type violations.
*
* @param annotation the annotation token
*/
private void checkCompactStyle(final DetailAST annotation) {
final int valuePairCount =
annotation.getChildCount(
TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR);
final DetailAST valuePair =
annotation.findFirstToken(
TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR);
if (valuePairCount == 1
&& ANNOTATION_ELEMENT_SINGLE_NAME.equals(
valuePair.getFirstChild().getText())) {
log(annotation.getLineNo(), MSG_KEY_ANNOTATION_INCORRECT_STYLE,
ElementStyle.COMPACT);
}
}
示例2: isEqualsMethod
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Tests whether a method definition AST defines an equals covariant.
* @param ast the method definition AST to test.
* Precondition: ast is a TokenTypes.METHOD_DEF node.
* @return true if ast defines an equals covariant.
*/
public static boolean isEqualsMethod(DetailAST ast) {
boolean equalsMethod = false;
if (ast.getType() == TokenTypes.METHOD_DEF) {
final DetailAST modifiers = ast.findFirstToken(TokenTypes.MODIFIERS);
final boolean staticOrAbstract =
modifiers.findFirstToken(TokenTypes.LITERAL_STATIC) != null
|| modifiers.findFirstToken(TokenTypes.ABSTRACT) != null;
if (!staticOrAbstract) {
final DetailAST nameNode = ast.findFirstToken(TokenTypes.IDENT);
final String name = nameNode.getText();
if ("equals".equals(name)) {
// one parameter?
final DetailAST paramsNode = ast.findFirstToken(TokenTypes.PARAMETERS);
equalsMethod = paramsNode.getChildCount() == 1;
}
}
}
return equalsMethod;
}
示例3: isOverridingMethod
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Determines whether an AST is a method definition for this check,
* with 0 parameters.
* @param ast the method definition AST.
* @return true if the method of ast is a method for this check.
*/
private boolean isOverridingMethod(DetailAST ast) {
boolean overridingMethod = false;
if (ast.getType() == TokenTypes.METHOD_DEF
&& !ScopeUtils.isInInterfaceOrAnnotationBlock(ast)) {
final DetailAST nameAST = ast.findFirstToken(TokenTypes.IDENT);
final String name = nameAST.getText();
final DetailAST modifiersAST = ast.findFirstToken(TokenTypes.MODIFIERS);
if (getMethodName().equals(name)
&& modifiersAST.findFirstToken(TokenTypes.LITERAL_NATIVE) == null) {
final DetailAST params = ast.findFirstToken(TokenTypes.PARAMETERS);
overridingMethod = params.getChildCount() == 0;
}
}
return overridingMethod;
}
示例4: checkIndentation
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void checkIndentation() {
final DetailAST modifiersNode = getMainAst().findFirstToken(TokenTypes.MODIFIERS);
if (modifiersNode.getChildCount() == 0) {
checkType();
}
else {
checkModifiers();
}
final DetailAST firstNode = getMainAst();
final DetailAST lastNode = getVarDefStatementSemicolon(firstNode);
if (lastNode != null && !isArrayDeclaration(firstNode)) {
checkWrappingIndentation(firstNode, lastNode);
}
}
示例5: visitToken
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
if (ast.getChildCount() == 0) {
//empty for iterator. test pad after semi.
final DetailAST semi = ast.getPreviousSibling();
final String line = getLines()[semi.getLineNo() - 1];
final int after = semi.getColumnNo() + 1;
//don't check if at end of line
if (after < line.length()) {
if (option == PadOption.NOSPACE
&& Character.isWhitespace(line.charAt(after))) {
log(semi.getLineNo(), after, MSG_WS_FOLLOWED, SEMICOLON);
}
else if (option == PadOption.SPACE
&& !Character.isWhitespace(line.charAt(after))) {
log(semi.getLineNo(), after, MSG_WS_NOT_FOLLOWED, SEMICOLON);
}
}
}
}
示例6: visitToken
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
final DetailAST params = ast.findFirstToken(TokenTypes.PARAMETERS);
final int count = params.getChildCount(TokenTypes.PARAMETER_DEF);
if (count > max && !shouldIgnoreNumberOfParameters(ast)) {
final DetailAST name = ast.findFirstToken(TokenTypes.IDENT);
log(name.getLineNo(), name.getColumnNo(), MSG_KEY, max, count);
}
}
示例7: checkExpandedStyle
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Checks for expanded style type violations.
*
* @param annotation the annotation token
*/
private void checkExpandedStyle(final DetailAST annotation) {
final int valuePairCount =
annotation.getChildCount(TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR);
if (valuePairCount == 0
&& annotation.branchContains(TokenTypes.EXPR)) {
log(annotation.getLineNo(), MSG_KEY_ANNOTATION_INCORRECT_STYLE,
ElementStyle.EXPANDED);
}
}
示例8: checkCompactNoArrayStyle
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Checks for compact no array style type violations.
*
* @param annotation the annotation token
*/
private void checkCompactNoArrayStyle(final DetailAST annotation) {
final DetailAST arrayInit =
annotation.findFirstToken(TokenTypes.ANNOTATION_ARRAY_INIT);
final int valuePairCount =
annotation.getChildCount(TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR);
//in compact style with one value
if (arrayInit != null
&& arrayInit.getChildCount(TokenTypes.EXPR) == 1) {
log(annotation.getLineNo(), MSG_KEY_ANNOTATION_INCORRECT_STYLE,
ElementStyle.COMPACT_NO_ARRAY);
}
//in expanded style with one value and the correct element name
else if (valuePairCount == 1) {
final DetailAST valuePair =
annotation.findFirstToken(TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR);
final DetailAST nestedArrayInit =
valuePair.findFirstToken(TokenTypes.ANNOTATION_ARRAY_INIT);
if (nestedArrayInit != null
&& ANNOTATION_ELEMENT_SINGLE_NAME.equals(
valuePair.getFirstChild().getText())
&& nestedArrayInit.getChildCount(TokenTypes.EXPR) == 1) {
log(annotation.getLineNo(), MSG_KEY_ANNOTATION_INCORRECT_STYLE,
ElementStyle.COMPACT_NO_ARRAY);
}
}
}
示例9: visitToken
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST arrayInit) {
final DetailAST rcurly = arrayInit.findFirstToken(TokenTypes.RCURLY);
final DetailAST previousSibling = rcurly.getPreviousSibling();
if (arrayInit.getLineNo() != rcurly.getLineNo()
&& arrayInit.getChildCount() != 1
&& rcurly.getLineNo() != previousSibling.getLineNo()
&& arrayInit.getLineNo() != previousSibling.getLineNo()
&& previousSibling.getType() != TokenTypes.COMMA) {
log(rcurly.getLineNo(), MSG_KEY);
}
}
示例10: isInHashCodeMethod
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Determines whether or not the given AST is in a valid hash code method.
* A valid hash code method is considered to be a method of the signature
* {@code public int hashCode()}.
*
* @param ast the AST from which to search for an enclosing hash code
* method definition
*
* @return {@code true} if {@code ast} is in the scope of a valid hash code method.
*/
private static boolean isInHashCodeMethod(DetailAST ast) {
boolean inHashCodeMethod = false;
// if not in a code block, can't be in hashCode()
if (ScopeUtils.isInCodeBlock(ast)) {
// find the method definition AST
DetailAST methodDefAST = ast.getParent();
while (methodDefAST != null
&& methodDefAST.getType() != TokenTypes.METHOD_DEF) {
methodDefAST = methodDefAST.getParent();
}
if (methodDefAST != null) {
// Check for 'hashCode' name.
final DetailAST identAST = methodDefAST.findFirstToken(TokenTypes.IDENT);
if ("hashCode".equals(identAST.getText())) {
// Check for no arguments.
final DetailAST paramAST = methodDefAST.findFirstToken(TokenTypes.PARAMETERS);
// we are in a 'public int hashCode()' method! The compiler will ensure
// the method returns an 'int' and is public.
inHashCodeMethod = paramAST.getChildCount() == 0;
}
}
}
return inHashCodeMethod;
}
示例11: isSimilarSignature
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Whether the method definition has the same name and number of parameters.
* @param ident the specified method call IDENT ast.
* @param ast the ast of a method definition to compare with.
* @return true if a method definition has the same name and number of parameters
* as the method call.
*/
private static boolean isSimilarSignature(DetailAST ident, DetailAST ast) {
boolean result = false;
final DetailAST elistToken = ident.getParent().findFirstToken(TokenTypes.ELIST);
if (elistToken != null && ident.getText().equals(ast.getText())) {
final int paramsNumber =
ast.getParent().findFirstToken(TokenTypes.PARAMETERS).getChildCount();
final int argsNumber = elistToken.getChildCount();
result = paramsNumber == argsNumber;
}
return result;
}
示例12: visitToken
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
final DetailAST leftCurly = findLeftCurly(ast);
if (leftCurly != null) {
if (option == BlockOption.STATEMENT) {
final boolean emptyBlock;
if (leftCurly.getType() == TokenTypes.LCURLY) {
emptyBlock = leftCurly.getNextSibling().getType() != TokenTypes.CASE_GROUP;
}
else {
emptyBlock = leftCurly.getChildCount() <= 1;
}
if (emptyBlock) {
log(leftCurly.getLineNo(),
leftCurly.getColumnNo(),
MSG_KEY_BLOCK_NO_STATEMENT,
ast.getText());
}
}
else if (!hasText(leftCurly)) {
log(leftCurly.getLineNo(),
leftCurly.getColumnNo(),
MSG_KEY_BLOCK_EMPTY,
ast.getText());
}
}
}
示例13: visitLiteralThrows
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Checks number of throws statements.
* @param ast throws for check.
*/
private void visitLiteralThrows(DetailAST ast) {
if ((!ignorePrivateMethods || !isInPrivateMethod(ast))
&& !isOverriding(ast)) {
// Account for all the commas!
final int count = (ast.getChildCount() + 1) / 2;
if (count > max) {
log(ast.getLineNo(), ast.getColumnNo(), MSG_KEY,
count, max);
}
}
}
示例14: isInEmptyForInitializerOrCondition
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Checks that semicolon is in empty for initializer or condition.
* @param semicolonAst DetailAST of semicolon.
* @return true if semicolon is in empty for initializer or condition.
*/
private static boolean isInEmptyForInitializerOrCondition(DetailAST semicolonAst) {
boolean result = false;
if (semicolonAst.getType() == TokenTypes.SEMI) {
final DetailAST sibling = semicolonAst.getPreviousSibling();
if (sibling != null
&& (sibling.getType() == TokenTypes.FOR_INIT
|| sibling.getType() == TokenTypes.FOR_CONDITION)
&& sibling.getChildCount() == 0) {
result = true;
}
}
return result;
}
示例15: isSetterMethod
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Returns whether an AST represents a setter method.
* @param ast the AST to check with
* @return whether the AST represents a setter method
*/
public static boolean isSetterMethod(final DetailAST ast) {
boolean setterMethod = false;
// Check have a method with exactly 7 children which are all that
// is allowed in a proper setter method which does not throw any
// exceptions.
if (ast.getType() == TokenTypes.METHOD_DEF
&& ast.getChildCount() == SETTER_GETTER_MAX_CHILDREN) {
final DetailAST type = ast.findFirstToken(TokenTypes.TYPE);
final String name = type.getNextSibling().getText();
final boolean matchesSetterFormat = SETTER_PATTERN.matcher(name).matches();
final boolean voidReturnType = type.findFirstToken(TokenTypes.LITERAL_VOID) != null;
final DetailAST params = ast.findFirstToken(TokenTypes.PARAMETERS);
final boolean singleParam = params.getChildCount(TokenTypes.PARAMETER_DEF) == 1;
if (matchesSetterFormat && voidReturnType && singleParam) {
// Now verify that the body consists of:
// SLIST -> EXPR -> ASSIGN
// SEMI
// RCURLY
final DetailAST slist = ast.findFirstToken(TokenTypes.SLIST);
if (slist != null && slist.getChildCount() == SETTER_BODY_SIZE) {
final DetailAST expr = slist.getFirstChild();
setterMethod = expr.getFirstChild().getType() == TokenTypes.ASSIGN;
}
}
}
return setterMethod;
}