001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2014 Oliver Burn 004// 005// This library is free software; you can redistribute it and/or 006// modify it under the terms of the GNU Lesser General Public 007// License as published by the Free Software Foundation; either 008// version 2.1 of the License, or (at your option) any later version. 009// 010// This library is distributed in the hope that it will be useful, 011// but WITHOUT ANY WARRANTY; without even the implied warranty of 012// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013// Lesser General Public License for more details. 014// 015// You should have received a copy of the GNU Lesser General Public 016// License along with this library; if not, write to the Free Software 017// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018//////////////////////////////////////////////////////////////////////////////// 019package com.puppycrawl.tools.checkstyle.checks.regexp; 020 021import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck; 022import java.io.File; 023import java.util.List; 024 025/** 026 * Implementation of a check that looks for a single line in any file type. 027 * @author Oliver Burn 028 */ 029public class RegexpSinglelineCheck extends AbstractFileSetCheck 030{ 031 /** The detection options to use. */ 032 private DetectorOptions mOptions = new DetectorOptions(0, this); 033 /** The detector to use. */ 034 private SinglelineDetector mDetector; 035 036 @Override 037 public void beginProcessing(String aCharset) 038 { 039 super.beginProcessing(aCharset); 040 mDetector = new SinglelineDetector(mOptions); 041 } 042 043 @Override 044 protected void processFiltered(File aFile, List<String> aLines) 045 { 046 mDetector.processLines(aLines); 047 } 048 049 /** 050 * Set the format of the regular expression to match. 051 * @param aFormat the format of the regular expression to match. 052 */ 053 public void setFormat(String aFormat) 054 { 055 mOptions.setFormat(aFormat); 056 } 057 058 /** 059 * Set the message to report for a match. 060 * @param aMessage the message to report for a match. 061 */ 062 public void setMessage(String aMessage) 063 { 064 mOptions.setMessage(aMessage); 065 } 066 067 /** 068 * Set the minimum number of matches required per file. 069 * @param aMinimum the minimum number of matches required per file. 070 */ 071 public void setMinimum(int aMinimum) 072 { 073 mOptions.setMinimum(aMinimum); 074 } 075 076 /** 077 * Set the maximum number of matches required per file. 078 * @param aMaximum the maximum number of matches required per file. 079 */ 080 public void setMaximum(int aMaximum) 081 { 082 mOptions.setMaximum(aMaximum); 083 } 084 085 /** 086 * Set whether to ignore case when matching. 087 * @param aIgnore whether to ignore case when matching. 088 */ 089 public void setIgnoreCase(boolean aIgnore) 090 { 091 mOptions.setIgnoreCase(aIgnore); 092 } 093}