From cde8e6d48a06a7e0fb178d0d7bcfb43a94a04771 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 27 Dec 2021 07:48:18 +0100 Subject: [PATCH] cleanup GitOrigin-RevId: 7639a808a5533eddc1f2781dd1f564f065dd6390 --- .../CompilerReferenceServiceBase.java | 176 +++++++++--------- 1 file changed, 85 insertions(+), 91 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/CompilerReferenceServiceBase.java b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/CompilerReferenceServiceBase.java index 4f4979d53019..949c050342ee 100644 --- a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/CompilerReferenceServiceBase.java +++ b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/CompilerReferenceServiceBase.java @@ -1,4 +1,4 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.compiler.backwardRefs; import com.intellij.compiler.CompilerDirectHierarchyInfo; @@ -12,7 +12,6 @@ import com.intellij.lang.injection.InjectedLanguageManager; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ReadAction; -import com.intellij.openapi.compiler.CompileScope; import com.intellij.openapi.compiler.CompilerManager; import com.intellij.openapi.diagnostic.ControlFlowException; import com.intellij.openapi.diagnostic.Logger; @@ -97,8 +96,8 @@ public abstract class CompilerReferenceServiceBase a.getFileTypes().stream()).collect(Collectors.toSet()); - Set affectedFileTypes = LanguageCompilerRefAdapter.EP_NAME.getExtensionList().stream().flatMap(a -> a.getAffectedFileTypes().stream()).collect(Collectors.toSet()); + myFileTypes = LanguageCompilerRefAdapter.EP_NAME.extensions().flatMap(a -> a.getFileTypes().stream()).collect(Collectors.toSet()); + Set affectedFileTypes = LanguageCompilerRefAdapter.EP_NAME.extensions().flatMap(a -> a.getAffectedFileTypes().stream()).collect(Collectors.toSet()); myDirtyScopeHolder = new DirtyScopeHolder(project, affectedFileTypes, myProjectFileIndex, @@ -123,13 +122,7 @@ public abstract class CompilerReferenceServiceBase { if (isUpToDate) { openReaderIfNeeded(IndexOpenReason.UP_TO_DATE_CACHE); @@ -150,67 +143,69 @@ public abstract class CompilerReferenceServiceBase closeReaderIfNeeded(IndexCloseReason.SHUTDOWN)); } - @Nullable @Override - public GlobalSearchScope getScopeWithCodeReferences(@NotNull PsiElement element) { - if (!isServiceEnabledFor(element)) return null; + public @Nullable GlobalSearchScope getScopeWithCodeReferences(@NotNull PsiElement element) { + if (!isServiceEnabledFor(element)) { + return null; + } try { - return CachedValuesManager.getCachedValue(element, - () -> CachedValueProvider.Result.create( - buildScopeWithReferences(getReferentFiles(element), element), - PsiModificationTracker.MODIFICATION_COUNT, - this)); + return CachedValuesManager.getCachedValue(element, () -> { + return CachedValueProvider.Result.create( + buildScopeWithReferences(getReferentFiles(element), element), + PsiModificationTracker.MODIFICATION_COUNT, + this); + }); } catch (RuntimeException e1) { return onException(e1, "scope without code references"); } } - @Nullable @Override - public GlobalSearchScope getScopeWithImplicitToStringCodeReferences(@NotNull PsiElement aClass) { - if (!isServiceEnabledFor(aClass)) return null; + public @Nullable GlobalSearchScope getScopeWithImplicitToStringCodeReferences(@NotNull PsiElement aClass) { + if (!isServiceEnabledFor(aClass)) { + return null; + } try { - return CachedValuesManager.getCachedValue(aClass, - () -> CachedValueProvider.Result.create( - buildScopeWithReferences(getReferentFileIdsViaImplicitToString(aClass), aClass), - PsiModificationTracker.MODIFICATION_COUNT, - this)); + return CachedValuesManager.getCachedValue(aClass, () -> { + return CachedValueProvider.Result.create( + buildScopeWithReferences(getReferentFileIdsViaImplicitToString(aClass), aClass), + PsiModificationTracker.MODIFICATION_COUNT, + this); + }); } - catch (RuntimeException e1) { - return onException(e1, "scope without implicit toString references"); + catch (RuntimeException e) { + return onException(e, "scope without implicit toString references"); } } - @Nullable @Override - public CompilerDirectHierarchyInfo getDirectInheritors(@NotNull PsiNamedElement aClass, - @NotNull GlobalSearchScope searchScope, - @NotNull FileType searchFileType) { + public @Nullable CompilerDirectHierarchyInfo getDirectInheritors(@NotNull PsiNamedElement aClass, + @NotNull GlobalSearchScope searchScope, + @NotNull FileType searchFileType) { return getHierarchyInfo(aClass, searchScope, searchFileType, CompilerHierarchySearchType.DIRECT_INHERITOR); } - @Nullable @Override - public CompilerDirectHierarchyInfo getFunExpressions(@NotNull PsiNamedElement functionalInterface, - @NotNull GlobalSearchScope searchScope, - @NotNull FileType searchFileType) { + public @Nullable CompilerDirectHierarchyInfo getFunExpressions(@NotNull PsiNamedElement functionalInterface, + @NotNull GlobalSearchScope searchScope, + @NotNull FileType searchFileType) { return getHierarchyInfo(functionalInterface, searchScope, searchFileType, CompilerHierarchySearchType.FUNCTIONAL_EXPRESSION); } - @Nullable @Override - public Integer getCompileTimeOccurrenceCount(@NotNull PsiElement element, boolean isConstructorSuggestion) { + public @Nullable Integer getCompileTimeOccurrenceCount(@NotNull PsiElement element, boolean isConstructorSuggestion) { if (!isServiceEnabledFor(element)) return null; try { - return CachedValuesManager.getCachedValue(element, - () -> CachedValueProvider.Result.create(ConcurrentFactoryMap.createMap( - (Boolean constructorSuggestion) -> calculateOccurrenceCount(element, - constructorSuggestion.booleanValue())), - PsiModificationTracker.MODIFICATION_COUNT, - this)).get(Boolean.valueOf(isConstructorSuggestion)); + return CachedValuesManager.getCachedValue(element, () -> { + return CachedValueProvider.Result.create(ConcurrentFactoryMap.createMap((Boolean constructorSuggestion) -> { + return calculateOccurrenceCount(element, constructorSuggestion.booleanValue()); + }), + PsiModificationTracker.MODIFICATION_COUNT, + this); + }).get(Boolean.valueOf(isConstructorSuggestion)); } catch (RuntimeException e) { return onException(e, "weighting for completion"); @@ -225,10 +220,16 @@ public abstract class CompilerReferenceServiceBase candidatesPerFile = ReadAction.compute(() -> { if (myProject.isDisposed()) throw new ProcessCanceledException(); - return CachedValuesManager.getCachedValue(aClass, () -> CachedValueProvider.Result.create( - ConcurrentFactoryMap.createMap((HierarchySearchKey key) -> calculateDirectInheritors(aClass, - key.mySearchFileType, - key.mySearchType)), - PsiModificationTracker.MODIFICATION_COUNT, this)).get(new HierarchySearchKey(searchType, searchFileType)); + return CachedValuesManager.getCachedValue(aClass, () -> { + return CachedValueProvider.Result.create( + ConcurrentFactoryMap.createMap((HierarchySearchKey key) -> calculateDirectInheritors(aClass, + key.mySearchFileType, + key.mySearchType)), + PsiModificationTracker.MODIFICATION_COUNT, this); + }).get(new HierarchySearchKey(searchType, searchFileType)); }); if (candidatesPerFile == null) return null; @@ -323,8 +328,7 @@ public abstract class CompilerReferenceServiceBase referentFiles, @NotNull PsiElement element) { + private @Nullable GlobalSearchScope buildScopeWithReferences(@Nullable Set referentFiles, @NotNull PsiElement element) { if (referentFiles == null) return null; GlobalSearchScope referencesScope = GlobalSearchScope.filesWithoutLibrariesScope(myProject, referentFiles); @@ -337,18 +341,16 @@ public abstract class CompilerReferenceServiceBase getReferentFiles(@NotNull PsiElement element) { + private @Nullable Set getReferentFiles(@NotNull PsiElement element) { return getReferentFiles(element, true, (ref, elementPlace) -> myReader.findReferentFileIds(ref, elementPlace == ElementPlace.SRC)); } @@ -369,15 +371,13 @@ public abstract class CompilerReferenceServiceBase getReferentFileIdsViaImplicitToString(@NotNull PsiElement element) { + private @Nullable Set getReferentFileIdsViaImplicitToString(@NotNull PsiElement element) { return getReferentFiles(element, false, (ref, elementPlace) -> myReader.findFileIdsWithImplicitToString(ref)); } - @Nullable - private Set getReferentFiles(@NotNull PsiElement element, - boolean buildHierarchyForLibraryElements, - @NotNull ReferentFileSearcher referentFileSearcher) { + private @Nullable Set getReferentFiles(@NotNull PsiElement element, + boolean buildHierarchyForLibraryElements, + @NotNull ReferentFileSearcher referentFileSearcher) { final CompilerElementInfo compilerElementInfo = asCompilerElements(element, buildHierarchyForLibraryElements, true); if (compilerElementInfo == null) return null; @@ -405,10 +405,9 @@ public abstract class CompilerReferenceServiceBase T computeInLibraryScope(ThrowableComputable action) throws E { + public @NotNull T computeInLibraryScope(ThrowableComputable action) throws E { myIsInsideLibraryScope.set(true); try { return action.compute(); @@ -637,8 +635,7 @@ public abstract class CompilerReferenceServiceBase referentFileIds = getReferentFiles(element); @@ -650,8 +647,7 @@ public abstract class CompilerReferenceServiceBase T onException(@NotNull Exception e, @NotNull String actionName) { + protected @Nullable T onException(@NotNull Exception e, @NotNull String actionName) { if (e instanceof ControlFlowException) { + //noinspection CastConflictsWithInstanceof throw (RuntimeException)e; } @@ -693,8 +688,7 @@ public abstract class CompilerReferenceServiceBase