Java Code Examples for com.puppycrawl.tools.checkstyle.api.DetailAST#getParent()
The following examples show how to use
com.puppycrawl.tools.checkstyle.api.DetailAST#getParent() .
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: SpringJavadocCheck.java From spring-javaformat with Apache License 2.0 | 6 votes |
private void checkSinceTag(DetailAST ast, TextBlock javadoc) { if (!TOP_LEVEL_TYPES.contains(ast.getType())) { return; } String[] text = javadoc.getText(); DetailAST interfaceDef = getInterfaceDef(ast); boolean privateType = !isPublicOrProtected(ast) && (interfaceDef == null || !isPublicOrProtected(interfaceDef)); boolean innerType = ast.getParent() != null; boolean found = false; for (int i = 0; i < text.length; i++) { Matcher matcher = SINCE_TAG_PATTERN.matcher(text[i]); if (matcher.find()) { found = true; String description = matcher.group(1).trim(); if (this.publicOnlySinceTags && privateType) { log(javadoc.getStartLineNo() + i, text[i].length() - description.length(), "javadoc.publicSince"); } } } if (this.requireSinceTag && !innerType && !found && !(this.publicOnlySinceTags && privateType)) { log(javadoc.getStartLineNo(), 0, "javadoc.missingSince"); } }
Example 2
Source File: UnusedParameterCheck.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** @see com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck */ public boolean mustCheckReferenceCount(DetailAST aAST) { boolean result = false; final DetailAST parent = aAST.getParent(); if (parent != null) { if (parent.getType() == TokenTypes.PARAMETERS) { final DetailAST grandparent = parent.getParent(); if (grandparent != null) { result = hasBody(grandparent) && (!mIgnoreNonLocal || isLocal(grandparent)); } } else if (parent.getType() == TokenTypes.LITERAL_CATCH) { result = !mIgnoreCatch; } } return result; }
Example 3
Source File: UnusedParameterCheck.java From contribution with GNU Lesser General Public License v2.1 | 6 votes |
/** @see com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck */ public boolean mustCheckReferenceCount(DetailAST aAST) { boolean result = false; final DetailAST parent = aAST.getParent(); if (parent != null) { if (parent.getType() == TokenTypes.PARAMETERS) { final DetailAST grandparent = parent.getParent(); if (grandparent != null) { result = hasBody(grandparent) && (!mIgnoreNonLocal || isLocal(grandparent)); } } else if (parent.getType() == TokenTypes.LITERAL_CATCH) { result = !mIgnoreCatch; } } return result; }
Example 4
Source File: SpringMethodVisibilityCheck.java From spring-javaformat with Apache License 2.0 | 5 votes |
private DetailAST findParent(DetailAST ast, int classDef) { while (ast != null) { if (ast.getType() == classDef) { return ast; } ast = ast.getParent(); } return null; }
Example 5
Source File: SpringJavadocCheck.java From spring-javaformat with Apache License 2.0 | 5 votes |
private DetailAST findParent(DetailAST ast, int classDef) { while (ast != null) { if (ast.getType() == classDef) { return ast; } ast = ast.getParent(); } return null; }
Example 6
Source File: SpringNoThisCheck.java From spring-javaformat with Apache License 2.0 | 5 votes |
private DetailAST getFirstNonDotParent(DetailAST ast) { DetailAST result = (ast != null ? ast.getParent() : null); while (result != null && result.getType() == TokenTypes.DOT) { result = result.getParent(); } return result; }
Example 7
Source File: OneMethodPrivateFieldCheck.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
/** @see com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck */ public void applyTo(Set aNodes) { // apply the check to each private field final Set methods = new HashSet(); final Iterator it = aNodes.iterator(); while (it.hasNext()) { methods.clear(); final DetailAST nameAST = (DetailAST) it.next(); // find methods using the field final Iterator refIt = getReferences(nameAST); while (refIt.hasNext()) { final Reference ref = (Reference) refIt.next(); final SymTabAST refNode = ref.getTreeNode(); final DetailAST refDetail = refNode.getDetailNode(); // don't need to check a self-reference if (refDetail == nameAST) { continue; } DetailAST parent = refDetail.getParent(); while (parent != null) { final int type = parent.getType(); if ((type == TokenTypes.METHOD_DEF) || (type == TokenTypes.CTOR_DEF) || (type == TokenTypes.INSTANCE_INIT) || (type == TokenTypes.STATIC_INIT)) { methods.add(parent); break; } // initializer for inner class? else if (type == TokenTypes.CLASS_DEF) { break; } parent = parent.getParent(); } } if (methods.size() == 1) { log( nameAST.getLineNo(), nameAST.getColumnNo(), getErrorKey(), nameAST.getText()); } } }
Example 8
Source File: OneMethodPrivateFieldCheck.java From contribution with GNU Lesser General Public License v2.1 | 4 votes |
/** @see com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck */ public void applyTo(Set aNodes) { // apply the check to each private field final Set methods = new HashSet(); final Iterator it = aNodes.iterator(); while (it.hasNext()) { methods.clear(); final DetailAST nameAST = (DetailAST) it.next(); // find methods using the field final Iterator refIt = getReferences(nameAST); while (refIt.hasNext()) { final Reference ref = (Reference) refIt.next(); final SymTabAST refNode = ref.getTreeNode(); final DetailAST refDetail = refNode.getDetailNode(); // don't need to check a self-reference if (refDetail == nameAST) { continue; } DetailAST parent = refDetail.getParent(); while (parent != null) { final int type = parent.getType(); if ((type == TokenTypes.METHOD_DEF) || (type == TokenTypes.CTOR_DEF) || (type == TokenTypes.INSTANCE_INIT) || (type == TokenTypes.STATIC_INIT)) { methods.add(parent); break; } // initializer for inner class? else if (type == TokenTypes.CLASS_DEF) { break; } parent = parent.getParent(); } } if (methods.size() == 1) { log( nameAST.getLineNo(), nameAST.getColumnNo(), getErrorKey(), nameAST.getText()); } } }