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 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 12 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
13 """ Copyright (c) 2002-2003 LOGILAB S.A. (Paris, FRANCE). | 13 """Interfaces for PyLint objects""" |
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 $" | |
20 | 14 |
21 from logilab.common.interface import Interface | 15 from logilab.common.interface import Interface |
22 | 16 |
23 | 17 |
24 class IChecker(Interface): | 18 class IChecker(Interface): |
25 """This is an base interface, not designed to be used elsewhere than for | 19 """This is an base interface, not designed to be used elsewhere than for |
26 sub interfaces definition. | 20 sub interfaces definition. |
27 """ | 21 """ |
28 | 22 |
29 def open(self): | 23 def open(self): |
30 """called before visiting project (i.e set of modules)""" | 24 """called before visiting project (i.e set of modules)""" |
31 | 25 |
32 def close(self): | 26 def close(self): |
33 """called after visiting project (i.e set of modules)""" | 27 """called after visiting project (i.e set of modules)""" |
34 | 28 |
35 ## def open_module(self): | |
36 ## """called before visiting a module""" | |
37 | |
38 ## def close_module(self): | |
39 ## """called after visiting a module""" | |
40 | |
41 | 29 |
42 class IRawChecker(IChecker): | 30 class IRawChecker(IChecker): |
43 """interface for checker which need to parse the raw file | 31 """interface for checker which need to parse the raw file |
44 """ | 32 """ |
45 | 33 |
46 def process_module(self, astng): | 34 def process_module(self, astroid): |
47 """ process a module | 35 """ process a module |
48 | 36 |
49 the module's content is accessible via astng.file_stream | 37 the module's content is accessible via astroid.file_stream |
50 """ | 38 """ |
51 | 39 |
52 | 40 |
53 class IASTNGChecker(IChecker): | 41 class ITokenChecker(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): |
54 """ interface for checker which prefers receive events according to | 51 """ interface for checker which prefers receive events according to |
55 statement type | 52 statement type |
56 """ | 53 """ |
57 | 54 |
58 | 55 |
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 | |
82 class IReporter(Interface): | 56 class IReporter(Interface): |
83 """ reporter collect messages and display results encapsulated in a layout | 57 """ reporter collect messages and display results encapsulated in a layout |
84 """ | 58 """ |
85 def add_message(self, msg_id, location, msg): | 59 def add_message(self, msg_id, location, msg): |
86 """add a message of a given type | 60 """add a message of a given type |
87 | 61 |
88 msg_id is a message identifier | 62 msg_id is a message identifier |
89 location is a 3-uple (module, object, line) | 63 location is a 3-uple (module, object, line) |
90 msg is the actual message | 64 msg is the actual message |
91 """ | 65 """ |
92 | 66 |
93 def display_results(self, layout): | 67 def display_results(self, layout): |
94 """display results encapsulated in the layout tree | 68 """display results encapsulated in the layout tree |
95 """ | 69 """ |
96 | 70 |
97 | 71 |
98 __all__ = ('IRawChecker', 'IStatable', 'ILinter', 'IReporter') | 72 __all__ = ('IRawChecker', 'IAstroidChecker', 'ITokenChecker', 'IReporter') |
OLD | NEW |