Clover Coverage Report - Checkstyle
Coverage timestamp: Fri May 9 2008 10:48:13 EST
../../../../../img/srcFileCovDistChart9.png 55% of files have more coverage
24   191   15   2.18
6   87   0.62   11
11     1.36  
1    
 
  AbstractFileSetCheck       Line # 30 82.9% 0.8292683
16.12 24 15 15 0.62
 
  ( 10 of 451)
 
1    ////////////////////////////////////////////////////////////////////////////////
2    // checkstyle: Checks Java source code for adherence to a set of rules.
3    // Copyright (C) 2001-2005 Oliver Burn
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    package com.puppycrawl.tools.checkstyle.api;
20   
21   
22    import java.io.File;
23    import java.io.UnsupportedEncodingException;
24   
25    /**
26    * Provides common functionality for many FileSetChecks.
27    *
28    * @author lkuehne
29    */
 
30    public abstract class AbstractFileSetCheck
31    extends AbstractViolationReporter
32    implements FileSetCheck
33    {
34    /** The dispatcher errors are fired to. */
35    private MessageDispatcher mDispatcher;
36   
37    /** the file extensions that are accepted by this filter */
38    private String[] mFileExtensions = {};
39   
40    /** collects the error messages */
41    private final LocalizedMessages mMessages = new LocalizedMessages();
42   
43    /** Name of a charset */
44    private String mCharset = System.getProperty("file.encoding", "UTF-8");
45   
46    /** @see com.puppycrawl.tools.checkstyle.api.FileSetCheck */
 
47  447 toggle public void destroy()
48    {
49    }
50   
51    /** @return the name of the charset */
 
52  441 toggle public String getCharset()
53    {
54  441 return mCharset;
55    }
56   
57    /**
58    * Sets a named charset.
59    * @param aCharset the name of a charset
60    * @throws UnsupportedEncodingException if aCharset is unsupported.
61    */
 
62  435 toggle public void setCharset(String aCharset)
63    throws UnsupportedEncodingException
64    {
65    // TODO: This is a hack to check that aCharset is supported.
66    // TODO: Find a better way in Java 1.3
67  435 try {
68  435 new String(new byte[] {}, aCharset);
69    }
70    catch (final UnsupportedEncodingException es) {
71  0 final String message = "unsupported charset: " + es.getMessage();
72  0 throw new UnsupportedEncodingException(message);
73    }
74  435 mCharset = aCharset;
75    }
76   
77    /** {@inheritDoc} */
 
78  448 toggle public final void setMessageDispatcher(MessageDispatcher aDispatcher)
79    {
80  448 mDispatcher = aDispatcher;
81    }
82   
83    /**
84    * A message dispatcher is used to fire violation messages to
85    * interested audit listeners.
86    *
87    * @return the current MessageDispatcher.
88    */
 
89  1252 toggle protected final MessageDispatcher getMessageDispatcher()
90    {
91  1252 return mDispatcher;
92    }
93   
94    /**
95    * Determines the set of files this FileSetCheck is interested in.
96    * Returns the files that have one of the currently active file extensions.
97    * If no file extensions are active the argument array is returned.
98    *
99    * <p>
100    * This method can be used in the implementation of <code>process()</code>
101    * to filter it's argument list for interesting files.
102    * </p>
103    *
104    * @param aFiles the candidates for processing
105    * @return the subset of aFiles that this FileSetCheck should process
106    * @see FileSetCheck#process
107    */
 
108  447 toggle protected final File[] filter(File[] aFiles)
109    {
110  447 return Utils.filterFilesByExtension(aFiles, mFileExtensions);
111    }
112   
113    /**
114    * Sets the file extensions that identify the files that pass the
115    * filter of this FileSetCheck.
116    * @param aExtensions the set of file extensions. A missing
117    * initial '.' character of an extension is automatically added.
118    */
 
119  448 toggle public final void setFileExtensions(String[] aExtensions)
120    {
121  448 if (aExtensions == null) {
122  0 mFileExtensions = null;
123  0 return;
124    }
125   
126  448 mFileExtensions = new String[aExtensions.length];
127  950 for (int i = 0; i < aExtensions.length; i++) {
128  502 final String extension = aExtensions[i];
129  502 if (extension.startsWith(".")) {
130  0 mFileExtensions[i] = extension;
131    }
132    else {
133  502 mFileExtensions[i] = "." + extension;
134    }
135    }
136    }
137   
138    /**
139    * Returns the collector for violation messages.
140    * Subclasses can use the collector to find out the violation
141    * messages to fire via the message dispatcher.
142    *
143    * @return the collector for localized messages.