Merge "Fixes issue with CaptureTypes not being registered at the right time." into studio-1.3-dev
diff --git a/android/src/META-INF/plugin.xml b/android/src/META-INF/plugin.xml
index 67a91e1..943b43d 100755
--- a/android/src/META-INF/plugin.xml
+++ b/android/src/META-INF/plugin.xml
@@ -189,6 +189,8 @@
<applicationService serviceImplementation="com.android.tools.idea.gradle.service.repo.ExternalRepository"/>
<applicationService serviceImplementation="com.android.tools.idea.gradle.editor.ui.GradleEditorEntityUiRegistry"/>
<applicationService serviceImplementation="com.android.tools.idea.profiling.capture.CaptureTypeService"/>
+ <fileEditorProvider implementation="com.android.tools.idea.profiling.capture.CaptureEditorProvider" />
+
<applicationService serviceInterface="com.android.tools.idea.stats.UsageTracker"
serviceImplementation="com.android.tools.idea.stats.UsageTrackerAnalyticsImpl"/>
@@ -250,14 +252,10 @@
<lang.commenter language="AIDL" implementationClass="com.intellij.lang.java.JavaCommenter"/>
-->
<fileEditorProvider implementation="com.android.tools.idea.editors.NinePatchEditorProvider" />
- <fileEditorProvider implementation="com.android.tools.idea.editors.vmtrace.VmTraceEditorProvider" />
<fileEditorProvider implementation="com.android.tools.idea.editors.navigation.NavigationEditorProvider" />
- <fileEditorProvider implementation="com.android.tools.idea.editors.allocations.AllocationsEditorProvider" />
<fileEditorProvider implementation="com.android.tools.idea.editors.strings.StringResourceEditorProvider" />
- <fileEditorProvider implementation="com.android.tools.idea.editors.hprof.HprofEditorProvider" />
<fileEditorProvider implementation="com.android.tools.idea.editors.theme.ThemeEditorProvider"/>
<fileEditorProvider implementation="com.android.tools.idea.editors.gfxtrace.GfxTraceEditorProvider" />
- <fileEditorProvider implementation="com.android.tools.idea.editors.systeminfo.SystemInfoEditorProvider" />
<runConfigurationProducer implementation="org.jetbrains.android.run.AndroidConfigurationProducer"/>
<runConfigurationProducer implementation="org.jetbrains.android.run.testing.AndroidTestConfigurationProducer" order="first"/>
@@ -723,6 +721,7 @@
<extensionPoint name="newModuleWizardPathFactory" interface="com.android.tools.idea.wizard.NewModuleWizardPathFactory"/>
<extensionPoint name="newModuleDynamicPathFactory" interface="com.android.tools.idea.wizard.NewModuleDynamicPathFactory"/>
<extensionPoint name="wizardParameterFactory" interface="com.android.tools.idea.wizard.WizardParameterFactory"/>
+ <extensionPoint qualifiedName="com.android.captureType" interface="com.android.tools.idea.profiling.capture.CaptureType"/>
<extensionPoint qualifiedName="com.android.gradle.syncErrorHandler"
interface="com.android.tools.idea.gradle.service.notification.errors.AbstractSyncErrorHandler"/>
<extensionPoint qualifiedName="com.android.gradle.buildVariantModuleCustomizer"
@@ -735,6 +734,13 @@
interface="com.android.tools.idea.run.CloudConfigurationProvider"/>
</extensionPoints>
+ <extensions defaultExtensionNs="com.android">
+ <captureType implementation="com.android.tools.idea.editors.hprof.HprofCaptureType"/>
+ <captureType implementation="com.android.tools.idea.editors.allocations.AllocationCaptureType"/>
+ <captureType implementation="com.android.tools.idea.editors.systeminfo.SystemInfoCaptureType"/>
+ <captureType implementation="com.android.tools.idea.editors.vmtrace.VmTraceCaptureType"/>
+ </extensions>
+
<extensions defaultExtensionNs="org.jetbrains.android">
<newModuleWizardPathFactory implementation="com.android.tools.idea.wizard.WrapArchiveWizardPathFactory"/>
<newModuleDynamicPathFactory implementation="com.android.tools.idea.wizard.LegacyWizardPathProvider"/>
diff --git a/android/src/com/android/tools/idea/editors/allocations/AllocationCaptureType.java b/android/src/com/android/tools/idea/editors/allocations/AllocationCaptureType.java
index 967e360..31a7c1a 100644
--- a/android/src/com/android/tools/idea/editors/allocations/AllocationCaptureType.java
+++ b/android/src/com/android/tools/idea/editors/allocations/AllocationCaptureType.java
@@ -16,10 +16,20 @@
package com.android.tools.idea.editors.allocations;
import com.android.tools.idea.profiling.capture.FileCaptureType;
+import com.intellij.openapi.fileEditor.FileEditor;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.VirtualFile;
import icons.AndroidIcons;
+import org.jetbrains.annotations.NotNull;
public class AllocationCaptureType extends FileCaptureType {
protected AllocationCaptureType() {
super("Allocation Tracking", AndroidIcons.Ddms.AllocationTracker, "Allocations_", ".alloc");
}
+
+ @NotNull
+ @Override
+ public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile file) {
+ return new AllocationsEditor(project, file);
+ }
}
diff --git a/android/src/com/android/tools/idea/editors/allocations/AllocationsEditorProvider.java b/android/src/com/android/tools/idea/editors/allocations/AllocationsEditorProvider.java
deleted file mode 100644
index 6e0cb04..0000000
--- a/android/src/com/android/tools/idea/editors/allocations/AllocationsEditorProvider.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * 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.
- */
-
-package com.android.tools.idea.editors.allocations;
-
-import com.android.tools.idea.profiling.capture.CaptureType;
-import com.android.tools.idea.profiling.capture.CaptureTypeService;
-import com.intellij.openapi.fileEditor.FileEditor;
-import com.intellij.openapi.fileEditor.FileEditorPolicy;
-import com.intellij.openapi.fileEditor.FileEditorProvider;
-import com.intellij.openapi.fileEditor.FileEditorState;
-import com.intellij.openapi.project.DumbAware;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Disposer;
-import com.intellij.openapi.vfs.VirtualFile;
-import org.jdom.Element;
-import org.jetbrains.annotations.NonNls;
-import org.jetbrains.annotations.NotNull;
-
-public class AllocationsEditorProvider implements FileEditorProvider, DumbAware {
- @NonNls private static final String ID = "allocations-editor";
-
- public AllocationsEditorProvider() {
- CaptureTypeService.getInstance().register(AllocationCaptureType.class, new AllocationCaptureType());
- }
-
- @Override
- public boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
- CaptureType type = CaptureTypeService.getInstance().getType(AllocationCaptureType.class);
- return type != null && type.isValidCapture(file);
- }
-
- @NotNull
- @Override
- public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile file) {
- return new AllocationsEditor(project, file);
- }
-
- @Override
- public void disposeEditor(@NotNull FileEditor editor) {
- Disposer.dispose(editor);
- }
-
- @NotNull
- @Override
- public FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
- return FileEditorState.INSTANCE;
- }
-
- @Override
- public void writeState(@NotNull FileEditorState state, @NotNull Project project, @NotNull Element targetElement) {
- }
-
- @NotNull
- @Override
- public String getEditorTypeId() {
- return ID;
- }
-
- @NotNull
- @Override
- public FileEditorPolicy getPolicy() {
- return FileEditorPolicy.HIDE_DEFAULT_EDITOR;
- }
-}
\ No newline at end of file
diff --git a/android/src/com/android/tools/idea/editors/hprof/HprofCaptureType.java b/android/src/com/android/tools/idea/editors/hprof/HprofCaptureType.java
index 0492054..b5cb427 100644
--- a/android/src/com/android/tools/idea/editors/hprof/HprofCaptureType.java
+++ b/android/src/com/android/tools/idea/editors/hprof/HprofCaptureType.java
@@ -17,10 +17,20 @@
import com.android.SdkConstants;
import com.android.tools.idea.profiling.capture.FileCaptureType;
+import com.intellij.openapi.fileEditor.FileEditor;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.VirtualFile;
import icons.AndroidIcons;
+import org.jetbrains.annotations.NotNull;
public class HprofCaptureType extends FileCaptureType {
protected HprofCaptureType() {
super("Heap Snapshot", AndroidIcons.Ddms.DumpHprof, "Snapshot_", SdkConstants.DOT_HPROF);
}
+
+ @NotNull
+ @Override
+ public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile file) {
+ return new HprofEditor(project, file);
+ }
}
diff --git a/android/src/com/android/tools/idea/editors/systeminfo/SystemInfoCaptureType.java b/android/src/com/android/tools/idea/editors/systeminfo/SystemInfoCaptureType.java
index 5be6780..cf9eb88 100644
--- a/android/src/com/android/tools/idea/editors/systeminfo/SystemInfoCaptureType.java
+++ b/android/src/com/android/tools/idea/editors/systeminfo/SystemInfoCaptureType.java
@@ -17,10 +17,25 @@
import com.android.SdkConstants;
import com.android.tools.idea.profiling.capture.FileCaptureType;
+import com.intellij.openapi.fileEditor.FileEditor;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.VirtualFile;
import icons.AndroidIcons;
+import org.jetbrains.annotations.NotNull;
public class SystemInfoCaptureType extends FileCaptureType {
protected SystemInfoCaptureType() {
super("System Information", AndroidIcons.Ddms.SysInfo, "SystemInfo_", SdkConstants.DOT_TXT);
}
+
+ @NotNull
+ @Override
+ public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile file) {
+ throw new IllegalStateException("Should not ask to create an editor");
+ }
+
+ @Override
+ public boolean accept(@NotNull VirtualFile file) {
+ return false;
+ }
}
diff --git a/android/src/com/android/tools/idea/editors/systeminfo/SystemInfoEditorProvider.java b/android/src/com/android/tools/idea/editors/systeminfo/SystemInfoEditorProvider.java
deleted file mode 100644
index 02f7d10..0000000
--- a/android/src/com/android/tools/idea/editors/systeminfo/SystemInfoEditorProvider.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * 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.
- */
-package com.android.tools.idea.editors.systeminfo;
-
-import com.android.tools.idea.profiling.capture.CaptureTypeService;
-import com.intellij.openapi.fileEditor.FileEditor;
-import com.intellij.openapi.fileEditor.FileEditorPolicy;
-import com.intellij.openapi.fileEditor.FileEditorProvider;
-import com.intellij.openapi.fileEditor.FileEditorState;
-import com.intellij.openapi.project.DumbAware;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Disposer;
-import com.intellij.openapi.vfs.VirtualFile;
-import org.jdom.Element;
-import org.jetbrains.annotations.NotNull;
-
-public class SystemInfoEditorProvider implements FileEditorProvider, DumbAware {
- public SystemInfoEditorProvider() {
- CaptureTypeService.getInstance().register(SystemInfoCaptureType.class, new SystemInfoCaptureType());
- }
-
- @Override
- public boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
- // Use the default text editor to open files of this capture type, thus this provider should not accept the files.
- return false;
- }
-
- @NotNull
- @Override
- public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile file) {
- throw new UnsupportedOperationException(
- "SystemInfoEditorProvider should let the default text editor provider handle this file type, and this method should not be called.");
- }
-
- @Override
- public void disposeEditor(@NotNull FileEditor editor) {
- Disposer.dispose(editor);
- }
-
- @NotNull
- @Override
- public FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
- return FileEditorState.INSTANCE;
- }
-
- @Override
- public void writeState(@NotNull FileEditorState state, @NotNull Project project, @NotNull Element targetElement) {
-
- }
-
- @NotNull
- @Override
- public String getEditorTypeId() {
- return "systeminfo-viewer";
- }
-
- @NotNull
- @Override
- public FileEditorPolicy getPolicy() {
- return FileEditorPolicy.HIDE_DEFAULT_EDITOR;
- }
-}
diff --git a/android/src/com/android/tools/idea/editors/vmtrace/VmTraceCaptureType.java b/android/src/com/android/tools/idea/editors/vmtrace/VmTraceCaptureType.java
index bef42e8..8bc0c77 100644
--- a/android/src/com/android/tools/idea/editors/vmtrace/VmTraceCaptureType.java
+++ b/android/src/com/android/tools/idea/editors/vmtrace/VmTraceCaptureType.java
@@ -16,7 +16,11 @@
package com.android.tools.idea.editors.vmtrace;
import com.android.tools.idea.profiling.capture.FileCaptureType;
+import com.intellij.openapi.fileEditor.FileEditor;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.VirtualFile;
import icons.AndroidIcons;
+import org.jetbrains.annotations.NotNull;
import static com.android.ddmlib.DdmConstants.DOT_TRACE;
@@ -24,4 +28,10 @@
protected VmTraceCaptureType() {
super("Method Tracing", AndroidIcons.Ddms.StartMethodProfiling, "Trace_", DOT_TRACE);
}
+
+ @NotNull
+ @Override
+ public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile file) {
+ return new VmTraceEditor(project, file);
+ }
}
diff --git a/android/src/com/android/tools/idea/editors/vmtrace/VmTraceEditorProvider.java b/android/src/com/android/tools/idea/editors/vmtrace/VmTraceEditorProvider.java
deleted file mode 100644
index eb164ec..0000000
--- a/android/src/com/android/tools/idea/editors/vmtrace/VmTraceEditorProvider.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * 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.
- */
-
-package com.android.tools.idea.editors.vmtrace;
-
-import com.android.tools.idea.profiling.capture.CaptureType;
-import com.android.tools.idea.profiling.capture.CaptureTypeService;
-import com.intellij.openapi.fileEditor.FileEditor;
-import com.intellij.openapi.fileEditor.FileEditorPolicy;
-import com.intellij.openapi.fileEditor.FileEditorProvider;
-import com.intellij.openapi.fileEditor.FileEditorState;
-import com.intellij.openapi.project.DumbAware;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Disposer;
-import com.intellij.openapi.vfs.VirtualFile;
-import org.jdom.Element;
-import org.jetbrains.annotations.NonNls;
-import org.jetbrains.annotations.NotNull;
-
-public class VmTraceEditorProvider implements FileEditorProvider, DumbAware {
- @NonNls private static final String ID = "vmtrace-editor";
-
- public VmTraceEditorProvider() {
- CaptureTypeService.getInstance().register(VmTraceCaptureType.class, new VmTraceCaptureType());
- }
-
- @Override
- public boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
- CaptureType type = CaptureTypeService.getInstance().getType(VmTraceCaptureType.class);
- return type != null && type.isValidCapture(file);
- }
-
- @NotNull
- @Override
- public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile file) {
- return new VmTraceEditor(project, file);
- }
-
- @Override
- public void disposeEditor(@NotNull FileEditor editor) {
- Disposer.dispose(editor);
- }
-
- @NotNull
- @Override
- public FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
- return FileEditorState.INSTANCE;
- }
-
- @Override
- public void writeState(@NotNull FileEditorState state, @NotNull Project project, @NotNull Element targetElement) {
- }
-
- @NotNull
- @Override
- public String getEditorTypeId() {
- return ID;
- }
-
- @NotNull
- @Override
- public FileEditorPolicy getPolicy() {
- return FileEditorPolicy.HIDE_DEFAULT_EDITOR;
- }
-}
diff --git a/android/src/com/android/tools/idea/editors/hprof/HprofEditorProvider.java b/android/src/com/android/tools/idea/profiling/capture/CaptureEditorProvider.java
similarity index 75%
rename from android/src/com/android/tools/idea/editors/hprof/HprofEditorProvider.java
rename to android/src/com/android/tools/idea/profiling/capture/CaptureEditorProvider.java
index 8194a6e..63ecfae 100644
--- a/android/src/com/android/tools/idea/editors/hprof/HprofEditorProvider.java
+++ b/android/src/com/android/tools/idea/profiling/capture/CaptureEditorProvider.java
@@ -13,10 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.tools.idea.editors.hprof;
+package com.android.tools.idea.profiling.capture;
-import com.android.tools.idea.profiling.capture.CaptureType;
-import com.android.tools.idea.profiling.capture.CaptureTypeService;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorPolicy;
import com.intellij.openapi.fileEditor.FileEditorProvider;
@@ -29,23 +27,23 @@
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
-public class HprofEditorProvider implements FileEditorProvider, DumbAware {
- @NonNls private static final String ID = "hprof-viewer";
-
- public HprofEditorProvider() {
- CaptureTypeService.getInstance().register(HprofCaptureType.class, new HprofCaptureType());
- }
+public class CaptureEditorProvider implements FileEditorProvider, DumbAware {
+ @NonNls private static final String ID = "capture-editor";
@Override
public boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
- CaptureType type = CaptureTypeService.getInstance().getType(HprofCaptureType.class);
- return type != null && type.isValidCapture(file);
+ CaptureType type = CaptureTypeService.getInstance().getTypeFor(file);
+ return type != null && type.accept(file);
}
@NotNull
@Override
public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile file) {
- return new HprofEditor(project, file);
+ CaptureType type = CaptureTypeService.getInstance().getTypeFor(file);
+ if (type == null) {
+ throw new IllegalStateException("Type has been removed between accept and createEditor");
+ }
+ return type.createEditor(project, file);
}
@Override
diff --git a/android/src/com/android/tools/idea/profiling/capture/CaptureType.java b/android/src/com/android/tools/idea/profiling/capture/CaptureType.java
index f4d3f92..b62c3af 100644
--- a/android/src/com/android/tools/idea/profiling/capture/CaptureType.java
+++ b/android/src/com/android/tools/idea/profiling/capture/CaptureType.java
@@ -15,6 +15,8 @@
*/
package com.android.tools.idea.profiling.capture;
+import com.intellij.openapi.fileEditor.FileEditor;
+import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
@@ -38,4 +40,11 @@
@NotNull
protected abstract Capture createCapture(@NotNull VirtualFile file);
+
+ @NotNull
+ public abstract FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile file);
+
+ public boolean accept(@NotNull VirtualFile file) {
+ return true;
+ }
}
diff --git a/android/src/com/android/tools/idea/profiling/capture/CaptureTypeService.java b/android/src/com/android/tools/idea/profiling/capture/CaptureTypeService.java
index 0126588b..c7d6ad2 100644
--- a/android/src/com/android/tools/idea/profiling/capture/CaptureTypeService.java
+++ b/android/src/com/android/tools/idea/profiling/capture/CaptureTypeService.java
@@ -15,34 +15,38 @@
*/
package com.android.tools.idea.profiling.capture;
-import com.google.common.collect.Maps;
import com.intellij.openapi.components.ServiceManager;
+import com.intellij.openapi.extensions.ExtensionPointName;
+import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import java.util.Collection;
-import java.util.Map;
-
public class CaptureTypeService {
- @NotNull Map<Class<? extends CaptureType>, CaptureType> myCaptureTypes = Maps.newHashMap();
+ ExtensionPointName<CaptureType> EP_NAME = ExtensionPointName.create("com.android.captureType");
@NotNull
public static CaptureTypeService getInstance() {
return ServiceManager.getService(CaptureTypeService.class);
}
- public <T extends CaptureType> void register(Class<T> clazz, T type) {
- myCaptureTypes.put(clazz, type);
- }
-
@NotNull
- public Collection<CaptureType> getCaptureTypes() {
- return myCaptureTypes.values();
+ public CaptureType[] getCaptureTypes() {
+ return EP_NAME.getExtensions();
}
@Nullable
public <T extends CaptureType> T getType(Class<T> type) {
- return (T)myCaptureTypes.get(type);
+ return EP_NAME.findExtension(type);
+ }
+
+ @Nullable
+ public CaptureType getTypeFor(@NotNull VirtualFile file) {
+ for (CaptureType type : getCaptureTypes()) {
+ if (type.isValidCapture(file)) {
+ return type;
+ }
+ }
+ return null;
}
}
diff --git a/android/testSrc/com/android/tools/idea/profiling/capture/CaptureServiceTest.java b/android/testSrc/com/android/tools/idea/profiling/capture/CaptureServiceTest.java
index 0c8ded7..49f6fc0 100644
--- a/android/testSrc/com/android/tools/idea/profiling/capture/CaptureServiceTest.java
+++ b/android/testSrc/com/android/tools/idea/profiling/capture/CaptureServiceTest.java
@@ -16,17 +16,29 @@
package com.android.tools.idea.profiling.capture;
import com.intellij.icons.AllIcons;
+import com.intellij.openapi.extensions.DefaultPluginDescriptor;
+import com.intellij.openapi.extensions.Extensions;
+import com.intellij.openapi.extensions.ExtensionsArea;
+import com.intellij.openapi.extensions.PluginId;
+import com.intellij.openapi.fileEditor.FileEditor;
+import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.IdeaTestCase;
+import org.jdom.Element;
+import org.jdom.input.SAXBuilder;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
-import java.io.IOException;
+import java.io.StringReader;
public class CaptureServiceTest extends IdeaTestCase {
- public void testUpdate() throws IOException {
+ static Element readElement(String text) throws Exception {
+ return new SAXBuilder().build(new StringReader(text)).getRootElement();
+ }
+
+ public void testUpdate() throws Exception {
CaptureService service = CaptureService.getInstance(myProject);
assertNull(service.getCapturesDirectory());
@@ -41,8 +53,13 @@
service.update();
assertTrue(service.getCaptures().isEmpty());
- MyCaptureType type = new MyCaptureType();
- CaptureTypeService.getInstance().register(MyCaptureType.class, type);
+ ExtensionsArea area = Extensions.getRootArea();
+ Element element = readElement(" <extensions defaultExtensionNs=\"org.jetbrains.android\">\n" +
+ " <captureType implementation=\"" + MyCaptureType.class.getName() +
+ "\"/>\n </extensions>");
+ area.registerExtension(new DefaultPluginDescriptor(PluginId.getId("org.jetbrains.android")), element.getChild("captureType"));
+ MyCaptureType type = CaptureTypeService.getInstance().getType(MyCaptureType.class);
+
service.update();
assertEquals(1, service.getCaptures().size());
assertEquals(type, service.getCaptures().iterator().next().getType());
@@ -74,6 +91,12 @@
@NotNull
@Override
+ public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile file) {
+ return null;
+ }
+
+ @NotNull
+ @Override
public String createCaptureFileName() {
return "1234";
}