Java Code Examples for com.puppycrawl.tools.checkstyle.api.TokenTypes#INSTANCE_INIT
The following examples show how to use
com.puppycrawl.tools.checkstyle.api.TokenTypes#INSTANCE_INIT .
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: 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 2
Source File: Resolver.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * processes a <code>BlockDef</code> and resolves references in it * * @param block the <code>BlockDef</code> to process */ protected void handleBlock(BlockDef block) { SymTabAST node = block.getTreeNode(); switch (node.getType()) { case TokenTypes.LITERAL_FOR : handleFor(block); break; case TokenTypes.LITERAL_IF : handleIf(block); break; case TokenTypes.LITERAL_WHILE : handleWhileAndSynchronized(block); break; case TokenTypes.LITERAL_DO : handleDoWhile(block); break; case TokenTypes.LITERAL_TRY : case TokenTypes.LITERAL_FINALLY : SymTabAST slist = node.findFirstToken(TokenTypes.SLIST); handleSList(slist, block); break; case TokenTypes.LITERAL_CATCH : handleCatch(block); break; case TokenTypes.LITERAL_SWITCH : handleSwitch(block); break; case TokenTypes.SLIST : handleSList(node, block); break; case TokenTypes.EXPR : resolveExpression(node, block, null, true); break; case TokenTypes.INSTANCE_INIT : case TokenTypes.STATIC_INIT : handleSList((SymTabAST) node.getFirstChild(), block); break; case TokenTypes.LITERAL_SYNCHRONIZED : handleWhileAndSynchronized(block); break; case TokenTypes.LITERAL_ASSERT : handleAssert(block); break; default : if (mInitialized) { final Log log = mLogFactory.getInstance(this.getClass()); log.error( "Unhandled block " + block + " of type " + node.getType()); } } }
Example 3
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()); } } }
Example 4
Source File: Resolver.java From contribution with GNU Lesser General Public License v2.1 | 4 votes |
/** * processes a <code>BlockDef</code> and resolves references in it * * @param block the <code>BlockDef</code> to process */ protected void handleBlock(BlockDef block) { SymTabAST node = block.getTreeNode(); switch (node.getType()) { case TokenTypes.LITERAL_FOR : handleFor(block); break; case TokenTypes.LITERAL_IF : handleIf(block); break; case TokenTypes.LITERAL_WHILE : handleWhileAndSynchronized(block); break; case TokenTypes.LITERAL_DO : handleDoWhile(block); break; case TokenTypes.LITERAL_TRY : case TokenTypes.LITERAL_FINALLY : SymTabAST slist = node.findFirstToken(TokenTypes.SLIST); handleSList(slist, block); break; case TokenTypes.LITERAL_CATCH : handleCatch(block); break; case TokenTypes.LITERAL_SWITCH : handleSwitch(block); break; case TokenTypes.SLIST : handleSList(node, block); break; case TokenTypes.EXPR : resolveExpression(node, block, null, true); break; case TokenTypes.INSTANCE_INIT : case TokenTypes.STATIC_INIT : handleSList((SymTabAST) node.getFirstChild(), block); break; case TokenTypes.LITERAL_SYNCHRONIZED : handleWhileAndSynchronized(block); break; case TokenTypes.LITERAL_ASSERT : handleAssert(block); break; default : if (mInitialized) { final Log log = mLogFactory.getInstance(this.getClass()); log.error( "Unhandled block " + block + " of type " + node.getType()); } } }