use of net.sf.eclipsecs.core.projectconfig.filters.UnOpenedFilesFilter in project eclipse-cs by checkstyle.
the class CheckFileOnOpenPartListener method isFileAffected.
/**
* Checks if the given file is affected by the UnOpenedFilesFilter and needs to be handled on
* editor open/close.
*
* @param file
* the file to check
* @return <code>true</code> if the file is affected, <code>false</code> otherwise
*/
private boolean isFileAffected(IFile file) {
boolean affected = false;
IProject project = file.getProject();
try {
// check if checkstyle is enabled on the project
if (project.isAccessible() && project.hasNature(CheckstyleNature.NATURE_ID)) {
IProjectConfiguration config = ProjectConfigurationFactory.getConfiguration(project);
// now check if the UnOpenedFilesFilter is active
boolean unOpenedFilesFilterActive = false;
boolean filtered = false;
List<IFilter> filters = config.getFilters();
for (IFilter filter : filters) {
if (filter instanceof UnOpenedFilesFilter && ((UnOpenedFilesFilter) filter).isEnabled()) {
unOpenedFilesFilterActive = true;
}
// check if the file would be filtered out
if (filter.isEnabled() && !(filter instanceof UnOpenedFilesFilter)) {
filtered = filtered || !filter.accept(file);
}
}
affected = unOpenedFilesFilterActive && !filtered;
}
} catch (CoreException e) {
// should never happen, since editor cannot be open
// when project isn't
CheckstyleLog.log(e);
} catch (CheckstylePluginException e) {
CheckstyleLog.log(e);
}
return affected;
}
Aggregations