Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: tools/dom/scripts/monitored.py

Issue 444743002: Use Blink IDL parser for dart libraries. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merged Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/dom/scripts/idlnode_test.py ('k') | tools/dom/scripts/multiemitter.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a 3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file. 4 # BSD-style license that can be found in the LICENSE file.
5 5
6
6 """This module provides maps and sets that report unused elements.""" 7 """This module provides maps and sets that report unused elements."""
7 8
8 _monitored_values = [] 9 _monitored_values = []
9 10
10 11
11 def FinishMonitoring(includeDart2jsOnly): 12 def FinishMonitoring(includeDart2jsOnly, logger):
12 for value in _monitored_values: 13 for value in _monitored_values:
13 if value._dart2jsOnly and not includeDart2jsOnly: 14 if value._dart2jsOnly and not includeDart2jsOnly:
14 continue 15 continue
15 value.CheckUsage() 16 value.CheckUsage(logger)
16 17
17 class MonitoredCollection(object): 18 class MonitoredCollection(object):
18 def __init__(self, name, dart2jsOnly): 19 def __init__(self, name, dart2jsOnly):
19 self.name = name 20 self.name = name
20 self._used_keys = set() 21 self._used_keys = set()
21 self._dart2jsOnly = dart2jsOnly 22 self._dart2jsOnly = dart2jsOnly
22 _monitored_values.append(self) 23 _monitored_values.append(self)
23 24
24 class Dict(MonitoredCollection): 25 class Dict(MonitoredCollection):
25 """Wrapper for a dict that reports unused keys.""" 26 """Wrapper for a dict that reports unused keys."""
(...skipping 16 matching lines...) Expand all
42 def __iter__(self): 43 def __iter__(self):
43 return self._map.__iter__() 44 return self._map.__iter__()
44 45
45 def get(self, key, default=None): 46 def get(self, key, default=None):
46 self._used_keys.add(key) 47 self._used_keys.add(key)
47 return self._map.get(key, default) 48 return self._map.get(key, default)
48 49
49 def keys(self): 50 def keys(self):
50 return self._map.keys() 51 return self._map.keys()
51 52
52 def CheckUsage(self): 53 def CheckUsage(self, logger):
53 for v in sorted(self._map.keys()): 54 for v in sorted(self._map.keys()):
54 if v not in self._used_keys: 55 if v not in self._used_keys:
55 print "dict '%s' has unused key '%s'" % (self.name, v) 56 logger.warn('dict \'%s\' has unused key \'%s\'' % (self.name, v))
56 57
57 58
58 class Set(MonitoredCollection): 59 class Set(MonitoredCollection):
59 """Wrapper for a set that reports unused keys.""" 60 """Wrapper for a set that reports unused keys."""
60 61
61 def __init__(self, name, a_set, dart2jsOnly=False): 62 def __init__(self, name, a_set, dart2jsOnly=False):
62 super(Set, self).__init__(name, dart2jsOnly) 63 super(Set, self).__init__(name, dart2jsOnly)
63 self._set = a_set 64 self._set = a_set
64 65
65 def __contains__(self, key): 66 def __contains__(self, key):
66 self._used_keys.add(key) 67 self._used_keys.add(key)
67 return key in self._set 68 return key in self._set
68 69
69 def __iter__(self): 70 def __iter__(self):
70 return self._set.__iter__() 71 return self._set.__iter__()
71 72
72 def add(self, key): 73 def add(self, key):
73 self._set += [key] 74 self._set += [key]
74 75
75 def CheckUsage(self): 76 def CheckUsage(self, logger):
76 for v in sorted(self._set): 77 for v in sorted(self._set):
77 if v not in self._used_keys: 78 if v not in self._used_keys:
78 print "set '%s' has unused key '%s'" % (self.name, v) 79 logger.warn('set \'%s\' has unused key \'%s\'' % (self.name, v))
OLDNEW
« no previous file with comments | « tools/dom/scripts/idlnode_test.py ('k') | tools/dom/scripts/multiemitter.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698