Class Adapters

java.lang.Object
org.eclipse.core.runtime.Adapters

public class Adapters extends Object
Provides a standard way to request adapters from adaptable objects
Since:
3.8
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    adapt(Object sourceObject, Class<T> adapter)
    If it is possible to adapt the given object to the given type, this returns the adapter.
    static <T> T
    adapt(Object sourceObject, Class<T> adapter, boolean allowActivation)
    If it is possible to adapt the given object to the given type, this returns the adapter.
    static <T> Optional<T>
    of(Object sourceObject, Class<T> adapter)
    If it is possible to adapt the given object to the given type, this returns an optional holding the adapter, in all other cases it returns an empty optional.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Adapters

      public Adapters()
  • Method Details

    • adapt

      public static <T> T adapt(Object sourceObject, Class<T> adapter, boolean allowActivation)
      If it is possible to adapt the given object to the given type, this returns the adapter. Performs the following checks:
      1. Returns sourceObject if it is an instance of the adapter type.
      2. If sourceObject implements IAdaptable, it is queried for adapters.
      3. Finally, the adapter manager is consulted for adapters
      Otherwise returns null.
      Type Parameters:
      T - class type to adapt to
      Parameters:
      sourceObject - object to adapt, can be null
      adapter - type to adapt to
      allowActivation - if true, plug-ins may be activated if necessary to provide the requested adapter. if false, the method will return null if an adapter cannot be provided from activated plug-ins.
      Returns:
      a representation of sourceObject that is assignable to the adapter type, or null if no such representation exists
    • adapt

      public static <T> T adapt(Object sourceObject, Class<T> adapter)
      If it is possible to adapt the given object to the given type, this returns the adapter.

      Convenience method for calling adapt(Object, Class, true).

      See adapt(Object, Class, boolean).

      Type Parameters:
      T - class type to adapt to
      Parameters:
      sourceObject - object to adapt, can be null
      adapter - type to adapt to
      Returns:
      a representation of sourceObject that is assignable to the adapter type, or null if no such representation exists
    • of

      public static <T> Optional<T> of(Object sourceObject, Class<T> adapter)
      If it is possible to adapt the given object to the given type, this returns an optional holding the adapter, in all other cases it returns an empty optional.
      Type Parameters:
      T - type to adapt to
      Parameters:
      sourceObject - object to adapt, if null then Optional.empty() is returned
      adapter - type to adapt to, must not be null
      Returns:
      an Optional representation of sourceObject that is assignable to the adapter type, or an empty Optional otherwise
      Since:
      3.16