diff options
Diffstat (limited to 'platform/extensions/testSrc/com/intellij')
12 files changed, 1224 insertions, 0 deletions
diff --git a/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/DependentObjectOne.java b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/DependentObjectOne.java new file mode 100644 index 00000000..489e8f34 --- /dev/null +++ b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/DependentObjectOne.java @@ -0,0 +1,31 @@ +/* + * 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. + */ +package com.intellij.openapi.extensions.impl; + +/** + * @author Alexander Kireyev + */ +public class DependentObjectOne { + private final XMLTestBean[] myTestBeans; + + public DependentObjectOne(XMLTestBean[] testBeans) { + myTestBeans = testBeans; + } + + public XMLTestBean[] getTestBeans() { + return myTestBeans; + } +} diff --git a/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/DependentObjectThree.java b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/DependentObjectThree.java new file mode 100644 index 00000000..f6ccabfb --- /dev/null +++ b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/DependentObjectThree.java @@ -0,0 +1,43 @@ +/* + * 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. + */ +package com.intellij.openapi.extensions.impl; + +/** + * @author Alexander Kireyev + */ +public class DependentObjectThree { + private final DependentObjectOne myOne; + private final DependentObjectTwo myTwo; + private final XMLTestBean[] myTestBeans; + + public DependentObjectThree(DependentObjectOne one, XMLTestBean[] testBeans, DependentObjectTwo two) { + myOne = one; + myTestBeans = testBeans; + myTwo = two; + } + + public DependentObjectOne getOne() { + return myOne; + } + + public XMLTestBean[] getTestBeans() { + return myTestBeans; + } + + public DependentObjectTwo getTwo() { + return myTwo; + } +} diff --git a/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/DependentObjectTwo.java b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/DependentObjectTwo.java new file mode 100644 index 00000000..b337a5e8 --- /dev/null +++ b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/DependentObjectTwo.java @@ -0,0 +1,31 @@ +/* + * 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. + */ +package com.intellij.openapi.extensions.impl; + +/** + * @author Alexander Kireyev + */ +public class DependentObjectTwo { + private final DependentObjectOne myOne; + + public DependentObjectTwo(DependentObjectOne one) { + myOne = one; + } + + public DependentObjectOne getOne() { + return myOne; + } +} diff --git a/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/ExtensionComponentAdapterTest.java b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/ExtensionComponentAdapterTest.java new file mode 100644 index 00000000..143fb898 --- /dev/null +++ b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/ExtensionComponentAdapterTest.java @@ -0,0 +1,43 @@ +// 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. +package com.intellij.openapi.extensions.impl; + +import com.intellij.openapi.extensions.DefaultPluginDescriptor; +import com.intellij.openapi.extensions.LoadingOrder; +import com.intellij.openapi.util.JDOMUtil; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jetbrains.annotations.NotNull; +import org.junit.Test; +import org.picocontainer.defaults.DefaultPicoContainer; + +import java.io.IOException; + +import static org.junit.Assert.assertEquals; + +/** + * @author Alexander Kireyev + */ +public class ExtensionComponentAdapterTest { + @Test + public void testLoadingOrderReading() { + assertEquals(LoadingOrder.ANY, createAdapter(LoadingOrder.ANY).getOrder()); + assertEquals(LoadingOrder.FIRST, createAdapter(LoadingOrder.FIRST).getOrder()); + assertEquals(LoadingOrder.LAST, createAdapter(LoadingOrder.LAST).getOrder()); + assertEquals(LoadingOrder.before("test"), createAdapter(LoadingOrder.readOrder("BEFORE test")).getOrder()); + assertEquals(LoadingOrder.after("test"), createAdapter(LoadingOrder.readOrder("AFTER test")).getOrder()); + } + + @Test + public void testUnknownAttributes() throws IOException, JDOMException { + String name = TestExtensionClassOne.class.getName(); + Element element = JDOMUtil.load("<bean implementation=\"123\"/>"); + DefaultPicoContainer container = new DefaultPicoContainer(); + DefaultPluginDescriptor descriptor = new DefaultPluginDescriptor("test"); + new ExtensionComponentAdapter(name, element, container, descriptor).getComponentInstance(container); + } + + @NotNull + private static ExtensionComponentAdapter createAdapter(@NotNull LoadingOrder order) { + return new ExtensionComponentAdapter(Object.class.getName(), null, null, null, order, null); + } +} diff --git a/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/ExtensionPointImplTest.java b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/ExtensionPointImplTest.java new file mode 100644 index 00000000..f2363240 --- /dev/null +++ b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/ExtensionPointImplTest.java @@ -0,0 +1,282 @@ +// 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. +package com.intellij.openapi.extensions.impl; + +import com.intellij.openapi.extensions.*; +import com.intellij.openapi.progress.ProcessCanceledException; +import com.intellij.util.SmartList; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.junit.Test; +import org.picocontainer.defaults.DefaultPicoContainer; + +import java.util.Arrays; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + +/** + * @author AKireyev + */ +public class ExtensionPointImplTest { + @Test + public void testCreate() { + ExtensionPoint<Integer> extensionPoint = buildExtensionPoint(Integer.class); + assertThat(extensionPoint.getName()).isEqualTo(ExtensionsImplTest.EXTENSION_POINT_NAME_1); + assertThat(extensionPoint.getClassName()).isEqualTo(Integer.class.getName()); + } + + @Test + public void testUnregisterObject() { + ExtensionPoint<Integer> extensionPoint = buildExtensionPoint(Integer.class); + extensionPoint.registerExtension(new Integer(123)); + Object[] extensions = extensionPoint.getExtensions(); + assertThat(extensions).hasSize(1); + extensionPoint.unregisterExtension(new Integer(123)); + extensions = extensionPoint.getExtensions(); + assertThat(extensions).isEmpty(); + } + + @Test + public void testRegisterUnregisterExtension() { + final AreaInstance area = new AreaInstance() {}; + final ExtensionPoint<Object> extensionPoint = new ExtensionPointImpl<>( + "an.extension.point", Object.class.getName(), ExtensionPoint.Kind.INTERFACE, buildExtensionArea(), area, + new UndefinedPluginDescriptor()); + + final boolean[] flags = new boolean[2]; + Extension extension = new Extension() { + @Override + public void extensionAdded(@NotNull ExtensionPoint extensionPoint1) { + assertThat(extensionPoint1).isSameAs(extensionPoint); + assertThat(extensionPoint1.getArea()).isSameAs(area); + flags[0] = true; + } + + @Override + public void extensionRemoved(@NotNull ExtensionPoint extensionPoint1) { + assertThat(extensionPoint1).isSameAs(extensionPoint); + assertThat(extensionPoint1.getArea()).isSameAs(area); + flags[1] = true; + } + }; + + extensionPoint.registerExtension(extension); + assertThat(flags[0]).describedAs("Register call is missed").isTrue(); + assertThat(flags[1]).isFalse(); + + extensionPoint.unregisterExtension(extension); + assertThat(flags[1]).describedAs("Unregister call is missed").isTrue(); + } + + @Test + public void testRegisterObject() { + ExtensionPoint<Integer> extensionPoint = buildExtensionPoint(Integer.class); + extensionPoint.registerExtension(new Integer(123)); + Object[] extensions = extensionPoint.getExtensions(); + assertThat(extensions).describedAs("One extension").hasSize(1); + assertThat(extensions).isInstanceOf(Integer[].class); + assertThat(extensions[0]).isEqualTo(new Integer(123)); + } + + @Test + public void testRegistrationOrder() { + ExtensionPoint<Integer> extensionPoint = buildExtensionPoint(Integer.class); + extensionPoint.registerExtension(new Integer(123)); + extensionPoint.registerExtension(new Integer(321), LoadingOrder.FIRST); + Object[] extensions = extensionPoint.getExtensions(); + assertThat(extensions).hasSize(2); + assertThat(extensions[0]).isEqualTo(new Integer(321)); + } + + @Test + public void testListener() { + ExtensionPoint<Integer> extensionPoint = buildExtensionPoint(Integer.class); + final boolean[] added = new boolean[1]; + final boolean[] removed = new boolean[1]; + extensionPoint.addExtensionPointListener(new ExtensionPointListener<Integer>() { + @Override + public void extensionAdded(@NotNull Integer extension, final PluginDescriptor pluginDescriptor) { + added[0] = true; + } + + @Override + public void extensionRemoved(@NotNull Integer extension, final PluginDescriptor pluginDescriptor) { + removed[0] = true; + } + }); + assertThat(added[0]).isFalse(); + assertThat(removed[0]).isFalse(); + extensionPoint.registerExtension(new Integer(123)); + assertThat(added[0]).isTrue(); + assertThat(removed[0]).isFalse(); + added[0] = false; + extensionPoint.unregisterExtension(new Integer(123)); + assertThat(added[0]).isFalse(); + assertThat(removed[0]).isTrue(); + } + + @Test + public void testLateListener() { + ExtensionPoint<Integer> extensionPoint = buildExtensionPoint(Integer.class); + final boolean[] added = new boolean[1]; + extensionPoint.registerExtension(new Integer(123)); + assertThat(added[0]).isFalse(); + extensionPoint.addExtensionPointListener(new ExtensionPointListener<Integer>() { + @Override + public void extensionAdded(@NotNull Integer extension, final PluginDescriptor pluginDescriptor) { + added[0] = true; + } + + @Override + public void extensionRemoved(@NotNull Integer extension, final PluginDescriptor pluginDescriptor) { + } + }); + assertThat(added[0]).isTrue(); + } + + @Test + @SuppressWarnings("unchecked") + public void testIncompatibleExtension() { + ExtensionPoint extensionPoint = buildExtensionPoint(Integer.class); + + try { + extensionPoint.registerExtension(new Double(0)); + fail("must throw"); + } + catch (AssertionError ignored) { + } + + assertThat(extensionPoint.getExtensions()).isEmpty(); + + extensionPoint.registerExtension(new Integer(0)); + assertThat(extensionPoint.getExtensions()).hasSize(1); + } + + @Test + public void testIncompatibleAdapter() { + ExtensionPointImpl<Integer> extensionPoint = buildExtensionPoint(Integer.class); + + extensionPoint.registerExtensionAdapter(stringAdapter()); + + try { + assertThat(extensionPoint.getExtensions()).isEmpty(); + fail("must throw"); + } + catch (AssertionError ignored) { + } + } + + @Test + public void testCompatibleAdapter() { + ExtensionPointImpl<Integer> extensionPoint = buildExtensionPoint(Integer.class); + extensionPoint.registerExtension(new Integer(0)); + assertThat(extensionPoint.getExtensions()).hasSize(1); + } + + @Test + public void testCancelledRegistration() { + ExtensionPoint<String> extensionPoint = buildExtensionPoint(String.class); + MyShootingComponentAdapter adapter = stringAdapter(); + + extensionPoint.registerExtension("first"); + assertThat(extensionPoint.getExtensions()).hasSize(1); + + extensionPoint.registerExtension("second", LoadingOrder.FIRST); // registers a wrapping adapter + ((ExtensionPointImpl)extensionPoint).registerExtensionAdapter(adapter); + adapter.setFire(true); + try { + extensionPoint.getExtensions(); + fail("PCE expected"); + } + catch (ProcessCanceledException ignored) { } + + adapter.setFire(false); + String[] extensions = extensionPoint.getExtensions(); + assertThat(extensions[0]).isEqualTo("second"); + assertThat(new SmartList<>(extensions[1])).containsAnyOf("", "first"); + assertThat(new SmartList<>(extensions[2])).containsAnyOf("", "first"); + assertThat(extensions[2]).isNotEqualTo(extensions[1]); + } + + @Test + public void testListenerNotifications() { + ExtensionPoint<String> extensionPoint = buildExtensionPoint(String.class); + final List<String> extensions = ContainerUtil.newArrayList(); + extensionPoint.addExtensionPointListener(new ExtensionPointListener<String>() { + @Override + public void extensionAdded(@NotNull String extension, @Nullable PluginDescriptor pluginDescriptor) { + extensions.add(extension); + } + }); + MyShootingComponentAdapter adapter = stringAdapter(); + + extensionPoint.registerExtension("first"); + assertThat(extensions).contains("first"); + + extensionPoint.registerExtension("second", LoadingOrder.FIRST); + ((ExtensionPointImpl)extensionPoint).registerExtensionAdapter(adapter); + adapter.setFire(true); + try { + extensionPoint.getExtensions(); + fail("PCE expected"); + } + catch (ProcessCanceledException ignored) { } + assertThat(extensions).contains("first", "second"); + + adapter.setFire(false); + extensionPoint.getExtensions(); + assertThat(extensions).contains("first", "second", ""); + } + + @Test + public void clientsCannotModifyCachedExtensions() { + ExtensionPoint<Integer> extensionPoint = buildExtensionPoint(Integer.class); + extensionPoint.registerExtension(4); + extensionPoint.registerExtension(2); + + Integer[] extensions = extensionPoint.getExtensions(); + assertThat(extensions).containsExactly(4, 2); + Arrays.sort(extensions); + assertThat(extensions).containsExactly(2, 4); + + assertThat(extensionPoint.getExtensions()).containsExactly(4, 2); + } + + private static <T> ExtensionPointImpl<T> buildExtensionPoint(Class<T> aClass) { + return new ExtensionPointImpl<>( + ExtensionsImplTest.EXTENSION_POINT_NAME_1, aClass.getName(), ExtensionPoint.Kind.INTERFACE, + buildExtensionArea(), null, new UndefinedPluginDescriptor()); + } + + private static ExtensionsAreaImpl buildExtensionArea() { + return new ExtensionsAreaImpl(new DefaultPicoContainer()); + } + + private static MyShootingComponentAdapter stringAdapter() { + return new MyShootingComponentAdapter(String.class.getName()); + } + + private static class MyShootingComponentAdapter extends ExtensionComponentAdapter { + private boolean myFire; + + MyShootingComponentAdapter(@NotNull String implementationClass) { + super(implementationClass, null, new DefaultPicoContainer(), new DefaultPluginDescriptor("test")); + } + + public void setFire(boolean fire) { + myFire = fire; + } + + @Override + public Object getExtension() { + if (myFire) { + throw new ProcessCanceledException(); + } + else { + return super.getExtension(); + } + } + } +} diff --git a/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/ExtensionsAreaTest.java b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/ExtensionsAreaTest.java new file mode 100644 index 00000000..c23a9580 --- /dev/null +++ b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/ExtensionsAreaTest.java @@ -0,0 +1,39 @@ +/* + * 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. + */ +package com.intellij.openapi.extensions.impl; + +import org.junit.Test; +import org.picocontainer.MutablePicoContainer; +import org.picocontainer.defaults.DefaultPicoContainer; + +import java.util.List; + +import static org.junit.Assert.assertEquals; + +/** + * @author mike + */ +public class ExtensionsAreaTest { + @Test + public void testGetComponentAdapterDoesntDuplicateAdapters() { + MutablePicoContainer picoContainer = + new ExtensionsAreaImpl("foo", null, new DefaultPicoContainer()).getPicoContainer(); + picoContainer.registerComponentImplementation("runnable", ExtensionsAreaTest.class); + + List adapters = picoContainer.getComponentAdaptersOfType(ExtensionsAreaTest.class); + assertEquals(1, adapters.size()); + } +} diff --git a/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/ExtensionsComplexTest.java b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/ExtensionsComplexTest.java new file mode 100644 index 00000000..59ffe6c6 --- /dev/null +++ b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/ExtensionsComplexTest.java @@ -0,0 +1,122 @@ +// 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. +package com.intellij.openapi.extensions.impl; + +import com.intellij.openapi.extensions.AreaInstance; +import com.intellij.openapi.extensions.ExtensionPoint; +import com.intellij.openapi.extensions.Extensions; +import com.intellij.openapi.util.JDOMUtil; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jetbrains.annotations.NonNls; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * @author Alexander Kireyev + */ +public class ExtensionsComplexTest { + private static final String PLUGIN_NAME = "the.test.plugin"; + private static final String PLUGIN_NAME_2 = "another.test.plugin"; + + private List<MyAreaInstance> myAreasToDispose; + + @Before + public void setUp() { + myAreasToDispose = new ArrayList<>(); + Extensions.registerAreaClass("area", null); + Extensions.registerAreaClass("child_area", "area"); + } + + @After + public void tearDown() { + for (MyAreaInstance instance : myAreasToDispose) { + Extensions.disposeArea(instance); + } + myAreasToDispose = null; + for (ExtensionPoint extensionPoint : Extensions.getRootArea().getExtensionPoints()) { + if (extensionPoint.getName().startsWith(PLUGIN_NAME) || extensionPoint.getName().startsWith(PLUGIN_NAME_2)) { + Extensions.getRootArea().unregisterExtensionPoint(extensionPoint.getName()); + } + } + } + + @Test + public void testPluginInit() throws IOException, JDOMException { + initExtensionPoints( + "<extensionPoints>\n" + + " <extensionPoint name=\"extensionPoint\" beanClass=\"com.intellij.openapi.extensions.impl.XMLTestBean\" />\n" + + " <extensionPoint name=\"dependentOne\" beanClass=\"com.intellij.openapi.extensions.impl.DependentObjectOne\" />\n" + + "</extensionPoints>", null); + initExtensions( + " <extensions xmlns=\"the.test.plugin\">\n" + + " <extensionPoint>\n" + + " <prop1>321</prop1>\n" + + " </extensionPoint>\n" + + " <dependentOne/>\n" + + " </extensions>", null); + + assertTrue(Extensions.getRootArea().hasExtensionPoint("the.test.plugin.extensionPoint")); + assertEquals(1, Extensions.getExtensions("the.test.plugin.extensionPoint").length); + ExtensionPoint<XMLTestBean> ep = Extensions.getRootArea().getExtensionPoint("the.test.plugin.extensionPoint"); + XMLTestBean bean = ep.getExtension(); + assertNotNull(bean); + assertEquals(321, bean.getProp1()); + assertEquals("the.test.plugin", bean.getPluginId().getIdString()); + + DependentObjectOne dependentObjectOne = (DependentObjectOne)Extensions.getRootArea().getExtensionPoint("the.test.plugin.dependentOne").getExtension(); + assertNotNull(dependentObjectOne); + assertEquals(1, dependentObjectOne.getTestBeans().length); + + AreaInstance areaInstance = new MyAreaInstance(); + Extensions.instantiateArea("area", areaInstance, null); + + initExtensionPoints( + "<extensionPoints>\n" + + " <extensionPoint name=\"dependentTwo\" beanClass=\"com.intellij.openapi.extensions.impl.DependentObjectTwo\" area=\"area\"/>\n" + + " <extensionPoint name=\"extensionPoint4area\" beanClass=\"com.intellij.openapi.extensions.impl.XMLTestBean\" area=\"area\" />\n" + + "</extensionPoints>", areaInstance); + + initExtensions( + " <extensions xmlns=\"the.test.plugin\">\n" + + " <extensionPoint4area area=\"area\"/>\n" + + " <dependentTwo area=\"area\"/>\n" + + " </extensions>", areaInstance); + + ExtensionPoint extensionPoint = Extensions.getArea(areaInstance).getExtensionPoint("the.test.plugin.extensionPoint4area"); + assertNotNull(extensionPoint); + assertSame(areaInstance, extensionPoint.getArea()); + assertNotNull(extensionPoint.getExtension()); + + DependentObjectTwo dependentObjectTwo = (DependentObjectTwo)Extensions.getArea(areaInstance).getExtensionPoint("the.test.plugin.dependentTwo").getExtension(); + assertNotNull(dependentObjectTwo); + assertSame(dependentObjectOne, dependentObjectTwo.getOne()); + } + + private static void initExtensionPoints(@NonNls String data, AreaInstance instance) throws IOException, JDOMException { + final Element element = JDOMUtil.load(data); + for (final Object o : element.getChildren()) { + Element child = (Element)o; + ((ExtensionsAreaImpl)Extensions.getArea(instance)).registerExtensionPoint(ExtensionsComplexTest.PLUGIN_NAME, child); + } + } + + private static void initExtensions(@NonNls String data, AreaInstance instance) throws IOException, JDOMException { + final Element element = JDOMUtil.load(data); + for (final Element child : element.getChildren()) { + ((ExtensionsAreaImpl)Extensions.getArea(instance)).registerExtension(element.getNamespaceURI(), child); + } + } + + private class MyAreaInstance implements AreaInstance { + private MyAreaInstance() { + myAreasToDispose.add(this); + } + } +} diff --git a/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/ExtensionsImplTest.java b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/ExtensionsImplTest.java new file mode 100644 index 00000000..795133a5 --- /dev/null +++ b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/ExtensionsImplTest.java @@ -0,0 +1,289 @@ +// 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. +package com.intellij.openapi.extensions.impl; + +import com.intellij.openapi.extensions.*; +import com.intellij.openapi.util.JDOMUtil; +import org.jdom.JDOMException; +import org.jetbrains.annotations.NotNull; +import org.junit.Test; +import org.picocontainer.MutablePicoContainer; +import org.picocontainer.defaults.DefaultPicoContainer; + +import java.io.IOException; +import java.util.Arrays; + +import static org.junit.Assert.*; + +/** + * @author AKireyev + */ +public class ExtensionsImplTest { + public static final String EXTENSION_POINT_NAME_1 = "ext.point.one"; + + @Test + public void testCreateAndAccess() { + ExtensionsAreaImpl extensionsArea = new ExtensionsAreaImpl(null); + int numEP = extensionsArea.getExtensionPoints().length; + extensionsArea.registerExtensionPoint(EXTENSION_POINT_NAME_1, Integer.class.getName()); + assertEquals("Additional EP available", numEP + 1, extensionsArea.getExtensionPoints().length); + assertNotNull("EP by name available", extensionsArea.getExtensionPoint(EXTENSION_POINT_NAME_1)); + } + + @Test(expected = RuntimeException.class) + public void testInvalidActions() { + ExtensionsAreaImpl extensionsArea = new ExtensionsAreaImpl(null); + extensionsArea.registerExtensionPoint(EXTENSION_POINT_NAME_1, Integer.class.getName()); + extensionsArea.registerExtensionPoint(EXTENSION_POINT_NAME_1, Boolean.class.getName()); + fail("Should not allow duplicate registration"); + } + + @Test + public void testUnregisterEP() { + ExtensionsAreaImpl extensionsArea = new ExtensionsAreaImpl(null); + int numEP = extensionsArea.getExtensionPoints().length; + extensionsArea.registerExtensionPoint(EXTENSION_POINT_NAME_1, Integer.class.getName()); + + final boolean[] removed = {false}; + extensionsArea.getExtensionPoint(EXTENSION_POINT_NAME_1).addExtensionPointListener(new ExtensionPointListener<Object>() { + @Override + public void extensionRemoved(@NotNull Object extension, PluginDescriptor pluginDescriptor) { + removed[0] = true; + } + }); + extensionsArea.getExtensionPoint(EXTENSION_POINT_NAME_1).registerExtension(new Integer(123)); + extensionsArea.unregisterExtensionPoint(EXTENSION_POINT_NAME_1); + assertEquals("Extension point should be removed", numEP, extensionsArea.getExtensionPoints().length); + assertTrue("Extension point disposed", removed[0]); + } + + @Test + public void testAvailabilityListener() { + ExtensionsAreaImpl extensionsArea = new ExtensionsAreaImpl(null); + MyListener.reset(); + extensionsArea.getExtensionPoint(EPAvailabilityListenerExtension.EXTENSION_POINT_NAME).registerExtension( + new EPAvailabilityListenerExtension(EXTENSION_POINT_NAME_1, MyListener.class.getName())); + assertEquals(0, MyListener.regCount); + assertEquals(0, MyListener.remCount); + extensionsArea.registerExtensionPoint(EXTENSION_POINT_NAME_1, Integer.class.getName()); + assertEquals(1, MyListener.regCount); + assertEquals(0, MyListener.remCount); + MyListener.reset(); + extensionsArea.unregisterExtensionPoint(EXTENSION_POINT_NAME_1); + assertEquals(1, MyListener.remCount); + assertEquals(0, MyListener.regCount); + } + + @Test + public void testAvailability2Listeners() { + ExtensionsAreaImpl extensionsArea = new ExtensionsAreaImpl(null); + MyListener.reset(); + extensionsArea.registerExtensionPoint(EXTENSION_POINT_NAME_1, Integer.class.getName()); + extensionsArea.getExtensionPoint(EPAvailabilityListenerExtension.EXTENSION_POINT_NAME).registerExtension( + new EPAvailabilityListenerExtension(EXTENSION_POINT_NAME_1, MyListener.class.getName())); + extensionsArea.getExtensionPoint(EPAvailabilityListenerExtension.EXTENSION_POINT_NAME).registerExtension( + new EPAvailabilityListenerExtension(EXTENSION_POINT_NAME_1, MyListener.class.getName())); + assertEquals(2, MyListener.regCount); + assertEquals(0, MyListener.remCount); + MyListener.reset(); + extensionsArea.unregisterExtensionPoint(EXTENSION_POINT_NAME_1); + assertEquals(2, MyListener.remCount); + assertEquals(0, MyListener.regCount); + } + + @Test + public void testAvailabilityListenerAfter() { + ExtensionsAreaImpl extensionsArea = new ExtensionsAreaImpl(null); + extensionsArea.registerExtensionPoint(EXTENSION_POINT_NAME_1, Integer.class.getName()); + MyListener.reset(); + extensionsArea.getExtensionPoint(EPAvailabilityListenerExtension.EXTENSION_POINT_NAME).registerExtension( + new EPAvailabilityListenerExtension(EXTENSION_POINT_NAME_1, MyListener.class.getName())); + assertEquals(1, MyListener.regCount); + assertEquals(0, MyListener.remCount); + } + + @Test + public void testTryPicoContainer() { + DefaultPicoContainer rootContainer = new DefaultPicoContainer(); + rootContainer.registerComponentInstance("plugin1", new DefaultPicoContainer(rootContainer)); + rootContainer.registerComponentInstance("plugin2", new DefaultPicoContainer(rootContainer)); + MutablePicoContainer container1 = (MutablePicoContainer)rootContainer.getComponentInstance("plugin1"); + MutablePicoContainer container2 = (MutablePicoContainer)rootContainer.getComponentInstance("plugin2"); + container1.registerComponentImplementation("component1", MyComponent1.class); + container1.registerComponentImplementation("component1.1", MyComponent1.class); + container2.registerComponentImplementation("component2", MyComponent2.class); + MyInterface1 testInstance = () -> { }; + rootContainer.registerComponentInstance(testInstance); + MyComponent1 component1 = (MyComponent1)container1.getComponentInstance("component1"); + assertEquals(testInstance, component1.testObject); + rootContainer.registerComponentInstance("component1", component1); + MyComponent1 component11 = (MyComponent1)container1.getComponentInstance("component1.1"); + rootContainer.registerComponentInstance("component11", component11); + MyComponent2 component2 = (MyComponent2)container2.getComponentInstance("component2"); + assertEquals(testInstance, component2.testObject); + assertTrue(Arrays.asList(component2.comp1).contains(component1)); + assertTrue(Arrays.asList(component2.comp1).contains(component11)); + rootContainer.registerComponentInstance("component2", component2); + rootContainer.registerComponentImplementation(MyTestComponent.class); + MyTestComponent testComponent = (MyTestComponent)rootContainer.getComponentInstance(MyTestComponent.class); + assertTrue(Arrays.asList(testComponent.comp1).contains(component1)); + assertTrue(Arrays.asList(testComponent.comp1).contains(component11)); + assertEquals(component2, testComponent.comp2); + } + + @Test + public void testTryPicoContainer2() { + DefaultPicoContainer rootContainer = new DefaultPicoContainer(); + rootContainer.registerComponentImplementation("component1", MyComponent1.class); + rootContainer.registerComponentImplementation("component1.1", MyComponent1.class); + rootContainer.registerComponentImplementation("component2", MyComponent2.class); + rootContainer.registerComponentImplementation(MyTestComponent.class); + MyInterface1 testInstance = () -> { }; + rootContainer.registerComponentInstance(testInstance); + MyTestComponent testComponent = (MyTestComponent)rootContainer.getComponentInstance(MyTestComponent.class); + MyComponent2 component2 = (MyComponent2)rootContainer.getComponentInstance("component2"); + MyComponent1 component11 = (MyComponent1)rootContainer.getComponentInstance("component1.1"); + MyComponent1 component1 = (MyComponent1)rootContainer.getComponentInstance("component1"); + assertEquals(testInstance, component1.testObject); + assertEquals(testInstance, component2.testObject); + assertTrue(Arrays.asList(component2.comp1).contains(component1)); + assertTrue(Arrays.asList(component2.comp1).contains(component11)); + assertTrue(Arrays.asList(testComponent.comp1).contains(component1)); + assertTrue(Arrays.asList(testComponent.comp1).contains(component11)); + assertEquals(component2, testComponent.comp2); + } + + @Test + public void testExtensionsNamespaces() throws IOException, JDOMException { + ExtensionsAreaImpl extensionsArea = new ExtensionsAreaImpl(new DefaultPicoContainer()); + extensionsArea.registerExtensionPoint("plugin.ep1", TestExtensionClassOne.class.getName(), ExtensionPoint.Kind.BEAN_CLASS); + extensionsArea.registerExtension("plugin", JDOMUtil.load( + "<plugin:ep1 xmlns:plugin=\"plugin\" order=\"LAST\"><text>3</text></plugin:ep1>")); + extensionsArea.registerExtension("plugin", JDOMUtil.load( + "<ep1 xmlns=\"plugin\" order=\"FIRST\"><text>1</text></ep1>")); + extensionsArea.registerExtension("plugin", JDOMUtil.load( + "<extension point=\"plugin.ep1\"><text>2</text></extension>")); + ExtensionPoint extensionPoint = extensionsArea.getExtensionPoint("plugin.ep1"); + TestExtensionClassOne[] extensions = (TestExtensionClassOne[]) extensionPoint.getExtensions(); + assertEquals(3, extensions.length); + assertEquals("1", extensions[0].getText()); + assertEquals("2", extensions[1].getText()); + assertEquals("3", extensions[2].getText()); + } + + @Test + public void testExtensionsWithOrdering() throws IOException, JDOMException { + ExtensionsAreaImpl extensionsArea = new ExtensionsAreaImpl(new DefaultPicoContainer()); + extensionsArea.registerExtensionPoint("ep1", TestExtensionClassOne.class.getName(), ExtensionPoint.Kind.BEAN_CLASS); + extensionsArea.registerExtension("", JDOMUtil.load( + "<extension point=\"ep1\" order=\"LAST\"><text>3</text></extension>")); + extensionsArea.registerExtension("", JDOMUtil.load( + "<extension point=\"ep1\" order=\"FIRST\"><text>1</text></extension>")); + extensionsArea.registerExtension("", JDOMUtil.load( + "<extension point=\"ep1\"><text>2</text></extension>")); + ExtensionPoint extensionPoint = extensionsArea.getExtensionPoint("ep1"); + TestExtensionClassOne[] extensions = (TestExtensionClassOne[]) extensionPoint.getExtensions(); + assertEquals(3, extensions.length); + assertEquals("1", extensions[0].getText()); + assertEquals("2", extensions[1].getText()); + assertEquals("3", extensions[2].getText()); + } + + @Test + public void testExtensionsWithOrderingUpdate() throws IOException, JDOMException { + ExtensionsAreaImpl extensionsArea = new ExtensionsAreaImpl(new DefaultPicoContainer()); + extensionsArea.registerExtensionPoint("ep1", TestExtensionClassOne.class.getName(), ExtensionPoint.Kind.BEAN_CLASS); + extensionsArea.registerExtension("", JDOMUtil.load("<extension point=\"ep1\" id=\"_7\" order=\"LAST\"><text>7</text></extension>")); + extensionsArea.registerExtension("", JDOMUtil.load("<extension point=\"ep1\" id=\"fst\" order=\"FIRST\"><text>1</text></extension>")); + extensionsArea.registerExtension("", JDOMUtil.load("<extension point=\"ep1\" id=\"id\"><text>3</text></extension>")); + ExtensionPoint<TestExtensionClassOne> extensionPoint = extensionsArea.getExtensionPoint("ep1"); + TestExtensionClassOne[] extensions = extensionPoint.getExtensions(); + assertEquals(3, extensions.length); + assertEquals("1", extensions[0].getText()); + assertEquals("3", extensions[1].getText()); + assertEquals("7", extensions[2].getText()); + TestExtensionClassOne extension = new TestExtensionClassOne("xxx"); + extensionPoint.registerExtension(extension); + extensionPoint.unregisterExtension(extension); + extensionsArea.registerExtension("", JDOMUtil.load("<extension point=\"ep1\" order=\"BEFORE id\"><text>2</text></extension>")); + extensionsArea.registerExtension("", JDOMUtil.load("<extension point=\"ep1\" order=\"AFTER id\"><text>4</text></extension>")); + extensionsArea.registerExtension("", JDOMUtil.load("<extension point=\"ep1\" order=\"last, after _7\"><text>8</text></extension>")); + extensionsArea.registerExtension("", JDOMUtil.load("<extension point=\"ep1\" order=\"after:id, before _7, after fst\"><text>5</text></extension>")); + extensionPoint.registerExtension(new TestExtensionClassOne("6")); + extensions = extensionPoint.getExtensions(); + assertEquals(8, extensions.length); + assertEquals("1", extensions[0].getText()); + assertEquals("2", extensions[1].getText()); + assertEquals("3", extensions[2].getText()); + assertTrue("4".equals(extensions[3].getText()) || "5".equals(extensions[3].getText()) ); + assertTrue("4".equals(extensions[4].getText()) || "5".equals(extensions[4].getText()) ); + assertEquals("6", extensions[5].getText()); + assertEquals("7", extensions[6].getText()); + assertEquals("8", extensions[7].getText()); + } + + public interface MyInterface1 extends Runnable { + } + + public interface MyInterface2 { + } + + public interface MyInterface3 extends Runnable { + } + + public interface MyInterface4 extends MyInterface1, MyInterface2, MyInterface3 { + } + + public static class MyClass implements MyInterface4 { + @Override + public void run() { + } + } + + public static class MyComponent1 { + public MyInterface1 testObject; + + public MyComponent1(MyInterface1 testObject) { + this.testObject = testObject; + } + } + + public static class MyComponent2 { + public MyInterface1 testObject; + public MyComponent1[] comp1; + + public MyComponent2(MyComponent1[] comp1, MyInterface1 testObject) { + this.comp1 = comp1; + this.testObject = testObject; + } + } + + public static class MyTestComponent { + public MyComponent1[] comp1; + public MyComponent2 comp2; + + public MyTestComponent(MyComponent1[] comp1, MyComponent2 comp2) { + this.comp1 = comp1; + this.comp2 = comp2; + } + } + + public static class MyListener implements ExtensionPointAvailabilityListener { + public static int regCount; + public static int remCount; + + @Override + public void extensionPointRegistered(@NotNull ExtensionPoint extensionPoint) { + regCount++; + } + + @Override + public void extensionPointRemoved(@NotNull ExtensionPoint extensionPoint) { + remCount++; + } + + public static void reset() { + regCount = 0; + remCount = 0; + } + } +} diff --git a/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/LoadingOrderTest.java b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/LoadingOrderTest.java new file mode 100644 index 00000000..4bb62e68 --- /dev/null +++ b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/LoadingOrderTest.java @@ -0,0 +1,190 @@ +// 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. +package com.intellij.openapi.extensions.impl; + +import com.intellij.openapi.extensions.LoadingOrder; +import com.intellij.openapi.extensions.SortingException; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * @author Alexander Kireyev + */ +public class LoadingOrderTest { + @Test + public void testSimpleSorting() { + List<LoadingOrder.Orderable> target = new ArrayList<>(); + target.add(createElement(LoadingOrder.ANY, null, "Any")); + target.add(createElement(LoadingOrder.FIRST, null, "1")); + target.add(createElement(LoadingOrder.LAST, null, "2")); + target.add(createElement(LoadingOrder.ANY, null, "Any")); + LoadingOrder.Orderable[] array = target.toArray(new LoadingOrder.Orderable[0]); + assertSequence(array, "1AnyAny2"); + } + + @Test + public void testStability() { + List<LoadingOrder.Orderable> target = new ArrayList<>(); + target.add(createElement(LoadingOrder.ANY, null, "1")); + target.add(createElement(LoadingOrder.ANY, null, "2")); + target.add(createElement(LoadingOrder.ANY, null, "3")); + target.add(createElement(LoadingOrder.ANY, null, "4")); + LoadingOrder.Orderable[] array = target.toArray(new LoadingOrder.Orderable[0]); + assertSequence(array, "1234"); + } + + @Test + public void testComplexSorting() { + List<LoadingOrder.Orderable> target = new ArrayList<>(); + String idOne = "idOne"; + String idTwo = "idTwo"; + target.add(createElement(LoadingOrder.before(idTwo), idOne, "2")); + target.add(createElement(LoadingOrder.FIRST, null, "0")); + target.add(createElement(LoadingOrder.LAST, null, "5")); + target.add(createElement(LoadingOrder.after(idTwo), null, "4")); + target.add(createElement(LoadingOrder.ANY, idTwo, "3")); + target.add(createElement(LoadingOrder.before(idOne), null, "1")); + LoadingOrder.Orderable[] array = target.toArray(new LoadingOrder.Orderable[0]); + assertSequence(array, "012345"); + } + + @Test + public void testComplexSorting2() { + List<LoadingOrder.Orderable> target = new ArrayList<>(); + String idOne = "idOne"; + target.add(createElement(LoadingOrder.before(idOne), null, "2")); + target.add(createElement(LoadingOrder.after(idOne), null, "4")); + target.add(createElement(LoadingOrder.FIRST, null, "1")); + target.add(createElement(LoadingOrder.ANY, idOne, "3")); + target.add(createElement(LoadingOrder.ANY, null, "5")); + target.add(createElement(LoadingOrder.LAST, null, "6")); + LoadingOrder.Orderable[] array = target.toArray(new LoadingOrder.Orderable[0]); + assertSequence(array, "123456"); + } + + @Test + public void testComplexSortingBeforeLast() { + List<LoadingOrder.Orderable> target = new ArrayList<>(); + target.add(createElement(LoadingOrder.LAST, "1", "1")); + target.add(createElement(LoadingOrder.readOrder("last,before 1"), null, "2")); + target.add(createElement(LoadingOrder.ANY, null, "3")); + target.add(createElement(LoadingOrder.before("1'"), null, "4")); + LoadingOrder.Orderable[] array = target.toArray(new LoadingOrder.Orderable[0]); + assertSequence(array, "3421"); + } + + private static void assertSequence(LoadingOrder.Orderable[] array, String expected) { + LoadingOrder.sort(array); + StringBuffer sequence = buildSequence(array); + assertEquals(expected, sequence.toString()); + } + + private static StringBuffer buildSequence(LoadingOrder.Orderable[] array) { + StringBuffer sequence = new StringBuffer(); + for (LoadingOrder.Orderable adapter : array) { + sequence.append(((MyOrderable)adapter).getID()); + } + return sequence; + } + + @Test + public void testFailingSortingBeforeFirst() { + List<LoadingOrder.Orderable> target = new ArrayList<>(); + target.add(createElement(LoadingOrder.ANY, null, "good")); + target.add(createElement(LoadingOrder.FIRST, "first", "bad")); + target.add(createElement(LoadingOrder.LAST, null, "good")); + target.add(createElement(LoadingOrder.before("first"), null, "bad")); + LoadingOrder.Orderable[] array = target.toArray(new LoadingOrder.Orderable[0]); + checkSortingFailure(array); + } + + @Test + public void testFailingSortingFirst() { + List<LoadingOrder.Orderable> target = new ArrayList<>(); + target.add(createElement(LoadingOrder.ANY, null, "2")); + target.add(createElement(LoadingOrder.FIRST, "first", "1")); + target.add(createElement(LoadingOrder.LAST, null, "3")); + target.add(createElement(LoadingOrder.FIRST, null, "1")); + LoadingOrder.Orderable[] array = target.toArray(new LoadingOrder.Orderable[0]); + assertSequence(array, "1123"); + } + + private static void checkSortingFailure(LoadingOrder.Orderable[] array) { + try { + LoadingOrder.sort(array); + fail("Should have failed"); + } + catch (SortingException e) { + LoadingOrder.Orderable[] conflictingElements = e.getConflictingElements(); + assertEquals(2, conflictingElements.length); + assertEquals("bad", ((MyOrderable)conflictingElements[0]).getID()); + assertEquals("bad", ((MyOrderable)conflictingElements[1]).getID()); + } + } + + @Test + public void testFailingSortingAfterLast() { + List<LoadingOrder.Orderable> target = new ArrayList<>(); + target.add(createElement(LoadingOrder.after("last"), null, "bad")); + target.add(createElement(LoadingOrder.FIRST, null, "good")); + target.add(createElement(LoadingOrder.LAST, "last", "bad")); + target.add(createElement(LoadingOrder.ANY, null, "good")); + LoadingOrder.Orderable[] array = target.toArray(new LoadingOrder.Orderable[0]); + checkSortingFailure(array); + } + + @Test + public void testFailingSortingLast() { + List<LoadingOrder.Orderable> target = new ArrayList<>(); + target.add(createElement(LoadingOrder.LAST, null, "3")); + target.add(createElement(LoadingOrder.FIRST, null, "1")); + target.add(createElement(LoadingOrder.LAST, "last", "3")); + target.add(createElement(LoadingOrder.ANY, null, "2")); + LoadingOrder.Orderable[] array = target.toArray(new LoadingOrder.Orderable[0]); + assertSequence(array, "1233"); + } + + @Test + public void testFailingSortingComplex() { + List<LoadingOrder.Orderable> target = new ArrayList<>(); + target.add(createElement(LoadingOrder.after("2"), "1", "bad")); + target.add(createElement(LoadingOrder.after("3"), "2", "bad")); + target.add(createElement(LoadingOrder.after("1"), "3", "bad")); + LoadingOrder.Orderable[] array = target.toArray(new LoadingOrder.Orderable[0]); + checkSortingFailure(array); + } + + private static LoadingOrder.Orderable createElement(final LoadingOrder order, final String idString, final String elementId) { + return new MyOrderable(order, idString, elementId); + } + + private static class MyOrderable implements LoadingOrder.Orderable { + private final LoadingOrder myOrder; + private final String myOrderId; + private final String myId; + + MyOrderable(LoadingOrder order, String orderId, String id) { + myOrder = order; + myOrderId = orderId; + myId = id; + } + + @Override + public String getOrderId() { + return myOrderId; + } + + @Override + public LoadingOrder getOrder() { + return myOrder; + } + + public String getID() { + return myId; + } + } +} diff --git a/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/NonCreatableClass.java b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/NonCreatableClass.java new file mode 100644 index 00000000..7094143b --- /dev/null +++ b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/NonCreatableClass.java @@ -0,0 +1,31 @@ +/* + * 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. + */ +package com.intellij.openapi.extensions.impl; + +/** + * @author Alexander Kireyev + */ +public class NonCreatableClass { + static { + if (true) { + throw new RuntimeException("Cannot be created"); + } + } + + public NonCreatableClass() { + throw new RuntimeException("Cannot be created"); + } +} diff --git a/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/TestExtensionClassOne.java b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/TestExtensionClassOne.java new file mode 100644 index 00000000..74e60447 --- /dev/null +++ b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/TestExtensionClassOne.java @@ -0,0 +1,37 @@ +/* + * 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. + */ +package com.intellij.openapi.extensions.impl; + +import com.intellij.util.xmlb.annotations.Tag; + +/** + * @author Alexander Kireyev + */ +public class TestExtensionClassOne { + @Tag("text") + public String myText; + + public TestExtensionClassOne() { + } + + public TestExtensionClassOne(String text) { + myText = text; + } + + public String getText() { + return myText; + } +} diff --git a/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/XMLTestBean.java b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/XMLTestBean.java new file mode 100644 index 00000000..5c800877 --- /dev/null +++ b/platform/extensions/testSrc/com/intellij/openapi/extensions/impl/XMLTestBean.java @@ -0,0 +1,86 @@ +/* + * 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. + */ +package com.intellij.openapi.extensions.impl; + +import com.intellij.openapi.extensions.PluginAware; +import com.intellij.openapi.extensions.PluginDescriptor; +import com.intellij.openapi.extensions.PluginId; +import com.intellij.util.xmlb.annotations.Tag; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * @author Alexander Kireyev + */ +public class XMLTestBean implements PluginAware { + private boolean otherProperty; + private int prop1; + private Object prop2; + private Collection<String> collectionProperty = new ArrayList<>(); + private PluginId pluginId; + + public XMLTestBean() { + } + + public XMLTestBean(Collection aCollectionProperty, boolean aOtherProperty, int aProp1) { + collectionProperty = aCollectionProperty; + otherProperty = aOtherProperty; + prop1 = aProp1; + } + + public boolean isOtherProperty() { + return otherProperty; + } + + public void setOtherProperty(boolean otherProperty) { + this.otherProperty = otherProperty; + } + + @Tag("prop1") + public int getProp1() { + return prop1; + } + + public void setProp1(int prop1) { + this.prop1 = prop1; + } + + public Object getProp2() { + return prop2; + } + + public void setProp2(Object prop2) { + this.prop2 = prop2; + } + + public Collection<String> getCollectionProperty() { + return collectionProperty; + } + + public void setCollectionProperty(Collection<String> collectionProperty) { + this.collectionProperty = collectionProperty; + } + + @Override + public void setPluginDescriptor(PluginDescriptor pluginDescriptor) { + pluginId = pluginDescriptor.getPluginId(); + } + + public PluginId getPluginId() { + return pluginId; + } +} |