mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-03 14:25:37 +02:00
Bug 559514 - Cleanup codebase
Generify Adapters. Change-Id: I06d06c1262492177c56b5e54a6e77bcee8605a74 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
This commit is contained in:
parent
f272b16a03
commit
6ce8bf9982
3 changed files with 12 additions and 42 deletions
|
@ -32,8 +32,7 @@ public class RemoteResourceAdapterFactory implements IAdapterFactory {
|
|||
|
||||
private Map<String, RemoteResourceFactory> fResourceFactory;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Object getAdapter(Object adaptableObject, Class adapterType) {
|
||||
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
|
||||
if (adapterType == IRemoteResource.class) {
|
||||
if (adaptableObject instanceof IResource) {
|
||||
loadExtensions();
|
||||
|
@ -43,21 +42,20 @@ public class RemoteResourceAdapterFactory implements IAdapterFactory {
|
|||
if (resource.getProject().hasNature(nature)) {
|
||||
RemoteResourceFactory factory = fResourceFactory.get(nature);
|
||||
if (factory != null) {
|
||||
return factory.getRemoteResource(resource);
|
||||
return adapterType.cast(factory.getRemoteResource(resource));
|
||||
}
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
// Treat as failure
|
||||
}
|
||||
}
|
||||
return new LocalResource(resource);
|
||||
return adapterType.cast(new LocalResource(resource));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Class[] getAdapterList() {
|
||||
public Class<?>[] getAdapterList() {
|
||||
return new Class[] { IRemoteResource.class };
|
||||
}
|
||||
|
||||
|
|
|
@ -107,11 +107,10 @@ public class DeferredFileStore implements IDeferredWorkbenchAdapter, IAdaptable
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public Object getAdapter(Class adapter) {
|
||||
public <T> T getAdapter(Class<T> adapter) {
|
||||
if (IWorkbenchAdapter.class.equals(adapter)) {
|
||||
return this;
|
||||
return adapter.cast(this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -146,14 +145,13 @@ public class DeferredFileStore implements IDeferredWorkbenchAdapter, IAdaptable
|
|||
* type to adapt to
|
||||
* @return a representation of sourceObject that is assignable to the adapter type, or null if no such representation exists
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected Object getAdapter(Object sourceObject, Class adapterType) {
|
||||
protected <T> T getAdapter(Object sourceObject, Class<T> adapterType) {
|
||||
Assert.isNotNull(adapterType);
|
||||
if (sourceObject == null) {
|
||||
return null;
|
||||
}
|
||||
if (adapterType.isInstance(sourceObject)) {
|
||||
return sourceObject;
|
||||
return adapterType.cast(sourceObject);
|
||||
}
|
||||
|
||||
if (sourceObject instanceof IAdaptable) {
|
||||
|
@ -163,14 +161,14 @@ public class DeferredFileStore implements IDeferredWorkbenchAdapter, IAdaptable
|
|||
if (result != null) {
|
||||
// Sanity-check
|
||||
Assert.isTrue(adapterType.isInstance(result));
|
||||
return result;
|
||||
return adapterType.cast(result);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(sourceObject instanceof PlatformObject)) {
|
||||
Object result = Platform.getAdapterManager().getAdapter(sourceObject, adapterType);
|
||||
if (result != null) {
|
||||
return result;
|
||||
return adapterType.cast(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,55 +49,29 @@ public class PendingUpdateAdapter implements IWorkbenchAdapter, IAdaptable {
|
|||
// No initial behavior
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Object getAdapter(Class adapter) {
|
||||
public <T> T getAdapter(Class<T> adapter) {
|
||||
if (adapter == IWorkbenchAdapter.class) {
|
||||
return this;
|
||||
return adapter.cast(this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Object[] getChildren(Object o) {
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public ImageDescriptor getImageDescriptor(Object object) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.ui.model.IWorkbenchAdapter#getLabel(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public String getLabel(Object o) {
|
||||
return Messages.PendingUpdateAdapter_Pending;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Object getParent(Object o) {
|
||||
return null;
|
||||
|
|
Loading…
Add table
Reference in a new issue