OLD | NEW |
1 # This program is free software; you can redistribute it and/or modify it under | 1 # This program is free software; you can redistribute it and/or modify it under |
2 # the terms of the GNU General Public License as published by the Free Software | 2 # the terms of the GNU General Public License as published by the Free Software |
3 # Foundation; either version 2 of the License, or (at your option) any later | 3 # Foundation; either version 2 of the License, or (at your option) any later |
4 # version. | 4 # version. |
5 # | 5 # |
6 # This program is distributed in the hope that it will be useful, but WITHOUT | 6 # This program is distributed in the hope that it will be useful, but WITHOUT |
7 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 7 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details | 8 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details |
9 # | 9 # |
10 # You should have received a copy of the GNU General Public License along with | 10 # You should have received a copy of the GNU General Public License along with |
11 # this program; if not, write to the Free Software Foundation, Inc., | 11 # this program; if not, write to the Free Software Foundation, Inc., |
12 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 12 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
13 """Interfaces for PyLint objects""" | 13 """ Copyright (c) 2002-2003 LOGILAB S.A. (Paris, FRANCE). |
| 14 http://www.logilab.fr/ -- mailto:contact@logilab.fr |
| 15 |
| 16 Interfaces for PyLint objects |
| 17 """ |
| 18 |
| 19 __revision__ = "$Id: interfaces.py,v 1.9 2004-04-24 12:14:53 syt Exp $" |
14 | 20 |
15 from logilab.common.interface import Interface | 21 from logilab.common.interface import Interface |
16 | 22 |
17 | 23 |
18 class IChecker(Interface): | 24 class IChecker(Interface): |
19 """This is an base interface, not designed to be used elsewhere than for | 25 """This is an base interface, not designed to be used elsewhere than for |
20 sub interfaces definition. | 26 sub interfaces definition. |
21 """ | 27 """ |
22 | 28 |
23 def open(self): | 29 def open(self): |
24 """called before visiting project (i.e set of modules)""" | 30 """called before visiting project (i.e set of modules)""" |
25 | 31 |
26 def close(self): | 32 def close(self): |
27 """called after visiting project (i.e set of modules)""" | 33 """called after visiting project (i.e set of modules)""" |
28 | 34 |
| 35 ## def open_module(self): |
| 36 ## """called before visiting a module""" |
| 37 |
| 38 ## def close_module(self): |
| 39 ## """called after visiting a module""" |
| 40 |
29 | 41 |
30 class IRawChecker(IChecker): | 42 class IRawChecker(IChecker): |
31 """interface for checker which need to parse the raw file | 43 """interface for checker which need to parse the raw file |
32 """ | 44 """ |
33 | 45 |
34 def process_module(self, astroid): | 46 def process_module(self, astng): |
35 """ process a module | 47 """ process a module |
36 | 48 |
37 the module's content is accessible via astroid.file_stream | 49 the module's content is accessible via astng.file_stream |
38 """ | 50 """ |
39 | 51 |
40 | 52 |
41 class ITokenChecker(IChecker): | 53 class IASTNGChecker(IChecker): |
42 """Interface for checkers that need access to the token list.""" | |
43 def process_tokens(self, tokens): | |
44 """Process a module. | |
45 | |
46 tokens is a list of all source code tokens in the file. | |
47 """ | |
48 | |
49 | |
50 class IAstroidChecker(IChecker): | |
51 """ interface for checker which prefers receive events according to | 54 """ interface for checker which prefers receive events according to |
52 statement type | 55 statement type |
53 """ | 56 """ |
54 | 57 |
55 | 58 |
| 59 class ILinter(Interface): |
| 60 """interface for the linter class |
| 61 |
| 62 the linter class will generate events to its registered checkers. |
| 63 Each checker may interact with the linter instance using this API |
| 64 """ |
| 65 |
| 66 def register_checker(self, checker): |
| 67 """register a new checker class |
| 68 |
| 69 checker is a class implementing IrawChecker or / and IASTNGChecker |
| 70 """ |
| 71 |
| 72 def add_message(self, msg_id, line=None, node=None, args=None): |
| 73 """add the message corresponding to the given id. |
| 74 |
| 75 If provided, msg is expanded using args |
| 76 |
| 77 astng checkers should provide the node argument, |
| 78 raw checkers should provide the line argument. |
| 79 """ |
| 80 |
| 81 |
56 class IReporter(Interface): | 82 class IReporter(Interface): |
57 """ reporter collect messages and display results encapsulated in a layout | 83 """ reporter collect messages and display results encapsulated in a layout |
58 """ | 84 """ |
59 def add_message(self, msg_id, location, msg): | 85 def add_message(self, msg_id, location, msg): |
60 """add a message of a given type | 86 """add a message of a given type |
61 | 87 |
62 msg_id is a message identifier | 88 msg_id is a message identifier |
63 location is a 3-uple (module, object, line) | 89 location is a 3-uple (module, object, line) |
64 msg is the actual message | 90 msg is the actual message |
65 """ | 91 """ |
66 | 92 |
67 def display_results(self, layout): | 93 def display_results(self, layout): |
68 """display results encapsulated in the layout tree | 94 """display results encapsulated in the layout tree |
69 """ | 95 """ |
70 | 96 |
71 | 97 |
72 __all__ = ('IRawChecker', 'IAstroidChecker', 'ITokenChecker', 'IReporter') | 98 __all__ = ('IRawChecker', 'IStatable', 'ILinter', 'IReporter') |
OLD | NEW |