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;
024import java.util.regex.Pattern;
025
026import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
027import com.puppycrawl.tools.checkstyle.api.FileText;
028
029/**
030 * Implementation of a check that looks that matches across multiple lines in
031 * any file type.
032 * @author Oliver Burn
033 */
034public class RegexpMultilineCheck extends AbstractFileSetCheck {
035    /** The detection options to use. */
036    private final 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        super.beginProcessing(charset);
044        detector = new MultilineDetector(options);
045    }
046
047    @Override
048    protected void processFiltered(File file, List<String> lines) {
049        detector.processLines(FileText.fromLines(file, lines));
050    }
051
052    /**
053     * Set the format of the regular expression to match.
054     * @param format the format of the regular expression to match.
055     */
056    public void setFormat(String format) {
057        options.setFormat(format);
058    }
059
060    /**
061     * Set the message to report for a match.
062     * @param message the message to report for a match.
063     */
064    public void setMessage(String message) {
065        options.setMessage(message);
066    }
067
068    /**
069     * Set the minimum number of matches required per file.
070     * @param minimum the minimum number of matches required per file.
071     */
072    public void setMinimum(int minimum) {
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        options.setMaximum(maximum);
082    }
083
084    /**
085     * Set whether to ignore case when matching.
086     * @param ignore whether to ignore case when matching.
087     */
088    public void setIgnoreCase(boolean ignore) {
089        options.setIgnoreCase(ignore);
090    }
091}