Search in sources :

Example 1 with CheckstyleInternalObject

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

the class CheckStyleCodeStyleImporter method importScheme.

@Nullable
@Override
public CodeStyleScheme importScheme(@NotNull final Project project, @NotNull final VirtualFile selectedFile, @NotNull final CodeStyleScheme currentScheme, @NotNull final SchemeFactory<CodeStyleScheme> schemeFactory) throws SchemeImportException {
    try {
        CodeStyleScheme targetScheme = currentScheme;
        if (currentScheme.isDefault()) {
            targetScheme = schemeFactory.createNewScheme(currentScheme.getName());
        }
        CheckstyleInternalObject configuration = loadConfiguration(project, selectedFile);
        if (configuration != null) {
            importConfiguration(checkstyleProjectService(project), configuration, targetScheme.getCodeStyleSettings());
            return targetScheme;
        }
    } catch (Exception e) {
        LOG.warn("Failed to import style", e);
        throw new SchemeImportException(e);
    }
    return null;
}
Also used : CodeStyleScheme(com.intellij.psi.codeStyle.CodeStyleScheme) SchemeImportException(com.intellij.openapi.options.SchemeImportException) CheckstyleInternalObject(org.infernus.idea.checkstyle.csapi.CheckstyleInternalObject) CheckStylePluginException(org.infernus.idea.checkstyle.exception.CheckStylePluginException) SchemeImportException(com.intellij.openapi.options.SchemeImportException) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with CheckstyleInternalObject

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

the class CheckStyleCodeStyleImporter method importScheme.

@Override
@Nullable
public CodeStyleScheme importScheme(@NotNull Project project, @NotNull VirtualFile selectedFile, @NotNull CodeStyleScheme currentScheme, @NotNull SchemeFactory<? extends CodeStyleScheme> schemeFactory) throws SchemeImportException {
    try {
        CodeStyleScheme targetScheme = currentScheme;
        if (currentScheme.isDefault()) {
            targetScheme = schemeFactory.createNewScheme(currentScheme.getName());
        }
        CheckstyleInternalObject configuration = loadConfiguration(project, selectedFile);
        if (configuration != null) {
            importConfiguration(checkstyleProjectService(project), configuration, targetScheme.getCodeStyleSettings());
            return targetScheme;
        }
    } catch (Exception e) {
        LOG.warn("Failed to import style", e);
        throw new SchemeImportException(e);
    }
    return null;
}
Also used : CodeStyleScheme(com.intellij.psi.codeStyle.CodeStyleScheme) SchemeImportException(com.intellij.openapi.options.SchemeImportException) CheckstyleInternalObject(org.infernus.idea.checkstyle.csapi.CheckstyleInternalObject) CheckStylePluginException(org.infernus.idea.checkstyle.exception.CheckStylePluginException) SchemeImportException(com.intellij.openapi.options.SchemeImportException) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with CheckstyleInternalObject

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

the class OpLoadConfigurationTest method testLoadBundledSunChecks.

@Test
public void testLoadBundledSunChecks() {
    final ConfigurationLocationFactory clf = new ConfigurationLocationFactory();
    CheckstyleProjectService projectService = mock(CheckstyleProjectService.class);
    when(projectService.underlyingClassLoader()).thenReturn(getClass().getClassLoader());
    CheckstyleInternalObject csConfig = new CheckstyleActionsImpl(PROJECT, projectService).loadConfiguration(clf.create(BundledConfig.SUN_CHECKS, mock(Project.class)), true, null);
    Assert.assertNotNull(csConfig);
}
Also used : CheckstyleActionsImpl(org.infernus.idea.checkstyle.service.CheckstyleActionsImpl) ConfigurationLocationFactory(org.infernus.idea.checkstyle.model.ConfigurationLocationFactory) CheckstyleInternalObject(org.infernus.idea.checkstyle.csapi.CheckstyleInternalObject) CheckstyleProjectService(org.infernus.idea.checkstyle.CheckstyleProjectService) Test(org.junit.Test)

Example 4 with CheckstyleInternalObject

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

the class OpLoadConfigurationTest method testLoadFromString.

@Test
public void testLoadFromString() throws IOException, URISyntaxException {
    CheckstyleProjectService projectService = mock(CheckstyleProjectService.class);
    when(projectService.underlyingClassLoader()).thenReturn(getClass().getClassLoader());
    final String configXml = FileUtil.readFile("cmd/config-ok.xml");
    CheckstyleInternalObject csConfig = new CheckstyleActionsImpl(PROJECT, projectService).loadConfiguration(configXml);
    Assert.assertNotNull(csConfig);
}
Also used : CheckstyleActionsImpl(org.infernus.idea.checkstyle.service.CheckstyleActionsImpl) CheckstyleInternalObject(org.infernus.idea.checkstyle.csapi.CheckstyleInternalObject) CheckstyleProjectService(org.infernus.idea.checkstyle.CheckstyleProjectService) Test(org.junit.Test)

Example 5 with CheckstyleInternalObject

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

the class OpLoadConfigurationTest method testLoadBundledGoogleChecks.

@Test
public void testLoadBundledGoogleChecks() {
    final ConfigurationLocationFactory clf = new ConfigurationLocationFactory();
    CheckstyleProjectService projectService = mock(CheckstyleProjectService.class);
    when(projectService.underlyingClassLoader()).thenReturn(getClass().getClassLoader());
    CheckstyleInternalObject csConfig = new CheckstyleActionsImpl(PROJECT, projectService).loadConfiguration(clf.create(BundledConfig.GOOGLE_CHECKS, mock(Project.class)), true, null);
    Assert.assertNotNull(csConfig);
}
Also used : CheckstyleActionsImpl(org.infernus.idea.checkstyle.service.CheckstyleActionsImpl) ConfigurationLocationFactory(org.infernus.idea.checkstyle.model.ConfigurationLocationFactory) CheckstyleInternalObject(org.infernus.idea.checkstyle.csapi.CheckstyleInternalObject) CheckstyleProjectService(org.infernus.idea.checkstyle.CheckstyleProjectService) Test(org.junit.Test)

Aggregations

CheckstyleInternalObject (org.infernus.idea.checkstyle.csapi.CheckstyleInternalObject)5 CheckstyleProjectService (org.infernus.idea.checkstyle.CheckstyleProjectService)3 CheckstyleActionsImpl (org.infernus.idea.checkstyle.service.CheckstyleActionsImpl)3 Test (org.junit.Test)3 SchemeImportException (com.intellij.openapi.options.SchemeImportException)2 CodeStyleScheme (com.intellij.psi.codeStyle.CodeStyleScheme)2 CheckStylePluginException (org.infernus.idea.checkstyle.exception.CheckStylePluginException)2 ConfigurationLocationFactory (org.infernus.idea.checkstyle.model.ConfigurationLocationFactory)2 Nullable (org.jetbrains.annotations.Nullable)2