Search in sources :

Example 1 with UnOpenedFilesFilter

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;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IFilter(net.sf.eclipsecs.core.projectconfig.filters.IFilter) IProjectConfiguration(net.sf.eclipsecs.core.projectconfig.IProjectConfiguration) UnOpenedFilesFilter(net.sf.eclipsecs.core.projectconfig.filters.UnOpenedFilesFilter) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) IProject(org.eclipse.core.resources.IProject)

Aggregations

IProjectConfiguration (net.sf.eclipsecs.core.projectconfig.IProjectConfiguration)1 IFilter (net.sf.eclipsecs.core.projectconfig.filters.IFilter)1 UnOpenedFilesFilter (net.sf.eclipsecs.core.projectconfig.filters.UnOpenedFilesFilter)1 CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1