Java Code Examples for com.puppycrawl.tools.checkstyle.api.DetailAST#getNextSibling()
The following examples show how to use
com.puppycrawl.tools.checkstyle.api.DetailAST#getNextSibling() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OverrideAnnotationOnTheSameLineCheck.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public void visitToken(DetailAST ast) { DetailAST node = ast.findFirstToken(MODIFIERS); if (node == null) node = ast.findFirstToken(ANNOTATIONS); if (node == null) return; for (node = node.getFirstChild(); node != null; node = node.getNextSibling()) { if (node.getType() == TokenTypes.ANNOTATION && Override.class.getSimpleName().equals(annotationName(node)) && node.getLineNo() != nextNode(node).getLineNo()) log(node.getLineNo(), DIFF_LINE_ERR_MSG, annotationName(node)); } }
Example 2
Source File: CSUtility.java From kieker with Apache License 2.0 | 6 votes |
/** * This method extracts all method definitions from the given class (or interface). * * @param ast * The class (or interface). * * @return A collection of available methods. */ public static Collection<DetailAST> getMethodsFromClass(final DetailAST ast) { final Collection<DetailAST> result = new ArrayList<DetailAST>(); final DetailAST objBlock = ast.findFirstToken(TokenTypes.OBJBLOCK); DetailAST child = objBlock.getFirstChild(); while (child != null) { if (child.getType() == TokenTypes.METHOD_DEF) { result.add(child); } child = child.getNextSibling(); } return result; }
Example 3
Source File: AnalysisComponentConstructorCheck.java From kieker with Apache License 2.0 | 6 votes |
/** * This method finds out whether the given class is an analysis component or * not (by searching for annotations with the names "Plugin" or * "Repository"). * * @param clazz * The class in question. * * @return true if and only if the class is an analysis component. */ private static boolean isAnalysisComponent(final DetailAST clazz) { // Get the list of modifiers as the annotations are within those final DetailAST modifiers = clazz.findFirstToken(TokenTypes.MODIFIERS); DetailAST modifier = modifiers.getFirstChild(); // Run through the modifiers while (modifier != null) { // If we find an annotation we check the name if ((modifier.getType() == TokenTypes.ANNOTATION) && (modifier.findFirstToken(TokenTypes.IDENT) != null)) { final String annotationName = modifier.findFirstToken(TokenTypes.IDENT).getText(); if (annotationName.equals(PLUGIN_ANNOTATION_NAME) || annotationName.equals(REPOSITORY_ANNOTATION_NAME)) { // We found an annotation with the correct name return true; } } modifier = modifier.getNextSibling(); } // Seems like there is no such annotation return false; }
Example 4
Source File: AnalysisComponentConstructorCheck.java From kieker with Apache License 2.0 | 6 votes |
@Override public void visitToken(final DetailAST ast) { // Check whether we are interested in the class (whether it is an // analysis component or not) if (!(this.ignoreAbstractClasses && CSUtility.isAbstract(ast)) && AnalysisComponentConstructorCheck.isAnalysisComponent(ast)) { // Now check the constructors DetailAST child = ast.findFirstToken(TokenTypes.OBJBLOCK).findFirstToken(TokenTypes.CTOR_DEF); while (child != null) { if ((child.getType() == TokenTypes.CTOR_DEF) && AnalysisComponentConstructorCheck.isValidConstructor(child)) { // We found a valid constructor return; } child = child.getNextSibling(); } // Seems like there is no valid constructor this.log(ast.getLineNo(), "invalid analysis component constructor"); } }
Example 5
Source File: MonitoringRecordFactoryConventionCheck.java From kieker with Apache License 2.0 | 6 votes |
/** * This method finds out whether the given class implements the record factory * or not. * * @param clazz * The class in question. * * @return true if and only if the class implements the record factory. */ private static boolean implementsFactory(final DetailAST clazz) { final DetailAST implementsClause = clazz.findFirstToken(TokenTypes.IMPLEMENTS_CLAUSE); if (implementsClause != null) { DetailAST clause = implementsClause.getFirstChild(); // Run through the whole implements clause while (clause != null) { // It has to be a combination of two names if ((clause.getType() == TokenTypes.DOT) && (clause.getChildCount() == 2)) { final String fstClauseIdent = clause.getFirstChild().getText(); final String sndClauseIdent = clause.getLastChild().getText(); return (FACTORY_FST_NAME.equals(fstClauseIdent)) && (FACTORY_SND_NAME.equals(sndClauseIdent)); } clause = clause.getNextSibling(); } } return false; }
Example 6
Source File: MonitoringRecordFactoryConventionCheck.java From kieker with Apache License 2.0 | 6 votes |
/** * This method checks the constructors of the record. * * @param ast * The record class. */ private void checkConstructors(final DetailAST ast) { DetailAST child = ast.findFirstToken(TokenTypes.OBJBLOCK).findFirstToken(TokenTypes.CTOR_DEF); while (child != null) { if ((child.getType() == TokenTypes.CTOR_DEF) && MonitoringRecordFactoryConventionCheck.isValidConstructor(child)) { // We found a valid constructor return; } child = child.getNextSibling(); } // Seems like there is no valid constructor this.log(ast.getLineNo(), "invalid factory constructor"); }
Example 7
Source File: MonitoringRecordFactoryConventionCheck.java From kieker with Apache License 2.0 | 6 votes |
/** * This method checks the fields of the record. * * @param ast * The record class. */ private void checkFields(final DetailAST ast) { DetailAST child = ast.findFirstToken(TokenTypes.OBJBLOCK).findFirstToken(TokenTypes.VARIABLE_DEF); while (child != null) { if ((child.getType() == TokenTypes.VARIABLE_DEF) && MonitoringRecordFactoryConventionCheck.isValidTypeField(child)) { // We found a valid field return; } child = child.getNextSibling(); } // Seems like there is no valid field this.log(ast.getLineNo(), "invalid factory field"); }
Example 8
Source File: PluralEnumNames.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
private boolean hasPublicStaticField(DetailAST ast) { DetailAST classBody = ast.findFirstToken(TokenTypes.OBJBLOCK); DetailAST maybeVariableDefinition = classBody.getFirstChild(); String className = ast.findFirstToken(TokenTypes.IDENT).getText(); // Filter out util classes if (className.endsWith("Utils")) { return false; } while (maybeVariableDefinition != null) { if (maybeVariableDefinition.getType() == TokenTypes.VARIABLE_DEF) { DetailAST modifiers = maybeVariableDefinition.findFirstToken(TokenTypes.MODIFIERS); if (modifiers != null && isPublic(modifiers) && isStatic(modifiers)) { return true; } } maybeVariableDefinition = maybeVariableDefinition.getNextSibling(); } return false; }
Example 9
Source File: SpringMethodOrderCheck.java From spring-javaformat with Apache License 2.0 | 6 votes |
@Override public void visitToken(DetailAST ast) { DetailAST block = ast.findFirstToken(TokenTypes.OBJBLOCK); DetailAST candidate = block.getFirstChild(); List<DetailAST> methods = new ArrayList<>(); while (candidate != null) { candidate = candidate.getNextSibling(); if (candidate != null && candidate.getType() == TokenTypes.METHOD_DEF) { DetailAST ident = candidate.findFirstToken(TokenTypes.IDENT); DetailAST parameters = candidate.findFirstToken(TokenTypes.PARAMETERS); if (isOrderedMethod(ident, parameters)) { methods.add(ident); } } } checkOrder(methods); }
Example 10
Source File: SpringMethodVisibilityCheck.java From spring-javaformat with Apache License 2.0 | 5 votes |
private boolean hasOverrideAnnotation(DetailAST modifiers) { DetailAST candidate = modifiers.getFirstChild(); while (candidate != null) { if (candidate.getType() == TokenTypes.ANNOTATION) { DetailAST dot = candidate.findFirstToken(TokenTypes.DOT); String name = (dot != null ? dot : candidate).findFirstToken(TokenTypes.IDENT).getText(); if ("Override".equals(name)) { return true; } } candidate = candidate.getNextSibling(); } return false; }
Example 11
Source File: MonitoringRecordFactoryConventionCheck.java From kieker with Apache License 2.0 | 5 votes |
/** * This method checks whether the given trees are more or less equal. This is * necessary as the available methods do not work as expected for this special * case. * * @param actual * The actual tree. * @param expected * The expected tree. * * @return true if and only if the trees are (more or less) equal. */ private static boolean treeCompare(final DetailAST actual, final DetailAST expected) { if ((actual != null) && (expected != null) && (actual.getType() == expected.getType())) { // If they are identifiers, we check the texts if ((actual.getType() == TokenTypes.IDENT) && (!actual.getText().equals(expected.getText()))) { return false; } // Everything fine so far. Check the equality of the children DetailAST actChild = actual.getFirstChild(); DetailAST expChild = expected.getFirstChild(); while (actChild != null) { // The treeCompare method checks whether one of the children is null (we // recognize therefore if the parents have different number of children). if (!MonitoringRecordFactoryConventionCheck.treeCompare(actChild, expChild)) { return false; } actChild = actChild.getNextSibling(); expChild = expChild.getNextSibling(); } // Everything seems to be fine - just make sure that expChild is null as well or // otherwise the parents had a different number of children return expChild == null; } return false; }
Example 12
Source File: SpringTernaryCheck.java From spring-javaformat with Apache License 2.0 | 5 votes |
private boolean isSimpleEqualsExpression(DetailAST expression) { if (expression == null || expression.getType() != TokenTypes.EQUAL) { return false; } DetailAST child = expression.getFirstChild(); while (child != null) { if (child.getChildCount() > 0) { return false; } child = child.getNextSibling(); } return true; }
Example 13
Source File: SpringTernaryCheck.java From spring-javaformat with Apache License 2.0 | 5 votes |
private void visitQuestion(DetailAST ast) { DetailAST expression = ast.getFirstChild(); if (!hasType(expression, TokenTypes.LPAREN)) { if (expression != null && requiresParens(expression)) { log(ast.getLineNo(), ast.getColumnNo(), "ternary.missingParen"); } } while (hasType(expression, TokenTypes.LPAREN)) { expression = expression.getNextSibling(); } if (isSimpleEqualsExpression(expression) && !isEqualsTestAllowed(ast)) { log(ast.getLineNo(), ast.getColumnNo(), "ternary.equalOperator"); } }
Example 14
Source File: SpringCatchCheck.java From spring-javaformat with Apache License 2.0 | 5 votes |
private void visitCatch(DetailAST ast) { DetailAST child = ast.getFirstChild(); while (child != null && child.getType() != TokenTypes.PARAMETER_DEF) { child = child.getNextSibling(); } if (child != null) { visitParameterDef(child); } }
Example 15
Source File: SpringLambdaCheck.java From spring-javaformat with Apache License 2.0 | 5 votes |
private int countDescendantsOfType(DetailAST ast, int... types) { int count = 0; for (int type : types) { count += ast.getChildCount(type); } DetailAST child = ast.getFirstChild(); while (child != null) { count += countDescendantsOfType(child, types); child = child.getNextSibling(); } return count; }
Example 16
Source File: NodeIterator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 2 votes |
/** * Get the next sibling of a DetailAST. * @param aAST the DetailAST. * @return the next sibling of aAST. */ protected DetailAST getNextSibling(DetailAST aAST) { return (DetailAST) aAST.getNextSibling(); }
Example 17
Source File: NodeIterator.java From contribution with GNU Lesser General Public License v2.1 | 2 votes |
/** * Get the next sibling of a DetailAST. * @param aAST the DetailAST. * @return the next sibling of aAST. */ protected DetailAST getNextSibling(DetailAST aAST) { return (DetailAST) aAST.getNextSibling(); }