mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
notnull, cleanup
This commit is contained in:
@@ -15,10 +15,12 @@
|
||||
*/
|
||||
package com.intellij.openapi.extensions;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author akireyev
|
||||
*/
|
||||
public interface AreaListener {
|
||||
void areaCreated(String areaClass, AreaInstance areaInstance);
|
||||
void areaDisposing(String areaClass, AreaInstance areaInstance);
|
||||
void areaCreated(@NotNull String areaClass, @NotNull AreaInstance areaInstance);
|
||||
void areaDisposing(@NotNull String areaClass, @NotNull AreaInstance areaInstance);
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ public interface ExtensionPoint<T> {
|
||||
|
||||
void reset();
|
||||
|
||||
@NotNull
|
||||
Class<T> getExtensionClass();
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -95,13 +95,13 @@ public class Extensions {
|
||||
@NotNull
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public static <T> T[] getExtensions(@NotNull ExtensionPointName<T> extensionPointName) {
|
||||
return (T[])getExtensions(extensionPointName.getName(), null);
|
||||
return getExtensions(extensionPointName.getName(), null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public static <T> T[] getExtensions(@NotNull ExtensionPointName<T> extensionPointName, AreaInstance areaInstance) {
|
||||
return Extensions.<T>getExtensions(extensionPointName.getName(), areaInstance);
|
||||
return getExtensions(extensionPointName.getName(), areaInstance);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -133,20 +133,19 @@ public class Extensions {
|
||||
throw new IllegalArgumentException("could not find extension implementation " + extClass);
|
||||
}
|
||||
|
||||
public static void instantiateArea(@NonNls @NotNull String areaClass, @Nullable AreaInstance areaInstance, @Nullable AreaInstance parentAreaInstance) {
|
||||
if (!ourAreaClass2Configuration.containsKey(areaClass)) {
|
||||
public static void instantiateArea(@NonNls @NotNull String areaClass, @NotNull AreaInstance areaInstance, @Nullable AreaInstance parentAreaInstance) {
|
||||
AreaClassConfiguration configuration = ourAreaClass2Configuration.get(areaClass);
|
||||
if (configuration == null) {
|
||||
throw new IllegalArgumentException("Area class is not registered: " + areaClass);
|
||||
}
|
||||
if (areaInstance == null || ourAreaInstance2area.containsKey(areaInstance)) {
|
||||
throw new IllegalArgumentException("Area already instantiated for: " + areaInstance);
|
||||
}
|
||||
ExtensionsArea parentArea = getArea(parentAreaInstance);
|
||||
AreaClassConfiguration configuration = ourAreaClass2Configuration.get(areaClass);
|
||||
if (!equals(parentArea.getAreaClass(), configuration.getParentClassName())) {
|
||||
throw new IllegalArgumentException("Wrong parent area. Expected class: " + configuration.getParentClassName() + " actual class: " + parentArea.getAreaClass());
|
||||
}
|
||||
ExtensionsAreaImpl area = new ExtensionsAreaImpl(areaClass, areaInstance, parentArea.getPicoContainer(), ourLogger);
|
||||
ourAreaInstance2area.put(areaInstance, area);
|
||||
if (ourAreaInstance2area.put(areaInstance, area) != null) {
|
||||
throw new IllegalArgumentException("Area already instantiated for: " + areaInstance);
|
||||
}
|
||||
for (AreaListener listener : getAreaListeners()) {
|
||||
listener.areaCreated(areaClass, areaInstance);
|
||||
}
|
||||
@@ -183,7 +182,8 @@ public class Extensions {
|
||||
for (AreaListener listener : getAreaListeners()) {
|
||||
listener.areaDisposing(areaClass, areaInstance);
|
||||
}
|
||||
} finally {
|
||||
}
|
||||
finally {
|
||||
ourAreaInstance2area.remove(areaInstance);
|
||||
}
|
||||
}
|
||||
@@ -200,11 +200,12 @@ public class Extensions {
|
||||
private final String myClassName;
|
||||
private final String myParentClassName;
|
||||
|
||||
AreaClassConfiguration(String className, String parentClassName) {
|
||||
AreaClassConfiguration(@NotNull String className, String parentClassName) {
|
||||
myClassName = className;
|
||||
myParentClassName = parentClassName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getClassName() {
|
||||
return myClassName;
|
||||
}
|
||||
|
||||
@@ -369,6 +369,7 @@ public class ExtensionPointImpl<T> implements ExtensionPoint<T> {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Class<T> getExtensionClass() {
|
||||
// racy single-check: we don't care whether the access to 'myExtensionClass' is thread-safe
|
||||
|
||||
+5
-4
@@ -69,8 +69,9 @@ public class ExtensionsAreaImpl implements ExtensionsArea {
|
||||
initialize();
|
||||
}
|
||||
|
||||
public ExtensionsAreaImpl(MutablePicoContainer picoContainer, LogProvider logger) {
|
||||
this(null, null, picoContainer, logger);
|
||||
@TestOnly
|
||||
ExtensionsAreaImpl(MutablePicoContainer parentPicoContainer, @NotNull LogProvider logger) {
|
||||
this(null, null, parentPicoContainer, logger);
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
@@ -148,7 +149,7 @@ public class ExtensionsAreaImpl implements ExtensionsArea {
|
||||
|
||||
ExtensionComponentAdapter adapter;
|
||||
final PicoContainer container = getPluginContainer(pluginId.getIdString());
|
||||
final ExtensionPoint extensionPoint = getExtensionPoint(epName);
|
||||
final ExtensionPointImpl extensionPoint = getExtensionPoint(epName);
|
||||
if (extensionPoint.getKind() == ExtensionPoint.Kind.INTERFACE) {
|
||||
String implClass = extensionElement.getAttributeValue("implementation");
|
||||
if (implClass == null) {
|
||||
@@ -161,7 +162,7 @@ public class ExtensionsAreaImpl implements ExtensionsArea {
|
||||
}
|
||||
myExtensionElement2extension.put(extensionElement, adapter);
|
||||
internalGetPluginContainer().registerComponent(adapter);
|
||||
getExtensionPoint(epName).registerExtensionAdapter(adapter);
|
||||
extensionPoint.registerExtensionAdapter(adapter);
|
||||
}
|
||||
|
||||
private static boolean shouldDeserializeInstance(Element extensionElement) {
|
||||
|
||||
@@ -252,14 +252,14 @@ public class IdeaPluginDescriptorImpl implements IdeaPluginDescriptor {
|
||||
if (myExtensions != null || myExtensionsPoints != null) {
|
||||
Extensions.getRootArea().getExtensionPoint(Extensions.AREA_LISTENER_EXTENSION_POINT).registerExtension(new AreaListener() {
|
||||
@Override
|
||||
public void areaCreated(String areaClass, AreaInstance areaInstance) {
|
||||
public void areaCreated(@NotNull String areaClass, @NotNull AreaInstance areaInstance) {
|
||||
if (PluginManager.shouldSkipPlugin(IdeaPluginDescriptorImpl.this)) return;
|
||||
final ExtensionsArea area = Extensions.getArea(areaInstance);
|
||||
area.registerAreaExtensionsAndPoints(IdeaPluginDescriptorImpl.this, myExtensionsPoints, myExtensions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void areaDisposing(String areaClass, AreaInstance areaInstance) {
|
||||
public void areaDisposing(@NotNull String areaClass, @NotNull AreaInstance areaInstance) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
|
||||
this(new DefaultComponentAdapterFactory(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ComponentAdapter> getComponentAdapters() {
|
||||
return componentAdapters.getImmutableSet();
|
||||
}
|
||||
@@ -62,6 +63,7 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
|
||||
return nonAssignableComponentAdapters.get().getReversedList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public final ComponentAdapter getComponentAdapter(Object componentKey) {
|
||||
ComponentAdapter adapter = getFromCache(componentKey);
|
||||
@@ -84,6 +86,7 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ComponentAdapter getComponentAdapterOfType(Class componentType) {
|
||||
// See http://jira.codehaus.org/secure/ViewIssue.jspa?key=PICO-115
|
||||
@@ -101,9 +104,7 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
|
||||
if (parent != null) {
|
||||
return parent.getComponentAdapterOfType(componentType);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
Class[] foundClasses = new Class[found.size()];
|
||||
@@ -115,6 +116,7 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getComponentAdaptersOfType(Class componentType) {
|
||||
if (componentType == null) {
|
||||
return Collections.emptyList();
|
||||
@@ -130,6 +132,7 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
|
||||
return found;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentAdapter registerComponent(ComponentAdapter componentAdapter) {
|
||||
Object componentKey = componentAdapter.getComponentKey();
|
||||
if (componentKeyToAdapterCache.containsKey(componentKey)) {
|
||||
@@ -156,6 +159,7 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
|
||||
return componentAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentAdapter unregisterComponent(Object componentKey) {
|
||||
ComponentAdapter adapter = componentKeyToAdapterCache.remove(componentKey);
|
||||
|
||||
@@ -171,10 +175,12 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getComponentInstances() throws PicoException {
|
||||
return getComponentInstancesOfType(Object.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getComponentInstancesOfType(Class componentType) {
|
||||
if (componentType == null) {
|
||||
return Collections.emptyList();
|
||||
@@ -204,17 +210,14 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object getComponentInstance(Object componentKey) {
|
||||
ComponentAdapter componentAdapter = getComponentAdapter(componentKey);
|
||||
if (componentAdapter != null) {
|
||||
return getInstance(componentAdapter);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
return componentAdapter == null ? null : getInstance(componentAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object getComponentInstanceOfType(Class componentType) {
|
||||
final ComponentAdapter componentAdapter = getComponentAdapterOfType(componentType);
|
||||
@@ -228,7 +231,7 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
|
||||
if (isLocal) {
|
||||
return getLocalInstance(componentAdapter);
|
||||
}
|
||||
else if (parent != null) {
|
||||
if (parent != null) {
|
||||
return parent.getComponentInstance(componentAdapter.getComponentKey());
|
||||
}
|
||||
|
||||
@@ -263,6 +266,7 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ComponentAdapter unregisterComponentByInstance(Object componentInstance) {
|
||||
Collection<ComponentAdapter> adapters = getComponentAdapters();
|
||||
@@ -276,36 +280,44 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void verify() throws PicoVerificationException {
|
||||
new VerifyingVisitor().traverse(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutablePicoContainer makeChildContainer() {
|
||||
DefaultPicoContainer pc = new DefaultPicoContainer(componentAdapterFactory, this);
|
||||
addChildContainer(pc);
|
||||
return pc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addChildContainer(PicoContainer child) {
|
||||
return children.add(child);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeChildContainer(PicoContainer child) {
|
||||
return children.remove(child);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(PicoVisitor visitor) {
|
||||
visitor.visitContainer(this);
|
||||
final List<ComponentAdapter> adapters = new ArrayList<ComponentAdapter>(getComponentAdapters());
|
||||
@@ -318,27 +330,33 @@ public class DefaultPicoContainer implements MutablePicoContainer, Serializable
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentAdapter registerComponentInstance(@NotNull Object component) {
|
||||
return registerComponentInstance(component.getClass(), component);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentAdapter registerComponentInstance(@NotNull Object componentKey, @NotNull Object componentInstance) {
|
||||
return registerComponent(new InstanceComponentAdapter(componentKey, componentInstance));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentAdapter registerComponentImplementation(@NotNull Class componentImplementation) {
|
||||
return registerComponentImplementation(componentImplementation, componentImplementation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentAdapter registerComponentImplementation(@NotNull Object componentKey, @NotNull Class componentImplementation) {
|
||||
return registerComponentImplementation(componentKey, componentImplementation, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentAdapter registerComponentImplementation(@NotNull Object componentKey, @NotNull Class componentImplementation, Parameter[] parameters) {
|
||||
ComponentAdapter componentAdapter = componentAdapterFactory.createComponentAdapter(componentKey, componentImplementation, parameters);
|
||||
return registerComponent(componentAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PicoContainer getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user