/*
 * 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;

import org.jetbrains.annotations.NonNls;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class Extensions {
  private static ExtensionsArea ourRootArea;

  public static void setRootArea(@Nullable ExtensionsArea extensionsArea) {
    ourRootArea = extensionsArea;
  }

  private Extensions() {
  }

  @Nonnull
  public static ExtensionsArea getRootArea() {
    return ourRootArea;
  }

  @Nonnull
  public static ExtensionsArea getArea(@Nullable AreaInstance areaInstance) {
    if (areaInstance == null) {
      return ourRootArea;
    }
    return areaInstance.getExtensionsArea();
  }

  @Nonnull
  public static Object[] getExtensions(@NonNls String extensionPointName) {
    return getExtensions(extensionPointName, null);
  }

  @Nonnull
  @SuppressWarnings({"unchecked"})
  public static <T> T[] getExtensions(@Nonnull ExtensionPointName<T> extensionPointName) {
    return (T[])getExtensions(extensionPointName.getName(), null);
  }

  @Nonnull
  @SuppressWarnings({"unchecked"})
  public static <T> T[] getExtensions(@Nonnull ExtensionPointName<T> extensionPointName, AreaInstance areaInstance) {
    return Extensions.<T>getExtensions(extensionPointName.getName(), areaInstance);
  }

  @Nonnull
  public static <T> T[] getExtensions(String extensionPointName, @Nullable AreaInstance areaInstance) {
    ExtensionsArea area = getArea(areaInstance);
    ExtensionPoint<T> extensionPoint = area.getExtensionPoint(extensionPointName);
    return extensionPoint.getExtensions();
  }

  @Nonnull
  public static <T, U extends T> U findExtension(@Nonnull ExtensionPointName<T> extensionPointName, @Nonnull Class<U> extClass) {
    for (T t : getExtensions(extensionPointName)) {
      if (extClass.isInstance(t)) {
        //noinspection unchecked
        return (U)t;
      }
    }
    throw new IllegalArgumentException("could not find extension implementation " + extClass);
  }

  @Nonnull
  public static <T, U extends T> U findExtension(@Nonnull ExtensionPointName<T> extensionPointName, AreaInstance areaInstance, @Nonnull Class<U> extClass) {
    for (T t : getExtensions(extensionPointName, areaInstance)) {
      if (extClass.isInstance(t)) {
        //noinspection unchecked
        return (U)t;
      }
    }
    throw new IllegalArgumentException("could not find extension implementation " + extClass);
  }
}

@@ -1256,32 +1256,46 @@
   %7D%0A%0A  @Nonnull%0A
+  @Deprecated%0A
   public static 
@@ -1346,32 +1346,32 @@
 ionPointName) %7B%0A
-
     return getEx
@@ -1449,32 +1449,46 @@
 (%7B%22unchecked%22%7D)%0A
+  @Deprecated%0A
   public static 
@@ -1680,16 +1680,30 @@
 cked%22%7D)%0A
+  @Deprecated%0A
   public
@@ -1904,32 +1904,46 @@
   %7D%0A%0A  @Nonnull%0A
+  @Deprecated%0A
   public static 
@@ -2213,32 +2213,46 @@
   %7D%0A%0A  @Nonnull%0A
+  @Deprecated%0A
   public static 
@@ -2613,32 +2613,32 @@
 extClass);%0A  %7D%0A%0A
-
   @Nonnull%0A  pub
@@ -2624,32 +2624,46 @@
   %7D%0A%0A  @Nonnull%0A
+  @Deprecated%0A
   public static 

make deprecated