KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mycompany > checks > LimitImplementationFiles


1 package com.mycompany.checks;
2
3 import java.io.File JavaDoc;
4 import com.puppycrawl.tools.checkstyle.api.*;
5
6 /**
7  * An example for a user provided FileSetCheck,
8  * checks that the number of files does not excced a certain limit.
9  *
10  * This Class is provided for educational purposes only, we do not
11  * consider it useful to check your production code.
12  *
13  * @author lkuehne
14  */

15 public class LimitImplementationFiles
16     extends AbstractFileSetCheck
17 {
18     /**
19      * the maximium number of implementation files,
20      * default is 100.
21      */

22     private int max = 100;
23
24     /**
25      * Give user a chance to configure max in the
26      * config file.
27      *
28      * @param aMax the user specified maximum.
29      */

30     public void setMax(int aMax)
31     {
32         max = aMax;
33     }
34
35     /**
36      * @see FileSetCheck
37      */

38     public void process(File JavaDoc[] files)
39     {
40         if (files != null && files.length > max) {
41
42             // figure out the file that contains the error
43
final String JavaDoc path = files[max].getPath();
44
45             // message collector is used to collect error messages,
46
// needs to be reset before starting to collect error messages
47
// for a file.
48
getMessageCollector().reset();
49
50             // message dispatcher is used to fire AuditEvents
51
MessageDispatcher dispatcher = getMessageDispatcher();
52
53             // signal start of file to AuditListeners
54
dispatcher.fireFileStarted(path);
55
56             // log the message
57
log(0, "max.files.exceeded", new Integer JavaDoc(max));
58
59             // you can call log() multiple times to flag multiple
60
// errors in the same file
61

62             // fire the errors for this file to the AuditListeners
63
fireErrors(path);
64
65             // signal end of file to AuditListeners
66
dispatcher.fireFileFinished(path);
67         }
68     }
69 }
70
Popular Tags