diff --git a/CHANGELOG.md b/CHANGELOG.md index 9628f6a3..07e4015e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # CheckStyle-IDEA Changelog +* **5.96.0** Fixed: Refactored code to avoid IDEA triggering the wrong constructor (#653). * **5.96.0** New: Added Checkstyle 10.18.2. * **5.95.0** Fixed: Improved property substitution for code-style importer (#651). * **5.95.0** New: Added CheckStyle 10.18.1. diff --git a/src/main/java/org/infernus/idea/checkstyle/util/ProjectFilePaths.java b/src/main/java/org/infernus/idea/checkstyle/util/ProjectFilePaths.java index c46a4018..71db6fe1 100644 --- a/src/main/java/org/infernus/idea/checkstyle/util/ProjectFilePaths.java +++ b/src/main/java/org/infernus/idea/checkstyle/util/ProjectFilePaths.java @@ -27,15 +27,10 @@ public ProjectFilePaths(@NotNull final Project project) { this(project, File.separatorChar, File::getAbsolutePath, project.getService(ProjectPaths.class)); } - public ProjectFilePaths(@NotNull final Project project, - @NotNull final ProjectPaths projectPaths) { - this(project, File.separatorChar, File::getAbsolutePath, projectPaths); - } - - public ProjectFilePaths(@NotNull final Project project, - final char separatorChar, - @NotNull final Function absolutePathOf, - @NotNull final ProjectPaths projectPaths) { + private ProjectFilePaths(@NotNull final Project project, + final char separatorChar, + @NotNull final Function absolutePathOf, + @NotNull final ProjectPaths projectPaths) { this.project = project; this.separatorChar = separatorChar; this.absolutePathOf = absolutePathOf; @@ -43,6 +38,18 @@ public ProjectFilePaths(@NotNull final Project project, this.projectPaths = projectPaths; } + public static ProjectFilePaths testInstanceWith(@NotNull final Project project, + @NotNull final ProjectPaths projectPaths) { + return new ProjectFilePaths(project, File.separatorChar, File::getAbsolutePath, projectPaths); + } + + public static ProjectFilePaths testInstanceWith(@NotNull final Project project, + final char separatorChar, + @NotNull final Function absolutePathOf, + @NotNull final ProjectPaths projectPaths) { + return new ProjectFilePaths(project, separatorChar, absolutePathOf, projectPaths); + } + @Nullable public String makeProjectRelative(@Nullable final String path) { if (path == null || project.isDefault()) { diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 1893b26d..055a7d8b 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -25,6 +25,7 @@ +
  • 5.96.0: Fixed: Refactored code to avoid IDEA triggering the wrong constructor (#653).
  • 5.96.0: New: Added Checkstyle 10.18.2.
  • 5.95.0: Fixed: Improved property substitution for code-style importer (#651).
  • 5.95.0: New: Added Checkstyle 10.18.1.
  • diff --git a/src/test/java/org/infernus/idea/checkstyle/config/DescriptorTest.java b/src/test/java/org/infernus/idea/checkstyle/config/DescriptorTest.java index eeaa4671..9d9abd5f 100644 --- a/src/test/java/org/infernus/idea/checkstyle/config/DescriptorTest.java +++ b/src/test/java/org/infernus/idea/checkstyle/config/DescriptorTest.java @@ -23,7 +23,7 @@ public class DescriptorTest { @Before public void setUp() { when(project.getService(ConfigurationLocationFactory.class)).thenReturn(new ConfigurationLocationFactory()); - when(project.getService(ProjectFilePaths.class)).thenReturn(new ProjectFilePaths(project, new ProjectPaths())); + when(project.getService(ProjectFilePaths.class)).thenReturn(ProjectFilePaths.testInstanceWith(project, new ProjectPaths())); } @Test diff --git a/src/test/java/org/infernus/idea/checkstyle/config/LegacyProjectConfigurationStateDeserialiserTest.java b/src/test/java/org/infernus/idea/checkstyle/config/LegacyProjectConfigurationStateDeserialiserTest.java index 7a28b310..d3751385 100644 --- a/src/test/java/org/infernus/idea/checkstyle/config/LegacyProjectConfigurationStateDeserialiserTest.java +++ b/src/test/java/org/infernus/idea/checkstyle/config/LegacyProjectConfigurationStateDeserialiserTest.java @@ -29,7 +29,7 @@ public class LegacyProjectConfigurationStateDeserialiserTest { private final Project project = TestHelper.mockProject(); private final ProjectPaths projectPaths = mock(ProjectPaths.class); private final ConfigurationLocationFactory configurationLocationFactory = new ConfigurationLocationFactory(); - private final ProjectFilePaths projectFilePaths = new ProjectFilePaths(project, File.separatorChar, File::getAbsolutePath, projectPaths); + private final ProjectFilePaths projectFilePaths = ProjectFilePaths.testInstanceWith(project, File.separatorChar, File::getAbsolutePath, projectPaths); @Before public void configureMocks() { diff --git a/src/test/java/org/infernus/idea/checkstyle/config/ModuleConfigurationStateTest.java b/src/test/java/org/infernus/idea/checkstyle/config/ModuleConfigurationStateTest.java index 8a862ddf..dfdc23a2 100644 --- a/src/test/java/org/infernus/idea/checkstyle/config/ModuleConfigurationStateTest.java +++ b/src/test/java/org/infernus/idea/checkstyle/config/ModuleConfigurationStateTest.java @@ -36,7 +36,7 @@ public class ModuleConfigurationStateTest { private final PluginConfigurationManager pluginConfigurationManager = new PluginConfigurationManager(project); private final ProjectPaths projectPaths = mock(ProjectPaths.class); private final ConfigurationLocationFactory configurationLocationFactory = new ConfigurationLocationFactory(); - private final ProjectFilePaths projectFilePaths = new ProjectFilePaths(project, File.separatorChar, File::getAbsolutePath, projectPaths); + private final ProjectFilePaths projectFilePaths = ProjectFilePaths.testInstanceWith(project, File.separatorChar, File::getAbsolutePath, projectPaths); private final NamedScope allScope = NamedScopeHelper.getScopeByIdWithDefaultFallback(project, "All"); private ConfigurationLocation expectedLocation; diff --git a/src/test/java/org/infernus/idea/checkstyle/model/ConfigurationLocationFactoryTest.java b/src/test/java/org/infernus/idea/checkstyle/model/ConfigurationLocationFactoryTest.java index a2da0fb4..a2b0876e 100644 --- a/src/test/java/org/infernus/idea/checkstyle/model/ConfigurationLocationFactoryTest.java +++ b/src/test/java/org/infernus/idea/checkstyle/model/ConfigurationLocationFactoryTest.java @@ -25,7 +25,7 @@ public class ConfigurationLocationFactoryTest { @Before public void setUp() { when(project.getService(ConfigurationLocationFactory.class)).thenReturn(underTest); - when(project.getService(ProjectFilePaths.class)).thenReturn(new ProjectFilePaths(project, new ProjectPaths())); + when(project.getService(ProjectFilePaths.class)).thenReturn(ProjectFilePaths.testInstanceWith(project, new ProjectPaths())); } @Test diff --git a/src/test/java/org/infernus/idea/checkstyle/model/ConfigurationLocationTest.java b/src/test/java/org/infernus/idea/checkstyle/model/ConfigurationLocationTest.java index 592939bf..2735f09e 100644 --- a/src/test/java/org/infernus/idea/checkstyle/model/ConfigurationLocationTest.java +++ b/src/test/java/org/infernus/idea/checkstyle/model/ConfigurationLocationTest.java @@ -241,7 +241,7 @@ public Object clone() { @Test public void testSorting() { final Project project = TestHelper.mockProject(); - when(project.getService(ProjectFilePaths.class)).thenReturn(new ProjectFilePaths(project, new ProjectPaths())); + when(project.getService(ProjectFilePaths.class)).thenReturn(ProjectFilePaths.testInstanceWith(project, new ProjectPaths())); List list = new ArrayList<>(); FileConfigurationLocation fcl = new FileConfigurationLocation(project, "id1", ConfigurationType.LOCAL_FILE); diff --git a/src/test/java/org/infernus/idea/checkstyle/model/FileConfigurationLocationTest.java b/src/test/java/org/infernus/idea/checkstyle/model/FileConfigurationLocationTest.java index cdc569b3..a89a1efa 100644 --- a/src/test/java/org/infernus/idea/checkstyle/model/FileConfigurationLocationTest.java +++ b/src/test/java/org/infernus/idea/checkstyle/model/FileConfigurationLocationTest.java @@ -151,7 +151,7 @@ private ProjectFilePaths testProjectFilePaths(final char separatorChar, final Pr return FilenameUtils.separatorsToUnix(file.getPath()); }; - return new ProjectFilePaths(project, separatorChar, absolutePathOf, projectPaths); + return ProjectFilePaths.testInstanceWith(project, separatorChar, absolutePathOf, projectPaths); } } diff --git a/src/test/java/org/infernus/idea/checkstyle/model/RelativeFileConfigurationLocationTest.java b/src/test/java/org/infernus/idea/checkstyle/model/RelativeFileConfigurationLocationTest.java index e5c5ec4c..ccf3725d 100644 --- a/src/test/java/org/infernus/idea/checkstyle/model/RelativeFileConfigurationLocationTest.java +++ b/src/test/java/org/infernus/idea/checkstyle/model/RelativeFileConfigurationLocationTest.java @@ -46,7 +46,7 @@ public void setUp() { }; final Project project = TestHelper.mockProject(); - ProjectFilePaths testProjectFilePaths = new ProjectFilePaths(project, '/', absolutePathOf, projectPaths); + ProjectFilePaths testProjectFilePaths = ProjectFilePaths.testInstanceWith(project, '/', absolutePathOf, projectPaths); when(project.getService(ProjectFilePaths.class)).thenReturn(testProjectFilePaths); when(projectBase.getPath()).thenReturn(PROJECT_BASE_PATH); diff --git a/src/test/java/org/infernus/idea/checkstyle/util/ProjectFilePathsTest.java b/src/test/java/org/infernus/idea/checkstyle/util/ProjectFilePathsTest.java index a098ff0f..d9c3cad5 100644 --- a/src/test/java/org/infernus/idea/checkstyle/util/ProjectFilePathsTest.java +++ b/src/test/java/org/infernus/idea/checkstyle/util/ProjectFilePathsTest.java @@ -145,7 +145,7 @@ private ProjectFilePaths projectFilePathsForUnix() { when(projectBaseFile.getPath()).thenReturn(UNIX_PROJECT_BASE_PATH); when(projectPaths.projectPath(project)).thenReturn(projectBaseFile); - return new ProjectFilePaths(project, '/', File::getAbsolutePath, projectPaths); + return ProjectFilePaths.testInstanceWith(project, '/', File::getAbsolutePath, projectPaths); } private ProjectFilePaths projectFilePathsForWindows() { @@ -156,7 +156,7 @@ private ProjectFilePaths projectFilePathsForWindows() { when(projectBaseFile.getPath()).thenReturn(WINDOWS_PROJECT_BASE_PATH); when(projectPaths.projectPath(project)).thenReturn(projectBaseFile); - return new ProjectFilePaths(project, '\\', file -> { + return ProjectFilePaths.testInstanceWith(project, '\\', file -> { // a nasty hack to pretend we're on a Windows box when required... if (file.getPath().startsWith("c:")) { return file.getPath().replace('/', '\\').replaceAll("\\\\\\\\", "\\\\");