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 options = new DetectorOptions(Pattern.MULTILINE,
037            this);
038    /** The detector to use. */
039    private MultilineDetector detector;
040
041    @Override
042    public void beginProcessing(String charset)
043    {
044        super.beginProcessing(charset);
045        detector = new MultilineDetector(options);
046    }
047
048    @Override
049    protected void processFiltered(File file, List<String> lines)
050    {
051        detector.processLines(FileText.fromLines(file, lines));
052    }
053
054    /**
055     * Set the format of the regular expression to match.
056     * @param format the format of the regular expression to match.
057     */
058    public void setFormat(String format)
059    {
060        options.setFormat(format);
061    }
062
063    /**
064     * Set the message to report for a match.
065     * @param message the message to report for a match.
066     */
067    public void setMessage(String message)
068    {
069        options.setMessage(message);
070    }
071
072    /**
073     * Set the minimum number of matches required per file.
074     * @param minimum the minimum number of matches required per file.
075     */
076    public void setMinimum(int minimum)
077    {
078        options.setMinimum(minimum);
079    }
080
081    /**
082     * Set the maximum number of matches required per file.
083     * @param maximum the maximum number of matches required per file.
084     */
085    public void setMaximum(int maximum)
086    {
087        options.setMaximum(maximum);
088    }
089
090    /**
091     * Set whether to ignore case when matching.
092     * @param ignore whether to ignore case when matching.
093     */
094    public void setIgnoreCase(boolean ignore)
095    {
096        options.setIgnoreCase(ignore);
097    }
098}