1 11 package org.eclipse.ui.internal.navigator; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.core.runtime.IAdaptable; 15 import org.eclipse.core.runtime.Platform; 16 import org.eclipse.core.runtime.PlatformObject; 17 18 23 public class AdaptabilityUtility { 24 25 36 public static Object getAdapter(Object anElement, Class anAdapterType) { 37 Assert.isNotNull(anAdapterType); 38 if (anElement == null) { 39 return null; 40 } 41 if (anAdapterType.isInstance(anElement)) { 42 return anElement; 43 } 44 45 if (anElement instanceof IAdaptable) { 46 IAdaptable adaptable = (IAdaptable) anElement; 47 48 Object result = adaptable.getAdapter(anAdapterType); 49 if (result != null) { 50 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; 64 } 65 66 } 67 | Popular Tags |