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 java.util.regex.Pattern; 022 023import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck; 024import com.puppycrawl.tools.checkstyle.api.FileText; 025import java.io.File; 026import java.util.List; 027 028/** 029 * Implementation of a check that looks that matches across multiple lines in 030 * any file type. 031 * @author Oliver Burn 032 */ 033public class RegexpMultilineCheck extends AbstractFileSetCheck 034{ 035 /** The detection options to use. */ 036 private DetectorOptions mOptions = new DetectorOptions(Pattern.MULTILINE, 037 this); 038 /** The detector to use. */ 039 private MultilineDetector mDetector; 040 041 @Override 042 public void beginProcessing(String aCharset) 043 { 044 super.beginProcessing(aCharset); 045 mDetector = new MultilineDetector(mOptions); 046 } 047 048 @Override 049 protected void processFiltered(File aFile, List<String> aLines) 050 { 051 mDetector.processLines(FileText.fromLines(aFile, aLines)); 052 } 053 054 /** 055 * Set the format of the regular expression to match. 056 * @param aFormat the format of the regular expression to match. 057 */ 058 public void setFormat(String aFormat) 059 { 060 mOptions.setFormat(aFormat); 061 } 062 063 /** 064 * Set the message to report for a match. 065 * @param aMessage the message to report for a match. 066 */ 067 public void setMessage(String aMessage) 068 { 069 mOptions.setMessage(aMessage); 070 } 071 072 /** 073 * Set the minimum number of matches required per file. 074 * @param aMinimum the minimum number of matches required per file. 075 */ 076 public void setMinimum(int aMinimum) 077 { 078 mOptions.setMinimum(aMinimum); 079 } 080 081 /** 082 * Set the maximum number of matches required per file. 083 * @param aMaximum the maximum number of matches required per file. 084 */ 085 public void setMaximum(int aMaximum) 086 { 087 mOptions.setMaximum(aMaximum); 088 } 089 090 /** 091 * Set whether to ignore case when matching. 092 * @param aIgnore whether to ignore case when matching. 093 */ 094 public void setIgnoreCase(boolean aIgnore) 095 { 096 mOptions.setIgnoreCase(aIgnore); 097 } 098}