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