diff --git a/java/compiler/impl/src/com/intellij/compiler/options/ValidationConfigurable.java b/java/compiler/impl/src/com/intellij/compiler/options/ValidationConfigurable.java index bcacc235a2e0..68a99bc134de 100644 --- a/java/compiler/impl/src/com/intellij/compiler/options/ValidationConfigurable.java +++ b/java/compiler/impl/src/com/intellij/compiler/options/ValidationConfigurable.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.compiler.options; import com.intellij.ide.util.ElementsChooser; @@ -21,7 +7,6 @@ import com.intellij.openapi.compiler.CompilerBundle; import com.intellij.openapi.compiler.CompilerManager; import com.intellij.openapi.compiler.Validator; import com.intellij.openapi.compiler.options.ExcludedEntriesConfigurable; -import com.intellij.openapi.compiler.options.ExcludesConfiguration; import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; @@ -71,13 +56,12 @@ public class ValidationConfigurable implements SearchableConfigurable, Configura myExcludedEntriesPanel.setBorder(IdeBorderFactory.createTitledBorder("Exclude from validation:", false, JBUI.insetsTop(8)).setShowLine(false)); } - private static ExcludedEntriesConfigurable createExcludedConfigurable(final Project project) { - final ExcludesConfiguration configuration = ValidationConfiguration.getExcludedEntriesConfiguration(project); - final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex(); + private static ExcludedEntriesConfigurable createExcludedConfigurable(@NotNull Project project) { + ProjectFileIndex index = project.isDefault() ? null : ProjectRootManager.getInstance(project).getFileIndex(); final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, false, false, false, true) { @Override public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { - return super.isFileVisible(file, showHiddenFiles) && (project.isDefault() || !index.isExcluded(file)); + return super.isFileVisible(file, showHiddenFiles) && (index == null || !index.isExcluded(file)); } }; @@ -87,7 +71,7 @@ public class ValidationConfigurable implements SearchableConfigurable, Configura Collections.addAll(allContentRoots, moduleContentRoots); } descriptor.setRoots(allContentRoots); - return new ExcludedEntriesConfigurable(project, descriptor, configuration); + return new ExcludedEntriesConfigurable(project, descriptor, ValidationConfiguration.getExcludedEntriesConfiguration(project)); } @Override diff --git a/java/java-impl/src/com/intellij/psi/NonClasspathResolveScopeEnlarger.java b/java/java-impl/src/com/intellij/psi/NonClasspathResolveScopeEnlarger.java index 981036ded84b..016316127211 100644 --- a/java/java-impl/src/com/intellij/psi/NonClasspathResolveScopeEnlarger.java +++ b/java/java-impl/src/com/intellij/psi/NonClasspathResolveScopeEnlarger.java @@ -16,10 +16,13 @@ import java.util.List; * @author peter */ public class NonClasspathResolveScopeEnlarger extends ResolveScopeEnlarger { - @Override public SearchScope getAdditionalResolveScope(@NotNull VirtualFile file, Project project) { - ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(project); + if (project.isDefault()) { + return null; + } + + ProjectFileIndex index = ProjectFileIndex.getInstance(project); if (index.isInLibraryClasses(file) || index.isInContent(file)) { return null; } diff --git a/java/java-impl/src/com/intellij/psi/impl/file/PsiJavaDirectoryFactory.java b/java/java-impl/src/com/intellij/psi/impl/file/PsiJavaDirectoryFactory.java index d90f4a8d4ec0..84b97cd77edc 100644 --- a/java/java-impl/src/com/intellij/psi/impl/file/PsiJavaDirectoryFactory.java +++ b/java/java-impl/src/com/intellij/psi/impl/file/PsiJavaDirectoryFactory.java @@ -1,20 +1,7 @@ -/* - * Copyright 2000-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.impl.file; +import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.io.FileUtil; @@ -29,11 +16,11 @@ import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; /** * @author yole */ -public class PsiJavaDirectoryFactory extends PsiDirectoryFactory { +public final class PsiJavaDirectoryFactory extends PsiDirectoryFactory { private final PsiManagerImpl myManager; - public PsiJavaDirectoryFactory(final PsiManagerImpl manager) { - myManager = manager; + public PsiJavaDirectoryFactory(@NotNull Project project) { + myManager = (PsiManagerImpl)PsiManager.getInstance(project); } @NotNull diff --git a/java/java-impl/src/com/intellij/psi/refResolve/RefResolveServiceImpl.java b/java/java-impl/src/com/intellij/psi/refResolve/RefResolveServiceImpl.java index ca63aa6d1fce..67bfbc6f549d 100644 --- a/java/java-impl/src/com/intellij/psi/refResolve/RefResolveServiceImpl.java +++ b/java/java-impl/src/com/intellij/psi/refResolve/RefResolveServiceImpl.java @@ -4,8 +4,9 @@ package com.intellij.psi.refResolve; import com.intellij.ide.PowerSaveMode; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationListener; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; -import com.intellij.openapi.application.ex.ApplicationEx; +import com.intellij.openapi.application.ex.ApplicationManagerEx; import com.intellij.openapi.application.ex.ApplicationUtil; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileTypeRegistry; @@ -61,7 +62,7 @@ import java.util.concurrent.FutureTask; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; -public class RefResolveServiceImpl extends RefResolveService implements Runnable, Disposable { +public final class RefResolveServiceImpl extends RefResolveService implements Runnable, Disposable { private static final Logger LOG = Logger.getInstance(RefResolveServiceImpl.class); private final AtomicInteger fileCount = new AtomicInteger(); @@ -71,7 +72,6 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable private final Deque filesToResolve = new ArrayDeque<>(); // guarded by filesToResolve private final ConcurrentBitSet fileIsInQueue = new ConcurrentBitSet(); private final ConcurrentBitSet fileIsResolved; - private final ApplicationEx myApplication; private final Project myProject; private volatile boolean myDisposed; private volatile boolean upToDate; @@ -79,16 +79,10 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable private final FileWriter log; private final ProjectFileIndex myProjectFileIndex; - public RefResolveServiceImpl(final Project project, - final MessageBus messageBus, - final PsiManager psiManager, - StartupManager startupManager, - ApplicationEx application, - ProjectFileIndex projectFileIndex) throws IOException { + public RefResolveServiceImpl(@NotNull Project project) throws IOException { myProject = project; ((FutureTask)resolveProcess).run(); - myApplication = application; - myProjectFileIndex = projectFileIndex; + myProjectFileIndex = ProjectFileIndex.getInstance(project); if (ENABLED) { log = new FileWriter(new File(getStorageDirectory(), "log.txt")); @@ -109,9 +103,9 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable fileIsResolved.clear(); } Disposer.register(this, storage); - if (!application.isUnitTestMode()) { - startupManager.runWhenProjectIsInitialized(() -> { - initListeners(messageBus, psiManager); + if (!ApplicationManager.getApplication().isUnitTestMode()) { + StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> { + initListeners(project.getMessageBus(), PsiManager.getInstance(project)); startThread(); }); } @@ -211,7 +205,7 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable } }); - myApplication.addApplicationListener(new ApplicationListener() { + ApplicationManagerEx.getApplicationEx().addApplicationListener(new ApplicationListener() { @Override public void beforeWriteActionStart(@NotNull Object action) { disable(); @@ -411,14 +405,14 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable upToDate = false; - myApplication.invokeLater(() -> { + ApplicationManagerEx.getApplicationEx().invokeLater(() -> { if (!resolveProcess.isDone()) return; log("Started to resolve " + files.size() + " files"); Task.Backgroundable backgroundable = new Task.Backgroundable(myProject, "Resolving files...", false) { @Override public void run(@NotNull final ProgressIndicator indicator) { - if (!myApplication.isDisposed()) { + if (!ApplicationManagerEx.getApplicationEx().isDisposed()) { processBatch(indicator, files); } } @@ -440,7 +434,7 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable private volatile int resolvedInPreviousBatch; private void processBatch(@NotNull final ProgressIndicator indicator, @NotNull Set files) { - assert !myApplication.isDispatchThread(); + assert !ApplicationManagerEx.getApplicationEx().isDispatchThread(); final int resolvedInPreviousBatch = this.resolvedInPreviousBatch; final int totalSize = files.size() + resolvedInPreviousBatch; final IntObjectMap fileToForwardIds = ContainerUtil.createConcurrentIntObjectMap(); @@ -522,7 +516,8 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable }, indicator); return result[0]; }; - List> futures = ContainerUtil.map(Collections.nCopies(parallelism, ""), s -> myApplication.executeOnPooledThread(processFileFromSet)); + List> futures = ContainerUtil.map(Collections.nCopies(parallelism, ""), s -> ApplicationManagerEx.getApplicationEx() + .executeOnPooledThread(processFileFromSet)); List results = ContainerUtil.map(futures, future -> { try { @@ -669,8 +664,8 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable assert forwardSize == backwardSize; // wrap in read action so that sudden quit (in write action) would not interrupt us - myApplication.runReadAction(() -> { - if (!myApplication.isDisposed()) { + ApplicationManagerEx.getApplicationEx().runReadAction(() -> { + if (!ApplicationManagerEx.getApplicationEx().isDisposed()) { fileToBackwardIds.forEachEntry(new TIntObjectProcedure() { @Override public boolean execute(int fileId, TIntArrayList backIds) { diff --git a/java/java-indexing-impl/src/com/intellij/openapi/roots/impl/ProjectPackageIndexImpl.java b/java/java-indexing-impl/src/com/intellij/openapi/roots/impl/ProjectPackageIndexImpl.java index a42fe07b59c7..2acb24134821 100644 --- a/java/java-indexing-impl/src/com/intellij/openapi/roots/impl/ProjectPackageIndexImpl.java +++ b/java/java-indexing-impl/src/com/intellij/openapi/roots/impl/ProjectPackageIndexImpl.java @@ -1,30 +1,17 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.roots.impl; +import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.PackageIndex; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Query; import org.jetbrains.annotations.NotNull; -public class ProjectPackageIndexImpl extends PackageIndex { +final class ProjectPackageIndexImpl extends PackageIndex { private final DirectoryIndex myDirectoryIndex; - public ProjectPackageIndexImpl(DirectoryIndex directoryIndex) { - myDirectoryIndex = directoryIndex; + ProjectPackageIndexImpl(@NotNull Project project) { + myDirectoryIndex = DirectoryIndex.getInstance(project); } @NotNull @@ -38,5 +25,4 @@ public class ProjectPackageIndexImpl extends PackageIndex { public Query getDirsByPackageName(@NotNull String packageName, boolean includeLibrarySources) { return myDirectoryIndex.getDirectoriesByPackageName(packageName, includeLibrarySources); } - } diff --git a/java/java-indexing-impl/src/com/intellij/psi/impl/file/impl/JavaFileManagerImpl.java b/java/java-indexing-impl/src/com/intellij/psi/impl/file/impl/JavaFileManagerImpl.java index 10a9e5d97e16..4f8a2b3eec62 100644 --- a/java/java-indexing-impl/src/com/intellij/psi/impl/file/impl/JavaFileManagerImpl.java +++ b/java/java-indexing-impl/src/com/intellij/psi/impl/file/impl/JavaFileManagerImpl.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.impl.file.impl; import com.intellij.ProjectTopics; @@ -38,17 +38,15 @@ import static java.util.Objects.requireNonNull; /** * @author dmitry lomov */ -public class JavaFileManagerImpl implements JavaFileManager, Disposable { +public final class JavaFileManagerImpl implements JavaFileManager, Disposable { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.file.impl.JavaFileManagerImpl"); private final PsiManagerEx myManager; private volatile Set myNontrivialPackagePrefixes; private boolean myDisposed; - private final PackageIndex myPackageIndex; public JavaFileManagerImpl(Project project) { myManager = PsiManagerEx.getInstanceEx(project); - myPackageIndex = PackageIndex.getInstance(myManager.getProject()); project.getMessageBus().connect().subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() { @Override public void rootsChanged(@NotNull final ModuleRootEvent event) { @@ -65,7 +63,7 @@ public class JavaFileManagerImpl implements JavaFileManager, Disposable { @Override @Nullable public PsiPackage findPackage(@NotNull String packageName) { - Query dirs = myPackageIndex.getDirsByPackageName(packageName, true); + Query dirs = PackageIndex.getInstance(myManager.getProject()).getDirsByPackageName(packageName, true); if (dirs.findFirst() == null) return null; return new PsiPackageImpl(myManager, packageName); } diff --git a/java/java-indexing-impl/src/com/intellij/psi/impl/file/impl/JavaOutOfSourcesResolveScopeProvider.java b/java/java-indexing-impl/src/com/intellij/psi/impl/file/impl/JavaOutOfSourcesResolveScopeProvider.java index a3e9e87f3a4c..0532f2f7e11c 100644 --- a/java/java-indexing-impl/src/com/intellij/psi/impl/file/impl/JavaOutOfSourcesResolveScopeProvider.java +++ b/java/java-indexing-impl/src/com/intellij/psi/impl/file/impl/JavaOutOfSourcesResolveScopeProvider.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.impl.file.impl; import com.intellij.lang.java.JavaLanguage; @@ -32,15 +18,15 @@ import org.jetbrains.annotations.Nullable; * For example, java files from test data. * There is still a possibility to modify this scope choice with the ResolveScopeEnlarger. */ -public class JavaOutOfSourcesResolveScopeProvider extends ResolveScopeProvider { +public final class JavaOutOfSourcesResolveScopeProvider extends ResolveScopeProvider { @Nullable @Override public GlobalSearchScope getResolveScope(@NotNull VirtualFile file, Project project) { // For java only! For other languages resolve may be implemented with different rules, requiring larger scope. final FileType type = file.getFileType(); if (type instanceof LanguageFileType && ((LanguageFileType)type).getLanguage() == JavaLanguage.INSTANCE) { - ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex(); - if (index.isInContent(file) && !index.isInSource(file)) { + ProjectFileIndex index = project.isDefault() ? null : ProjectRootManager.getInstance(project).getFileIndex(); + if (index == null || (index.isInContent(file) && !index.isInSource(file))) { return GlobalSearchScope.fileScope(project, file); } } diff --git a/java/java-psi-api/src/com/intellij/openapi/roots/PackageIndex.java b/java/java-psi-api/src/com/intellij/openapi/roots/PackageIndex.java index 83d166a3eab5..2d2f0d99ba09 100644 --- a/java/java-psi-api/src/com/intellij/openapi/roots/PackageIndex.java +++ b/java/java-psi-api/src/com/intellij/openapi/roots/PackageIndex.java @@ -1,21 +1,6 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.roots; -import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Query; @@ -25,8 +10,8 @@ import org.jetbrains.annotations.NotNull; * Provides a possibility to query the directories corresponding to a specific Java package name. */ public abstract class PackageIndex { - public static PackageIndex getInstance(Project project) { - return ServiceManager.getService(project, PackageIndex.class); + public static PackageIndex getInstance(@NotNull Project project) { + return project.getService(PackageIndex.class); } /** diff --git a/java/java-psi-impl/src/com/intellij/core/JavaCoreProjectEnvironment.java b/java/java-psi-impl/src/com/intellij/core/JavaCoreProjectEnvironment.java index a7ccfde32ec4..395d36a13c78 100644 --- a/java/java-psi-impl/src/com/intellij/core/JavaCoreProjectEnvironment.java +++ b/java/java-psi-impl/src/com/intellij/core/JavaCoreProjectEnvironment.java @@ -36,14 +36,14 @@ public class JavaCoreProjectEnvironment extends CoreProjectEnvironment { public JavaCoreProjectEnvironment(@NotNull Disposable parentDisposable, @NotNull CoreApplicationEnvironment applicationEnvironment) { super(parentDisposable, applicationEnvironment); - myProject.registerService(PsiElementFactory.class, new PsiElementFactoryImpl(myPsiManager)); + myProject.registerService(PsiElementFactory.class, new PsiElementFactoryImpl(myProject)); myProject.registerService(JavaPsiImplementationHelper.class, createJavaPsiImplementationHelper()); myProject.registerService(PsiResolveHelper.class, new PsiResolveHelperImpl(myPsiManager)); myProject.registerService(LanguageLevelProjectExtension.class, new CoreLanguageLevelProjectExtension()); - myProject.registerService(JavaResolveCache.class, new JavaResolveCache(myMessageBus)); + myProject.registerService(JavaResolveCache.class, new JavaResolveCache(myProject)); myProject.registerService(JavaCodeStyleSettingsFacade.class, new CoreJavaCodeStyleSettingsFacade()); myProject.registerService(JavaCodeStyleManager.class, new CoreJavaCodeStyleManager()); - myProject.registerService(ControlFlowFactory.class, new ControlFlowFactory(myPsiManager)); + myProject.registerService(ControlFlowFactory.class, new ControlFlowFactory(myProject)); myPackageIndex = createCorePackageIndex(); myProject.registerService(PackageIndex.class, myPackageIndex); diff --git a/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowFactory.java b/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowFactory.java index 78ae601366ce..68225db84c98 100644 --- a/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowFactory.java +++ b/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowFactory.java @@ -1,19 +1,4 @@ -/* - * Copyright 2000-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.controlFlow; import com.intellij.openapi.components.ServiceManager; @@ -27,7 +12,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Map; -public class ControlFlowFactory { +public final class ControlFlowFactory { // psiElements hold weakly, controlFlows softly private final Map> cachedFlows = ContainerUtil.createConcurrentWeakKeySoftValueMap(); @@ -37,9 +22,8 @@ public class ControlFlowFactory { return INSTANCE_KEY.getValue(project); } - - public ControlFlowFactory(PsiManagerEx psiManager) { - psiManager.registerRunnableToRunOnChange(() -> clearCache()); + public ControlFlowFactory(@NotNull Project project) { + PsiManagerEx.getInstanceEx(project).registerRunnableToRunOnChange(() -> clearCache()); } private void clearCache() { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java index 03e6ad8ba579..a750583b960e 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java @@ -32,13 +32,14 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentMap; -public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements PsiElementFactory { +public final class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements PsiElementFactory { private final ConcurrentMap myArrayClasses = ContainerUtil.newConcurrentMap(); private final ConcurrentMap myCachedObjectType = ContainerUtil.createConcurrentSoftMap(); - public PsiElementFactoryImpl(@NotNull PsiManagerEx manager) { - super(manager); - manager.registerRunnableToRunOnChange(myCachedObjectType::clear); + public PsiElementFactoryImpl(@NotNull Project project) { + super(project); + + ((PsiManagerEx)myManager).registerRunnableToRunOnChange(myCachedObjectType::clear); } @NotNull diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java index a40801e86ab8..782f14adaa99 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java @@ -6,6 +6,7 @@ import com.intellij.lang.java.parser.DeclarationParser; import com.intellij.lang.java.parser.JavaParser; import com.intellij.lang.java.parser.JavaParserUtil; import com.intellij.lang.java.parser.ReferenceParser; +import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.openapi.util.text.StringUtil; import com.intellij.pom.java.LanguageLevel; @@ -90,8 +91,8 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { protected final PsiManager myManager; - public PsiJavaParserFacadeImpl(PsiManager manager) { - myManager = manager; + public PsiJavaParserFacadeImpl(@NotNull Project project) { + myManager = PsiManager.getInstance(project); } protected PsiJavaFile createDummyJavaFile(String text) { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveCache.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveCache.java index 750ed0f6f197..b79c43b24c7f 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveCache.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveCache.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. /* * @author max @@ -38,7 +24,6 @@ import com.intellij.psi.util.TypeConversionUtil; import com.intellij.util.ConcurrencyUtil; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.messages.MessageBus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -61,15 +46,13 @@ public class JavaResolveCache { private static final Object NULL = Key.create("NULL"); - public JavaResolveCache(@Nullable("can be null in com.intellij.core.JavaCoreApplicationEnvironment.JavaCoreApplicationEnvironment") MessageBus messageBus) { - if (messageBus != null) { - messageBus.connect().subscribe(PsiManagerImpl.ANY_PSI_CHANGE_TOPIC, new AnyPsiChangeListener.Adapter() { - @Override - public void beforePsiChanged(boolean isPhysical) { - clearCaches(isPhysical); - } - }); - } + public JavaResolveCache(@NotNull Project project) { + project.getMessageBus().connect().subscribe(PsiManagerImpl.ANY_PSI_CHANGE_TOPIC, new AnyPsiChangeListener.Adapter() { + @Override + public void beforePsiChanged(boolean isPhysical) { + clearCaches(isPhysical); + } + }); } private void clearCaches(boolean isPhysical) { diff --git a/platform/core-api/src/com/intellij/openapi/components/ServiceManager.java b/platform/core-api/src/com/intellij/openapi/components/ServiceManager.java index b5f0e1bf1b52..4849b3dc0578 100644 --- a/platform/core-api/src/com/intellij/openapi/components/ServiceManager.java +++ b/platform/core-api/src/com/intellij/openapi/components/ServiceManager.java @@ -33,7 +33,7 @@ public final class ServiceManager { } /** - * Creates lazy caching key to store project-level service instance from {@link #getService(Project, Class)}. + * Creates lazy caching key to store project-level service instance from {@link Project#getService(Class)}. * * @param serviceClass Service class to create key for. * @param Service class type. diff --git a/platform/core-api/src/com/intellij/psi/PsiDocumentManager.java b/platform/core-api/src/com/intellij/psi/PsiDocumentManager.java index e48bdd8dd667..30dd98822d0f 100644 --- a/platform/core-api/src/com/intellij/psi/PsiDocumentManager.java +++ b/platform/core-api/src/com/intellij/psi/PsiDocumentManager.java @@ -32,7 +32,7 @@ public abstract class PsiDocumentManager { * @return the document manager instance. */ public static PsiDocumentManager getInstance(@NotNull Project project) { - return project.getComponent(PsiDocumentManager.class); + return project.getService(PsiDocumentManager.class); } /** diff --git a/platform/core-api/src/com/intellij/psi/PsiManager.java b/platform/core-api/src/com/intellij/psi/PsiManager.java index 4af155a5c1da..ca3ae3ead23c 100644 --- a/platform/core-api/src/com/intellij/psi/PsiManager.java +++ b/platform/core-api/src/com/intellij/psi/PsiManager.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2019 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi; import com.intellij.openapi.Disposable; @@ -27,7 +13,6 @@ import org.jetbrains.annotations.Nullable; * The main entry point for accessing the PSI services for a project. */ public abstract class PsiManager extends UserDataHolderBase { - /** * Returns the PSI manager instance for the specified project. * @@ -36,7 +21,7 @@ public abstract class PsiManager extends UserDataHolderBase { */ @NotNull public static PsiManager getInstance(@NotNull Project project) { - return project.getComponent(PsiManager.class); + return project.getService(PsiManager.class); } /** diff --git a/platform/core-api/src/com/intellij/psi/search/GlobalSearchScope.java b/platform/core-api/src/com/intellij/psi/search/GlobalSearchScope.java index 5ab0eafa399e..ce345a090813 100644 --- a/platform/core-api/src/com/intellij/psi/search/GlobalSearchScope.java +++ b/platform/core-api/src/com/intellij/psi/search/GlobalSearchScope.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.search; import com.intellij.openapi.fileTypes.FileType; @@ -755,9 +755,9 @@ public abstract class GlobalSearchScope extends SearchScope implements ProjectAw super(project); myVirtualFile = virtualFile; myDisplayName = displayName; - final FileIndexFacade facade = FileIndexFacade.getInstance(project); - myModule = virtualFile == null || project.isDefault() ? null : facade.getModuleForFile(virtualFile); - mySearchOutsideContent = project.isDefault() || virtualFile != null && myModule == null && !facade.isInLibraryClasses(virtualFile) && !facade.isInLibrarySource(virtualFile); + FileIndexFacade facade = project.isDefault() ? null : FileIndexFacade.getInstance(project); + myModule = virtualFile == null || facade == null ? null : facade.getModuleForFile(virtualFile); + mySearchOutsideContent = facade == null || virtualFile != null && myModule == null && !facade.isInLibraryClasses(virtualFile) && !facade.isInLibrarySource(virtualFile); } @Override diff --git a/platform/core-impl/src/com/intellij/core/CoreProjectEnvironment.java b/platform/core-impl/src/com/intellij/core/CoreProjectEnvironment.java index 8d709065e49c..67c13e1df05f 100644 --- a/platform/core-impl/src/com/intellij/core/CoreProjectEnvironment.java +++ b/platform/core-impl/src/com/intellij/core/CoreProjectEnvironment.java @@ -53,17 +53,16 @@ public class CoreProjectEnvironment { myProject.registerService(ResolveCache.class, new ResolveCache(myProject)); myPsiManager = new PsiManagerImpl(myProject); - registerProjectComponent(PsiManager.class, myPsiManager); + myProject.registerService(PsiManager.class, myPsiManager); myProject.registerService(SmartPointerManager.class, SmartPointerManagerImpl.class); - registerProjectComponent(PsiDocumentManager.class, new CorePsiDocumentManager(myProject, myPsiManager, - myMessageBus, - new MockDocumentCommitProcessor())); + myProject.registerService(DocumentCommitProcessor.class, new MockDocumentCommitProcessor()); + myProject.registerService(PsiDocumentManager.class, new CorePsiDocumentManager(myProject)); myProject.registerService(ResolveScopeManager.class, createResolveScopeManager(myPsiManager)); myProject.registerService(PsiFileFactory.class, new PsiFileFactoryImpl(myPsiManager)); myProject.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(myProject, new PsiCachedValuesFactory(myPsiManager))); - myProject.registerService(PsiDirectoryFactory.class, new PsiDirectoryFactoryImpl(myPsiManager)); + myProject.registerService(PsiDirectoryFactory.class, new PsiDirectoryFactoryImpl(myProject)); myProject.registerService(ProjectScopeBuilder.class, createProjectScopeBuilder()); myProject.registerService(DumbService.class, new MockDumbService(myProject)); myProject.registerService(CoreEncodingProjectManager.class, CoreEncodingProjectManager.class); diff --git a/platform/core-impl/src/com/intellij/core/CorePsiDocumentManager.java b/platform/core-impl/src/com/intellij/core/CorePsiDocumentManager.java index 616c52ec8c97..60ab35893144 100644 --- a/platform/core-impl/src/com/intellij/core/CorePsiDocumentManager.java +++ b/platform/core-impl/src/com/intellij/core/CorePsiDocumentManager.java @@ -1,36 +1,15 @@ -/* - * Copyright 2000-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.core; import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiManager; -import com.intellij.psi.impl.DocumentCommitProcessor; import com.intellij.psi.impl.PsiDocumentManagerBase; -import com.intellij.util.messages.MessageBus; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; /** * @author nik */ -class CorePsiDocumentManager extends PsiDocumentManagerBase { - CorePsiDocumentManager(@NotNull Project project, - @NotNull PsiManager psiManager, - @NotNull MessageBus bus, - @NonNls @NotNull DocumentCommitProcessor documentCommitProcessor) { - super(project, psiManager, bus, documentCommitProcessor); +final class CorePsiDocumentManager extends PsiDocumentManagerBase { + CorePsiDocumentManager(@NotNull Project project) { + super(project); } } diff --git a/platform/core-impl/src/com/intellij/psi/AbstractFileViewProvider.java b/platform/core-impl/src/com/intellij/psi/AbstractFileViewProvider.java index 6d1479d1ef85..ae8732613380 100644 --- a/platform/core-impl/src/com/intellij/psi/AbstractFileViewProvider.java +++ b/platform/core-impl/src/com/intellij/psi/AbstractFileViewProvider.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi; import com.intellij.injected.editor.DocumentWindow; @@ -105,7 +91,7 @@ public abstract class AbstractFileViewProvider extends UserDataHolderBase implem if (isPhysical() && vFile.isInLocalFileSystem()) { // check directories consistency VirtualFile parent = vFile.getParent(); if (parent == null) return false; - + PsiDirectory psiDir = getManager().findDirectory(parent); if (psiDir == null) { FileIndexFacade indexFacade = FileIndexFacade.getInstance(getManager().getProject()); diff --git a/platform/core-impl/src/com/intellij/psi/DummyHolderViewProvider.java b/platform/core-impl/src/com/intellij/psi/DummyHolderViewProvider.java index 5652219361a7..35fe4706c170 100644 --- a/platform/core-impl/src/com/intellij/psi/DummyHolderViewProvider.java +++ b/platform/core-impl/src/com/intellij/psi/DummyHolderViewProvider.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi; import com.intellij.lang.Language; diff --git a/platform/core-impl/src/com/intellij/psi/impl/DocumentCommitThread.java b/platform/core-impl/src/com/intellij/psi/impl/DocumentCommitThread.java index d4d7c63da06d..a23994d0a4ee 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/DocumentCommitThread.java +++ b/platform/core-impl/src/com/intellij/psi/impl/DocumentCommitThread.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.impl; import com.google.common.annotations.VisibleForTesting; @@ -44,7 +44,7 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; -public class DocumentCommitThread implements Runnable, Disposable, DocumentCommitProcessor { +public final class DocumentCommitThread implements Runnable, Disposable, DocumentCommitProcessor { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.DocumentCommitThread"); private static final String SYNC_COMMIT_REASON = "Sync commit"; @@ -52,7 +52,6 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi private final Object lock = new Object(); private final HashSetQueue documentsToCommit = new HashSetQueue<>(); // guarded by lock private final HashSetQueue documentsToApplyInEDT = new HashSetQueue<>(); // guarded by lock - private final ApplicationEx myApplication; private volatile boolean isDisposed; private CommitTask currentTask; // guarded by lock private boolean myEnabled; // true if we can do commits. set to false temporarily during the write action. guarded by lock @@ -60,8 +59,9 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi static DocumentCommitThread getInstance() { return (DocumentCommitThread)ServiceManager.getService(DocumentCommitProcessor.class); } - DocumentCommitThread(final ApplicationEx application) { - myApplication = application; + + DocumentCommitThread() { + ApplicationEx application = (ApplicationEx)ApplicationManager.getApplication(); // install listener in EDT to avoid missing events in case we are inside write action right now application.invokeLater(() -> { if (application.isDisposed()) return; @@ -248,7 +248,7 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi // returns true if queue changed private boolean pollQueue() { - assert !myApplication.isDispatchThread() : Thread.currentThread(); + assert !ApplicationManager.getApplication().isDispatchThread() : Thread.currentThread(); CommitTask task; synchronized (lock) { if (!myEnabled || (task = documentsToCommit.poll()) == null) { @@ -284,7 +284,7 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi failureReason = result.get().second; if (success) { - assert !myApplication.isDispatchThread(); + assert !ApplicationManager.getApplication().isDispatchThread(); TransactionGuardImpl guard = (TransactionGuardImpl)TransactionGuard.getInstance(); guard.submitTransaction(task.project, task.myCreationContext, finishRunnable); } @@ -409,7 +409,7 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi final List finishProcessors = new SmartList<>(); List reparseInjectedProcessors = new SmartList<>(); Runnable runnable = () -> { - myApplication.assertReadAccessAllowed(); + ApplicationManager.getApplication().assertReadAccessAllowed(); if (project.isDisposed()) return; Lock lock = getDocumentLock(document); @@ -450,8 +450,10 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi } } }; - if (!myApplication.tryRunReadAction(runnable)) { - log(project, "Could not start read action", task, myApplication.isReadAccessAllowed(), Thread.currentThread()); + + ApplicationEx app = (ApplicationEx)ApplicationManager.getApplication(); + if (!app.tryRunReadAction(runnable)) { + log(project, "Could not start read action", task, app.isReadAccessAllowed(), Thread.currentThread()); return new Pair<>(null, "Could not start read action"); } @@ -471,7 +473,7 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi @NotNull List finishProcessors, @NotNull List reparseInjectedProcessors) { return () -> { - myApplication.assertIsDispatchThread(); + ApplicationManager.getApplication().assertIsDispatchThread(); Document document = task.getDocument(); Project project = task.project; PsiDocumentManagerBase documentManager = (PsiDocumentManagerBase)PsiDocumentManager.getInstance(project); @@ -530,7 +532,7 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi @Override public String toString() { - return "Document commit thread; application: "+myApplication+"; isDisposed: "+isDisposed+"; myEnabled: "+isEnabled(); + return "Document commit thread; application: "+ApplicationManager.getApplication()+"; isDisposed: "+isDisposed+"; myEnabled: "+isEnabled(); } @TestOnly diff --git a/platform/core-impl/src/com/intellij/psi/impl/PsiCachedValuesFactory.java b/platform/core-impl/src/com/intellij/psi/impl/PsiCachedValuesFactory.java index 0026d51dd02d..13bd697093d6 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/PsiCachedValuesFactory.java +++ b/platform/core-impl/src/com/intellij/psi/impl/PsiCachedValuesFactory.java @@ -1,21 +1,8 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.impl; +import com.intellij.openapi.project.Project; import com.intellij.psi.PsiManager; import com.intellij.psi.util.CachedValue; import com.intellij.psi.util.CachedValueProvider; @@ -27,9 +14,14 @@ import org.jetbrains.annotations.NotNull; /** * @author Dmitry Avdeev */ -public class PsiCachedValuesFactory implements CachedValuesFactory { +public final class PsiCachedValuesFactory implements CachedValuesFactory { private final PsiManager myManager; + public PsiCachedValuesFactory(@NotNull Project project) { + myManager = PsiManager.getInstance(project); + } + + @Deprecated public PsiCachedValuesFactory(PsiManager manager) { myManager = manager; } diff --git a/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java b/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java index dd7113f9b17f..8ba2aba0274f 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java +++ b/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java @@ -36,7 +36,6 @@ import com.intellij.psi.util.PsiUtilCore; import com.intellij.util.*; import com.intellij.util.concurrency.Semaphore; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.messages.MessageBus; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.*; @@ -51,7 +50,7 @@ public abstract class PsiDocumentManagerBase extends PsiDocumentManager implemen protected final Project myProject; private final PsiManager myPsiManager; - private final DocumentCommitProcessor myDocumentCommitProcessor; + protected final DocumentCommitProcessor myDocumentCommitProcessor; final Set myUncommittedDocuments = ContainerUtil.newConcurrentSet(); private final Map myUncommittedInfos = ContainerUtil.newConcurrentMap(); boolean myStopTrackingDocuments; @@ -63,18 +62,16 @@ public abstract class PsiDocumentManagerBase extends PsiDocumentManager implemen private final List myListeners = ContainerUtil.createLockFreeCopyOnWriteList(); - protected PsiDocumentManagerBase(@NotNull final Project project, - @NotNull PsiManager psiManager, - @NotNull MessageBus bus, - @NotNull DocumentCommitProcessor documentCommitProcessor) { + protected PsiDocumentManagerBase(@NotNull Project project) { myProject = project; - myPsiManager = psiManager; - myDocumentCommitProcessor = documentCommitProcessor; - mySynchronizer = new PsiToDocumentSynchronizer(this, bus); + myPsiManager = PsiManager.getInstance(project); + myDocumentCommitProcessor = ApplicationManager.getApplication().getService(DocumentCommitProcessor.class); + mySynchronizer = new PsiToDocumentSynchronizer(this, project.getMessageBus()); myPsiManager.addPsiTreeChangeListener(mySynchronizer); - bus.connect(this).subscribe(PsiDocumentTransactionListener.TOPIC, - (document, file) -> myUncommittedDocuments.remove(document)); + project.getMessageBus().connect(this).subscribe(PsiDocumentTransactionListener.TOPIC, (document, file) -> { + myUncommittedDocuments.remove(document); + }); } @Override diff --git a/platform/core-impl/src/com/intellij/psi/impl/PsiManagerEx.java b/platform/core-impl/src/com/intellij/psi/impl/PsiManagerEx.java index b7428648eb31..06433cf9ee57 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/PsiManagerEx.java +++ b/platform/core-impl/src/com/intellij/psi/impl/PsiManagerEx.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.impl; import com.intellij.openapi.Disposable; @@ -32,6 +18,7 @@ public abstract class PsiManagerEx extends PsiManager { //noinspection SSBasedInspection return (PsiManagerEx)getInstance(project); } + public abstract boolean isBatchFilesProcessingMode(); @TestOnly diff --git a/platform/core-impl/src/com/intellij/psi/impl/PsiManagerImpl.java b/platform/core-impl/src/com/intellij/psi/impl/PsiManagerImpl.java index 5cf8b5b6fe24..01fac7a9435e 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/PsiManagerImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/PsiManagerImpl.java @@ -1,5 +1,4 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - package com.intellij.psi.impl; import com.intellij.lang.PsiBuilderFactory; @@ -14,6 +13,7 @@ import com.intellij.openapi.progress.util.ProgressWrapper; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.FileIndexFacade; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.NotNullLazyValue; import com.intellij.openapi.vfs.NonPhysicalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileFilter; @@ -33,11 +33,11 @@ import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; -public class PsiManagerImpl extends PsiManagerEx { +public final class PsiManagerImpl extends PsiManagerEx { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.PsiManagerImpl"); private final Project myProject; - private final FileIndexFacade myFileIndex; + private final NotNullLazyValue myFileIndex; private final PsiModificationTracker myModificationTracker; private final FileManagerImpl myFileManager; @@ -60,7 +60,7 @@ public class PsiManagerImpl extends PsiManagerEx { PsiBuilderFactory.getInstance(); myProject = project; - myFileIndex = FileIndexFacade.getInstance(project); + myFileIndex = NotNullLazyValue.createValue(() -> FileIndexFacade.getInstance(project)); myModificationTracker = PsiModificationTracker.SERVICE.getInstance(project); myFileManager = new FileManagerImpl(this, myFileIndex); @@ -107,7 +107,7 @@ public class PsiManagerImpl extends PsiManagerEx { } if (file != null && file.isPhysical() && virtualFile.getFileSystem() instanceof NonPhysicalFileSystem) return true; - return virtualFile != null && myFileIndex.isInContent(virtualFile); + return virtualFile != null && myFileIndex.getValue().isInContent(virtualFile); } @Override @@ -153,8 +153,8 @@ public class PsiManagerImpl extends PsiManagerEx { return myFileManager.findFile(file); } + @NotNull @Override - @Nullable public FileViewProvider findViewProvider(@NotNull VirtualFile file) { ProgressIndicatorProvider.checkCanceled(); return myFileManager.findViewProvider(file); diff --git a/platform/core-impl/src/com/intellij/psi/impl/PsiParserFacadeImpl.java b/platform/core-impl/src/com/intellij/psi/impl/PsiParserFacadeImpl.java index c34e5ab7aa10..da0c027f8b6f 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/PsiParserFacadeImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/PsiParserFacadeImpl.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.impl; @@ -21,6 +7,7 @@ import com.intellij.lang.Commenter; import com.intellij.lang.Language; import com.intellij.lang.LanguageCommenters; import com.intellij.openapi.fileTypes.LanguageFileType; +import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.impl.source.DummyHolderFactory; import com.intellij.psi.impl.source.SourceTreeToPsiMap; @@ -34,11 +21,11 @@ import org.jetbrains.annotations.NotNull; /** * @author yole */ -public class PsiParserFacadeImpl implements PsiParserFacade { - protected final PsiManagerEx myManager; +public final class PsiParserFacadeImpl implements PsiParserFacade { + private final PsiManagerEx myManager; - public PsiParserFacadeImpl(PsiManagerEx manager) { - myManager = manager; + public PsiParserFacadeImpl(@NotNull Project project) { + myManager = PsiManagerEx.getInstanceEx(project); } @Override @@ -106,7 +93,7 @@ public class PsiParserFacadeImpl implements PsiParserFacade { throw new IncorrectOperationException("Incorrect comment \"" + aFile.getText() + "\"."); } - protected PsiFile createDummyFile(String text, final LanguageFileType fileType) { + private PsiFile createDummyFile(String text, final LanguageFileType fileType) { String ext = fileType.getDefaultExtension(); @NonNls String fileName = "_Dummy_." + ext; diff --git a/platform/core-impl/src/com/intellij/psi/impl/file/PsiDirectoryFactoryImpl.java b/platform/core-impl/src/com/intellij/psi/impl/file/PsiDirectoryFactoryImpl.java index d99960200b33..ba9d47f52111 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/file/PsiDirectoryFactoryImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/file/PsiDirectoryFactoryImpl.java @@ -1,41 +1,29 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.impl.file; +import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiDirectoryContainer; +import com.intellij.psi.PsiManager; import com.intellij.psi.impl.PsiManagerImpl; import org.jetbrains.annotations.NotNull; /** * @author yole */ -public class PsiDirectoryFactoryImpl extends PsiDirectoryFactory { - private final PsiManagerImpl myManager; +public final class PsiDirectoryFactoryImpl extends PsiDirectoryFactory { + private final Project myProject; - public PsiDirectoryFactoryImpl(final PsiManagerImpl manager) { - myManager = manager; + public PsiDirectoryFactoryImpl(@NotNull Project project) { + myProject = project; } @NotNull @Override - public PsiDirectory createDirectory(@NotNull final VirtualFile file) { - return new PsiDirectoryImpl(myManager, file); + public PsiDirectory createDirectory(@NotNull VirtualFile file) { + return new PsiDirectoryImpl((PsiManagerImpl)PsiManager.getInstance(myProject), file); } @Override diff --git a/platform/core-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java b/platform/core-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java index 733a4858e2af..63dc318b3d69 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java @@ -12,10 +12,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.project.DumbService; import com.intellij.openapi.roots.FileIndexFacade; -import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.LowMemoryWatcher; -import com.intellij.openapi.util.StackOverflowPreventedException; +import com.intellij.openapi.util.*; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.InvalidVirtualFileAccessException; import com.intellij.openapi.vfs.VfsUtilCore; @@ -43,7 +40,7 @@ public final class FileManagerImpl implements FileManager { private final Key myPsiHardRefKey = Key.create("HARD_REFERENCE_TO_PSI"); //non-static! private final PsiManagerImpl myManager; - private final FileIndexFacade myFileIndex; + private final NotNullLazyValue myFileIndex; private final AtomicReference> myVFileToPsiDirMap = new AtomicReference<>(); private final AtomicReference> myVFileToViewProviderMap = new AtomicReference<>(); @@ -57,7 +54,7 @@ public final class FileManagerImpl implements FileManager { private final MessageBusConnection myConnection; - public FileManagerImpl(PsiManagerImpl manager, FileIndexFacade fileIndex) { + public FileManagerImpl(@NotNull PsiManagerImpl manager, @NotNull NotNullLazyValue fileIndex) { myManager = manager; myFileIndex = fileIndex; myConnection = manager.getProject().getMessageBus().connect(); @@ -406,7 +403,8 @@ public final class FileManagerImpl implements FileManager { private boolean isExcludedOrIgnored(@NotNull VirtualFile vFile) { if (myManager.getProject().isDefault()) return false; - return Registry.is("ide.hide.excluded.files") ? myFileIndex.isExcludedFile(vFile) : myFileIndex.isUnderIgnored(vFile); + FileIndexFacade fileIndexFacade = myFileIndex.getValue(); + return Registry.is("ide.hide.excluded.files") ? fileIndexFacade.isExcludedFile(vFile) : fileIndexFacade.isUnderIgnored(vFile); } public PsiDirectory getCachedDirectory(@NotNull VirtualFile vFile) { diff --git a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerManagerImpl.java b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerManagerImpl.java index df8ce9e72ef0..8e4b9352eabd 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerManagerImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerManagerImpl.java @@ -1,19 +1,4 @@ -/* - * Copyright 2000-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.impl.smartPointers; import com.intellij.openapi.application.ApplicationManager; @@ -38,15 +23,15 @@ import org.jetbrains.annotations.TestOnly; import java.lang.ref.Reference; import java.util.List; -public class SmartPointerManagerImpl extends SmartPointerManager { +public final class SmartPointerManagerImpl extends SmartPointerManager { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.smartPointers.SmartPointerManagerImpl"); private final Project myProject; private final Key POINTERS_KEY; private final PsiDocumentManagerBase myPsiDocManager; - public SmartPointerManagerImpl(Project project, PsiDocumentManagerBase psiDocManager) { + public SmartPointerManagerImpl(@NotNull Project project) { myProject = project; - myPsiDocManager = psiDocManager; + myPsiDocManager = (PsiDocumentManagerBase)PsiDocumentManager.getInstance(project); POINTERS_KEY = Key.create("SMART_POINTERS " + (project.isDefault() ? "default" : project.hashCode())); } @@ -63,7 +48,7 @@ public class SmartPointerManagerImpl extends SmartPointerManager { if (pointers != null) pointers.fastenBelts(this); } - private static final Key> CACHED_SMART_POINTER_KEY = Key.create("CACHED_SMART_POINTER_KEY"); + private static final Key>> CACHED_SMART_POINTER_KEY = Key.create("CACHED_SMART_POINTER_KEY"); @Override @NotNull public SmartPsiElementPointer createSmartPsiElementPointer(@NotNull E element) { @@ -116,8 +101,8 @@ public class SmartPointerManagerImpl extends SmartPointerManager { } private static SmartPsiElementPointerImpl getCachedPointer(@NotNull E element) { - Reference data = element.getUserData(CACHED_SMART_POINTER_KEY); - SmartPsiElementPointerImpl cachedPointer = SoftReference.dereference(data); + Reference> data = element.getUserData(CACHED_SMART_POINTER_KEY); + SmartPsiElementPointerImpl cachedPointer = SoftReference.dereference(data); if (cachedPointer != null) { PsiElement cachedElement = cachedPointer.getElement(); if (cachedElement != element) { @@ -125,7 +110,7 @@ public class SmartPointerManagerImpl extends SmartPointerManager { } } //noinspection unchecked - return cachedPointer; + return (SmartPsiElementPointerImpl)cachedPointer; } @Override @@ -168,22 +153,22 @@ public class SmartPointerManagerImpl extends SmartPointerManager { return; } ensureMyProject(pointer.getProject()); - int refCount = ((SmartPsiElementPointerImpl)pointer).incrementAndGetReferenceCount(-1); + int refCount = ((SmartPsiElementPointerImpl)pointer).incrementAndGetReferenceCount(-1); if (refCount == -1) { LOG.error("Double smart pointer removal"); return; } if (refCount == 0) { - PsiElement element = ((SmartPointerEx)pointer).getCachedElement(); + PsiElement element = ((SmartPointerEx)pointer).getCachedElement(); if (element != null) { element.putUserData(CACHED_SMART_POINTER_KEY, null); } - SmartPointerElementInfo info = ((SmartPsiElementPointerImpl)pointer).getElementInfo(); + SmartPointerElementInfo info = ((SmartPsiElementPointerImpl)pointer).getElementInfo(); info.cleanup(); - SmartPointerTracker.PointerReference reference = ((SmartPsiElementPointerImpl)pointer).pointerReference; + SmartPointerTracker.PointerReference reference = ((SmartPsiElementPointerImpl)pointer).pointerReference; if (reference != null) { if (reference.get() != pointer) { throw new IllegalStateException("Reference points to " + reference.get()); diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/cherrypick/VcsCherryPickManager.java b/platform/dvcs-impl/src/com/intellij/dvcs/cherrypick/VcsCherryPickManager.java index 940163a37870..c3c82bf8030c 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/cherrypick/VcsCherryPickManager.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/cherrypick/VcsCherryPickManager.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.dvcs.cherrypick; import com.google.common.collect.Lists; @@ -28,13 +28,11 @@ import java.util.*; public class VcsCherryPickManager { private static final Logger LOG = Logger.getInstance(VcsCherryPickManager.class); @NotNull private final Project myProject; - @NotNull private final ProjectLevelVcsManager myProjectLevelVcsManager; @NotNull private final Set myIdsInProgress = ContainerUtil.newConcurrentSet(); @NotNull private final BackgroundTaskQueue myTaskQueue; - public VcsCherryPickManager(@NotNull Project project, @NotNull ProjectLevelVcsManager projectLevelVcsManager) { + public VcsCherryPickManager(@NotNull Project project) { myProject = project; - myProjectLevelVcsManager = projectLevelVcsManager; myTaskQueue = new BackgroundTaskQueue(project, "Cherry-picking"); } @@ -53,7 +51,7 @@ public class VcsCherryPickManager { @Nullable private VcsCherryPicker getCherryPickerForCommit(@NotNull VcsFullCommitDetails commitDetails) { - AbstractVcs vcs = myProjectLevelVcsManager.getVcsFor(commitDetails.getRoot()); + AbstractVcs vcs = ProjectLevelVcsManager.getInstance(myProject).getVcsFor(commitDetails.getRoot()); if (vcs == null) return null; VcsKey key = vcs.getKeyInstanceMethod(); return getCherryPickerFor(key); diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/impl/DocumentMarkupModelManager.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/impl/DocumentMarkupModelManager.java index 9d4541e87436..8a2862f5288b 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/impl/DocumentMarkupModelManager.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/impl/DocumentMarkupModelManager.java @@ -1,7 +1,7 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.editor.impl; -import com.intellij.openapi.Disposable; +import com.intellij.openapi.components.Service; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.project.Project; @@ -9,23 +9,19 @@ import com.intellij.openapi.util.Disposer; import com.intellij.util.containers.WeakList; import org.jetbrains.annotations.NotNull; -public class DocumentMarkupModelManager { +@Service +public final class DocumentMarkupModelManager { private static final Logger LOG = Logger.getInstance(DocumentMarkupModelManager.class); private final WeakList myDocumentSet = new WeakList<>(); private volatile boolean myDisposed; - public static DocumentMarkupModelManager getInstance(Project project) { - return project.getComponent(DocumentMarkupModelManager.class); + public static DocumentMarkupModelManager getInstance(@NotNull Project project) { + return project.getService(DocumentMarkupModelManager.class); } public DocumentMarkupModelManager(@NotNull Project project) { - Disposer.register(project, new Disposable() { - @Override - public void dispose() { - cleanupProjectMarkups(project); - } - }); + Disposer.register(project, () -> cleanupProjectMarkups(project)); } public void registerDocument(Document document) { diff --git a/platform/editor-ui-ex/src/com/intellij/psi/impl/search/PsiTodoSearchHelperImpl.java b/platform/editor-ui-ex/src/com/intellij/psi/impl/search/PsiTodoSearchHelperImpl.java index 0e6243097c84..a8fdf09e43e2 100644 --- a/platform/editor-ui-ex/src/com/intellij/psi/impl/search/PsiTodoSearchHelperImpl.java +++ b/platform/editor-ui-ex/src/com/intellij/psi/impl/search/PsiTodoSearchHelperImpl.java @@ -1,9 +1,9 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.impl.search; import com.intellij.ide.todo.TodoConfiguration; import com.intellij.ide.todo.TodoIndexPatternProvider; +import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiFile; import com.intellij.psi.impl.PsiManagerEx; @@ -19,12 +19,20 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -public class PsiTodoSearchHelperImpl implements PsiTodoSearchHelper { +public final class PsiTodoSearchHelperImpl implements PsiTodoSearchHelper { private final PsiManagerEx myManager; private static final TodoItem[] EMPTY_TODO_ITEMS = new TodoItem[0]; - public PsiTodoSearchHelperImpl(PsiManagerEx manager) { - myManager = manager; + public PsiTodoSearchHelperImpl(@NotNull Project project) { + myManager = PsiManagerEx.getInstanceEx(project); + } + + /** + * @deprecated Use {@link #PsiTodoSearchHelperImpl(Project)} + */ + @Deprecated + public PsiTodoSearchHelperImpl(@NotNull PsiManagerEx psiManager) { + myManager = psiManager; } @Override diff --git a/platform/indexing-impl/src/com/intellij/psi/impl/file/impl/ResolveScopeManagerImpl.java b/platform/indexing-impl/src/com/intellij/psi/impl/file/impl/ResolveScopeManagerImpl.java index e65dc0ebfc8b..4236f4de3f50 100644 --- a/platform/indexing-impl/src/com/intellij/psi/impl/file/impl/ResolveScopeManagerImpl.java +++ b/platform/indexing-impl/src/com/intellij/psi/impl/file/impl/ResolveScopeManagerImpl.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.impl.file.impl; import com.intellij.injected.editor.VirtualFileWindow; @@ -24,7 +24,7 @@ import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.Map; -public class ResolveScopeManagerImpl extends ResolveScopeManager { +public final class ResolveScopeManagerImpl extends ResolveScopeManager { private final Project myProject; private final ProjectRootManager myProjectRootManager; private final PsiManager myManager; @@ -32,10 +32,10 @@ public class ResolveScopeManagerImpl extends ResolveScopeManager { private final Map myDefaultResolveScopesCache; private final AdditionalIndexableFileSet myAdditionalIndexableFileSet; - public ResolveScopeManagerImpl(Project project, ProjectRootManager projectRootManager, PsiManager psiManager) { + public ResolveScopeManagerImpl(Project project) { myProject = project; - myProjectRootManager = projectRootManager; - myManager = psiManager; + myProjectRootManager = ProjectRootManager.getInstance(project); + myManager = PsiManager.getInstance(project); myAdditionalIndexableFileSet = new AdditionalIndexableFileSet(project); myDefaultResolveScopesCache = ConcurrentFactoryMap.create( @@ -56,7 +56,7 @@ public class ResolveScopeManagerImpl extends ResolveScopeManager { }, ContainerUtil::createConcurrentWeakKeySoftValueMap); - ((PsiManagerImpl)psiManager).registerRunnableToRunOnChange(myDefaultResolveScopesCache::clear); + ((PsiManagerImpl)myManager).registerRunnableToRunOnChange(myDefaultResolveScopesCache::clear); } private GlobalSearchScope getResolveScopeFromProviders(@NotNull final VirtualFile vFile) { diff --git a/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java b/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java index 5bdbcc2a6fe1..9b2cafa7f4ba 100644 --- a/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java +++ b/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java @@ -78,8 +78,17 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { return scope; } - public PsiSearchHelperImpl(@NotNull PsiManagerEx manager) { - myManager = manager; + public PsiSearchHelperImpl(@NotNull Project project) { + myManager = PsiManagerEx.getInstanceEx(project); + myDumbService = DumbService.getInstance(myManager.getProject()); + } + + /** + * @deprecated Use {@link #PsiSearchHelperImpl(Project)} + */ + @Deprecated + public PsiSearchHelperImpl(@NotNull PsiManagerEx psiManager) { + myManager = psiManager; myDumbService = DumbService.getInstance(myManager.getProject()); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java index 7f03fbc7d190..d4554fabaf46 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java @@ -28,7 +28,6 @@ import com.intellij.testFramework.TestModeFlags; import com.intellij.util.PairProcessor; import com.intellij.util.containers.ConcurrentFactoryMap; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.messages.MessageBus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; @@ -47,9 +46,9 @@ public class TemplateManagerImpl extends TemplateManager implements Disposable { private static final Key TEMPLATE_STATE_KEY = Key.create("TEMPLATE_STATE_KEY"); private final TemplateManagerListener myEventPublisher; - public TemplateManagerImpl(@NotNull Project project, @NotNull MessageBus messageBus) { + public TemplateManagerImpl(@NotNull Project project) { myProject = project; - myEventPublisher = messageBus.syncPublisher(TEMPLATE_STARTED_TOPIC); + myEventPublisher = project.getMessageBus().syncPublisher(TEMPLATE_STARTED_TOPIC); EditorFactoryListener myEditorFactoryListener = new EditorFactoryListener() { @Override public void editorReleased(@NotNull EditorFactoryEvent event) { diff --git a/platform/lang-impl/src/com/intellij/execution/startup/ProjectStartupTaskManager.java b/platform/lang-impl/src/com/intellij/execution/startup/ProjectStartupTaskManager.java index 15dec0d721c1..8c2ca2d925b2 100644 --- a/platform/lang-impl/src/com/intellij/execution/startup/ProjectStartupTaskManager.java +++ b/platform/lang-impl/src/com/intellij/execution/startup/ProjectStartupTaskManager.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.startup; import com.intellij.execution.RunManager; @@ -20,7 +6,6 @@ import com.intellij.execution.RunnerAndConfigurationSettings; import com.intellij.execution.impl.RunManagerImpl; import com.intellij.notification.NotificationGroup; import com.intellij.openapi.Disposable; -import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.impl.ProjectLifecycleListener; import com.intellij.openapi.ui.MessageType; @@ -30,24 +15,21 @@ import org.jetbrains.annotations.NotNull; import java.util.*; -/** - * @author Irina.Chernushina on 8/19/2015. - */ -public class ProjectStartupTaskManager { +public final class ProjectStartupTaskManager { public static final NotificationGroup NOTIFICATION_GROUP = NotificationGroup.logOnlyGroup("Project Startup Tasks Messages"); @NonNls public static final String PREFIX = "Project Startup Tasks: "; private final Project myProject; private final ProjectStartupSharedConfiguration myShared; private final ProjectStartupLocalConfiguration myLocal; - public static ProjectStartupTaskManager getInstance(@NotNull final Project project) { - return ServiceManager.getService(project, ProjectStartupTaskManager.class); + public static ProjectStartupTaskManager getInstance(@NotNull Project project) { + return project.getService(ProjectStartupTaskManager.class); } - public ProjectStartupTaskManager(Project project, ProjectStartupSharedConfiguration shared, ProjectStartupLocalConfiguration local) { + public ProjectStartupTaskManager(@NotNull Project project) { myProject = project; - myShared = shared; - myLocal = local; + myShared = myProject.getService(ProjectStartupSharedConfiguration.class); + myLocal = myProject.getService(ProjectStartupLocalConfiguration.class); verifyState(); } @@ -68,22 +50,24 @@ public class ProjectStartupTaskManager { } private void verifyState() { - if (! myShared.isEmpty()) { - final Collection sharedConfigurations = getSharedConfigurations(); - final List canNotBeShared = new ArrayList<>(); - final Iterator iterator = sharedConfigurations.iterator(); - while (iterator.hasNext()) { - final RunnerAndConfigurationSettings configuration = iterator.next(); - if (!configuration.isShared()) { - iterator.remove(); - canNotBeShared.add(configuration); - } - } - if (! canNotBeShared.isEmpty()) { - canNotBeShared.addAll(getLocalConfigurations()); - setStartupConfigurations(sharedConfigurations, canNotBeShared); + if (myShared.isEmpty()) { + return; + } + + final Collection sharedConfigurations = getSharedConfigurations(); + final List canNotBeShared = new ArrayList<>(); + final Iterator iterator = sharedConfigurations.iterator(); + while (iterator.hasNext()) { + final RunnerAndConfigurationSettings configuration = iterator.next(); + if (!configuration.isShared()) { + iterator.remove(); + canNotBeShared.add(configuration); } } + if (! canNotBeShared.isEmpty()) { + canNotBeShared.addAll(getLocalConfigurations()); + setStartupConfigurations(sharedConfigurations, canNotBeShared); + } } public Collection getSharedConfigurations() { @@ -113,12 +97,17 @@ public class ProjectStartupTaskManager { } public void rename(final String oldId, RunnerAndConfigurationSettings settings) { - if (myShared.rename(oldId, settings)) return; + if (myShared.rename(oldId, settings)) { + return; + } myLocal.rename(oldId, settings); + } public void delete(final String id) { - if (myShared.deleteConfiguration(id)) return; + if (myShared.deleteConfiguration(id)) { + return; + } myLocal.deleteConfiguration(id); } diff --git a/platform/lang-impl/src/com/intellij/facet/impl/ui/FacetDependentToolWindowManager.java b/platform/lang-impl/src/com/intellij/facet/impl/ui/FacetDependentToolWindowManager.java index fdd4a8c686dc..bd5471b35fb5 100644 --- a/platform/lang-impl/src/com/intellij/facet/impl/ui/FacetDependentToolWindowManager.java +++ b/platform/lang-impl/src/com/intellij/facet/impl/ui/FacetDependentToolWindowManager.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.facet.impl.ui; import com.intellij.facet.*; @@ -12,25 +12,16 @@ import org.jetbrains.annotations.NotNull; import java.util.List; -public class FacetDependentToolWindowManager implements ProjectComponent { +final class FacetDependentToolWindowManager implements ProjectComponent { private final Project myProject; - private final ProjectWideFacetListenersRegistry myFacetListenersRegistry; - private final ProjectFacetManager myFacetManager; - private final ToolWindowManagerEx myToolWindowManager; - protected FacetDependentToolWindowManager(Project project, - ProjectWideFacetListenersRegistry facetListenersRegistry, - ProjectFacetManager facetManager, - ToolWindowManagerEx toolWindowManager) { + private FacetDependentToolWindowManager(@NotNull Project project) { myProject = project; - myFacetListenersRegistry = facetListenersRegistry; - myFacetManager = facetManager; - myToolWindowManager = toolWindowManager; } @Override public void projectOpened() { - myFacetListenersRegistry.registerListener(new ProjectWideFacetAdapter() { + ProjectWideFacetListenersRegistry.getInstance(myProject).registerListener(new ProjectWideFacetAdapter() { @Override public void facetAdded(@NotNull Facet facet) { for (FacetDependentToolWindow extension : getDependentExtensions(facet)) { @@ -40,25 +31,32 @@ public class FacetDependentToolWindowManager implements ProjectComponent { @Override public void facetRemoved(@NotNull Facet facet) { - if (!myFacetManager.hasFacets(facet.getTypeId())) { - for (FacetDependentToolWindow extension : getDependentExtensions(facet)) { - ToolWindow toolWindow = myToolWindowManager.getToolWindow(extension.id); - if (toolWindow != null) { - // check for other facets - List facetTypes = extension.getFacetTypes(); - for (FacetType facetType : facetTypes) { - if (myFacetManager.hasFacets(facetType.getId())) return; + ProjectFacetManager facetManager = ProjectFacetManager.getInstance(myProject); + if (facetManager.hasFacets(facet.getTypeId())) { + return; + } + + ToolWindowManagerEx toolWindowManager = ToolWindowManagerEx.getInstanceEx(myProject); + for (FacetDependentToolWindow extension : getDependentExtensions(facet)) { + ToolWindow toolWindow = toolWindowManager.getToolWindow(extension.id); + if (toolWindow != null) { + // check for other facets + List facetTypes = extension.getFacetTypes(); + for (FacetType facetType : facetTypes) { + if (facetManager.hasFacets(facetType.getId())) { + return; } - myToolWindowManager.unregisterToolWindow(extension.id); } + toolWindowManager.unregisterToolWindow(extension.id); } } } }, myProject); + ProjectFacetManager facetManager = ProjectFacetManager.getInstance(myProject); loop: for (FacetDependentToolWindow extension : FacetDependentToolWindow.EXTENSION_POINT_NAME.getExtensionList()) { for (FacetType type : extension.getFacetTypes()) { - if (myFacetManager.hasFacets(type.getId())) { + if (facetManager.hasFacets(type.getId())) { ensureToolWindowExists(extension); continue loop; } @@ -67,9 +65,9 @@ public class FacetDependentToolWindowManager implements ProjectComponent { } private void ensureToolWindowExists(FacetDependentToolWindow extension) { - ToolWindow toolWindow = myToolWindowManager.getToolWindow(extension.id); + ToolWindow toolWindow = ToolWindowManagerEx.getInstanceEx(myProject).getToolWindow(extension.id); if (toolWindow == null) { - myToolWindowManager.initToolWindow(extension); + ToolWindowManagerEx.getInstanceEx(myProject).initToolWindow(extension); } } diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/ProjectViewDirectoryHelper.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/ProjectViewDirectoryHelper.java index f082e2b84fed..8ecdf79ec032 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/ProjectViewDirectoryHelper.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/ProjectViewDirectoryHelper.java @@ -1,5 +1,4 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - package com.intellij.ide.projectView.impl.nodes; import com.intellij.ide.projectView.ProjectViewSettings; @@ -50,6 +49,12 @@ public class ProjectViewDirectoryHelper { return ServiceManager.getService(project, ProjectViewDirectoryHelper.class); } + public ProjectViewDirectoryHelper(Project project) { + myProject = project; + myIndex = DirectoryIndex.getInstance(project); + } + + @Deprecated public ProjectViewDirectoryHelper(Project project, DirectoryIndex index) { myProject = project; myIndex = index; @@ -93,7 +98,7 @@ public class ProjectViewDirectoryHelper { if (result.length() > 0) result.append(",").append(FontUtil.spaceAndThinSpace()); result.append(FileUtil.getLocationRelativeToUserHome(directory.getPresentableUrl())); } - + return result.length() == 0 ? null : result.toString(); } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ModuleRootManagerComponent.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ModuleRootManagerComponent.java index bdce338f5965..d4bf352e5197 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ModuleRootManagerComponent.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ModuleRootManagerComponent.java @@ -9,7 +9,6 @@ import com.intellij.openapi.roots.impl.storage.ClassPathStorageUtil; import com.intellij.openapi.roots.impl.storage.ClasspathStorage; import com.intellij.openapi.roots.libraries.LibraryTable; import com.intellij.openapi.util.registry.Registry; -import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager; import com.intellij.util.SmartList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.TestOnly; @@ -31,10 +30,8 @@ import java.util.List; public class ModuleRootManagerComponent extends ModuleRootManagerImpl implements PersistentStateComponentWithModificationTracker, StateStorageChooserEx { - public ModuleRootManagerComponent(Module module, - ProjectRootManagerImpl projectRootManager, - VirtualFilePointerManager filePointerManager) { - super(module, projectRootManager, filePointerManager); + public ModuleRootManagerComponent(Module module) { + super(module); } @NotNull diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerComponent.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerComponent.java index 524238ad7dc3..835c702a96ac 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerComponent.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerComponent.java @@ -225,7 +225,7 @@ public class ProjectRootManagerComponent extends ProjectRootManagerImpl implemen } } - + List recursiveUrls = ContainerUtil.map(recursivePaths, VfsUtilCore::pathToUrl); Set excludedUrls = new THashSet<>(); // changes in files provided by this method should be watched manually because no-one's bothered to set up correct pointers for them @@ -247,7 +247,7 @@ public class ProjectRootManagerComponent extends ProjectRootManagerImpl implemen // module roots already fire validity change events, see usages of ProjectRootManagerComponent.getRootsValidityChangedListener collectModuleWatchRoots(recursivePaths, flatPaths); - + return Pair.create(recursivePaths, flatPaths); } @@ -300,7 +300,11 @@ public class ProjectRootManagerComponent extends ProjectRootManagerImpl implemen @Override protected void clearScopesCaches() { super.clearScopesCaches(); - LibraryScopeCache.getInstance(myProject).clear(); + + LibraryScopeCache libraryScopeCache = myProject.getServiceIfCreated(LibraryScopeCache.class); + if (libraryScopeCache != null) { + libraryScopeCache.clear(); + } } @Override diff --git a/platform/lang-impl/src/com/intellij/psi/impl/PsiDocumentManagerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/PsiDocumentManagerImpl.java index 9f6d3b5dd8c9..3c5b2c04bedd 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/PsiDocumentManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/PsiDocumentManagerImpl.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.impl; @@ -27,14 +27,12 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.pom.core.impl.PomModelImpl; import com.intellij.psi.FileViewProvider; import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; import com.intellij.psi.impl.source.PostprocessReformattingAspect; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageManagerImpl; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; import com.intellij.util.ArrayUtil; import com.intellij.util.FileContentUtil; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.messages.MessageBus; import com.intellij.util.messages.MessageBusConnection; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -44,20 +42,15 @@ import org.jetbrains.annotations.TestOnly; import java.util.*; //todo listen & notifyListeners readonly events? -public class PsiDocumentManagerImpl extends PsiDocumentManagerBase { - private final DocumentCommitProcessor myDocumentCommitThread; +public final class PsiDocumentManagerImpl extends PsiDocumentManagerBase { private final boolean myUnitTestMode = ApplicationManager.getApplication().isUnitTestMode(); - public PsiDocumentManagerImpl(@NotNull final Project project, - @NotNull PsiManager psiManager, - @NotNull EditorFactory editorFactory, - @NotNull MessageBus bus, - @NotNull final DocumentCommitProcessor documentCommitThread) { - super(project, psiManager, bus, documentCommitThread); - myDocumentCommitThread = documentCommitThread; - editorFactory.getEventMulticaster().addDocumentListener(this, this); - ((EditorEventMulticasterImpl)editorFactory.getEventMulticaster()).addPrioritizedDocumentListener(new PriorityEventCollector(), this); - MessageBusConnection connection = bus.connect(this); + public PsiDocumentManagerImpl(@NotNull Project project) { + super(project); + + EditorFactory.getInstance().getEventMulticaster().addDocumentListener(this, this); + ((EditorEventMulticasterImpl)EditorFactory.getInstance().getEventMulticaster()).addPrioritizedDocumentListener(new PriorityEventCollector(), this); + MessageBusConnection connection = project.getMessageBus().connect(this); connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerListener() { @Override public void fileContentLoaded(@NotNull final VirtualFile virtualFile, @NotNull Document document) { @@ -65,7 +58,7 @@ public class PsiDocumentManagerImpl extends PsiDocumentManagerBase { fireDocumentCreated(document, psiFile); } }); - Disposer.register(this, () -> ((DocumentCommitThread)myDocumentCommitThread).cancelTasksOnProjectDispose(project)); + Disposer.register(this, () -> ((DocumentCommitThread)myDocumentCommitProcessor).cancelTasksOnProjectDispose(project)); } @Nullable @@ -155,7 +148,7 @@ public class PsiDocumentManagerImpl extends PsiDocumentManagerBase { @TestOnly public void clearUncommittedDocuments() { super.clearUncommittedDocuments(); - ((DocumentCommitThread)myDocumentCommitThread).clearQueue(); + ((DocumentCommitThread)myDocumentCommitProcessor).clearQueue(); } @NotNull diff --git a/platform/lang-impl/src/com/intellij/psi/search/ProjectScopeBuilderImpl.java b/platform/lang-impl/src/com/intellij/psi/search/ProjectScopeBuilderImpl.java index 5053a3838b12..307917949cae 100644 --- a/platform/lang-impl/src/com/intellij/psi/search/ProjectScopeBuilderImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/search/ProjectScopeBuilderImpl.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.search; import com.intellij.core.CoreProjectScopeBuilder; @@ -68,8 +68,10 @@ public class ProjectScopeBuilderImpl extends ProjectScopeBuilder { @NotNull @Override public GlobalSearchScope buildAllScope() { - final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(myProject); - if (projectRootManager == null) return new EverythingGlobalScope(myProject); + ProjectRootManager projectRootManager = myProject.isDefault() ? null : ProjectRootManager.getInstance(myProject); + if (projectRootManager == null) { + return new EverythingGlobalScope(myProject); + } boolean searchOutsideRootModel = false; for (SearchScopeEnlarger each : SearchScopeEnlarger.EXTENSION.getExtensionList()) { diff --git a/platform/platform-impl/src/com/intellij/ide/actionMacro/ActionMacroManager.java b/platform/platform-impl/src/com/intellij/ide/actionMacro/ActionMacroManager.java index 79d1d9a05a63..15baf14c50a0 100644 --- a/platform/platform-impl/src/com/intellij/ide/actionMacro/ActionMacroManager.java +++ b/platform/platform-impl/src/com/intellij/ide/actionMacro/ActionMacroManager.java @@ -49,7 +49,7 @@ import java.util.HashSet; import java.util.Set; @State(name = "ActionMacroManager", storages = @Storage("macros.xml")) -public class ActionMacroManager implements PersistentStateComponent, Disposable { +public final class ActionMacroManager implements PersistentStateComponent, Disposable { private static final Logger LOG = Logger.getInstance(ActionMacroManager.class); private static final String TYPING_SAMPLE = "WWWWWWWWWWWWWWWWWWWW"; @@ -108,9 +108,9 @@ public class ActionMacroManager implements PersistentStateComponent, Di registerActions(); } - @Nullable - @Override - public Element getState() { + @NotNull + @Override + public Element getState() { Element element = new Element("state"); for (ActionMacro macro : myMacros) { Element macroElement = new Element(ELEMENT_MACRO); diff --git a/platform/platform-impl/src/com/intellij/idea/ApplicationLoader.kt b/platform/platform-impl/src/com/intellij/idea/ApplicationLoader.kt index 350b5839fc34..2e07354cfa42 100644 --- a/platform/platform-impl/src/com/intellij/idea/ApplicationLoader.kt +++ b/platform/platform-impl/src/com/intellij/idea/ApplicationLoader.kt @@ -125,13 +125,14 @@ private fun startApp(app: ApplicationImpl, starter: ApplicationStarter, initAppA } // preload services only after icon activation - val future = registerRegistryAndInitStoreFuture.thenCompose { - val preloadServiceActivity = StartUpMeasurer.start("preload services") - preloadServices(app, it) - .thenRun(Runnable { - preloadServiceActivity.end() - }) - } + val future = registerRegistryAndInitStoreFuture + .thenCompose { + val preloadServiceActivity = StartUpMeasurer.start("preload services") + app.preloadServices(it) + .thenRun(Runnable { + preloadServiceActivity.end() + }) + } if (!headless) { if (SystemInfo.isMac) { @@ -204,7 +205,7 @@ private fun preloadIcons() { } @ApiStatus.Internal -fun registerRegistryAndInitStore(registerFuture: CompletableFuture>, app: ApplicationImpl): CompletableFuture> { +fun registerRegistryAndInitStore(registerFuture: CompletableFuture>, app: ApplicationImpl): CompletableFuture> { return registerFuture .thenCompose { plugins -> val future = CompletableFuture.runAsync(Runnable { @@ -217,7 +218,10 @@ fun registerRegistryAndInitStore(registerFuture: CompletableFuture + } } } @@ -523,22 +527,6 @@ private fun processProgramArguments(args: Array): List { return arguments } -@ApiStatus.Internal -fun preloadServices(app: ApplicationImpl, plugins: List): CompletableFuture<*> { - val futures = mutableListOf>() - val executor = AppExecutorUtil.createBoundedApplicationPoolExecutor("preload services", Runtime.getRuntime().availableProcessors(), false) - for (plugin in plugins) { - for (service in (plugin as IdeaPluginDescriptorImpl).app.services) { - if (service.preload) { - futures.add(CompletableFuture.runAsync(Runnable { app.precreateService(service.getInterface()) }, executor)) - } - } - } - - executor.shutdown() - return CompletableFuture.allOf(*futures.toTypedArray()) -} - private fun CompletableFuture<*>.thenRunOrHandleError(handler: () -> Unit): CompletableFuture? { return thenRun(handler) .exceptionally { diff --git a/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoManagerImpl.java index 0607480ae694..cf109320e3c2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoManagerImpl.java @@ -102,8 +102,8 @@ public final class UndoManagerImpl extends UndoManager implements Disposable { this(null); } - public UndoManagerImpl(@Nullable ProjectEx project) { - myProject = project; + public UndoManagerImpl(@Nullable Project project) { + myProject = (ProjectEx)project; myMerger = new CommandMerger(this); if (myProject != null && myProject.isDefault()) { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/VisibleEditorsTracker.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/VisibleEditorsTracker.java index da04193e06cb..4012f6920a8f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/VisibleEditorsTracker.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/VisibleEditorsTracker.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.editor.impl; import com.intellij.openapi.application.ApplicationManager; @@ -11,7 +11,7 @@ import org.jetbrains.annotations.NotNull; import java.util.HashSet; import java.util.Set; -public class VisibleEditorsTracker implements CommandListener { +public final class VisibleEditorsTracker implements CommandListener { private final Set myEditorsVisibleOnCommandStart = new HashSet<>(); private long myCurrentCommandStart; private long myLastCommandFinish; diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/ex/IdeDocumentHistory.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/ex/IdeDocumentHistory.java index 64b90dd8b1e6..b963a3f60985 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/ex/IdeDocumentHistory.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/ex/IdeDocumentHistory.java @@ -1,4 +1,3 @@ - // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.fileEditor.ex; @@ -12,7 +11,7 @@ import java.util.List; public abstract class IdeDocumentHistory { public static IdeDocumentHistory getInstance(Project project) { - return project.getComponent(IdeDocumentHistory.class); + return project.getService(IdeDocumentHistory.class); } public abstract void includeCurrentCommandAsNavigation(); diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java index b9caf6ea649a..529431e299ef 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java @@ -54,7 +54,6 @@ import com.intellij.util.text.DateFormatUtil; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.TestOnly; import java.io.File; import java.io.IOException; @@ -75,7 +74,6 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory implements Dispos private final Project myProject; private FileDocumentManager myFileDocumentManager; - private FileEditorManagerEx myFileEditorManager; private final LinkedList myBackPlaces = new LinkedList<>(); // LinkedList of PlaceInfo's private final LinkedList myForwardPlaces = new LinkedList<>(); // LinkedList of PlaceInfo's @@ -98,9 +96,8 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory implements Dispos private RecentlyChangedFilesState myRecentlyChangedFiles = new RecentlyChangedFilesState(); - public IdeDocumentHistoryImpl(@NotNull Project project, @NotNull FileEditorManagerEx fileEditorManager) { + public IdeDocumentHistoryImpl(@NotNull Project project) { myProject = project; - myFileEditorManager = fileEditorManager; MessageBusConnection busConnection = project.getMessageBus().connect(this); busConnection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() { @@ -165,6 +162,10 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory implements Dispos myRecentFilesTimestampsMap = initRecentFilesTimestampMap(project); } + protected FileEditorManagerEx getFileEditorManager() { + return FileEditorManagerEx.getInstanceEx(myProject); + } + @NotNull private PersistentHashMap initRecentFilesTimestampMap(@NotNull Project project) { File file = ProjectUtil.getProjectCachePath(project, "recentFilesTimeStamps.dat").toFile(); @@ -195,11 +196,6 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory implements Dispos return map; } - @TestOnly - public void setFileEditorManager(@NotNull FileEditorManagerEx value) { - myFileEditorManager = value; - } - private void registerViewed(@NotNull VirtualFile file) { if (ApplicationManager.getApplication().isUnitTestMode()) { return; @@ -554,7 +550,7 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory implements Dispos public void gotoPlaceInfo(@NotNull PlaceInfo info) { final boolean wasActive = ToolWindowManager.getInstance(myProject).isEditorComponentActive(); EditorWindow wnd = info.getWindow(); - FileEditorManagerEx editorManager = myFileEditorManager; + FileEditorManagerEx editorManager = getFileEditorManager(); final Pair editorsWithProviders = wnd != null && wnd.isValid() ? editorManager.openFileWithProviders(info.getFile(), wasActive, wnd) : editorManager.openFileWithProviders(info.getFile(), wasActive, false); @@ -576,7 +572,7 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory implements Dispos */ @Nullable protected FileEditorWithProvider getSelectedEditor() { - FileEditorManagerEx editorManager = myFileEditorManager; + FileEditorManagerEx editorManager = getFileEditorManager(); VirtualFile file = editorManager.getCurrentFile(); return file == null ? null : editorManager.getSelectedEditorWithProvider(file); } @@ -586,7 +582,7 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory implements Dispos return null; } - FileEditorManagerEx editorManager = myFileEditorManager; + FileEditorManagerEx editorManager = getFileEditorManager(); final VirtualFile file = editorManager.getFile(fileEditor); LOG.assertTrue(file != null); FileEditorState state = fileEditor.getState(FileEditorStateLevel.NAVIGATION); diff --git a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectImpl.java index 9c403d9145fb..b49431d8064d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectImpl.java @@ -39,12 +39,14 @@ import com.intellij.openapi.wm.impl.FrameTitleBuilder; import com.intellij.project.ProjectStoreOwner; import com.intellij.psi.impl.DebugUtil; import com.intellij.serviceContainer.PlatformComponentManagerImpl; +import com.intellij.util.ExceptionUtil; import com.intellij.util.PathUtil; import com.intellij.util.TimedReference; import org.jetbrains.annotations.*; import javax.swing.*; import java.nio.file.Path; +import java.util.concurrent.ExecutionException; public class ProjectImpl extends PlatformComponentManagerImpl implements ProjectEx, ProjectStoreOwner { private static final Logger LOG = Logger.getInstance("#com.intellij.project.impl.ProjectImpl"); @@ -240,7 +242,21 @@ public class ProjectImpl extends PlatformComponentManagerImpl implements Project public void init(@Nullable ProgressIndicator indicator) { Application application = ApplicationManager.getApplication(); + + // before components + if (!isDefault()) { + Activity activity = StartUpMeasurer.start("preload project services"); + try { + preloadServices(PluginManagerCore.getLoadedPlugins()).get(); + } + catch (InterruptedException | ExecutionException e) { + ExceptionUtil.rethrow(e); + } + activity.end(); + } + createComponents(indicator); + if (indicator != null && !application.isHeadlessEnvironment()) { distributeProgress(indicator); } diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 01b8e16ea590..d51328bbea96 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -88,7 +88,11 @@ serviceImplementation="com.intellij.facet.impl.FacetTypeRegistryImpl"/> + serviceImplementation="com.intellij.openapi.roots.impl.DirectoryIndexImpl" preload="true"/> + + diff --git a/platform/platform-resources/src/componentSets/Editor.xml b/platform/platform-resources/src/componentSets/Editor.xml index 4c248431aa8b..f78f79a211fe 100644 --- a/platform/platform-resources/src/componentSets/Editor.xml +++ b/platform/platform-resources/src/componentSets/Editor.xml @@ -10,14 +10,8 @@ com.intellij.openapi.keymap.impl.ModifierKeyDoubleClickHandler - - - - com.intellij.openapi.editor.impl.DocumentMarkupModelManager - - - com.intellij.openapi.fileEditor.ex.IdeDocumentHistory - com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl - - + + + \ No newline at end of file diff --git a/platform/platform-resources/src/componentSets/Lang.xml b/platform/platform-resources/src/componentSets/Lang.xml index 97772ebf3f22..3d849b92715f 100644 --- a/platform/platform-resources/src/componentSets/Lang.xml +++ b/platform/platform-resources/src/componentSets/Lang.xml @@ -6,19 +6,9 @@ - - com.intellij.psi.PsiManager - com.intellij.psi.impl.PsiManagerImpl - - com.intellij.psi.impl.file.impl.PsiVFSListener - - com.intellij.psi.PsiDocumentManager - com.intellij.psi.impl.PsiDocumentManagerImpl - - com.intellij.openapi.module.ModuleManager diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/HeavyFileEditorManagerTestCase.java b/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/HeavyFileEditorManagerTestCase.java index de98f2efefd3..b55b7d85ae4b 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/HeavyFileEditorManagerTestCase.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/HeavyFileEditorManagerTestCase.java @@ -1,9 +1,8 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.fileEditor; -import com.intellij.openapi.fileEditor.ex.IdeDocumentHistory; import com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl; -import com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl; +import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.PlatformTestUtil; @@ -24,9 +23,9 @@ public abstract class HeavyFileEditorManagerTestCase extends CodeInsightFixtureT public void setUp() throws Exception { super.setUp(); - FileEditorManagerImpl manager = new FileEditorManagerImpl(getProject()); - ((IdeDocumentHistoryImpl)IdeDocumentHistory.getInstance(getProject())).setFileEditorManager(manager); - ServiceContainerUtil.registerComponentInstance(getProject(), FileEditorManager.class, manager, getTestRootDisposable()); + Project project = getProject(); + FileEditorManagerImpl manager = new FileEditorManagerImpl(project); + ServiceContainerUtil.registerComponentInstance(project, FileEditorManager.class, manager, getTestRootDisposable()); } @Override diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/NewDocumentHistoryTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/NewDocumentHistoryTest.java index c0beb436f91f..e3e96fd31e0b 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/NewDocumentHistoryTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/NewDocumentHistoryTest.java @@ -19,7 +19,7 @@ public class NewDocumentHistoryTest extends HeavyFileEditorManagerTestCase { @Override public void setUp() throws Exception { super.setUp(); - myHistory = new IdeDocumentHistoryImpl(getProject(), FileEditorManagerEx.getInstanceEx(getProject())); + myHistory = new IdeDocumentHistoryImpl(getProject()); } @Override diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryTest.java index b833b9759b30..cc2741770279 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryTest.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.fileEditor.impl; import com.intellij.mock.Mock; @@ -6,6 +6,7 @@ import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorProvider; import com.intellij.openapi.fileEditor.FileEditorState; import com.intellij.openapi.fileEditor.FileEditorStateLevel; +import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx; import com.intellij.openapi.fileEditor.ex.FileEditorWithProvider; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Pair; @@ -42,7 +43,13 @@ public class IdeDocumentHistoryTest extends HeavyPlatformTestCase { } }; - myHistory = new IdeDocumentHistoryImpl(getProject(), new EditorManager()) { + EditorManager editorManager = new EditorManager(); + myHistory = new IdeDocumentHistoryImpl(getProject()) { + @Override + protected FileEditorManagerEx getFileEditorManager() { + return editorManager; + } + @Override protected FileEditorWithProvider getSelectedEditor() { return mySelectedEditor == null ? null : new FileEditorWithProvider(mySelectedEditor, myProvider); diff --git a/platform/projectModel-api/src/com/intellij/openapi/module/ModuleUtilCore.java b/platform/projectModel-api/src/com/intellij/openapi/module/ModuleUtilCore.java index 89a749ac5ca5..bf4432ddea2f 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/module/ModuleUtilCore.java +++ b/platform/projectModel-api/src/com/intellij/openapi/module/ModuleUtilCore.java @@ -1,4 +1,4 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.module; import com.intellij.openapi.application.ReadAction; @@ -66,7 +66,10 @@ public class ModuleUtilCore { @Nullable public static Module findModuleForFile(@NotNull VirtualFile file, @NotNull Project project) { - return ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(file); + if (project.isDefault()) { + return null; + } + return ProjectFileIndex.getInstance(project).getModuleForFile(file); } @Nullable diff --git a/platform/projectModel-api/src/com/intellij/openapi/roots/ProjectFileIndex.java b/platform/projectModel-api/src/com/intellij/openapi/roots/ProjectFileIndex.java index 9e3a43271392..57520e826d6b 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/roots/ProjectFileIndex.java +++ b/platform/projectModel-api/src/com/intellij/openapi/roots/ProjectFileIndex.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.roots; import com.intellij.openapi.components.ServiceManager; @@ -43,7 +29,7 @@ public interface ProjectFileIndex extends FileIndex { @NotNull static ProjectFileIndex getInstance(@NotNull Project project) { - return ServiceManager.getService(project, ProjectFileIndex.class); + return project.getService(ProjectFileIndex.class); } /** diff --git a/platform/projectModel-impl/src/com/intellij/core/CoreModule.java b/platform/projectModel-impl/src/com/intellij/core/CoreModule.java index 996bed8c10e9..e0d65c90cfdf 100644 --- a/platform/projectModel-impl/src/com/intellij/core/CoreModule.java +++ b/platform/projectModel-impl/src/com/intellij/core/CoreModule.java @@ -12,14 +12,11 @@ import com.intellij.openapi.module.impl.ModuleScopeProvider; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ModuleFileIndex; import com.intellij.openapi.roots.ModuleRootManager; -import com.intellij.openapi.roots.impl.DirectoryIndex; import com.intellij.openapi.roots.impl.ModuleFileIndexImpl; import com.intellij.openapi.roots.impl.ModuleRootManagerImpl; -import com.intellij.openapi.roots.impl.ProjectRootManagerImpl; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.util.PathUtil; import org.jetbrains.annotations.NotNull; @@ -43,9 +40,7 @@ public class CoreModule extends MockComponentManager implements ModuleEx { initModuleExtensions(); final ModuleRootManagerImpl moduleRootManager = - new ModuleRootManagerImpl(this, - ProjectRootManagerImpl.getInstanceImpl(project), - VirtualFilePointerManager.getInstance()) { + new ModuleRootManagerImpl(this) { @Override public void loadState(@NotNull ModuleRootManagerState object) { loadState(object, false); @@ -54,7 +49,7 @@ public class CoreModule extends MockComponentManager implements ModuleEx { Disposer.register(parentDisposable, moduleRootManager); getPicoContainer().registerComponentInstance(ModuleRootManager.class, moduleRootManager); getPicoContainer().registerComponentInstance(PathMacroManager.class, createModulePathMacroManager(project)); - getPicoContainer().registerComponentInstance(ModuleFileIndex.class, createModuleFileIndex(project)); + getPicoContainer().registerComponentInstance(ModuleFileIndex.class, createModuleFileIndex()); myModuleScopeProvider = createModuleScopeProvider(); } @@ -75,8 +70,8 @@ public class CoreModule extends MockComponentManager implements ModuleEx { return new ModulePathMacroManager(this); } - protected ModuleFileIndex createModuleFileIndex(@NotNull Project project) { - return new ModuleFileIndexImpl(this, DirectoryIndex.getInstance(project)); + protected ModuleFileIndex createModuleFileIndex() { + return new ModuleFileIndexImpl(this); } @Override diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndex.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndex.java index c1b895c0b5e4..e2492f596123 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndex.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndex.java @@ -2,7 +2,6 @@ package com.intellij.openapi.roots.impl; -import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.OrderEntry; @@ -23,8 +22,9 @@ import java.util.Set; @ApiStatus.Internal public abstract class DirectoryIndex { public static DirectoryIndex getInstance(Project project) { - assert !project.isDefault() : "Must not call DirectoryIndex for default project"; - return ServiceManager.getService(project, DirectoryIndex.class); + // todo enable later when all usages will be fixed + //assert !project.isDefault() : "Must not call DirectoryIndex for default project"; + return project.getService(DirectoryIndex.class); } @NotNull diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/FileIndexBase.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/FileIndexBase.java index c8bc08cfb3a8..97dcb9b8fc98 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/FileIndexBase.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/FileIndexBase.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.roots.impl; import com.intellij.injected.editor.VirtualFileWindow; @@ -39,9 +25,9 @@ abstract class FileIndexBase implements FileIndex { private final FileTypeRegistry myFileTypeRegistry; final DirectoryIndex myDirectoryIndex; - FileIndexBase(@NotNull DirectoryIndex directoryIndex, @NotNull FileTypeRegistry fileTypeManager) { + FileIndexBase(@NotNull DirectoryIndex directoryIndex) { myDirectoryIndex = directoryIndex; - myFileTypeRegistry = fileTypeManager; + myFileTypeRegistry = FileTypeRegistry.getInstance(); } protected abstract boolean isScopeDisposed(); diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ModuleFileIndexImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ModuleFileIndexImpl.java index 5d8b6f0f23a1..9146c4b54505 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ModuleFileIndexImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ModuleFileIndexImpl.java @@ -1,9 +1,7 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - package com.intellij.openapi.roots.impl; import com.intellij.openapi.application.ReadAction; -import com.intellij.openapi.fileTypes.FileTypeRegistry; import com.intellij.openapi.module.Module; import com.intellij.openapi.roots.*; import com.intellij.openapi.vfs.VirtualFile; @@ -15,12 +13,13 @@ import org.jetbrains.jps.model.module.JpsModuleSourceRootType; import java.util.*; -public class ModuleFileIndexImpl extends FileIndexBase implements ModuleFileIndex { +public final class ModuleFileIndexImpl extends FileIndexBase implements ModuleFileIndex { @NotNull private final Module myModule; - public ModuleFileIndexImpl(@NotNull Module module, @NotNull DirectoryIndex directoryIndex) { - super(directoryIndex, FileTypeRegistry.getInstance()); + public ModuleFileIndexImpl(@NotNull Module module) { + super(DirectoryIndex.getInstance(module.getProject())); + myModule = module; } diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ModuleRootManagerImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ModuleRootManagerImpl.java index fb9caa5c96eb..a4b606e3da97 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ModuleRootManagerImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ModuleRootManagerImpl.java @@ -1,6 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.roots.impl; import com.intellij.openapi.Disposable; @@ -48,14 +46,12 @@ public class ModuleRootManagerImpl extends ModuleRootManagerEx implements Dispos protected final SimpleModificationTracker myModificationTracker = new SimpleModificationTracker(); - public ModuleRootManagerImpl(@NotNull Module module, - @NotNull ProjectRootManagerImpl projectRootManager, - @NotNull VirtualFilePointerManager filePointerManager) { + public ModuleRootManagerImpl(@NotNull Module module) { myModule = module; - myProjectRootManager = projectRootManager; - myFilePointerManager = filePointerManager; + myProjectRootManager = ProjectRootManagerImpl.getInstanceImpl(module.getProject()); + myFilePointerManager = VirtualFilePointerManager.getInstance(); - myRootModel = new RootModelImpl(this, projectRootManager, filePointerManager); + myRootModel = new RootModelImpl(this, myProjectRootManager, myFilePointerManager); myOrderRootsCache = new OrderRootsCache(module); } diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectFileIndexFacade.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectFileIndexFacade.java index 2450358eb1bd..76a27e0beaab 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectFileIndexFacade.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectFileIndexFacade.java @@ -10,7 +10,6 @@ import com.intellij.openapi.roots.FileIndexFacade; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.ModificationTracker; -import com.intellij.openapi.util.NotNullLazyValue; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -21,14 +20,14 @@ import java.util.Collection; * @author yole */ public final class ProjectFileIndexFacade extends FileIndexFacade { - // PsiManagerImpl is created for default project, but DirectoryIndex must be not created for default project. - private final NotNullLazyValue myDirectoryIndex = NotNullLazyValue.createValue(() -> DirectoryIndex.getInstance(myProject)); + private final DirectoryIndex myDirectoryIndex; private final ProjectFileIndex myFileIndex; ProjectFileIndexFacade(@NotNull Project project) { super(project); myFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); + myDirectoryIndex = DirectoryIndex.getInstance(project); } @Override @@ -80,7 +79,7 @@ public final class ProjectFileIndexFacade extends FileIndexFacade { while (true) { if (childDir == null) return false; if (childDir.equals(baseDir)) return true; - if (!myDirectoryIndex.getValue().getInfoForFile(childDir).isInProject(childDir)) return false; + if (!myDirectoryIndex.getInfoForFile(childDir).isInProject(childDir)) return false; childDir = childDir.getParent(); } } @@ -101,7 +100,7 @@ public final class ProjectFileIndexFacade extends FileIndexFacade { public boolean isInProjectScope(@NotNull VirtualFile file) { // optimization: equivalent to the super method but has fewer getInfoForFile() calls if (file instanceof VirtualFileWindow) return true; - DirectoryInfo info = myDirectoryIndex.getValue().getInfoForFile(file); + DirectoryInfo info = myDirectoryIndex.getInfoForFile(file); if (!info.isInProject(file)) return false; if (info.hasLibraryClassRoot() && !info.isInModuleSource(file)) return false; return info.getModule() != null; diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectFileIndexImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectFileIndexImpl.java index b7bda1c61548..b82074cce07f 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectFileIndexImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectFileIndexImpl.java @@ -1,5 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.roots.impl; import com.intellij.injected.editor.VirtualFileWindow; @@ -23,11 +22,22 @@ import java.util.List; import java.util.Set; public class ProjectFileIndexImpl extends FileIndexBase implements ProjectFileIndex { - private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.impl.ProjectFileIndexImpl"); + private static final Logger LOG = Logger.getInstance(ProjectFileIndexImpl.class); private final Project myProject; - public ProjectFileIndexImpl(@NotNull Project project, @NotNull DirectoryIndex directoryIndex, @NotNull FileTypeRegistry fileTypeManager) { - super(directoryIndex, fileTypeManager); + public ProjectFileIndexImpl(@NotNull Project project) { + super(DirectoryIndex.getInstance(project)); + + myProject = project; + } + + /** + * @deprecated Do not pass DirectoryIndex explicitly. + */ + @Deprecated + public ProjectFileIndexImpl(@NotNull Project project, @NotNull DirectoryIndex index, @NotNull FileTypeRegistry fileTypeManager) { + super(index); + myProject = project; } @@ -218,7 +228,7 @@ public class ProjectFileIndexImpl extends FileIndexBase implements ProjectFileIn public SourceFolder getSourceFolder(@NotNull VirtualFile fileOrDir) { return myDirectoryIndex.getSourceRootFolder(getInfoForFileOrDirectory(fileOrDir)); } - + @Override protected boolean isScopeDisposed() { return myProject.isDisposed(); diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerImpl.java index d002832282ca..676b155dab05 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerImpl.java @@ -114,7 +114,7 @@ public class ProjectRootManagerImpl extends ProjectRootManagerEx implements Pers @Override @NotNull public ProjectFileIndex getFileIndex() { - return ProjectFileIndex.SERVICE.getInstance(myProject); + return ProjectFileIndex.getInstance(myProject); } @Override diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/TestModulePropertiesImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/TestModulePropertiesImpl.java index 2ef7b3f50157..768834dd29f7 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/TestModulePropertiesImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/TestModulePropertiesImpl.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.roots.impl; import com.intellij.openapi.components.PersistentStateComponent; @@ -20,13 +20,11 @@ import org.jetbrains.annotations.Nullable; @State(name = "TestModuleProperties") class TestModulePropertiesImpl extends TestModuleProperties implements PersistentStateComponent, ProjectModelElement { - private final ModulePointerManager myModulePointerManager; private ModulePointer myProductionModulePointer; private final Module myModule; - TestModulePropertiesImpl(@NotNull Module module, @NotNull ModulePointerManager modulePointerManager) { + TestModulePropertiesImpl(@NotNull Module module) { myModule = module; - myModulePointerManager = modulePointerManager; } @Nullable @@ -43,7 +41,7 @@ class TestModulePropertiesImpl extends TestModuleProperties implements Persisten @Override public void setProductionModuleName(@Nullable String moduleName) { - myProductionModulePointer = moduleName != null ? myModulePointerManager.create(moduleName) : null; + myProductionModulePointer = moduleName != null ? ModulePointerManager.getInstance(myModule.getProject()).create(moduleName) : null; } @Nullable diff --git a/platform/service-container/src/com/intellij/serviceContainer/ConstructorInjectionComponentAdapter.kt b/platform/service-container/src/com/intellij/serviceContainer/ConstructorInjectionComponentAdapter.kt index fb6e65a4e5ca..3cc5181ba30a 100644 --- a/platform/service-container/src/com/intellij/serviceContainer/ConstructorInjectionComponentAdapter.kt +++ b/platform/service-container/src/com/intellij/serviceContainer/ConstructorInjectionComponentAdapter.kt @@ -8,8 +8,10 @@ import org.picocontainer.PicoInitializationException import org.picocontainer.PicoIntrospectionException import org.picocontainer.defaults.AmbiguousComponentResolutionException import org.picocontainer.defaults.TooManySatisfiableConstructorsException +import java.io.File import java.lang.reflect.Constructor import java.lang.reflect.InvocationTargetException +import java.nio.file.Path internal fun instantiateUsingPicoContainer(aClass: Class<*>, requestorKey: Any, componentManager: PlatformComponentManagerImpl, parameterResolver: ConstructorParameterResolver): T { val result = getGreediestSatisfiableConstructor(aClass, requestorKey, componentManager, parameterResolver) @@ -45,7 +47,9 @@ private fun getGreediestSatisfiableConstructor(aClass: Class<*>, requestorKey: A val parameterTypes = constructor.parameterTypes for (expectedType in parameterTypes) { - if (expectedType.isPrimitive || expectedType.isEnum || expectedType.isArray || Collection::class.java.isAssignableFrom(expectedType)) { + if (expectedType.isPrimitive || expectedType.isEnum || expectedType.isArray || + Collection::class.java.isAssignableFrom(expectedType) || + expectedType === File::class.java || expectedType === Path::class.java) { continue@loop } @@ -98,7 +102,7 @@ private fun getGreediestSatisfiableConstructor(aClass: Class<*>, requestorKey: A return Pair(greediestConstructor, greediestConstructorParameterTypes!!) } !unsatisfiableDependencyTypes.isNullOrEmpty() -> { - throw PicoIntrospectionException("$requestorKey has unsatisfied dependency: $unsatisfiedDependencyType among unsatisfiable dependencies: " + + throw PicoIntrospectionException("${aClass.name} has unsatisfied dependency: $unsatisfiedDependencyType among unsatisfiable dependencies: " + "$unsatisfiableDependencyTypes where $componentManager was the leaf container being asked for dependencies.") } else -> { @@ -156,6 +160,23 @@ internal abstract class ConstructorParameterResolver { return byKey } + // see UndoManagerImpl / RunManager / JavaModuleExternalPathsImpl for example + val expectedClassName = expectedType.name + + if (container.parent == null) { + if (expectedClassName == "com.intellij.openapi.project.Project") { + return null + } + } + else { + if (expectedClassName == "com.intellij.configurationStore.StreamProvider" || + expectedClassName == "com.intellij.openapi.roots.LanguageLevelModuleExtensionImpl" || + expectedClassName == "com.intellij.openapi.roots.impl.CompilerModuleExtensionImpl" || + expectedClassName == "com.intellij.openapi.roots.impl.JavaModuleExternalPathsImpl") { + return null + } + } + val found = container.getComponentAdaptersOfType(expectedType) found.removeIf { it.componentKey == excludeKey } return when { diff --git a/platform/service-container/src/com/intellij/serviceContainer/PlatformComponentManagerImpl.kt b/platform/service-container/src/com/intellij/serviceContainer/PlatformComponentManagerImpl.kt index 6039df711059..630169e32ca5 100644 --- a/platform/service-container/src/com/intellij/serviceContainer/PlatformComponentManagerImpl.kt +++ b/platform/service-container/src/com/intellij/serviceContainer/PlatformComponentManagerImpl.kt @@ -21,17 +21,20 @@ import com.intellij.openapi.progress.ProgressManager import com.intellij.openapi.util.Disposer import com.intellij.util.IncorrectOperationException import com.intellij.util.SmartList +import com.intellij.util.concurrency.AppExecutorUtil import com.intellij.util.containers.ContainerUtil import com.intellij.util.io.storage.HeavyProcessLatch import com.intellij.util.messages.* import com.intellij.util.messages.impl.MessageBusImpl import com.intellij.util.pico.DefaultPicoContainer +import org.jetbrains.annotations.ApiStatus import org.jetbrains.annotations.ApiStatus.Internal import org.jetbrains.annotations.TestOnly import java.lang.reflect.Constructor import java.lang.reflect.InvocationTargetException import java.lang.reflect.Modifier import java.util.* +import java.util.concurrent.CompletableFuture import java.util.concurrent.ConcurrentMap abstract class PlatformComponentManagerImpl @JvmOverloads constructor(internal val parent: ComponentManager?, setExtensionsRootArea: Boolean = parent == null) : ComponentManagerImpl(parent), LazyListenerCreator { @@ -104,6 +107,14 @@ abstract class PlatformComponentManagerImpl @JvmOverloads constructor(internal v plugins as List val activityNamePrefix = activityNamePrefix() val parallelActivity = if (activityNamePrefix == null) null else ParallelActivity.PREPARE_APP_INIT + + val app = getApplication() + val headless = app == null || app.isHeadlessEnvironment + var componentConfigCount = 0 + var map: ConcurrentMap>? = null + val isHeadlessMode = app?.isHeadlessEnvironment == true + val isUnitTestMode = app?.isUnitTestMode == true + parallelActivity.run("${activityNamePrefix}service and ep registration") { // register services before registering extensions because plugins can access services in their // extensions which can be invoked right away if the plugin is loaded dynamically @@ -111,6 +122,35 @@ abstract class PlatformComponentManagerImpl @JvmOverloads constructor(internal v val containerDescriptor = getContainerDescriptor(plugin) registerServices(containerDescriptor.services, plugin) + for (descriptor in containerDescriptor.components) { + if (!descriptor.prepareClasses(headless) || !isComponentSuitable(descriptor)) { + continue + } + + try { + registerComponent(descriptor, plugin) + componentConfigCount++ + } + catch (e: Throwable) { + handleInitComponentError(e, null, plugin.pluginId) + } + } + + val listeners = getContainerDescriptor(plugin).listeners + if (listeners.isNotEmpty()) { + if (map == null) { + map = ContainerUtil.newConcurrentMap() + } + + for (listener in listeners) { + if ((isUnitTestMode && !listener.activeInTestMode) || (isHeadlessMode && !listener.activeInHeadlessMode)) { + continue + } + + map!!.getOrPut(listener.topicClassName) { SmartList() }.add(listener) + } + } + containerDescriptor.extensionPoints?.let { extensionArea.registerExtensionPoints(plugin, it, this) } @@ -124,47 +164,6 @@ abstract class PlatformComponentManagerImpl @JvmOverloads constructor(internal v } } - val app = getApplication() - val headless = app == null || app.isHeadlessEnvironment - - var map: ConcurrentMap>? = null - val isHeadlessMode = app?.isHeadlessEnvironment == true - val isUnitTestMode = app?.isUnitTestMode == true - - var componentConfigCount = 0 - for (plugin in plugins) { - val containerDescriptor = getContainerDescriptor(plugin) - - for (config in containerDescriptor.components) { - if (!config.prepareClasses(headless) || !isComponentSuitable(config)) { - continue - } - - try { - registerComponent(config, plugin) - componentConfigCount++ - } - catch (e: Throwable) { - handleInitComponentError(e, null, plugin.pluginId) - } - } - - val listeners = containerDescriptor.listeners - if (listeners.isNotEmpty()) { - if (map == null) { - map = ContainerUtil.newConcurrentMap() - } - - for (listener in listeners) { - if ((isUnitTestMode && !listener.activeInTestMode) || (isHeadlessMode && !listener.activeInHeadlessMode)) { - continue - } - - map.getOrPut(listener.topicClassName) { SmartList() }.add(listener) - } - } - } - if (myComponentConfigCount <= 0) { myComponentConfigCount = componentConfigCount } @@ -178,7 +177,7 @@ abstract class PlatformComponentManagerImpl @JvmOverloads constructor(internal v // ensure that messageBus is created, regardless of lazy listeners map state val messageBus = messageBus as MessageBusImpl if (map != null) { - messageBus.setLazyListeners(map) + messageBus.setLazyListeners(map!!) } } @@ -217,7 +216,7 @@ abstract class PlatformComponentManagerImpl @JvmOverloads constructor(internal v } @TestOnly - fun registerComponentInstance(componentKey: Class, componentImplementation: T, parentDisposable: Disposable?): T? { + fun replaceComponentInstance(componentKey: Class, componentImplementation: T, parentDisposable: Disposable?): T? { val adapter = myPicoContainer.getComponentAdapter(componentKey) as MyComponentAdapter return adapter.replaceInstance(componentImplementation, parentDisposable) } @@ -529,7 +528,7 @@ abstract class PlatformComponentManagerImpl @JvmOverloads constructor(internal v final override fun instantiateClassWithConstructorInjection(aClass: Class, key: Any, pluginId: PluginId?): T { // constructorParameterResolver is very expensive, because pico container behaviour is to find greediest satisfiable constructor, // so, if class has constructors (Project) and (Project, Foo, Bar), then Foo and Bar unrelated classes will be searched for. - // To avoid this expensive nearly linear search of extension, first resolve without our logic, and in case of error try expensive. + // To avoid this expensive nearly linear search of extension, first resolve without our logic to resolve extensions, and in case of error try expensive. try { return instantiateUsingPicoContainer(aClass, key, this, constructorParameterResolver) } @@ -539,11 +538,8 @@ abstract class PlatformComponentManagerImpl @JvmOverloads constructor(internal v catch (e: ExtensionNotApplicableException) { throw e } - catch (e: IncorrectOperationException) { - throw e - } catch (e: Exception) { - if (lightServices == null) { + if (lightServices == null || e is IncorrectOperationException) { throw e } else { @@ -557,7 +553,7 @@ abstract class PlatformComponentManagerImpl @JvmOverloads constructor(internal v val app = getApplication() @Suppress("SpellCheckingInspection") if (app != null && app.isUnitTestMode && pluginId?.idString != "org.jetbrains.kotlin" && pluginId?.idString != "Lombook Plugin") { - throw UnsupportedOperationException("In tests deprecated constructor injection for extension is disabled", e) + throw UnsupportedOperationException("In tests, extension classes are not resolved for constructor injection, to enforce removing such deprecated references.", e) } } @@ -648,13 +644,28 @@ abstract class PlatformComponentManagerImpl @JvmOverloads constructor(internal v return unloadedInstances } - @Internal - fun precreateService(serviceClass: String) { - (myPicoContainer.getServiceAdapter(serviceClass) as ServiceComponentAdapter?)?.getInstance(this) - } - @Internal open fun activityNamePrefix(): String? = null + + @ApiStatus.Internal + fun preloadServices(plugins: List): CompletableFuture<*> { + @Suppress("UNCHECKED_CAST") + plugins as List + + val futures = mutableListOf>() + val executor = AppExecutorUtil.createBoundedApplicationPoolExecutor("preload services", Runtime.getRuntime().availableProcessors(), false) + for (plugin in plugins) { + for (service in getContainerDescriptor(plugin).services) { + if (service.preload) { + futures.add(CompletableFuture.runAsync(Runnable { + (myPicoContainer.getServiceAdapter(service.getInterface()) as ServiceComponentAdapter?)?.getInstance(this) + }, executor)) + } + } + } + executor.shutdown() + return CompletableFuture.allOf(*futures.toTypedArray()) + } } private fun createPluginExceptionIfNeeded(error: Throwable, pluginId: PluginId): RuntimeException { diff --git a/platform/service-container/testSrc/com/intellij/serviceContainer/ConstructorInjectionTest.kt b/platform/service-container/testSrc/com/intellij/serviceContainer/ConstructorInjectionTest.kt index 16de62d6d948..55bbdc5c3f1b 100644 --- a/platform/service-container/testSrc/com/intellij/serviceContainer/ConstructorInjectionTest.kt +++ b/platform/service-container/testSrc/com/intellij/serviceContainer/ConstructorInjectionTest.kt @@ -9,7 +9,6 @@ import com.intellij.openapi.components.ServiceDescriptor import com.intellij.openapi.components.impl.stores.IComponentStore import com.intellij.openapi.extensions.DefaultPluginDescriptor import com.intellij.openapi.extensions.PluginId -import com.intellij.openapi.extensions.impl.ExtensionsAreaImpl import com.intellij.util.messages.MessageBus import org.junit.Test @@ -19,7 +18,7 @@ class ConstructorInjectionTest { @Test fun `interface extension`() { val componentManager = TestComponentManager() - val area = componentManager.extensionArea as ExtensionsAreaImpl + val area = componentManager.extensionArea val point = area.registerPoint("bar", Bar::class.java, pluginDescriptor) @Suppress("DEPRECATION") point.registerExtension(BarImpl()) diff --git a/platform/testFramework/src/com/intellij/idea/IdeaTestApplication.java b/platform/testFramework/src/com/intellij/idea/IdeaTestApplication.java index 0d184bf78937..ee2122fc4468 100644 --- a/platform/testFramework/src/com/intellij/idea/IdeaTestApplication.java +++ b/platform/testFramework/src/com/intellij/idea/IdeaTestApplication.java @@ -100,7 +100,7 @@ public final class IdeaTestApplication implements Disposable { app.registerComponents(it); return it; }), app) - .thenCompose(it -> ApplicationLoader.preloadServices(app, it)) + .thenCompose(it -> app.preloadServices(it)) .get(20, TimeUnit.SECONDS); } catch (TimeoutException e) { diff --git a/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java b/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java index 375ad5b973e1..7a2bb7ee1db7 100644 --- a/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java @@ -108,11 +108,11 @@ public abstract class ParsingTestCase extends UsefulTestCase { app.registerService(FileDocumentManager.class, new MockFileDocumentManagerImpl(charSequence -> { return editorFactory.createDocument(charSequence); }, FileDocumentManagerImpl.HARD_REF_TO_DOCUMENT_KEY)); - appContainer.registerComponentInstance(PsiDocumentManager.class, new MockPsiDocumentManager()); app.registerService(PsiBuilderFactory.class, new PsiBuilderFactoryImpl()); app.registerService(DefaultASTFactory.class, new DefaultASTFactoryImpl()); app.registerService(ReferenceProvidersRegistry.class, new ReferenceProvidersRegistryImpl()); + myProject.registerService(PsiDocumentManager.class, new MockPsiDocumentManager()); myProject.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(myProject, new PsiCachedValuesFactory(myPsiManager))); myProject.registerService(PsiManager.class, myPsiManager); myProject.registerService(StartupManager.class, new StartupManagerImpl(myProject)); diff --git a/platform/testFramework/src/com/intellij/testFramework/ServiceContainerUtil.kt b/platform/testFramework/src/com/intellij/testFramework/ServiceContainerUtil.kt index af4cab20bdcb..15792973a574 100644 --- a/platform/testFramework/src/com/intellij/testFramework/ServiceContainerUtil.kt +++ b/platform/testFramework/src/com/intellij/testFramework/ServiceContainerUtil.kt @@ -24,14 +24,14 @@ fun ComponentManager.replaceService(serviceInterface: Class, instan */ @TestOnly fun ComponentManager.registerComponentInstance(componentInterface: Class, instance: T, parentDisposable: Disposable?): T? { - return (this as PlatformComponentManagerImpl).registerComponentInstance(componentInterface, instance, parentDisposable) + return (this as PlatformComponentManagerImpl).replaceComponentInstance(componentInterface, instance, parentDisposable) } @Suppress("DeprecatedCallableAddReplaceWith") @TestOnly @Deprecated("Pass parentDisposable") fun ComponentManager.registerComponentInstance(componentInterface: Class, instance: T): T? { - return (this as PlatformComponentManagerImpl).registerComponentInstance(componentInterface, instance, null) + return (this as PlatformComponentManagerImpl).replaceComponentInstance(componentInterface, instance, null) } @TestOnly diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsManagerConfigurableProvider.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsManagerConfigurableProvider.java index daa5dffe208b..798981e30219 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsManagerConfigurableProvider.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsManagerConfigurableProvider.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.vcs.configurable; import com.intellij.openapi.options.Configurable; @@ -36,6 +22,6 @@ public final class VcsManagerConfigurableProvider extends ConfigurableProvider { @Override public boolean canCreateConfigurable() { - return ProjectLevelVcsManager.getInstance(myProject).getAllVcss().length > 0; + return !myProject.isDefault() && ProjectLevelVcsManager.getInstance(myProject).getAllVcss().length > 0; } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LineStatusTrackerManager.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LineStatusTrackerManager.kt index 959c9a3b0ace..21bcfa62d070 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LineStatusTrackerManager.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LineStatusTrackerManager.kt @@ -26,7 +26,6 @@ import com.intellij.openapi.editor.ex.EditorEx import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx import com.intellij.openapi.project.Project -import com.intellij.openapi.roots.impl.DirectoryIndex import com.intellij.openapi.startup.StartupManager import com.intellij.openapi.util.io.FileUtilRt import com.intellij.openapi.util.registry.Registry @@ -58,7 +57,7 @@ import java.nio.charset.Charset import java.util.* import java.util.concurrent.Future -class LineStatusTrackerManager(private val project: Project, @Suppress("UNUSED_PARAMETER") makeSureIndexIsInitializedFirst: DirectoryIndex) : LineStatusTrackerManagerI, Disposable { +class LineStatusTrackerManager(private val project: Project) : LineStatusTrackerManagerI, Disposable { private val LOCK = Any() private var isDisposed = false diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/PartialLineStatusTrackerManagerState.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/PartialLineStatusTrackerManagerState.kt index 98b01ec5055f..abe44c1b5a01 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/PartialLineStatusTrackerManagerState.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/PartialLineStatusTrackerManagerState.kt @@ -1,8 +1,11 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.vcs.impl import com.intellij.diff.util.Range -import com.intellij.openapi.components.* +import com.intellij.openapi.components.PersistentStateComponent +import com.intellij.openapi.components.State +import com.intellij.openapi.components.Storage +import com.intellij.openapi.components.StoragePathMacros import com.intellij.openapi.project.Project import com.intellij.openapi.util.registry.Registry import com.intellij.openapi.vcs.changes.ChangeListManager @@ -17,10 +20,7 @@ private typealias TrackerState = ChangelistsLocalLineStatusTracker.State private typealias FullTrackerState = ChangelistsLocalLineStatusTracker.FullState @State(name = "LineStatusTrackerManager", storages = [(Storage(value = StoragePathMacros.WORKSPACE_FILE))]) -class PartialLineStatusTrackerManagerState( - private val project: Project, - private val lineStatusTracker: LineStatusTrackerManager -) : ProjectComponent, PersistentStateComponent { +class PartialLineStatusTrackerManagerState(private val project: Project) : PersistentStateComponent { private val NODE_PARTIAL_FILE = "file" private val ATT_PATH = "path" @@ -36,10 +36,9 @@ class PartialLineStatusTrackerManagerState( private val ATT_END_2 = "end2" private val ATT_CHANGELIST_ID = "changelist" - override fun getState(): Element { val element = Element("state") - val fileStates = lineStatusTracker.collectPartiallyChangedFilesStates() + val fileStates = (LineStatusTrackerManager.getInstance(project) as LineStatusTrackerManager).collectPartiallyChangedFilesStates() for (state in fileStates) { element.addContent(writePartialFileState(state)) } @@ -57,7 +56,7 @@ class PartialLineStatusTrackerManagerState( if (fileStates.isNotEmpty()) { ChangeListManager.getInstance(project).invokeAfterUpdate( { - lineStatusTracker.restoreTrackersForPartiallyChangedFiles(fileStates) + (LineStatusTrackerManager.getInstance(project) as LineStatusTrackerManager).restoreTrackersForPartiallyChangedFiles(fileStates) }, InvokeAfterUpdateMode.SILENT, null, null) } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerConfigurable.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerConfigurable.java index 2ebbc075c768..91b95632344e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerConfigurable.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerConfigurable.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.groovy.compiler; @@ -83,13 +69,13 @@ public class GroovyCompilerConfigurable implements SearchableConfigurable, Confi return myExcludes; } - private ExcludedEntriesConfigurable createExcludedConfigurable(final Project project) { + private ExcludedEntriesConfigurable createExcludedConfigurable(@NotNull Project project) { final ExcludesConfiguration configuration = myConfig.getExcludeFromStubGeneration(); - final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex(); + ProjectFileIndex index = project.isDefault() ? null : ProjectRootManager.getInstance(project).getFileIndex(); final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, false, false, false, true) { @Override public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { - return super.isFileVisible(file, showHiddenFiles) && !index.isExcluded(file); + return super.isFileVisible(file, showHiddenFiles) && (index == null || !index.isExcluded(file)); } }; descriptor.setRoots(ContainerUtil.concat(ContainerUtil.>map(ModuleManager.getInstance(project).getModules(), diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/StringDescriptorManager.java b/plugins/ui-designer/src/com/intellij/uiDesigner/StringDescriptorManager.java index bb8370159e36..8f03691c94e8 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/StringDescriptorManager.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/StringDescriptorManager.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.uiDesigner; @@ -15,7 +15,6 @@ import com.intellij.uiDesigner.lw.StringDescriptor; import com.intellij.uiDesigner.radComponents.RadComponent; import com.intellij.uiDesigner.radComponents.RadRootContainer; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.messages.MessageBus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -29,9 +28,9 @@ public class StringDescriptorManager { private Module myModule; private final Map, PropertiesFile> myPropertiesFileCache = ContainerUtil.createSoftValueMap(); - public StringDescriptorManager(final Module module, MessageBus bus) { + public StringDescriptorManager(@NotNull Module module) { myModule = module; - bus.connect().subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() { + module.getMessageBus().connect().subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() { @Override public void rootsChanged(@NotNull final ModuleRootEvent event) { synchronized(myPropertiesFileCache) { diff --git a/xml/impl/src/com/intellij/javaee/PsiExternalResourceNotifier.java b/xml/impl/src/com/intellij/javaee/PsiExternalResourceNotifier.java index b8db1f8267a5..d9a7be666187 100644 --- a/xml/impl/src/com/intellij/javaee/PsiExternalResourceNotifier.java +++ b/xml/impl/src/com/intellij/javaee/PsiExternalResourceNotifier.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.javaee; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; @@ -7,27 +7,26 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; import com.intellij.psi.impl.PsiManagerEx; -public class PsiExternalResourceNotifier { +public final class PsiExternalResourceNotifier { private final PsiManagerEx myPsiManager; - private final ExternalResourceManagerEx myExternalResourceManager; private final DaemonCodeAnalyzer myDaemonCodeAnalyzer; - public PsiExternalResourceNotifier(PsiManagerEx psiManager, ExternalResourceManager externalResourceManager, - final DaemonCodeAnalyzer daemonCodeAnalyzer, Project project) { - myPsiManager = psiManager; - myExternalResourceManager = (ExternalResourceManagerEx)externalResourceManager; - myDaemonCodeAnalyzer = daemonCodeAnalyzer; + public PsiExternalResourceNotifier(Project project) { + myPsiManager = PsiManagerEx.getInstanceEx(project); + + ExternalResourceManagerEx externalResourceManager = ExternalResourceManagerEx.getInstanceEx(); + myDaemonCodeAnalyzer = DaemonCodeAnalyzer.getInstance(project); final ExternalResourceListener myExternalResourceListener = new MyExternalResourceListener(); - myExternalResourceManager.addExternalResourceListener(myExternalResourceListener); + externalResourceManager.addExternalResourceListener(myExternalResourceListener); Disposer.register(project, new Disposable() { @Override public void dispose() { - myExternalResourceManager.removeExternalResourceListener(myExternalResourceListener); + externalResourceManager.removeExternalResourceListener(myExternalResourceListener); } }); } - private class MyExternalResourceListener implements ExternalResourceListener { + private final class MyExternalResourceListener implements ExternalResourceListener { @Override public void externalResourceChanged() { myPsiManager.beforeChange(true);