mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Corrected extensions+container integration
This commit is contained in:
@@ -131,31 +131,37 @@ public class AreaPicoContainer extends AbstractDelegatingMutablePicoContainer im
|
||||
}
|
||||
|
||||
public Collection getComponentAdapters() {
|
||||
final List result = new ArrayList();
|
||||
final Set result = new HashSet();
|
||||
if (getParent() != null) {
|
||||
result.addAll(getParent().getComponentAdapters());
|
||||
}
|
||||
|
||||
result.addAll(super.getComponentAdapters());
|
||||
|
||||
accept(new EmptyPicoVisitor() {
|
||||
public void visitComponentAdapter(ComponentAdapter componentAdapter) {
|
||||
result.add(componentAdapter);
|
||||
public void visitContainer(PicoContainer pico) {
|
||||
if (pico != getDelegate()) result.addAll(pico.getComponentAdapters());
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public List getComponentAdaptersOfType(final Class componentType) {
|
||||
final List result = new ArrayList();
|
||||
final Set result = new HashSet();
|
||||
if (getParent() != null) {
|
||||
result.addAll(getParent().getComponentAdaptersOfType(componentType));
|
||||
}
|
||||
accept(new EmptyPicoVisitor() {
|
||||
public void visitComponentAdapter(ComponentAdapter componentAdapter) {
|
||||
if (componentType.isAssignableFrom(componentAdapter.getComponentImplementation())) {
|
||||
result.add(componentAdapter);
|
||||
}
|
||||
|
||||
final List componentAdapters = new ArrayList(getComponentAdapters());
|
||||
for (Iterator iterator = componentAdapters.iterator(); iterator.hasNext();) {
|
||||
ComponentAdapter componentAdapter = (ComponentAdapter) iterator.next();
|
||||
if (componentType.isAssignableFrom(componentAdapter.getComponentImplementation())) {
|
||||
result.add(componentAdapter);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
return new ArrayList(result);
|
||||
}
|
||||
|
||||
public MutablePicoContainer makeChildContainer() {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.intellij.openapi.extensions.impl;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.picocontainer.defaults.DefaultPicoContainer;
|
||||
import org.picocontainer.MutablePicoContainer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author mike
|
||||
*/
|
||||
public class ExtensionsAreaTest extends TestCase {
|
||||
private ExtensionsAreaImpl myExtensionsArea;
|
||||
private MutablePicoContainer myPicoContainer;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
myExtensionsArea = new ExtensionsAreaImpl("foo", null, new DefaultPicoContainer(), null);
|
||||
myPicoContainer = myExtensionsArea.getPicoContainer();
|
||||
}
|
||||
|
||||
public void testGetComponentAdapterDoesntDuplicateAdapters() throws Exception {
|
||||
myPicoContainer.registerComponentImplementation("runnable", ExtensionsAreaTest.class);
|
||||
|
||||
final List adapters = myPicoContainer.getComponentAdaptersOfType(ExtensionsAreaTest.class);
|
||||
assertEquals(1, adapters.size());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user