| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| InnerTypeLastCheck |
|
| 3.3333333333333335;3.333 |
| 1 | //////////////////////////////////////////////////////////////////////////////// | |
| 2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
| 3 | // Copyright (C) 2001-2014 Oliver Burn | |
| 4 | // | |
| 5 | // This library is free software; you can redistribute it and/or | |
| 6 | // modify it under the terms of the GNU Lesser General Public | |
| 7 | // License as published by the Free Software Foundation; either | |
| 8 | // version 2.1 of the License, or (at your option) any later version. | |
| 9 | // | |
| 10 | // This library is distributed in the hope that it will be useful, | |
| 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | // Lesser General Public License for more details. | |
| 14 | // | |
| 15 | // You should have received a copy of the GNU Lesser General Public | |
| 16 | // License along with this library; if not, write to the Free Software | |
| 17 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 18 | //////////////////////////////////////////////////////////////////////////////// | |
| 19 | package com.puppycrawl.tools.checkstyle.checks.design; | |
| 20 | ||
| 21 | import com.puppycrawl.tools.checkstyle.api.Check; | |
| 22 | import com.puppycrawl.tools.checkstyle.api.DetailAST; | |
| 23 | import com.puppycrawl.tools.checkstyle.api.TokenTypes; | |
| 24 | ||
| 25 | /** | |
| 26 | * <p> | |
| 27 | * Check nested (internal) classes/interfaces are declared at the bottom of the | |
| 28 | * class after all method and field declarations. | |
| 29 | * </p> | |
| 30 | * | |
| 31 | * @author <a href="mailto:ryly@mail.ru">Ruslan Dyachenko</a> | |
| 32 | */ | |
| 33 | 1 | public class InnerTypeLastCheck extends Check |
| 34 | { | |
| 35 | @Override | |
| 36 | public int[] getDefaultTokens() | |
| 37 | { | |
| 38 | 1 | return new int[] {TokenTypes.CLASS_DEF, TokenTypes.INTERFACE_DEF}; |
| 39 | } | |
| 40 | ||
| 41 | /** Meet a root class. */ | |
| 42 | 1 | private boolean mRootClass = true; |
| 43 | ||
| 44 | @Override | |
| 45 | public void visitToken(DetailAST aAST) | |
| 46 | { | |
| 47 | /** First root class */ | |
| 48 | 10 | if (mRootClass) { |
| 49 | 3 | mRootClass = false; |
| 50 | } | |
| 51 | else { | |
| 52 | 7 | DetailAST nextSibling = aAST.getNextSibling(); |
| 53 | while (null != nextSibling | |
| 54 | 32 | && ((nextSibling.getType() != TokenTypes.CLASS_DEF) |
| 55 | || (nextSibling.getType() != TokenTypes.INTERFACE_DEF))) | |
| 56 | { | |
| 57 | 25 | if (nextSibling.getType() == TokenTypes.VARIABLE_DEF |
| 58 | || nextSibling.getType() == TokenTypes.METHOD_DEF) | |
| 59 | { | |
| 60 | 11 | log(nextSibling.getLineNo(), nextSibling.getColumnNo(), |
| 61 | "arrangement.members.before.inner"); | |
| 62 | } | |
| 63 | 25 | nextSibling = nextSibling.getNextSibling(); |
| 64 | } | |
| 65 | } | |
| 66 | 10 | } |
| 67 | ||
| 68 | @Override | |
| 69 | public void leaveToken(DetailAST aAST) | |
| 70 | { | |
| 71 | /** Is this a root class */ | |
| 72 | 10 | if (null == aAST.getParent()) { |
| 73 | 3 | mRootClass = true; |
| 74 | } | |
| 75 | 10 | } |
| 76 | } |