Search in sources :

Example 1 with TabWidthAndBaseDirProvider

use of org.infernus.idea.checkstyle.csapi.TabWidthAndBaseDirProvider in project checkstyle-idea by jshiell.

the class ServiceLayerBasicTest method createChecker.

private CheckStyleChecker createChecker(@NotNull final String configXmlFile) throws IOException, URISyntaxException {
    final ConfigurationLocation configLoc = new StringConfigurationLocation(FileUtil.readFile(configXmlFile), mock(Project.class));
    final Module module = mock(Module.class);
    when(module.getProject()).thenReturn(PROJECT);
    final TabWidthAndBaseDirProvider configurations = mock(TabWidthAndBaseDirProvider.class);
    when(configurations.tabWidth()).thenReturn(2);
    when(configurations.baseDir()).thenReturn(Optional.of(new File(getClass().getResource(configXmlFile).toURI()).getParent()));
    final CheckstyleActions csInstance = checkstyleProjectService.getCheckstyleInstance();
    return csInstance.createChecker(module, configLoc, Collections.emptyMap(), configurations, getClass().getClassLoader());
}
Also used : CheckstyleActions(org.infernus.idea.checkstyle.csapi.CheckstyleActions) Project(com.intellij.openapi.project.Project) ConfigurationLocation(org.infernus.idea.checkstyle.model.ConfigurationLocation) TabWidthAndBaseDirProvider(org.infernus.idea.checkstyle.csapi.TabWidthAndBaseDirProvider) Module(com.intellij.openapi.module.Module) File(java.io.File)

Example 2 with TabWidthAndBaseDirProvider

use of org.infernus.idea.checkstyle.csapi.TabWidthAndBaseDirProvider in project checkstyle-idea by jshiell.

the class OpCreateChecker method execute.

@Override
@NotNull
public CheckStyleChecker execute(@NotNull final Project project) throws CheckstyleException {
    final Configuration csConfig = loadConfig(project);
    final Checker checker = new Checker();
    // for Checkstyle to load modules (checks)
    checker.setModuleClassLoader(getClass().getClassLoader());
    // for checks to load the classes and resources to be analyzed
    setClassLoader(checker, loaderOfCheckedCode);
    try {
        checker.configure(csConfig);
    } catch (Error e) {
        // e.g. java.lang.NoClassDefFoundError thrown by Checkstyle for pre-8.0 custom checks
        throw new CheckstyleToolException(e);
    }
    CheckerWithConfig cwc = new CheckerWithConfig(checker, csConfig);
    final TabWidthAndBaseDirProvider configs = configurations != null ? configurations : new Configurations(module, csConfig);
    return new CheckStyleChecker(cwc, configs.tabWidth(), configs.baseDir(), checkstyleProjectService.getCheckstyleInstance());
}
Also used : CheckStyleChecker(org.infernus.idea.checkstyle.checker.CheckStyleChecker) CheckStyleChecker(org.infernus.idea.checkstyle.checker.CheckStyleChecker) Checker(com.puppycrawl.tools.checkstyle.Checker) Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) CheckerWithConfig(org.infernus.idea.checkstyle.service.entities.CheckerWithConfig) CheckstyleToolException(org.infernus.idea.checkstyle.exception.CheckstyleToolException) TabWidthAndBaseDirProvider(org.infernus.idea.checkstyle.csapi.TabWidthAndBaseDirProvider) Configurations(org.infernus.idea.checkstyle.service.Configurations) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with TabWidthAndBaseDirProvider

use of org.infernus.idea.checkstyle.csapi.TabWidthAndBaseDirProvider in project checkstyle-idea by jshiell.

the class VersionMixExceptionTest method createChecker.

private CheckStyleChecker createChecker(@NotNull final Module pModule) throws URISyntaxException, IOException {
    final ConfigurationLocation configLoc = new StringConfigurationLocation(readFile(CONFIG_FILE), mock(Project.class));
    final TabWidthAndBaseDirProvider configurations = mock(TabWidthAndBaseDirProvider.class);
    when(configurations.tabWidth()).thenReturn(2);
    final String baseDir = new File(getClass().getResource(CONFIG_FILE).toURI()).getParent();
    when(configurations.baseDir()).thenReturn(Optional.of(baseDir));
    return csService.getCheckstyleInstance().createChecker(pModule, configLoc, Collections.emptyMap(), configurations, getClass().getClassLoader());
}
Also used : Project(com.intellij.openapi.project.Project) ConfigurationLocation(org.infernus.idea.checkstyle.model.ConfigurationLocation) TabWidthAndBaseDirProvider(org.infernus.idea.checkstyle.csapi.TabWidthAndBaseDirProvider) ScannableFile(org.infernus.idea.checkstyle.checker.ScannableFile) File(java.io.File)

Aggregations

TabWidthAndBaseDirProvider (org.infernus.idea.checkstyle.csapi.TabWidthAndBaseDirProvider)3 Project (com.intellij.openapi.project.Project)2 File (java.io.File)2 ConfigurationLocation (org.infernus.idea.checkstyle.model.ConfigurationLocation)2 Module (com.intellij.openapi.module.Module)1 Checker (com.puppycrawl.tools.checkstyle.Checker)1 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)1 CheckStyleChecker (org.infernus.idea.checkstyle.checker.CheckStyleChecker)1 ScannableFile (org.infernus.idea.checkstyle.checker.ScannableFile)1 CheckstyleActions (org.infernus.idea.checkstyle.csapi.CheckstyleActions)1 CheckstyleToolException (org.infernus.idea.checkstyle.exception.CheckstyleToolException)1 Configurations (org.infernus.idea.checkstyle.service.Configurations)1 CheckerWithConfig (org.infernus.idea.checkstyle.service.entities.CheckerWithConfig)1 NotNull (org.jetbrains.annotations.NotNull)1