View Javadoc
1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2017 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ////////////////////////////////////////////////////////////////////////////////
19  
20  package com.puppycrawl.tools.checkstyle.api;
21  
22  import java.io.File;
23  import java.util.SortedSet;
24  
25  /**
26   * Interface for Checking a set of files for some criteria.
27   *
28   * @author lkuehne
29   * @author oliver
30   */
31  public interface FileSetCheck
32      extends Configurable, Contextualizable {
33      /**
34       * Sets the MessageDispatcher that is used to dispatch error
35       * messages to AuditListeners during processing.
36       * @param dispatcher the dispatcher
37       */
38      void setMessageDispatcher(MessageDispatcher dispatcher);
39  
40      /**
41       * Initialise the instance. This is the time to verify that everything
42       * required to perform it job.
43       */
44      void init();
45  
46      /** Cleans up the object. **/
47      void destroy();
48  
49      /**
50       * Called when about to be called to process a set of files.
51       * @param charset the character set used to read the files.
52       */
53      void beginProcessing(String charset);
54  
55      /**
56       * Request to process a file. The implementation should use the supplied
57       * contents and not read the contents again. This reduces the amount of
58       * file I/O.
59       * <p>
60       * The file set to process might contain files that are not
61       * interesting to the FileSetCheck. Such files should be ignored,
62       * no error message should be fired for them. For example a FileSetCheck
63       * that checks java files should ignore HTML or properties files.
64       * </p>
65       * <p>
66       * The method should return the set of messages to be logged.
67       * </p>
68       *
69       * @param file the file to be processed
70       * @param fileText the contents of the file.
71       * @return the sorted set of messages to be logged.
72       * @throws CheckstyleException if error condition within Checkstyle occurs
73       */
74      SortedSet<LocalizedMessage> process(File file, FileText fileText) throws CheckstyleException;
75  
76      /**
77       * Called when all the files have been processed. This is the time to
78       * perform any checks that need to be done across a set of files. In this
79       * method, the implementation is responsible for the logging of messages.
80       */
81      void finishProcessing();
82  }