Skip to content

Commit 9dc92de

Browse files
committed
1051: Fixed already disposed exception
1 parent fa1e9af commit 9dc92de

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/com/magento/idea/magento2plugin/magento/packages/MagentoComponentManager.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
/**
1+
/*
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
package com.magento.idea.magento2plugin.magento.packages;
67

78
import com.intellij.json.psi.JsonFile;
89
import com.intellij.json.psi.JsonObject;
10+
import com.intellij.openapi.components.Service;
911
import com.intellij.openapi.project.DumbService;
1012
import com.intellij.openapi.project.Project;
1113
import com.intellij.openapi.vfs.VirtualFile;
@@ -18,29 +20,27 @@
1820
import com.intellij.psi.xml.XmlTag;
1921
import com.intellij.util.indexing.FileBasedIndex;
2022
import com.magento.idea.magento2plugin.stubs.indexes.ModulePackageIndex;
21-
import org.jetbrains.annotations.NotNull;
22-
import org.jetbrains.annotations.Nullable;
2323
import java.util.ArrayList;
2424
import java.util.Collection;
2525
import java.util.HashMap;
2626
import java.util.Map;
27+
import org.jetbrains.annotations.NotNull;
28+
import org.jetbrains.annotations.Nullable;
29+
30+
@Service
31+
public final class MagentoComponentManager {
2732

28-
public class MagentoComponentManager {
2933
private Map<String, MagentoComponent> components = new HashMap<>();
3034
private long cacheStartTime;
3135
private static final int CACHE_LIFE_TIME = 20000;
32-
private static MagentoComponentManager magentoComponentManager;
33-
private Project project;
36+
private final Project project;
3437

35-
private MagentoComponentManager(Project project){
38+
public MagentoComponentManager(final Project project) {
3639
this.project = project;
3740
}
3841

39-
public static MagentoComponentManager getInstance(@NotNull Project project) {
40-
if (magentoComponentManager == null) {
41-
magentoComponentManager = new MagentoComponentManager(project);
42-
}
43-
return magentoComponentManager;
42+
public static MagentoComponentManager getInstance(final @NotNull Project project) {
43+
return project.getService(MagentoComponentManager.class);
4444
}
4545

4646
public Collection<MagentoComponent> getAllComponents() {
@@ -60,8 +60,8 @@ public <T extends MagentoComponent> Collection<T> getAllComponentsOfType(@NotNul
6060
return result;
6161
}
6262

63-
synchronized private Map<String, MagentoComponent> getComponents() {
64-
if (DumbService.getInstance(project).isDumb() || project.isDisposed()) {
63+
private synchronized Map<String, MagentoComponent> getComponents() {
64+
if (project.isDisposed() || DumbService.getInstance(project).isDumb()) {
6565
return new HashMap<>();
6666
}
6767

0 commit comments

Comments
 (0)