Package org.eclipse.core.runtime
Class Adapters
java.lang.Object
org.eclipse.core.runtime.Adapters
Provides a standard way to request adapters from adaptable objects
- Since:
- 3.8
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
If it is possible to adapt the given object to the given type, this returns the adapter.static <T> T
If it is possible to adapt the given object to the given type, this returns the adapter.static <T> Optional<T>
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.
-
Constructor Details
-
Adapters
public Adapters()
-
-
Method Details
-
adapt
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
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
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
-