Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/checkstyle-checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,9 @@
<property name="allowUnknownTags" value="true"/>
</module>
<module name="JavadocVariable"/>
<module name="MissingJavadocMethod">
<property name="scope" value="private"/>
</module>
<module name="MissingJavadocPackage"/>
<module name="MissingJavadocType">
<property name="scope" value="private"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ public static Locale getPlatformLocale() {
return platformLocale;
}

/**
* Sets the platform locale.
*
* @param locale
* the locale to set
*/
public static void setPlatformLocale(final Locale locale) {
platformLocale = locale;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public final class Messages extends NLS {
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}

/**
* Utility class, not intended to be instantiated.
*/
private Messages() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ public void runAudit(IProject project, IProgressMonitor monitor)
}
}

/**
* Handles a failure that occurred during the checkstyle run.
*
* @param project
* the project being audited
* @param error
* the thrown checkstyle exception
* @throws CheckstylePluginException
* an unexpected exception occurred
*/
private void handleCheckstyleFailure(IProject project, CheckstyleException error)
throws CheckstylePluginException {
try {
Expand Down Expand Up @@ -196,6 +206,11 @@ public void addFile(IFile file) {
mFiles.put(file.getLocation().toString(), file);
}

/**
* Determines whether files have been added to the audit.
*
* @return <code>true</code> if at least one file has been added, <code>false</code> otherwise
*/
public boolean hasFiles() {
return !mFiles.isEmpty();
}
Expand Down Expand Up @@ -260,6 +275,12 @@ private class CheckstyleAuditListener implements AuditListener {
*/
private Set<IPath> mConnectedFileBufferPaths = new HashSet<>();

/**
* Creates a listener for the checkstyle audit.
*
* @param project
* the project to audit
*/
CheckstyleAuditListener(IProject project) {
mProject = project;

Expand Down Expand Up @@ -395,6 +416,9 @@ public void auditFinished(AuditEvent event) {
public void auditStarted(AuditEvent event) {
}

/**
* Cleans up the state of the listener.
*/
public void cleanup() {

mDocument = null;
Expand Down Expand Up @@ -446,6 +470,13 @@ private void calculateMarkerOffset(AuditEvent error, Map<String, Object> markerA
}
}

/**
* Connects the file buffer for the given resource.
*
* @param resource
* the resource to connect
* @return the connected document or <code>null</code>
*/
private IDocument connectFileBuffer(IResource resource) {
IDocument document = null;
if (resource instanceof IFile) {
Expand All @@ -463,13 +494,25 @@ private IDocument connectFileBuffer(IResource resource) {
return document;
}

/**
* Disconnects the file buffer for the given resource.
*
* @param resource
* the resource to disconnect
*/
private void disconnectFileBuffer(IResource resource) {
if (resource instanceof IFile) {
final IPath path = resource.getFullPath();
disconnectFileBuffer(path);
}
}

/**
* Disconnects the file buffer for the given path.
*
* @param path
* the path to disconnect
*/
private void disconnectFileBuffer(IPath path) {

try {
Expand All @@ -484,6 +527,13 @@ private void disconnectFileBuffer(IPath path) {
}
}

/**
* Converts a severity level into the corresponding marker severity value.
*
* @param severity
* the severity level
* @return the marker severity value
*/
private int getSeverityValue(SeverityLevel severity) {
int result = IMarker.SEVERITY_WARNING;

Expand All @@ -500,6 +550,13 @@ else if (severity.equals(SeverityLevel.ERROR)) {
return result;
}

/**
* Builds the message shown for the given audit event.
*
* @param error
* the audit event
* @return the assembled message
*/
private String getMessage(AuditEvent error) {

String moduleId = error.getModuleId();
Expand Down Expand Up @@ -534,6 +591,13 @@ private String getMessage(AuditEvent error) {
return buf.toString();
}

/**
* Determines the rule name for the given audit event.
*
* @param error
* the audit event
* @return the rule name
*/
private String getRuleName(AuditEvent error) {
final String ruleName;
final RuleMetadata metaData = MetadataFactory.getRuleMetadata(error.getSourceName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,27 @@ private static Checker createCheckerInternal(InputSource input, PropertyResolver
return checker;
}

/**
* Sets the locale on the given checker if it changed.
*
* @param checker
* the checker to update
*/
private static void setLocaleIfChanged(final Checker checker) {
final String lc = getLocale();
if (lc != null && !lc.equals(CheckstylePlugin.getPlatformLocale().getLanguage())) {
setLocale(checker, lc);
}
}

/**
* Sets the locale on the given checker.
*
* @param checker
* the checker to update
* @param lang
* the language to apply
*/
private static void setLocale(final Checker checker, final String lang) {
final String lastLocale;
if (lang != null) {
Expand All @@ -277,6 +291,11 @@ private static void setLocale(final Checker checker, final String lang) {
}
}

/**
* Returns the configured locale language.
*
* @return the configured language or <code>null</code> if the default should be used
*/
private static String getLocale() {
String lang = CheckstylePluginPrefs.getString(CheckstylePluginPrefs.PREF_LOCALE_LANGUAGE);
if (lang != null && (lang.isEmpty() || "default".equals(lang))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,20 @@ public final class CheckstyleMarker {
*/
public static final int CATEGORY_ID = 999;

/**
* Utility class, not intended to be instantiated.
*/
private CheckstyleMarker() {
// utility class
}

/**
* Determines whether the given marker is a checkstyle marker.
*
* @param marker
* the marker to check
* @return <code>true</code> if the marker is a checkstyle marker
*/
public static boolean isCheckstyleMarker(IMarker marker) {
boolean isCheckstyleMarker;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public final class CheckConfigurationFactory {
refresh();
}

/**
* Utility class, not intended to be instantiated.
*/
private CheckConfigurationFactory() {
}

Expand Down Expand Up @@ -213,6 +216,13 @@ public FileVisitResult visitFile(final Path file, final BasicFileAttributes attr
}
}

/**
* Calculates the state location within the given workspace root.
*
* @param newWorkspaceRoot
* the new workspace root
* @return the target state location
*/
private static IPath getTargetStateLocation(IPath newWorkspaceRoot) {
final IPath currentWorkspaceRoot = Platform.getLocation();
IPath currentStateLocation = CheckstylePlugin.getDefault().getStateLocation();
Expand Down Expand Up @@ -277,6 +287,11 @@ private static void loadFromPersistence() throws CheckstylePluginException {
}
}

/**
* Returns the file used to store the check configurations in the state location.
*
* @return the internal configuration file
*/
private static File getInternalConfigurationFile() {
IPath configPath = CheckstylePlugin.getDefault().getStateLocation();
configPath = configPath.append(CHECKSTYLE_CONFIG_FILE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
*/
public final class CheckConfigurationTester {

/**
* Utility class, not intended to be instantiated.
*/
private CheckConfigurationTester() {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
*/
public final class CheckConfigurationXmlWriter {

/**
* Utility class, not intended to be instantiated.
*/
private CheckConfigurationXmlWriter() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ public ConfigProperty(String name, String value) {
this.value = value;
}

/**
* Determines the initial value for a property from its metadata.
*
* @param metaData
* the property metadata
* @return the initial value
*/
private static String determineInitialValue(ConfigPropertyMetadata metaData) {
final String value;
if (metaData.getOverrideDefault() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ public static List<Module> read(InputSource input) throws CheckstylePluginExcept
return rules;
}

/**
* Extracts the modules declared in the given document.
*
* @param document
* the document to read
* @return the list of modules
*/
private static List<Module> getModules(final Document document) {

final List<Module> modules = new ArrayList<>();
Expand All @@ -170,6 +177,13 @@ public void visit(final Element node) {
return modules;
}

/**
* Creates a module from the given XML element.
*
* @param node
* the module element
* @return the created module
*/
private static Module createModule(final Element node) {
final String name = node.attributeValue(XMLTags.NAME_TAG);
final RuleMetadata metadata = MetadataFactory.getRuleMetadata(name);
Expand All @@ -190,6 +204,14 @@ private static Module createModule(final Element node) {
return module;
}

/**
* Adds the property elements of the module element to the module.
*
* @param moduleEl
* the module element
* @param module
* the module to fill
*/
private static void addProperties(final Element moduleEl, final Module module) {

final List<Element> propertyEls = moduleEl.elements(XMLTags.PROPERTY_TAG);
Expand Down Expand Up @@ -233,6 +255,14 @@ else if (module.getMetaData() != null) {
}
}

/**
* Adds the message elements of the module element to the module.
*
* @param moduleEl
* the module element
* @param module
* the module to fill
*/
private static void addMessages(final Element moduleEl, final Module module) {

final List<Element> messageEls = moduleEl.elements(XMLTags.MESSAGE_TAG);
Expand All @@ -246,6 +276,14 @@ private static void addMessages(final Element moduleEl, final Module module) {
}
}

/**
* Adds the metadata elements of the module element to the module.
*
* @param moduleEl
* the module element
* @param module
* the module to fill
*/
private static void addMetadata(final Element moduleEl, final Module module) {

final List<Element> metaEls = moduleEl.elements(XMLTags.METADATA_TAG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ public static void write(OutputStream out, List<Module> modules,
}
}

/**
* Writes the given module and its remaining children into the result tree.
*
* @param module
* the module to write
* @param parent
* the parent branch in the result tree
* @param parentSeverity
* the severity inherited from the parent module
* @param remainingModules
* the list of modules that still need to be written
*/
private static void writeModules(Module module, Branch parent, Severity parentSeverity,
List<Module> remainingModules) {
final Element moduleEl = writeModule(module, parent);
Expand Down
Loading
Loading