mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 14:55:41 +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;
|
private Map<String, RemoteResourceFactory> fResourceFactory;
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
|
||||||
public Object getAdapter(Object adaptableObject, Class adapterType) {
|
|
||||||
if (adapterType == IRemoteResource.class) {
|
if (adapterType == IRemoteResource.class) {
|
||||||
if (adaptableObject instanceof IResource) {
|
if (adaptableObject instanceof IResource) {
|
||||||
loadExtensions();
|
loadExtensions();
|
||||||
|
@ -43,21 +42,20 @@ public class RemoteResourceAdapterFactory implements IAdapterFactory {
|
||||||
if (resource.getProject().hasNature(nature)) {
|
if (resource.getProject().hasNature(nature)) {
|
||||||
RemoteResourceFactory factory = fResourceFactory.get(nature);
|
RemoteResourceFactory factory = fResourceFactory.get(nature);
|
||||||
if (factory != null) {
|
if (factory != null) {
|
||||||
return factory.getRemoteResource(resource);
|
return adapterType.cast(factory.getRemoteResource(resource));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
// Treat as failure
|
// Treat as failure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new LocalResource(resource);
|
return adapterType.cast(new LocalResource(resource));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
public Class<?>[] getAdapterList() {
|
||||||
public Class[] getAdapterList() {
|
|
||||||
return new Class[] { IRemoteResource.class };
|
return new Class[] { IRemoteResource.class };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,11 +107,10 @@ public class DeferredFileStore implements IDeferredWorkbenchAdapter, IAdaptable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
@Override
|
@Override
|
||||||
public Object getAdapter(Class adapter) {
|
public <T> T getAdapter(Class<T> adapter) {
|
||||||
if (IWorkbenchAdapter.class.equals(adapter)) {
|
if (IWorkbenchAdapter.class.equals(adapter)) {
|
||||||
return this;
|
return adapter.cast(this);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -146,14 +145,13 @@ public class DeferredFileStore implements IDeferredWorkbenchAdapter, IAdaptable
|
||||||
* type to adapt to
|
* type to adapt to
|
||||||
* @return a representation of sourceObject that is assignable to the adapter type, or null if no such representation exists
|
* @return a representation of sourceObject that is assignable to the adapter type, or null if no such representation exists
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
protected <T> T getAdapter(Object sourceObject, Class<T> adapterType) {
|
||||||
protected Object getAdapter(Object sourceObject, Class adapterType) {
|
|
||||||
Assert.isNotNull(adapterType);
|
Assert.isNotNull(adapterType);
|
||||||
if (sourceObject == null) {
|
if (sourceObject == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (adapterType.isInstance(sourceObject)) {
|
if (adapterType.isInstance(sourceObject)) {
|
||||||
return sourceObject;
|
return adapterType.cast(sourceObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourceObject instanceof IAdaptable) {
|
if (sourceObject instanceof IAdaptable) {
|
||||||
|
@ -163,14 +161,14 @@ public class DeferredFileStore implements IDeferredWorkbenchAdapter, IAdaptable
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
// Sanity-check
|
// Sanity-check
|
||||||
Assert.isTrue(adapterType.isInstance(result));
|
Assert.isTrue(adapterType.isInstance(result));
|
||||||
return result;
|
return adapterType.cast(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(sourceObject instanceof PlatformObject)) {
|
if (!(sourceObject instanceof PlatformObject)) {
|
||||||
Object result = Platform.getAdapterManager().getAdapter(sourceObject, adapterType);
|
Object result = Platform.getAdapterManager().getAdapter(sourceObject, adapterType);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
return result;
|
return adapterType.cast(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,55 +49,29 @@ public class PendingUpdateAdapter implements IWorkbenchAdapter, IAdaptable {
|
||||||
// No initial behavior
|
// No initial behavior
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("rawtypes")
|
public <T> T getAdapter(Class<T> adapter) {
|
||||||
public Object getAdapter(Class adapter) {
|
|
||||||
if (adapter == IWorkbenchAdapter.class) {
|
if (adapter == IWorkbenchAdapter.class) {
|
||||||
return this;
|
return adapter.cast(this);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getChildren(Object o) {
|
public Object[] getChildren(Object o) {
|
||||||
return new Object[0];
|
return new Object[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(java.lang.Object)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public ImageDescriptor getImageDescriptor(Object object) {
|
public ImageDescriptor getImageDescriptor(Object object) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.eclipse.ui.model.IWorkbenchAdapter#getLabel(java.lang.Object)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public String getLabel(Object o) {
|
public String getLabel(Object o) {
|
||||||
return Messages.PendingUpdateAdapter_Pending;
|
return Messages.PendingUpdateAdapter_Pending;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Object getParent(Object o) {
|
public Object getParent(Object o) {
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Add table
Reference in a new issue