-/*
- * 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;
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;
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));
}
};
Collections.addAll(allContentRoots, moduleContentRoots);
}
descriptor.setRoots(allContentRoots);
- return new ExcludedEntriesConfigurable(project, descriptor, configuration);
+ return new ExcludedEntriesConfigurable(project, descriptor, ValidationConfiguration.getExcludedEntriesConfiguration(project));
}
@Override
* @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;
}
-/*
- * 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;
/**
* @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
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;
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();
private final Deque<VirtualFile> 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;
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"));
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();
});
}
}
});
- myApplication.addApplicationListener(new ApplicationListener() {
+ ApplicationManagerEx.getApplicationEx().addApplicationListener(new ApplicationListener() {
@Override
public void beforeWriteActionStart(@NotNull Object action) {
disable();
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);
}
}
private volatile int resolvedInPreviousBatch;
private void processBatch(@NotNull final ProgressIndicator indicator, @NotNull Set<VirtualFile> files) {
- assert !myApplication.isDispatchThread();
+ assert !ApplicationManagerEx.getApplicationEx().isDispatchThread();
final int resolvedInPreviousBatch = this.resolvedInPreviousBatch;
final int totalSize = files.size() + resolvedInPreviousBatch;
final IntObjectMap<int[]> fileToForwardIds = ContainerUtil.createConcurrentIntObjectMap();
}, indicator);
return result[0];
};
- List<Future<Boolean>> futures = ContainerUtil.map(Collections.nCopies(parallelism, ""), s -> myApplication.executeOnPooledThread(processFileFromSet));
+ List<Future<Boolean>> futures = ContainerUtil.map(Collections.nCopies(parallelism, ""), s -> ApplicationManagerEx.getApplicationEx()
+ .executeOnPooledThread(processFileFromSet));
List<Boolean> results = ContainerUtil.map(futures, future -> {
try {
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<TIntArrayList>() {
@Override
public boolean execute(int fileId, TIntArrayList backIds) {
-/*
- * 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
public Query<VirtualFile> getDirsByPackageName(@NotNull String packageName, boolean includeLibrarySources) {
return myDirectoryIndex.getDirectoriesByPackageName(packageName, includeLibrarySources);
}
-
}
-// 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;
/**
* @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<String> 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) {
@Override
@Nullable
public PsiPackage findPackage(@NotNull String packageName) {
- Query<VirtualFile> dirs = myPackageIndex.getDirsByPackageName(packageName, true);
+ Query<VirtualFile> dirs = PackageIndex.getInstance(myManager.getProject()).getDirsByPackageName(packageName, true);
if (dirs.findFirst() == null) return null;
return new PsiPackageImpl(myManager, packageName);
}
-/*
- * 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;
* 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);
}
}
-/*
- * 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;
* 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);
}
/**
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);
-/*
- * 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;
import java.util.Map;
-public class ControlFlowFactory {
+public final class ControlFlowFactory {
// psiElements hold weakly, controlFlows softly
private final Map<PsiElement, ConcurrentList<ControlFlowContext>> cachedFlows = ContainerUtil.createConcurrentWeakKeySoftValueMap();
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() {
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<LanguageLevel, PsiClass> myArrayClasses = ContainerUtil.newConcurrentMap();
private final ConcurrentMap<GlobalSearchScope, PsiClassType> 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
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;
protected final PsiManager myManager;
- public PsiJavaParserFacadeImpl(PsiManager manager) {
- myManager = manager;
+ public PsiJavaParserFacadeImpl(@NotNull Project project) {
+ myManager = PsiManager.getInstance(project);
}
protected PsiJavaFile createDummyJavaFile(String text) {
-/*
- * 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
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;
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) {
}
/**
- * 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 <T> Service class type.
* @return the document manager instance.
*/
public static PsiDocumentManager getInstance(@NotNull Project project) {
- return project.getComponent(PsiDocumentManager.class);
+ return project.getService(PsiDocumentManager.class);
}
/**
-/*
- * 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;
* 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.
*
*/
@NotNull
public static PsiManager getInstance(@NotNull Project project) {
- return project.getComponent(PsiManager.class);
+ return project.getService(PsiManager.class);
}
/**
-// 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;
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
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);
-/*
- * 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);
}
}
-/*
- * 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;
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());
-/*
- * 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;
-// 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;
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";
private final Object lock = new Object();
private final HashSetQueue<CommitTask> documentsToCommit = new HashSetQueue<>(); // guarded by lock
private final HashSetQueue<CommitTask> 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
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;
// 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) {
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);
}
final List<BooleanRunnable> finishProcessors = new SmartList<>();
List<BooleanRunnable> reparseInjectedProcessors = new SmartList<>();
Runnable runnable = () -> {
- myApplication.assertReadAccessAllowed();
+ ApplicationManager.getApplication().assertReadAccessAllowed();
if (project.isDisposed()) return;
Lock lock = getDocumentLock(document);
}
}
};
- 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");
}
@NotNull List<? extends BooleanRunnable> finishProcessors,
@NotNull List<? extends BooleanRunnable> reparseInjectedProcessors) {
return () -> {
- myApplication.assertIsDispatchThread();
+ ApplicationManager.getApplication().assertIsDispatchThread();
Document document = task.getDocument();
Project project = task.project;
PsiDocumentManagerBase documentManager = (PsiDocumentManagerBase)PsiDocumentManager.getInstance(project);
@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
-/*
- * 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;
/**
* @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;
}
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.*;
protected final Project myProject;
private final PsiManager myPsiManager;
- private final DocumentCommitProcessor myDocumentCommitProcessor;
+ protected final DocumentCommitProcessor myDocumentCommitProcessor;
final Set<Document> myUncommittedDocuments = ContainerUtil.newConcurrentSet();
private final Map<Document, UncommittedInfo> myUncommittedInfos = ContainerUtil.newConcurrentMap();
boolean myStopTrackingDocuments;
private final List<Listener> 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
-/*
- * 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;
//noinspection SSBasedInspection
return (PsiManagerEx)getInstance(project);
}
+
public abstract boolean isBatchFilesProcessingMode();
@TestOnly
// 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;
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;
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<? extends FileIndexFacade> myFileIndex;
private final PsiModificationTracker myModificationTracker;
private final FileManagerImpl myFileManager;
PsiBuilderFactory.getInstance();
myProject = project;
- myFileIndex = FileIndexFacade.getInstance(project);
+ myFileIndex = NotNullLazyValue.createValue(() -> FileIndexFacade.getInstance(project));
myModificationTracker = PsiModificationTracker.SERVICE.getInstance(project);
myFileManager = new FileManagerImpl(this, myFileIndex);
}
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
return myFileManager.findFile(file);
}
+ @NotNull
@Override
- @Nullable
public FileViewProvider findViewProvider(@NotNull VirtualFile file) {
ProgressIndicatorProvider.checkCanceled();
return myFileManager.findViewProvider(file);
-/*
- * 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.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;
/**
* @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
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;
-/*
- * 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
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;
private final Key<FileViewProvider> myPsiHardRefKey = Key.create("HARD_REFERENCE_TO_PSI"); //non-static!
private final PsiManagerImpl myManager;
- private final FileIndexFacade myFileIndex;
+ private final NotNullLazyValue<? extends FileIndexFacade> myFileIndex;
private final AtomicReference<ConcurrentMap<VirtualFile, PsiDirectory>> myVFileToPsiDirMap = new AtomicReference<>();
private final AtomicReference<ConcurrentMap<VirtualFile, FileViewProvider>> myVFileToViewProviderMap = new AtomicReference<>();
private final MessageBusConnection myConnection;
- public FileManagerImpl(PsiManagerImpl manager, FileIndexFacade fileIndex) {
+ public FileManagerImpl(@NotNull PsiManagerImpl manager, @NotNull NotNullLazyValue<? extends FileIndexFacade> fileIndex) {
myManager = manager;
myFileIndex = fileIndex;
myConnection = manager.getProject().getMessageBus().connect();
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) {
-/*
- * 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;
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<SmartPointerTracker> 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()));
}
if (pointers != null) pointers.fastenBelts(this);
}
- private static final Key<Reference<SmartPsiElementPointerImpl>> CACHED_SMART_POINTER_KEY = Key.create("CACHED_SMART_POINTER_KEY");
+ private static final Key<Reference<SmartPsiElementPointerImpl<?>>> CACHED_SMART_POINTER_KEY = Key.create("CACHED_SMART_POINTER_KEY");
@Override
@NotNull
public <E extends PsiElement> SmartPsiElementPointer<E> createSmartPsiElementPointer(@NotNull E element) {
}
private static <E extends PsiElement> SmartPsiElementPointerImpl<E> getCachedPointer(@NotNull E element) {
- Reference<SmartPsiElementPointerImpl> data = element.getUserData(CACHED_SMART_POINTER_KEY);
- SmartPsiElementPointerImpl cachedPointer = SoftReference.dereference(data);
+ Reference<SmartPsiElementPointerImpl<?>> data = element.getUserData(CACHED_SMART_POINTER_KEY);
+ SmartPsiElementPointerImpl<?> cachedPointer = SoftReference.dereference(data);
if (cachedPointer != null) {
PsiElement cachedElement = cachedPointer.getElement();
if (cachedElement != element) {
}
}
//noinspection unchecked
- return cachedPointer;
+ return (SmartPsiElementPointerImpl<E>)cachedPointer;
}
@Override
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());
-// 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;
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<CommitId> 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");
}
@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);
-// 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;
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<Document> 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) {
-// 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;
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
-// 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;
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;
private final Map<VirtualFile, GlobalSearchScope> 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(
},
ContainerUtil::createConcurrentWeakKeySoftValueMap);
- ((PsiManagerImpl)psiManager).registerRunnableToRunOnChange(myDefaultResolveScopesCache::clear);
+ ((PsiManagerImpl)myManager).registerRunnableToRunOnChange(myDefaultResolveScopesCache::clear);
}
private GlobalSearchScope getResolveScopeFromProviders(@NotNull final VirtualFile vFile) {
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());
}
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;
private static final Key<TemplateState> 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) {
-/*
- * 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;
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;
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();
}
}
private void verifyState() {
- if (! myShared.isEmpty()) {
- final Collection<RunnerAndConfigurationSettings> sharedConfigurations = getSharedConfigurations();
- final List<RunnerAndConfigurationSettings> canNotBeShared = new ArrayList<>();
- final Iterator<RunnerAndConfigurationSettings> 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<RunnerAndConfigurationSettings> sharedConfigurations = getSharedConfigurations();
+ final List<RunnerAndConfigurationSettings> canNotBeShared = new ArrayList<>();
+ final Iterator<RunnerAndConfigurationSettings> 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<RunnerAndConfigurationSettings> getSharedConfigurations() {
}
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);
}
-// 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.*;
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<Facet>() {
+ ProjectWideFacetListenersRegistry.getInstance(myProject).registerListener(new ProjectWideFacetAdapter<Facet>() {
@Override
public void facetAdded(@NotNull Facet facet) {
for (FacetDependentToolWindow extension : getDependentExtensions(facet)) {
@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<FacetType> 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<FacetType> 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;
}
}
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);
}
}
// 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;
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;
if (result.length() > 0) result.append(",").append(FontUtil.spaceAndThinSpace());
result.append(FileUtil.getLocationRelativeToUserHome(directory.getPresentableUrl()));
}
-
+
return result.length() == 0 ? null : result.toString();
}
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;
public class ModuleRootManagerComponent extends ModuleRootManagerImpl implements
PersistentStateComponentWithModificationTracker<ModuleRootManagerImpl.ModuleRootManagerState>,
StateStorageChooserEx {
- public ModuleRootManagerComponent(Module module,
- ProjectRootManagerImpl projectRootManager,
- VirtualFilePointerManager filePointerManager) {
- super(module, projectRootManager, filePointerManager);
+ public ModuleRootManagerComponent(Module module) {
+ super(module);
}
@NotNull
}
}
-
+
List<String> recursiveUrls = ContainerUtil.map(recursivePaths, VfsUtilCore::pathToUrl);
Set<String> 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
// module roots already fire validity change events, see usages of ProjectRootManagerComponent.getRootsValidityChangedListener
collectModuleWatchRoots(recursivePaths, flatPaths);
-
+
return Pair.create(recursivePaths, flatPaths);
}
@Override
protected void clearScopesCaches() {
super.clearScopesCaches();
- LibraryScopeCache.getInstance(myProject).clear();
+
+ LibraryScopeCache libraryScopeCache = myProject.getServiceIfCreated(LibraryScopeCache.class);
+ if (libraryScopeCache != null) {
+ libraryScopeCache.clear();
+ }
}
@Override
-// 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.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;
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) {
fireDocumentCreated(document, psiFile);
}
});
- Disposer.register(this, () -> ((DocumentCommitThread)myDocumentCommitThread).cancelTasksOnProjectDispose(project));
+ Disposer.register(this, () -> ((DocumentCommitThread)myDocumentCommitProcessor).cancelTasksOnProjectDispose(project));
}
@Nullable
@TestOnly
public void clearUncommittedDocuments() {
super.clearUncommittedDocuments();
- ((DocumentCommitThread)myDocumentCommitThread).clearQueue();
+ ((DocumentCommitThread)myDocumentCommitProcessor).clearQueue();
}
@NotNull
-// 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;
@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()) {
import java.util.Set;
@State(name = "ActionMacroManager", storages = @Storage("macros.xml"))
-public class ActionMacroManager implements PersistentStateComponent<Element>, Disposable {
+public final class ActionMacroManager implements PersistentStateComponent<Element>, Disposable {
private static final Logger LOG = Logger.getInstance(ActionMacroManager.class);
private static final String TYPING_SAMPLE = "WWWWWWWWWWWWWWWWWWWW";
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);
}
// 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) {
}
@ApiStatus.Internal
-fun registerRegistryAndInitStore(registerFuture: CompletableFuture<List<IdeaPluginDescriptor>>, app: ApplicationImpl): CompletableFuture<List<IdeaPluginDescriptor>> {
+fun registerRegistryAndInitStore(registerFuture: CompletableFuture<List<IdeaPluginDescriptor>>, app: ApplicationImpl): CompletableFuture<List<IdeaPluginDescriptorImpl>> {
return registerFuture
.thenCompose { plugins ->
val future = CompletableFuture.runAsync(Runnable {
initConfigurationStore(app, null)
future
- .thenApply { plugins }
+ .thenApply {
+ @Suppress("UNCHECKED_CAST")
+ plugins as List<IdeaPluginDescriptorImpl>
+ }
}
}
return arguments
}
-@ApiStatus.Internal
-fun preloadServices(app: ApplicationImpl, plugins: List<IdeaPluginDescriptor>): CompletableFuture<*> {
- val futures = mutableListOf<CompletableFuture<Void>>()
- 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<Void>? {
return thenRun(handler)
.exceptionally {
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()) {
-// 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;
import java.util.HashSet;
import java.util.Set;
-public class VisibleEditorsTracker implements CommandListener {
+public final class VisibleEditorsTracker implements CommandListener {
private final Set<Editor> myEditorsVisibleOnCommandStart = new HashSet<>();
private long myCurrentCommandStart;
private long myLastCommandFinish;
-
// 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;
public abstract class IdeDocumentHistory {
public static IdeDocumentHistory getInstance(Project project) {
- return project.getComponent(IdeDocumentHistory.class);
+ return project.getService(IdeDocumentHistory.class);
}
public abstract void includeCurrentCommandAsNavigation();
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;
private final Project myProject;
private FileDocumentManager myFileDocumentManager;
- private FileEditorManagerEx myFileEditorManager;
private final LinkedList<PlaceInfo> myBackPlaces = new LinkedList<>(); // LinkedList of PlaceInfo's
private final LinkedList<PlaceInfo> myForwardPlaces = new LinkedList<>(); // LinkedList of PlaceInfo's
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() {
myRecentFilesTimestampsMap = initRecentFilesTimestampMap(project);
}
+ protected FileEditorManagerEx getFileEditorManager() {
+ return FileEditorManagerEx.getInstanceEx(myProject);
+ }
+
@NotNull
private PersistentHashMap<String, Long> initRecentFilesTimestampMap(@NotNull Project project) {
File file = ProjectUtil.getProjectCachePath(project, "recentFilesTimeStamps.dat").toFile();
return map;
}
- @TestOnly
- public void setFileEditorManager(@NotNull FileEditorManagerEx value) {
- myFileEditorManager = value;
- }
-
private void registerViewed(@NotNull VirtualFile file) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
return;
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<FileEditor[], FileEditorProvider[]> editorsWithProviders = wnd != null && wnd.isValid()
? editorManager.openFileWithProviders(info.getFile(), wasActive, wnd)
: editorManager.openFileWithProviders(info.getFile(), wasActive, false);
*/
@Nullable
protected FileEditorWithProvider getSelectedEditor() {
- FileEditorManagerEx editorManager = myFileEditorManager;
+ FileEditorManagerEx editorManager = getFileEditorManager();
VirtualFile file = editorManager.getCurrentFile();
return file == null ? null : editorManager.getSelectedEditorWithProvider(file);
}
return null;
}
- FileEditorManagerEx editorManager = myFileEditorManager;
+ FileEditorManagerEx editorManager = getFileEditorManager();
final VirtualFile file = editorManager.getFile(fileEditor);
LOG.assertTrue(file != null);
FileEditorState state = fileEditor.getState(FileEditorStateLevel.NAVIGATION);
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");
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);
}
serviceImplementation="com.intellij.facet.impl.FacetTypeRegistryImpl"/>
<projectService serviceInterface="com.intellij.openapi.roots.impl.DirectoryIndex"
- serviceImplementation="com.intellij.openapi.roots.impl.DirectoryIndexImpl"/>
+ serviceImplementation="com.intellij.openapi.roots.impl.DirectoryIndexImpl" preload="true"/>
+ <projectService serviceInterface="com.intellij.psi.PsiManager"
+ serviceImplementation="com.intellij.psi.impl.PsiManagerImpl" preload="true"/>
+ <projectService serviceInterface="com.intellij.psi.PsiDocumentManager"
+ serviceImplementation="com.intellij.psi.impl.PsiDocumentManagerImpl" preload="true"/>
<projectService serviceInterface="com.intellij.util.indexing.FileBasedIndexScanRunnableCollector"
serviceImplementation="com.intellij.util.indexing.FileBasedIndexScanRunnableCollectorImpl"/>
<implementation-class>com.intellij.openapi.keymap.impl.ModifierKeyDoubleClickHandler</implementation-class>
</component>
</application-components>
-
- <project-components>
- <component>
- <implementation-class>com.intellij.openapi.editor.impl.DocumentMarkupModelManager</implementation-class>
- </component>
- <component>
- <interface-class>com.intellij.openapi.fileEditor.ex.IdeDocumentHistory</interface-class>
- <implementation-class>com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl</implementation-class>
- </component>
- </project-components>
+ <extensions defaultExtensionNs="com.intellij">
+ <projectService serviceInterface="com.intellij.openapi.fileEditor.ex.IdeDocumentHistory"
+ serviceImplementation="com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl" preload="true"/>
+ </extensions>
</idea-plugin>
\ No newline at end of file
<loadForDefaultProject/>
</component>
- <component>
- <interface-class>com.intellij.psi.PsiManager</interface-class>
- <implementation-class>com.intellij.psi.impl.PsiManagerImpl</implementation-class>
- <loadForDefaultProject/>
- </component>
<component>
<implementation-class>com.intellij.psi.impl.file.impl.PsiVFSListener</implementation-class>
</component>
- <component>
- <interface-class>com.intellij.psi.PsiDocumentManager</interface-class>
- <implementation-class>com.intellij.psi.impl.PsiDocumentManagerImpl</implementation-class>
- <loadForDefaultProject/>
- </component>
<component>
<interface-class>com.intellij.openapi.module.ModuleManager</interface-class>
// 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;
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
@Override
public void setUp() throws Exception {
super.setUp();
- myHistory = new IdeDocumentHistoryImpl(getProject(), FileEditorManagerEx.getInstanceEx(getProject()));
+ myHistory = new IdeDocumentHistoryImpl(getProject());
}
@Override
-// 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;
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;
}
};
- 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);
-// 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;
@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
-/*
- * 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;
@NotNull
static ProjectFileIndex getInstance(@NotNull Project project) {
- return ServiceManager.getService(project, ProjectFileIndex.class);
+ return project.getService(ProjectFileIndex.class);
}
/**
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;
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);
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();
}
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
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;
@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
-/*
- * 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;
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();
// 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;
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;
}
-/*
- * 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;
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);
}
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;
* @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<DirectoryIndex> 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
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();
}
}
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;
-// 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;
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;
}
public SourceFolder getSourceFolder(@NotNull VirtualFile fileOrDir) {
return myDirectoryIndex.getSourceRootFolder(getInfoForFileOrDirectory(fileOrDir));
}
-
+
@Override
protected boolean isScopeDisposed() {
return myProject.isDisposed();
@Override
@NotNull
public ProjectFileIndex getFileIndex() {
- return ProjectFileIndex.SERVICE.getInstance(myProject);
+ return ProjectFileIndex.getInstance(myProject);
}
@Override
-// 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;
@State(name = "TestModuleProperties")
class TestModulePropertiesImpl extends TestModuleProperties implements PersistentStateComponent<TestModulePropertiesImpl.TestModulePropertiesState>,
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
@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
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 <T> instantiateUsingPicoContainer(aClass: Class<*>, requestorKey: Any, componentManager: PlatformComponentManagerImpl, parameterResolver: ConstructorParameterResolver): T {
val result = getGreediestSatisfiableConstructor(aClass, requestorKey, componentManager, parameterResolver)
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
}
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 -> {
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 {
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 {
plugins as List<IdeaPluginDescriptorImpl>
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<String, MutableList<ListenerDescriptor>>? = 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
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)
}
}
}
- val app = getApplication()
- val headless = app == null || app.isHeadlessEnvironment
-
- var map: ConcurrentMap<String, MutableList<ListenerDescriptor>>? = 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
}
// 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!!)
}
}
}
@TestOnly
- fun <T : Any> registerComponentInstance(componentKey: Class<T>, componentImplementation: T, parentDisposable: Disposable?): T? {
+ fun <T : Any> replaceComponentInstance(componentKey: Class<T>, componentImplementation: T, parentDisposable: Disposable?): T? {
val adapter = myPicoContainer.getComponentAdapter(componentKey) as MyComponentAdapter
return adapter.replaceInstance(componentImplementation, parentDisposable)
}
final override fun <T : Any> instantiateClassWithConstructorInjection(aClass: Class<T>, 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)
}
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 {
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)
}
}
return unloadedInstances
}
- @Internal
- fun precreateService(serviceClass: String) {
- (myPicoContainer.getServiceAdapter(serviceClass) as ServiceComponentAdapter?)?.getInstance<Any>(this)
- }
-
@Internal
open fun activityNamePrefix(): String? = null
+
+ @ApiStatus.Internal
+ fun preloadServices(plugins: List<IdeaPluginDescriptor>): CompletableFuture<*> {
+ @Suppress("UNCHECKED_CAST")
+ plugins as List<IdeaPluginDescriptorImpl>
+
+ val futures = mutableListOf<CompletableFuture<Void>>()
+ 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<Any>(this)
+ }, executor))
+ }
+ }
+ }
+ executor.shutdown()
+ return CompletableFuture.allOf(*futures.toTypedArray())
+ }
}
private fun createPluginExceptionIfNeeded(error: Throwable, pluginId: PluginId): RuntimeException {
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
@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())
app.registerComponents(it);
return it;
}), app)
- .thenCompose(it -> ApplicationLoader.preloadServices(app, it))
+ .thenCompose(it -> app.preloadServices(it))
.get(20, TimeUnit.SECONDS);
}
catch (TimeoutException e) {
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));
*/
@TestOnly
fun <T : Any> ComponentManager.registerComponentInstance(componentInterface: Class<T>, 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 <T : Any> ComponentManager.registerComponentInstance(componentInterface: Class<T>, instance: T): T? {
- return (this as PlatformComponentManagerImpl).registerComponentInstance(componentInterface, instance, null)
+ return (this as PlatformComponentManagerImpl).replaceComponentInstance(componentInterface, instance, null)
}
@TestOnly
-/*
- * 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;
@Override
public boolean canCreateConfigurable() {
- return ProjectLevelVcsManager.getInstance(myProject).getAllVcss().length > 0;
+ return !myProject.isDefault() && ProjectLevelVcsManager.getInstance(myProject).getAllVcss().length > 0;
}
}
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
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
-// 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
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<Element> {
+class PartialLineStatusTrackerManagerState(private val project: Project) : PersistentStateComponent<Element> {
private val NODE_PARTIAL_FILE = "file"
private val ATT_PATH = "path"
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))
}
if (fileStates.isNotEmpty()) {
ChangeListManager.getInstance(project).invokeAfterUpdate(
{
- lineStatusTracker.restoreTrackersForPartiallyChangedFiles(fileStates)
+ (LineStatusTrackerManager.getInstance(project) as LineStatusTrackerManager).restoreTrackersForPartiallyChangedFiles(fileStates)
}, InvokeAfterUpdateMode.SILENT, null, null)
}
}
-/*
- * 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;
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.<Module, List<VirtualFile>>map(ModuleManager.getInstance(project).getModules(),
-// 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;
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;
private Module myModule;
private final Map<Pair<Locale, String>, 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) {
-// 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;
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);