aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorZuy Alexey <zuy.alexey@gmail.com>2016-04-26 03:05:30 +0300
committerRoman Ivanov <romani@users.noreply.github.com>2016-04-25 17:05:30 -0700
commit6273f207202078c76b8451a841ceb62ef6fe05ed (patch)
tree3dcd5f3875a1e413f9cca5da344bcaf684192dc2 /src/main
parent3defd234041f34854f50f1a77ae94d18fb730036 (diff)
downloadcheckstyle-6273f207202078c76b8451a841ceb62ef6fe05ed.tar.gz
minor: reorganized Checker class (#3128)
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/puppycrawl/tools/checkstyle/Checker.java266
1 files changed, 133 insertions, 133 deletions
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/Checker.java b/src/main/java/com/puppycrawl/tools/checkstyle/Checker.java
index 1f32b76f4..221137214 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/Checker.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/Checker.java
@@ -133,90 +133,6 @@ public class Checker extends AutomaticBean implements MessageDispatcher {
cache.load();
}
- @Override
- public void finishLocalSetup() throws CheckstyleException {
- final Locale locale = new Locale(localeLanguage, localeCountry);
- LocalizedMessage.setLocale(locale);
-
- if (moduleFactory == null) {
-
- if (moduleClassLoader == null) {
- throw new CheckstyleException(
- "if no custom moduleFactory is set, "
- + "moduleClassLoader must be specified");
- }
-
- final Set<String> packageNames = PackageNamesLoader
- .getPackageNames(moduleClassLoader);
- moduleFactory = new PackageObjectFactory(packageNames,
- moduleClassLoader);
- }
-
- final DefaultContext context = new DefaultContext();
- context.add("charset", charset);
- context.add("classLoader", classLoader);
- context.add("moduleFactory", moduleFactory);
- context.add("severity", severityLevel.getName());
- context.add("basedir", basedir);
- childContext = context;
- }
-
- @Override
- protected void setupChild(Configuration childConf)
- throws CheckstyleException {
- final String name = childConf.getName();
- final Object child;
-
- try {
- child = moduleFactory.createModule(name);
-
- if (child instanceof AutomaticBean) {
- final AutomaticBean bean = (AutomaticBean) child;
- bean.contextualize(childContext);
- bean.configure(childConf);
- }
- }
- catch (final CheckstyleException ex) {
- throw new CheckstyleException("cannot initialize module " + name
- + " - " + ex.getMessage(), ex);
- }
- if (child instanceof FileSetCheck) {
- final FileSetCheck fsc = (FileSetCheck) child;
- fsc.init();
- addFileSetCheck(fsc);
- }
- else if (child instanceof Filter) {
- final Filter filter = (Filter) child;
- addFilter(filter);
- }
- else if (child instanceof AuditListener) {
- final AuditListener listener = (AuditListener) child;
- addListener(listener);
- }
- else {
- throw new CheckstyleException(name
- + " is not allowed as a child in Checker");
- }
- }
-
- /**
- * Adds a FileSetCheck to the list of FileSetChecks
- * that is executed in process().
- * @param fileSetCheck the additional FileSetCheck
- */
- public void addFileSetCheck(FileSetCheck fileSetCheck) {
- fileSetCheck.setMessageDispatcher(this);
- fileSetChecks.add(fileSetCheck);
- }
-
- /**
- * Adds a filter to the end of the audit event filter chain.
- * @param filter the additional filter
- */
- public void addFilter(Filter filter) {
- filters.addFilter(filter);
- }
-
/**
* Removes filter.
* @param filter filter to remove.
@@ -240,14 +156,6 @@ public class Checker extends AutomaticBean implements MessageDispatcher {
}
/**
- * Add the listener that will be used to receive events from the audit.
- * @param listener the nosy thing
- */
- public final void addListener(AuditListener listener) {
- listeners.add(listener);
- }
-
- /**
* Removes a given listener.
* @param listener a listener to remove
*/
@@ -256,6 +164,14 @@ public class Checker extends AutomaticBean implements MessageDispatcher {
}
/**
+ * Sets base directory.
+ * @param basedir the base directory to strip off in file names
+ */
+ public void setBasedir(String basedir) {
+ this.basedir = basedir;
+ }
+
+ /**
* Processes a set of files with all FileSetChecks.
* Once this is done, it is highly recommended to call for
* the destroy method to close and remove the listeners.
@@ -289,6 +205,22 @@ public class Checker extends AutomaticBean implements MessageDispatcher {
return errorCount;
}
+ /** Notify all listeners about the audit start. */
+ private void fireAuditStarted() {
+ final AuditEvent event = new AuditEvent(this);
+ for (final AuditListener listener : listeners) {
+ listener.auditStarted(event);
+ }
+ }
+
+ /** Notify all listeners about the audit end. */
+ private void fireAuditFinished() {
+ final AuditEvent event = new AuditEvent(this);
+ for (final AuditListener listener : listeners) {
+ listener.auditFinished(event);
+ }
+ }
+
/**
* Processes a list of files with all FileSetChecks.
* @param files a list of files to process.
@@ -315,7 +247,7 @@ public class Checker extends AutomaticBean implements MessageDispatcher {
catch (Exception ex) {
// We need to catch all exceptions to put a reason failure (file name) in exception
throw new CheckstyleException("Exception was thrown while processing "
- + file.getPath(), ex);
+ + file.getPath(), ex);
}
catch (Error error) {
// We need to catch all errors to put a reason failure (file name) in error
@@ -341,37 +273,13 @@ public class Checker extends AutomaticBean implements MessageDispatcher {
catch (final IOException ioe) {
LOG.debug("IOException occurred.", ioe);
fileMessages.add(new LocalizedMessage(0,
- Definitions.CHECKSTYLE_BUNDLE, "general.exception",
- new String[] {ioe.getMessage()}, null, getClass(), null));
+ Definitions.CHECKSTYLE_BUNDLE, "general.exception",
+ new String[] {ioe.getMessage()}, null, getClass(), null));
}
return fileMessages;
}
/**
- * Sets base directory.
- * @param basedir the base directory to strip off in file names
- */
- public void setBasedir(String basedir) {
- this.basedir = basedir;
- }
-
- /** Notify all listeners about the audit start. */
- private void fireAuditStarted() {
- final AuditEvent event = new AuditEvent(this);
- for (final AuditListener listener : listeners) {
- listener.auditStarted(event);
- }
- }
-
- /** Notify all listeners about the audit end. */
- private void fireAuditFinished() {
- final AuditEvent event = new AuditEvent(this);
- for (final AuditListener listener : listeners) {
- listener.auditFinished(event);
- }
- }
-
- /**
* Notify all listeners about the beginning of a file audit.
*
* @param fileName
@@ -387,6 +295,25 @@ public class Checker extends AutomaticBean implements MessageDispatcher {
}
/**
+ * Notify all listeners about the errors in a file.
+ *
+ * @param fileName the audited file
+ * @param errors the audit errors from the file
+ */
+ @Override
+ public void fireErrors(String fileName, SortedSet<LocalizedMessage> errors) {
+ final String stripped = CommonUtils.relativizeAndNormalizePath(basedir, fileName);
+ for (final LocalizedMessage element : errors) {
+ final AuditEvent event = new AuditEvent(this, stripped, element);
+ if (filters.accept(event)) {
+ for (final AuditListener listener : listeners) {
+ listener.addError(event);
+ }
+ }
+ }
+ }
+
+ /**
* Notify all listeners about the end of a file audit.
*
* @param fileName
@@ -401,23 +328,96 @@ public class Checker extends AutomaticBean implements MessageDispatcher {
}
}
- /**
- * Notify all listeners about the errors in a file.
- *
- * @param fileName the audited file
- * @param errors the audit errors from the file
- */
@Override
- public void fireErrors(String fileName, SortedSet<LocalizedMessage> errors) {
- final String stripped = CommonUtils.relativizeAndNormalizePath(basedir, fileName);
- for (final LocalizedMessage element : errors) {
- final AuditEvent event = new AuditEvent(this, stripped, element);
- if (filters.accept(event)) {
- for (final AuditListener listener : listeners) {
- listener.addError(event);
- }
+ public void finishLocalSetup() throws CheckstyleException {
+ final Locale locale = new Locale(localeLanguage, localeCountry);
+ LocalizedMessage.setLocale(locale);
+
+ if (moduleFactory == null) {
+
+ if (moduleClassLoader == null) {
+ throw new CheckstyleException(
+ "if no custom moduleFactory is set, "
+ + "moduleClassLoader must be specified");
}
+
+ final Set<String> packageNames = PackageNamesLoader
+ .getPackageNames(moduleClassLoader);
+ moduleFactory = new PackageObjectFactory(packageNames,
+ moduleClassLoader);
}
+
+ final DefaultContext context = new DefaultContext();
+ context.add("charset", charset);
+ context.add("classLoader", classLoader);
+ context.add("moduleFactory", moduleFactory);
+ context.add("severity", severityLevel.getName());
+ context.add("basedir", basedir);
+ childContext = context;
+ }
+
+ @Override
+ protected void setupChild(Configuration childConf)
+ throws CheckstyleException {
+ final String name = childConf.getName();
+ final Object child;
+
+ try {
+ child = moduleFactory.createModule(name);
+
+ if (child instanceof AutomaticBean) {
+ final AutomaticBean bean = (AutomaticBean) child;
+ bean.contextualize(childContext);
+ bean.configure(childConf);
+ }
+ }
+ catch (final CheckstyleException ex) {
+ throw new CheckstyleException("cannot initialize module " + name
+ + " - " + ex.getMessage(), ex);
+ }
+ if (child instanceof FileSetCheck) {
+ final FileSetCheck fsc = (FileSetCheck) child;
+ fsc.init();
+ addFileSetCheck(fsc);
+ }
+ else if (child instanceof Filter) {
+ final Filter filter = (Filter) child;
+ addFilter(filter);
+ }
+ else if (child instanceof AuditListener) {
+ final AuditListener listener = (AuditListener) child;
+ addListener(listener);
+ }
+ else {
+ throw new CheckstyleException(name
+ + " is not allowed as a child in Checker");
+ }
+ }
+
+ /**
+ * Adds a FileSetCheck to the list of FileSetChecks
+ * that is executed in process().
+ * @param fileSetCheck the additional FileSetCheck
+ */
+ public void addFileSetCheck(FileSetCheck fileSetCheck) {
+ fileSetCheck.setMessageDispatcher(this);
+ fileSetChecks.add(fileSetCheck);
+ }
+
+ /**
+ * Adds a filter to the end of the audit event filter chain.
+ * @param filter the additional filter
+ */
+ public void addFilter(Filter filter) {
+ filters.addFilter(filter);
+ }
+
+ /**
+ * Add the listener that will be used to receive events from the audit.
+ * @param listener the nosy thing
+ */
+ public final void addListener(AuditListener listener) {
+ listeners.add(listener);
}
/**