001////////////////////////////////////////////////////////////////////////////////
002// checkstyle: Checks Java source code for adherence to a set of rules.
003// Copyright (C) 2001-2015 the original author or authors.
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////////////////////////////////////////////////////////////////////////////////
019
020package com.puppycrawl.tools.checkstyle.checks.regexp;
021
022import java.io.File;
023import java.util.List;
024
025import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
026
027/**
028 * Implementation of a check that looks for a single line in any file type.
029 * @author Oliver Burn
030 */
031public class RegexpSinglelineCheck extends AbstractFileSetCheck {
032    /** The detection options to use. */
033    private final DetectorOptions options = new DetectorOptions(0, this);
034    /** The detector to use. */
035    private SinglelineDetector detector;
036
037    @Override
038    public void beginProcessing(String charset) {
039        super.beginProcessing(charset);
040        detector = new SinglelineDetector(options);
041    }
042
043    @Override
044    protected void processFiltered(File file, List<String> lines) {
045        detector.processLines(lines);
046    }
047
048    /**
049     * Set the format of the regular expression to match.
050     * @param format the format of the regular expression to match.
051     */
052    public void setFormat(String format) {
053        options.setFormat(format);
054    }
055
056    /**
057     * Set the message to report for a match.
058     * @param message the message to report for a match.
059     */
060    public void setMessage(String message) {
061        options.setMessage(message);
062    }
063
064    /**
065     * Set the minimum number of matches required per file.
066     * @param minimum the minimum number of matches required per file.
067     */
068    public void setMinimum(int minimum) {
069        options.setMinimum(minimum);
070    }
071
072    /**
073     * Set the maximum number of matches required per file.
074     * @param maximum the maximum number of matches required per file.
075     */
076    public void setMaximum(int maximum) {
077        options.setMaximum(maximum);
078    }
079
080    /**
081     * Set whether to ignore case when matching.
082     * @param ignore whether to ignore case when matching.
083     */
084    public void setIgnoreCase(boolean ignore) {
085        options.setIgnoreCase(ignore);
086    }
087}