|
Lines 10-17
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.ui.internal.navigator; |
11 |
package org.eclipse.ui.internal.navigator; |
| 12 |
|
12 |
|
|
|
13 |
import org.eclipse.core.runtime.Assert; |
| 13 |
import org.eclipse.core.runtime.IAdaptable; |
14 |
import org.eclipse.core.runtime.IAdaptable; |
| 14 |
import org.eclipse.core.runtime.Platform; |
15 |
import org.eclipse.core.runtime.Platform; |
|
|
16 |
import org.eclipse.core.runtime.PlatformObject; |
| 15 |
|
17 |
|
| 16 |
/** |
18 |
/** |
| 17 |
* Provides utilities for working with adaptable and non-adaptable objects. |
19 |
* Provides utilities for working with adaptable and non-adaptable objects. |
|
Lines 26-45
Link Here
|
| 26 |
* |
28 |
* |
| 27 |
* @param anElement |
29 |
* @param anElement |
| 28 |
* The element to adapt, which may or may not implement |
30 |
* The element to adapt, which may or may not implement |
| 29 |
* {@link IAdaptable} |
31 |
* {@link IAdaptable}, or null |
| 30 |
* @param anAdapterType |
32 |
* @param anAdapterType |
| 31 |
* The class type to return |
33 |
* The class type to return |
| 32 |
* @return An adapter of the requested type or null |
34 |
* @return An adapter of the requested type or null |
| 33 |
*/ |
35 |
*/ |
| 34 |
public static Object getAdapter(Object anElement, Class anAdapterType) { |
36 |
public static Object getAdapter(Object anElement, Class anAdapterType) { |
| 35 |
if (anElement == null) { |
37 |
Assert.isNotNull(anAdapterType); |
| 36 |
return null; |
38 |
if (anElement == null) { |
| 37 |
} else if (anElement instanceof IAdaptable) { |
39 |
return null; |
| 38 |
return ((IAdaptable) anElement).getAdapter(anAdapterType); |
40 |
} |
| 39 |
} else { |
41 |
if (anAdapterType.isInstance(anElement)) { |
| 40 |
return Platform.getAdapterManager().getAdapter(anElement, |
42 |
return anElement; |
| 41 |
anAdapterType); |
43 |
} |
| 42 |
} |
44 |
|
|
|
45 |
if (anElement instanceof IAdaptable) { |
| 46 |
IAdaptable adaptable = (IAdaptable) anElement; |
| 47 |
|
| 48 |
Object result = adaptable.getAdapter(anAdapterType); |
| 49 |
if (result != null) { |
| 50 |
// Sanity-check |
| 51 |
Assert.isTrue(anAdapterType.isInstance(result)); |
| 52 |
return result; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
if (!(anElement instanceof PlatformObject)) { |
| 57 |
Object result = Platform.getAdapterManager().getAdapter(anElement, anAdapterType); |
| 58 |
if (result != null) { |
| 59 |
return result; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
return null; |
| 43 |
} |
64 |
} |
| 44 |
|
65 |
|
| 45 |
} |
66 |
} |