Skip to content

Commit 34562bc

Browse files
committed
Remove ProjectFileIndex.SERVICE usage due to deprecation in newer IDEA versions
1 parent 99b6f3f commit 34562bc

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/main/java/org/infernus/idea/checkstyle/actions/ScanCurrentFile.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,18 @@ private VirtualFile getSelectedFile(
9292

9393
// validate selected file against scan scope
9494
if (selectedFile != null && scanScope != ScanScope.Everything) {
95-
final ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(project);
96-
if (projectFileIndex != null) {
97-
if (!projectFileIndex.isInSourceContent(selectedFile)) {
95+
final ProjectFileIndex projectFileIndex = ProjectFileIndex.getInstance(project);
96+
if (!projectFileIndex.isInSourceContent(selectedFile)) {
97+
selectedFile = null;
98+
}
99+
if (!scanScope.includeNonJavaSources() && selectedFile != null) {
100+
if (!FileTypes.isJava(selectedFile.getFileType())) {
98101
selectedFile = null;
99102
}
100-
if (!scanScope.includeNonJavaSources() && selectedFile != null) {
101-
if (!FileTypes.isJava(selectedFile.getFileType())) {
102-
selectedFile = null;
103-
}
104-
}
105-
if (!scanScope.includeTestClasses() && selectedFile != null) {
106-
if (projectFileIndex.isInTestSourceContent(selectedFile)) {
107-
selectedFile = null;
108-
}
103+
}
104+
if (!scanScope.includeTestClasses() && selectedFile != null) {
105+
if (projectFileIndex.isInTestSourceContent(selectedFile)) {
106+
selectedFile = null;
109107
}
110108
}
111109
}

src/main/java/org/infernus/idea/checkstyle/checker/PsiFileValidator.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private PsiFileValidator() {
2929
public static boolean isScannable(@Nullable final PsiFile psiFile,
3030
@NotNull final Optional<Module> module,
3131
@NotNull final PluginConfigurationManager pluginConfig,
32-
@Nullable ConfigurationLocation overrideConfigLocation) {
32+
@Nullable final ConfigurationLocation overrideConfigLocation) {
3333
return psiFile != null
3434
&& psiFile.isValid()
3535
&& psiFile.isPhysical()
@@ -64,10 +64,10 @@ private static boolean isGenerated(final PsiFile psiFile) {
6464
private static boolean isInSource(
6565
@NotNull final PsiFile psiFile,
6666
@NotNull final PluginConfigurationManager pluginConfig,
67-
@Nullable ConfigurationLocation overrideConfigLocation) {
67+
@Nullable final ConfigurationLocation overrideConfigLocation) {
6868
final boolean shouldBeScanned = pluginConfig.getCurrent().getScanScope() == ScanScope.Everything
6969
|| (psiFile.getVirtualFile() != null
70-
&& ProjectFileIndex.SERVICE.getInstance(psiFile.getProject()).isInSourceContent(psiFile.getVirtualFile()));
70+
&& ProjectFileIndex.getInstance(psiFile.getProject()).isInSourceContent(psiFile.getVirtualFile()));
7171
return shouldBeScanned && isInNamedScopeIfPresent(
7272
psiFile,
7373
overrideConfigLocation != null
@@ -79,7 +79,8 @@ private static boolean isInSource(
7979
* Returns true, if the given psiFile is contained in any named scope of the given pluginConfig.
8080
* If no NamedScope is provided, true will be returned.
8181
*/
82-
private static boolean isInNamedScopeIfPresent(@NotNull PsiFile psiFile, Collection<ConfigurationLocation> activeLocations) {
82+
private static boolean isInNamedScopeIfPresent(@NotNull final PsiFile psiFile,
83+
final Collection<ConfigurationLocation> activeLocations) {
8384
return activeLocations.stream()
8485
.map(ConfigurationLocation::getNamedScope)
8586
.flatMap(Optional::stream)

0 commit comments

Comments
 (0)