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

Unified Diff: tools/checkdeps/checker.py

Issue 10790014: Add Java support to checkdeps.py (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: tools/checkdeps/checker.py
diff --git a/tools/checkdeps/checker.py b/tools/checkdeps/checker.py
new file mode 100644
index 0000000000000000000000000000000000000000..5938eb74955c8d1d2a9213bdea2a615a853cdb71
--- /dev/null
+++ b/tools/checkdeps/checker.py
@@ -0,0 +1,57 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os
+
+
+class Checker(object):
M-A Ruel 2012/07/17 14:23:20 Note that an "interface" is not a contractual defi
Iain Merrick 2012/07/17 15:55:08 OK, if you prefer to keep the contract implicit, t
+ """Base class for language-specific checker modules.
+
+ Properties:
+ _base_directory: root directory against which imports are resolved.
+ _verbose: True if CheckFile should print detailed progress information.
+ """
+
+ def __init__(self, base_directory, verbose):
+ self._base_directory = base_directory
+ self._verbose = verbose
+
+ def Extensions(self):
+ """Returns a list of file extensions that this checker can handle."""
+ raise NotImplementedError(self.__class__.__name__ + ".Extensions")
+
+ def CheckFile(self, rules, file_name):
+ """Checks the given file with the given rule set.
+
+ Args:
+ rules: The set of rules that apply to files in this directory.
+ file_name: The source file to check.
+
+ Returns: Either a string describing the error if there was one, or None if
+ the file checked out OK.
+ """
+ raise NotImplementedError(self.__class__.__name__ + ".CheckFile")
+
+
+class Factory(object):
M-A Ruel 2012/07/17 14:23:20 This is overdesign at that point; this is no Java.
+ """Helper class for locating the correct Checker for each file."""
+
+ def __init__(self, base_directory, verbose):
+ """Loads and initializes all known subclasses of Checker.
+
+ Args:
+ base_directory: root directory against which imports are resolved.
+ verbose: True if CheckFile should print detailed progress information.
+ """
+ self._checkers = [
+ c(base_directory, verbose) for c in Checker.__subclasses__()]
+
+ def GetChecker(self, filename):
+ """Returns the Checker for the given file, or None if no check is needed."""
+ basename, extension = os.path.splitext(filename)
+ for c in self._checkers:
+ if extension in c.Extensions():
+ return c
+ return None
+

Powered by Google App Engine
This is Rietveld 408576698