Coverage Report - com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractParenPadCheck
100%
18/18
88%
23/26
5.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.whitespace;
 20  
 
 21  
 import com.puppycrawl.tools.checkstyle.api.DetailAST;
 22  
 import com.puppycrawl.tools.checkstyle.api.Utils;
 23  
 import com.puppycrawl.tools.checkstyle.checks.AbstractOptionCheck;
 24  
 
 25  
 /**
 26  
  * <p>Abstract class for checking the padding of parentheses. That is whether a
 27  
  * space is required after a left parenthesis and before a right parenthesis,
 28  
  * or such spaces are forbidden.
 29  
  * </p>
 30  
  * @author Oliver Burn
 31  
  * @version 1.0
 32  
  */
 33  
 abstract class AbstractParenPadCheck
 34  
     extends AbstractOptionCheck<PadOption>
 35  
 {
 36  
     /**
 37  
      * Sets the paren pad otion to nospace.
 38  
      */
 39  
     AbstractParenPadCheck()
 40  
     {
 41  8
         super(PadOption.NOSPACE, PadOption.class);
 42  8
     }
 43  
 
 44  
     /**
 45  
      * Process a token representing a left parentheses.
 46  
      * @param aAST the token representing a left parentheses
 47  
      */
 48  
     protected void processLeft(DetailAST aAST)
 49  
     {
 50  134
         final String line = getLines()[aAST.getLineNo() - 1];
 51  134
         final int after = aAST.getColumnNo() + 1;
 52  134
         if (after < line.length()) {
 53  134
             if ((PadOption.NOSPACE == getAbstractOption())
 54  
                 && (Character.isWhitespace(line.charAt(after))))
 55  
             {
 56  6
                 log(aAST.getLineNo(), after, "ws.followed", "(");
 57  
             }
 58  128
             else if ((PadOption.SPACE == getAbstractOption())
 59  
                      && !Character.isWhitespace(line.charAt(after))
 60  
                      && (line.charAt(after) != ')'))
 61  
             {
 62  24
                 log(aAST.getLineNo(), after, "ws.notFollowed", "(");
 63  
             }
 64  
         }
 65  134
     }
 66  
 
 67  
     /**
 68  
      * Process a token representing a right parentheses.
 69  
      * @param aAST the token representing a right parentheses
 70  
      */
 71  
     protected void processRight(DetailAST aAST)
 72  
     {
 73  128
         final String line = getLines()[aAST.getLineNo() - 1];
 74  128
         final int before = aAST.getColumnNo() - 1;
 75  128
         if (before >= 0) {
 76  128
             if ((PadOption.NOSPACE == getAbstractOption())
 77  
                 && Character.isWhitespace(line.charAt(before))
 78  
                 && !Utils.whitespaceBefore(before, line))
 79  
             {
 80  10
                 log(aAST.getLineNo(), before, "ws.preceded", ")");
 81  
             }
 82  118
             else if ((PadOption.SPACE == getAbstractOption())
 83  
                 && !Character.isWhitespace(line.charAt(before))
 84  
                 && (line.charAt(before) != '('))
 85  
             {
 86  18
                 log(aAST.getLineNo(), aAST.getColumnNo(),
 87  
                     "ws.notPreceded", ")");
 88  
             }
 89  
         }
 90  128
     }
 91  
 }