Package org.eclipse.core.runtime
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:
IAdaptable
,IAdapterManager
-
-
Constructor Summary
Constructors Constructor Description Adapters()
-
Method Summary
All Methods Static Methods Concrete Methods 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.
-
-
-
Method Detail
-
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:- Returns
sourceObject
if it is an instance of the adapter type. - If sourceObject implements IAdaptable, it is queried for adapters.
- Finally, the adapter manager is consulted for adapters
- Type Parameters:
T
- class type to adapt to- Parameters:
sourceObject
- object to adapt, can be nulladapter
- type to adapt toallowActivation
- 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
- Returns
-
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)
.- Type Parameters:
T
- class type to adapt to- Parameters:
sourceObject
- object to adapt, can be nulladapter
- 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, ifnull
thenOptional.empty()
is returnedadapter
- type to adapt to, must not benull
- Returns:
- an Optional representation of sourceObject that is assignable to the adapter type, or an empty Optional otherwise
- Since:
- 3.16
-
-