diff options
| author | Andrey Loskutov | 2015-03-21 13:06:44 +0000 |
|---|---|---|
| committer | Andrey Loskutov | 2015-03-21 22:04:47 +0000 |
| commit | 6d5ada0f9513a3b1180e03eecfd21307c3bc4854 (patch) | |
| tree | 0e7b8c6906ace652b03d814877ff166e9a92d912 | |
| parent | d7d9395d22b6019bc48f09e73936a1c1c4abc4e6 (diff) | |
| download | eclipse.platform.ui-6d5ada0f9513a3b1180e03eecfd21307c3bc4854.tar.gz eclipse.platform.ui-6d5ada0f9513a3b1180e03eecfd21307c3bc4854.tar.xz eclipse.platform.ui-6d5ada0f9513a3b1180e03eecfd21307c3bc4854.zip | |
Bug 461762 - [cleanup] clean up org.eclipse.ui.ide and update to Java
1.7 - part 3
Generified all non generic variants of <T> T getAdapter().
Change-Id: I9cf4bef235c7892dcf6639e4e53dc8314d8d2af6
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
17 files changed, 183 insertions, 328 deletions
diff --git a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/part/FileEditorInput.java b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/part/FileEditorInput.java index c278b0cc42f..9390ca48be2 100644 --- a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/part/FileEditorInput.java +++ b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/part/FileEditorInput.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Andrey Loskutov <loskutov@gmx.de> - generified interface, bug 461762 *******************************************************************************/ package org.eclipse.ui.part; @@ -14,18 +15,14 @@ import java.net.URI; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; - +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IStorage; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.content.IContentType; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IStorage; - import org.eclipse.jface.resource.ImageDescriptor; - import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.IMemento; import org.eclipse.ui.IPathEditorInput; @@ -253,9 +250,9 @@ public class FileEditorInput extends PlatformObject implements IFileEditorInput, * @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class) */ @Override - public Object getAdapter(Class adapter) { - if (IWorkbenchAdapter.class.equals(adapter)) { - return new IWorkbenchAdapter() { + public <T> T getAdapter(Class<T> adapterType) { + if (IWorkbenchAdapter.class.equals(adapterType)) { + return adapterType.cast(new IWorkbenchAdapter() { @Override public Object[] getChildren(Object o) { @@ -276,9 +273,9 @@ public class FileEditorInput extends PlatformObject implements IFileEditorInput, public Object getParent(Object o) { return FileEditorInput.this.getFile().getParent(); } - }; + }); } - return super.getAdapter(adapter); + return super.getAdapter(adapterType); } } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/FileStoreEditorInput.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/FileStoreEditorInput.java index 417422843b7..81d9d50d72f 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/FileStoreEditorInput.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/FileStoreEditorInput.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 IBM Corporation and others. + * Copyright (c) 2007, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Andrey Loskutov <loskutov@gmx.de> - generified interface, bug 461762 *******************************************************************************/ package org.eclipse.ui.ide; @@ -96,10 +97,12 @@ public class FileStoreEditorInput implements IURIEditorInput, IPersistableElemen return fileStore.toString(); } + @SuppressWarnings("unchecked") @Override - public Object getAdapter(Class adapter) { - if (IWorkbenchAdapter.class.equals(adapter)) - return workbenchAdapter; + public <T> T getAdapter(Class<T> adapter) { + if (IWorkbenchAdapter.class.equals(adapter)) { + return (T) workbenchAdapter; + } return Platform.getAdapterManager().getAdapter(this, adapter); } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/ResourceUtil.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/ResourceUtil.java index 4db5f04b382..98d6767cc66 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/ResourceUtil.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/ResourceUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. + * Copyright (c) 2005, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Andrey Loskutov <loskutov@gmx.de> - generified interface, bug 461762 *******************************************************************************/ package org.eclipse.ui.ide; @@ -129,7 +130,7 @@ public final class ResourceUtil { if (element instanceof IResource) { return (IResource) element; } - return (IResource) getAdapter(element, IResource.class, true); + return getAdapter(element, IResource.class, true); } /** @@ -251,16 +252,16 @@ public final class ResourceUtil { * @return the adapter * @since 3.2 */ - public static Object getAdapter(Object element, Class adapterType, boolean forceLoad) { + public static <T> T getAdapter(Object element, Class<T> adapterType, boolean forceLoad) { if (element instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) element; - Object o = adaptable.getAdapter(adapterType); + T o = adaptable.getAdapter(adapterType); if (o != null) { return o; } } if (forceLoad) { - return Platform.getAdapterManager().loadAdapter(element, adapterType.getName()); + return adapterType.cast(Platform.getAdapterManager().loadAdapter(element, adapterType.getName())); } return Platform.getAdapterManager().getAdapter(element, adapterType); } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/WorkspaceUndoUtil.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/WorkspaceUndoUtil.java index 77a28653afb..205eab78116 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/WorkspaceUndoUtil.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/WorkspaceUndoUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 IBM Corporation and others. + * Copyright (c) 2006, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Andrey Loskutov <loskutov@gmx.de> - generified interface, bug 461762 *******************************************************************************/ package org.eclipse.ui.ide.undo; @@ -137,9 +138,9 @@ public class WorkspaceUndoUtil { public static IAdaptable getUIInfoAdapter(final Shell shell) { return new IAdaptable() { @Override - public Object getAdapter(Class clazz) { + public <T> T getAdapter(Class<T> clazz) { if (clazz == Shell.class) { - return shell; + return clazz.cast(shell); } return null; } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IURIEditorInputAdapterFactory.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IURIEditorInputAdapterFactory.java index a11bba21aea..74b931925f7 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IURIEditorInputAdapterFactory.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IURIEditorInputAdapterFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. + * Copyright (c) 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,17 +7,16 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Andrey Loskutov <loskutov@gmx.de> - generified interface, bug 461762 *******************************************************************************/ package org.eclipse.ui.internal.ide; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.filesystem.URIUtil; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdapterFactory; import org.eclipse.core.runtime.IPath; - import org.eclipse.ui.IPathEditorInput; import org.eclipse.ui.IURIEditorInput; import org.eclipse.ui.ide.FileStoreEditorInput; @@ -49,19 +48,19 @@ public class IURIEditorInputAdapterFactory implements IAdapterFactory { /** The list of provided adapters. */ - private static final Class[] ADAPTER_LIST= new Class[] { IPathEditorInput.class }; + private static final Class<?>[] ADAPTER_LIST = new Class[] { IPathEditorInput.class }; @Override - public Object getAdapter(Object adaptableObject, Class adapterType) { + public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) { if (IPathEditorInput.class.equals(adapterType)) { if (adaptableObject instanceof IURIEditorInput) { IFileStore fileStore; try { fileStore= EFS.getStore(((IURIEditorInput) adaptableObject).getURI()); if (fileStore.getFileSystem() == EFS.getLocalFileSystem()) { - return new PathEditorInputAdapter(fileStore); + return adapterType.cast(new PathEditorInputAdapter(fileStore)); } } catch (CoreException e) { return null; @@ -73,7 +72,7 @@ public class IURIEditorInputAdapterFactory implements IAdapterFactory { @Override - public Class[] getAdapterList() { + public Class<?>[] getAdapterList() { return ADAPTER_LIST; } } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/WelcomeEditorInput.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/WelcomeEditorInput.java index 27a28029495..b67cea5ffc7 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/WelcomeEditorInput.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/WelcomeEditorInput.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Andrey Loskutov <loskutov@gmx.de> - generified interface, bug 461762 *******************************************************************************/ package org.eclipse.ui.internal.ide.dialogs; @@ -45,7 +46,7 @@ public class WelcomeEditorInput implements IEditorInput { } @Override - public Object getAdapter(Class adapter) { + public <T> T getAdapter(Class<T> adapter) { return null; } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/FileInputAdapterFactory.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/FileInputAdapterFactory.java index 616d71c69ac..da1e9de89bc 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/FileInputAdapterFactory.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/FileInputAdapterFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,14 +7,13 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Andrey Loskutov <loskutov@gmx.de> - generified interface, bug 461762 *******************************************************************************/ package org.eclipse.ui.internal.ide.model; -import org.eclipse.core.runtime.IAdapterFactory; - import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; - +import org.eclipse.core.runtime.IAdapterFactory; import org.eclipse.ui.IFileEditorInput; /** @@ -25,28 +24,20 @@ import org.eclipse.ui.IFileEditorInput; */ public class FileInputAdapterFactory implements IAdapterFactory { - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, - * java.lang.Class) - */ + @Override - public Object getAdapter(Object adaptableObject, Class adapterType) { - if (IFile.class.equals(adapterType)) - return ((IFileEditorInput) adaptableObject).getFile(); - if (IResource.class.equals(adapterType)) - return ((IFileEditorInput) adaptableObject).getFile(); + public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) { + if (IFile.class.equals(adapterType)) { + return adapterType.cast(((IFileEditorInput) adaptableObject).getFile()); + } + if (IResource.class.equals(adapterType)) { + return adapterType.cast(((IFileEditorInput) adaptableObject).getFile()); + } return null; } - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() - */ @Override - public Class[] getAdapterList() { + public Class<?>[] getAdapterList() { return new Class[] { IFile.class, IResource.class }; } } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/StandardPropertiesAdapterFactory.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/StandardPropertiesAdapterFactory.java index 8aef51f8962..f76c2f792dc 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/StandardPropertiesAdapterFactory.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/StandardPropertiesAdapterFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Andrey Loskutov <loskutov@gmx.de> - generified interface, bug 461762 *******************************************************************************/ package org.eclipse.ui.internal.ide.model; @@ -21,31 +22,26 @@ import org.eclipse.ui.views.properties.ResourcePropertySource; * Dispenses an <code>IPropertySource</code> adapter for the core resource objects. */ public class StandardPropertiesAdapterFactory implements IAdapterFactory { - /* (non-Javadoc) - * Method declared on IAdapterFactory. - */ + @Override - public Object getAdapter(Object o, Class adapterType) { + public <T> T getAdapter(Object o, Class<T> adapterType) { if (adapterType.isInstance(o)) { - return o; + return adapterType.cast(o); } if (adapterType == IPropertySource.class) { if (o instanceof IResource) { IResource resource = (IResource) o; if (resource.getType() == IResource.FILE) { - return new FilePropertySource((IFile) o); + return adapterType.cast(new FilePropertySource((IFile) o)); } - return new ResourcePropertySource((IResource) o); + return adapterType.cast(new ResourcePropertySource((IResource) o)); } } return null; } - /* (non-Javadoc) - * Method declared on IAdapterFactory. - */ @Override - public Class[] getAdapterList() { + public Class<?>[] getAdapterList() { // org.eclipe.ui.views is an optional dependency try { Class.forName("org.eclipse.ui.views.properties.IPropertySource"); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/WorkbenchAdapterFactory.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/WorkbenchAdapterFactory.java index 498627af1e9..e1135f0980a 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/WorkbenchAdapterFactory.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/WorkbenchAdapterFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Fair Isaac Corporation <Hemant.Singh@Gmail.com> - http://bugs.eclipse.org/333590 + * Andrey Loskutov <loskutov@gmx.de> - generified interface, bug 461762 *******************************************************************************/ package org.eclipse.ui.internal.ide.model; @@ -31,26 +32,27 @@ import org.eclipse.ui.model.IWorkbenchAdapter3; * navigating, and populating menus for core objects. */ public class WorkbenchAdapterFactory implements IAdapterFactory { - private Object workspaceAdapter = new WorkbenchWorkspace(); - private Object rootAdapter = new WorkbenchRootResource(); + private WorkbenchWorkspace workspaceAdapter = new WorkbenchWorkspace(); - private Object projectAdapter = new WorkbenchProject(); + private WorkbenchRootResource rootAdapter = new WorkbenchRootResource(); - private Object folderAdapter = new WorkbenchFolder(); + private WorkbenchProject projectAdapter = new WorkbenchProject(); - private Object fileAdapter = new WorkbenchFile(); + private WorkbenchFolder folderAdapter = new WorkbenchFolder(); - private Object markerAdapter = new WorkbenchMarker(); + private WorkbenchFile fileAdapter = new WorkbenchFile(); - private Object resourceFactory = new ResourceFactory(); + private WorkbenchMarker markerAdapter = new WorkbenchMarker(); - private Object workspaceFactory = new WorkspaceFactory(); + private ResourceFactory resourceFactory = new ResourceFactory(); + + private WorkspaceFactory workspaceFactory = new WorkspaceFactory(); /** * Returns the IActionFilter for an object. */ - protected Object getActionFilter(Object o) { + protected IActionFilter getActionFilter(Object o) { if (o instanceof IResource) { switch (((IResource) o).getType()) { case IResource.FILE: @@ -81,26 +83,26 @@ public class WorkbenchAdapterFactory implements IAdapterFactory { * given object */ @Override - public Object getAdapter(Object o, Class adapterType) { + public <T> T getAdapter(Object o, Class<T> adapterType) { if (adapterType.isInstance(o)) { - return o; + return adapterType.cast(o); } if (adapterType == IWorkbenchAdapter.class || adapterType == IWorkbenchAdapter2.class || adapterType == IWorkbenchAdapter3.class) { - return getWorkbenchElement(o); + return adapterType.cast(getWorkbenchElement(o)); } if (adapterType == IPersistableElement.class) { - return getPersistableElement(o); + return adapterType.cast(getPersistableElement(o)); } if (adapterType == IElementFactory.class) { - return getElementFactory(o); + return adapterType.cast(getElementFactory(o)); } if (adapterType == IActionFilter.class) { - return getActionFilter(o); + return adapterType.cast(getActionFilter(o)); } if (adapterType == IUndoContext.class) { - return getUndoContext(o); + return adapterType.cast(getUndoContext(o)); } return null; } @@ -117,7 +119,7 @@ public class WorkbenchAdapterFactory implements IAdapterFactory { * @return the collection of adapter types */ @Override - public Class[] getAdapterList() { + public Class<?>[] getAdapterList() { return new Class[] { IWorkbenchAdapter.class, IWorkbenchAdapter2.class, IWorkbenchAdapter3.class, IElementFactory.class, IPersistableElement.class, IActionFilter.class, @@ -129,7 +131,7 @@ public class WorkbenchAdapterFactory implements IAdapterFactory { * associated with the given object. Returns <code>null</code> if * no such object can be found. */ - protected Object getElementFactory(Object o) { + protected IElementFactory getElementFactory(Object o) { if (o instanceof IResource) { return resourceFactory; } @@ -144,7 +146,7 @@ public class WorkbenchAdapterFactory implements IAdapterFactory { * associated with the given object. Returns <code>null</code> if * no such object can be found. */ - protected Object getPersistableElement(Object o) { + protected IPersistableElement getPersistableElement(Object o) { if (o instanceof IResource) { return new ResourceFactory((IResource) o); } @@ -159,7 +161,7 @@ public class WorkbenchAdapterFactory implements IAdapterFactory { * associated with the given object. Returns <code>null</code> if * no such object can be found. */ - protected Object getWorkbenchElement(Object o) { + protected IWorkbenchAdapter getWorkbenchElement(Object o) { if (o instanceof IResource) { switch (((IResource) o).getType()) { case IResource.FILE: @@ -185,7 +187,7 @@ public class WorkbenchAdapterFactory implements IAdapterFactory { /** * Returns the IUndoContext for an object. */ - protected Object getUndoContext(Object o) { + protected IUndoContext getUndoContext(Object o) { if (o instanceof IWorkspace) { return PlatformUI.getWorkbench().getOperationSupport().getUndoContext(); } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/WorkbenchStatus.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/WorkbenchStatus.java index c1720bf21c1..5b26c4f8650 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/WorkbenchStatus.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/WorkbenchStatus.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,12 +7,12 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Andrey Loskutov <loskutov@gmx.de> - generified interface, bug 461762 *******************************************************************************/ package org.eclipse.ui.internal.ide.model; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IStatus; - import org.eclipse.ui.model.IWorkbenchAdapter; import org.eclipse.ui.model.WorkbenchAdapter; @@ -38,10 +38,10 @@ public class WorkbenchStatus extends WorkbenchAdapter implements IAdaptable { * associated with this object. Returns <code>null</code> if * no such object can be found. */ - @Override - public Object getAdapter(Class adapter) { - if (adapter == IWorkbenchAdapter.class) { - return this; + @Override + public <T> T getAdapter(Class<T> adapterType) { + if (adapterType == IWorkbenchAdapter.class) { + return adapterType.cast(this); } return null; } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/WorkingSetAdapterFactory.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/WorkingSetAdapterFactory.java index 14e10bebc5f..5a7ee17e66f 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/WorkingSetAdapterFactory.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/WorkingSetAdapterFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. + * Copyright (c) 2005, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,12 +7,10 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Andrey Loskutov <loskutov@gmx.de> - generified interface, bug 461762 *******************************************************************************/ package org.eclipse.ui.internal.ide.model; -import java.util.ArrayList; -import java.util.List; - import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.mapping.ResourceMapping; import org.eclipse.core.runtime.IAdaptable; @@ -40,7 +38,6 @@ public class WorkingSetAdapterFactory implements IAdapterFactory { if (adaptable instanceof IWorkingSet) { IWorkingSet workingSet = (IWorkingSet) adaptable; IAdaptable[] elements = workingSet.getElements(); - List result = new ArrayList(); for (int i = 0; i < elements.length; i++) { IAdaptable element = elements[i]; ResourceMapping mapping = getContributedResourceMapping(element); @@ -48,12 +45,9 @@ public class WorkingSetAdapterFactory implements IAdapterFactory { mapping = getResourceMapping(element); } if (mapping != null) { - result.add(mapping); + return new WorkingSetResourceMapping(workingSet); } } - if (!result.isEmpty()) { - return new WorkingSetResourceMapping(workingSet); - } } return null; } @@ -106,78 +100,59 @@ public class WorkingSetAdapterFactory implements IAdapterFactory { private IWorkbenchAdapter workbenchAdapter = new WorkbenchAdapter(); - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, - * java.lang.Class) - */ @Override - public Object getAdapter(Object adaptableObject, Class adapterType) { + public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) { if (adaptableObject instanceof IWorkingSet) { if (adapterType == IContributorResourceAdapter.class) { - return contributorResourceAdapter; + return adapterType.cast(contributorResourceAdapter); } if (adapterType == IWorkbenchAdapter.class) { - return workbenchAdapter; + return adapterType.cast(workbenchAdapter); } if (adapterType == ResourceMapping.class) { IWorkingSet workingSet = (IWorkingSet) adaptableObject; IAdaptable[] elements = workingSet.getElements(); - List result = new ArrayList(); for (int i = 0; i < elements.length; i++) { IAdaptable element = elements[i]; ResourceMapping mapping = getResourceMapping(element); if (mapping != null) { - result.add(mapping); + return adapterType.cast(new WorkingSetResourceMapping(workingSet)); } } - if (!result.isEmpty()) { - return new WorkingSetResourceMapping(workingSet); - } } } return null; } - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() - */ @Override - public Class[] getAdapterList() { - return new Class[] { IContributorResourceAdapter2.class, - IWorkbenchAdapter.class, ResourceMapping.class }; + public Class<?>[] getAdapterList() { + return new Class[] { IContributorResourceAdapter2.class, IWorkbenchAdapter.class, ResourceMapping.class }; } static ResourceMapping getResourceMapping(Object o) { // First, ask the object directly for a resource mapping - Object mapping = internalGetAdapter(o, ResourceMapping.class); - if (mapping instanceof ResourceMapping) { - return (ResourceMapping) mapping; + ResourceMapping mapping = internalGetAdapter(o, ResourceMapping.class); + if (mapping != null) { + return mapping; } // If this fails, ask for a resource and convert to a resource mapping - Object resource = internalGetAdapter(o, IResource.class); + IResource resource = internalGetAdapter(o, IResource.class); if (resource != null) { mapping = internalGetAdapter(resource, ResourceMapping.class); - if (mapping instanceof ResourceMapping) { - return (ResourceMapping) mapping; + if (mapping != null) { + return mapping; } } return null; } - static ResourceMapping getContributedResourceMapping( - IAdaptable element) { - Object resourceAdapter = internalGetAdapter(element, - IContributorResourceAdapter.class); + static ResourceMapping getContributedResourceMapping(IAdaptable element) { + Object resourceAdapter = internalGetAdapter(element, IContributorResourceAdapter.class); if (resourceAdapter != null) { if (resourceAdapter instanceof IContributorResourceAdapter2) { // First, use the mapping contributor adapter to get the mapping IContributorResourceAdapter2 mappingAdapter = (IContributorResourceAdapter2) resourceAdapter; - ResourceMapping mapping = mappingAdapter - .getAdaptedResourceMapping(element); + ResourceMapping mapping = mappingAdapter.getAdaptedResourceMapping(element); if (mapping != null) { return mapping; } @@ -185,13 +160,11 @@ public class WorkingSetAdapterFactory implements IAdapterFactory { if (resourceAdapter instanceof IContributorResourceAdapter) { // Next, use the resource adapter to get a resource and then get // the mapping for that resource - IResource resource = ((IContributorResourceAdapter) resourceAdapter) - .getAdaptedResource(element); + IResource resource = ((IContributorResourceAdapter) resourceAdapter).getAdaptedResource(element); if (resource != null) { - Object mapping = internalGetAdapter(resource, - ResourceMapping.class); - if (mapping instanceof ResourceMapping) { - return (ResourceMapping) mapping; + ResourceMapping mapping = internalGetAdapter(resource, ResourceMapping.class); + if (mapping != null) { + return mapping; } } } @@ -199,18 +172,18 @@ public class WorkingSetAdapterFactory implements IAdapterFactory { return null; } - static Object internalGetAdapter(Object o, Class adapter) { + static <T> T internalGetAdapter(Object o, Class<T> adapterType) { if (o instanceof IAdaptable) { IAdaptable element = (IAdaptable) o; - Object adapted = element.getAdapter(adapter); + T adapted = element.getAdapter(adapterType); if (adapted != null) { - return adapted; + return adapterType.cast(adapted); } } // Fallback to the adapter manager in case the object doesn't // implement getAdapter or in the case where the implementation // doesn't consult the manager - return Platform.getAdapterManager().getAdapter(o, adapter); + return Platform.getAdapterManager().getAdapter(o, adapterType); } } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerEntry.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerEntry.java index e317d280d32..74b47da03c1 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerEntry.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerEntry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation and others. + * Copyright (c) 2007, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Andrey Loskutov <loskutov@gmx.de> - generified interface, bug 461762 *******************************************************************************/ package org.eclipse.ui.internal.views.markers; @@ -39,29 +40,18 @@ import com.ibm.icu.text.Collator; class MarkerEntry extends MarkerSupportItem implements IAdaptable { static { Platform.getAdapterManager().registerAdapters(new IAdapterFactory() { - /* - * (non-Javadoc) - * - * @see - * org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang - * .Object, java.lang.Class) - */ + @Override - public Object getAdapter(Object adaptableObject, Class adapterType) { + public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) { if (adapterType == IMarker.class && adaptableObject instanceof MarkerEntry) - return ((MarkerEntry) adaptableObject).getMarker(); + return adapterType.cast(((MarkerEntry) adaptableObject).getMarker()); return null; } - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() - */ @Override - public Class[] getAdapterList() { + public Class<?>[] getAdapterList() { return new Class[] { IMarker.class }; } }, MarkerEntry.class); @@ -69,7 +59,7 @@ class MarkerEntry extends MarkerSupportItem implements IAdaptable { // The key for the string we built for display private static final Object LOCATION_STRING = "LOCATION_STRING"; //$NON-NLS-1$ private MarkerCategory category; - private Map cache = null; + private Map cache; /** * Set the MarkerEntry to be stale, if discovered at any point of time @@ -94,24 +84,13 @@ class MarkerEntry extends MarkerSupportItem implements IAdaptable { stale = false; } - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ @Override - public Object getAdapter(Class adapter) { + public <T> T getAdapter(Class<T> adapter) { if (adapter.equals(IMarker.class)) - return marker; + return adapter.cast(marker); return null; } - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.internal.provisional.views.markers.MarkerItem#getAttributeValue(java.lang.String, - * boolean) - */ @Override public boolean getAttributeValue(String attribute, boolean defaultValue) { Object value = getAttributeValue(attribute); @@ -120,12 +99,6 @@ class MarkerEntry extends MarkerSupportItem implements IAdaptable { return ((Boolean) value).booleanValue(); } - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.views.markers.MarkerItem#getAttributeValue(java.lang.String, - * int) - */ @Override public int getAttributeValue(String attribute, int defaultValue) { @@ -164,10 +137,6 @@ class MarkerEntry extends MarkerSupportItem implements IAdaptable { return value; } - - /* (non-Javadoc) - * @see org.eclipse.ui.internal.views.markers.MarkerSupportItem#getAttributeValue(java.lang.String, java.lang.String) - */ @Override public String getAttributeValue(String attribute, String defaultValue) { @@ -230,11 +199,6 @@ class MarkerEntry extends MarkerSupportItem implements IAdaptable { return key; } - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.internal.views.markers.MarkerSupportItem#getCreationTime() - */ @Override long getCreationTime() { if(stale){ @@ -249,32 +213,17 @@ class MarkerEntry extends MarkerSupportItem implements IAdaptable { } } - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.internal.views.markers.MarkerSupportItem#getDescription() - */ @Override String getDescription() { return getAttributeValue(IMarker.MESSAGE, MarkerSupportInternalUtilities.UNKNOWN_ATRRIBTE_VALUE_STRING); } - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.internal.views.markers.MarkerSupportItem#getID() - */ @Override long getID() { return marker.getId(); } - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.views.markers.MarkerItem#getLocation() - */ @Override public String getLocation() { if(stale||checkIfMarkerStale()){ @@ -310,21 +259,11 @@ class MarkerEntry extends MarkerSupportItem implements IAdaptable { } - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.views.markers.MarkerItem#getMarker() - */ @Override public IMarker getMarker() { return marker; } - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.internal.views.markers.MarkerSupportItem#getMarkerTypeName() - */ @Override String getMarkerTypeName() { if(stale){ @@ -356,21 +295,11 @@ class MarkerEntry extends MarkerSupportItem implements IAdaptable { } } - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.internal.views.markers.MarkerSupportItem#getParent() - */ @Override MarkerSupportItem getParent() { return category; } - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.views.markers.MarkerItem#getPath() - */ @Override public String getPath() { String folder = getAttributeValue(MarkerViewUtil.PATH_ATTRIBUTE, null); @@ -392,11 +321,6 @@ class MarkerEntry extends MarkerSupportItem implements IAdaptable { return folder; } - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.internal.views.markers.MarkerSupportItem#isConcrete() - */ @Override boolean isConcrete() { return true; @@ -469,9 +393,6 @@ class MarkerEntry extends MarkerSupportItem implements IAdaptable { return stale; } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { final int prime = 31; @@ -480,9 +401,6 @@ class MarkerEntry extends MarkerSupportItem implements IAdaptable { return result; } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(Object obj) { if (this == obj) { diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerHelpAdapterFactory.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerHelpAdapterFactory.java index 793e6d8b154..02d0d57b755 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerHelpAdapterFactory.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerHelpAdapterFactory.java @@ -1,6 +1,6 @@ package org.eclipse.ui.internal.views.markers; /******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. + * Copyright (c) 2007, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ package org.eclipse.ui.internal.views.markers; * * Contributors: * IBM Corporation - initial API and implementation + * Andrey Loskutov <loskutov@gmx.de> - generified interface, bug 461762 *******************************************************************************/ import org.eclipse.core.resources.IMarker; @@ -25,16 +26,17 @@ import org.eclipse.ui.ide.IDE; */ public class MarkerHelpAdapterFactory implements IAdapterFactory { - private static final Class[] classes = new Class[] {IContextProvider.class}; + private static final Class<?>[] classes = new Class[] { IContextProvider.class }; @Override - public Object getAdapter(Object adaptableObject, Class adapterType) { - if (!(adaptableObject instanceof ExtendedMarkersView)) + public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) { + if (!(adaptableObject instanceof ExtendedMarkersView)) { return null; + } final ExtendedMarkersView view = (ExtendedMarkersView) adaptableObject; - return new IContextProvider(){ + return adapterType.cast(new IContextProvider() { @Override public int getContextChangeMask() { @@ -47,37 +49,27 @@ public class MarkerHelpAdapterFactory implements IAdapterFactory { // See if there is a context registered for the current selection IMarker[] markers = view.getSelectedMarkers(); if(markers.length > 0) { - contextId = IDE.getMarkerHelpRegistry().getHelp( - markers[0]); + contextId = IDE.getMarkerHelpRegistry().getHelp(markers[0]); } //TODO this needs to be migrated to the ide plug-in - if (contextId == null) + if (contextId == null) { contextId = PlatformUI.PLUGIN_ID + ".problem_view_context";//$NON-NLS-1$ + } return HelpSystem.getContext(contextId); } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.help.IContextProvider#getSearchExpression(java.lang.Object) - */ @Override public String getSearchExpression(Object target) { return null; } - }; + }); } - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() - */ @Override - public Class[] getAdapterList() { + public Class<?>[] getAdapterList() { return classes; } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerShowInAdapter.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerShowInAdapter.java index 7429ab5e99d..c34dbf3b6cc 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerShowInAdapter.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerShowInAdapter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. + * Copyright (c) 2007, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Andrey Loskutov <loskutov@gmx.de> - generified interface, bug 461762 *******************************************************************************/ package org.eclipse.ui.internal.views.markers; @@ -14,6 +15,7 @@ import java.util.Collection; import java.util.HashSet; import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IAdapterFactory; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.part.IShowInSource; @@ -28,26 +30,21 @@ import org.eclipse.ui.part.ShowInContext; */ public class MarkerShowInAdapter implements IAdapterFactory { - private static Class[] classes = new Class[] { IShowInSource.class }; + private static Class<?>[] classes = new Class[] { IShowInSource.class }; - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, - * java.lang.Class) - */ @Override - public Object getAdapter(Object adaptableObject, Class adapterType) { - if (!(adaptableObject instanceof ExtendedMarkersView)) + public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) { + if (!(adaptableObject instanceof ExtendedMarkersView)) { return null; + } final ExtendedMarkersView view = (ExtendedMarkersView) adaptableObject; - return new IShowInSource() { + return adapterType.cast(new IShowInSource() { @Override public ShowInContext getShowInContext() { IMarker[] markers = view.getSelectedMarkers(); - Collection resources = new HashSet(); + Collection<IResource> resources = new HashSet<IResource>(); for (int i = 0; i < markers.length; i++) { resources.add(markers[i].getResource()); } @@ -55,17 +52,12 @@ public class MarkerShowInAdapter implements IAdapterFactory { new StructuredSelection(resources.toArray())); } - }; + }); } - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() - */ @Override - public Class[] getAdapterList() { + public Class<?>[] getAdapterList() { return classes; } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/bookmarkexplorer/BookmarkNavigator.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/bookmarkexplorer/BookmarkNavigator.java index 41de06a68df..27104293314 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/bookmarkexplorer/BookmarkNavigator.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/bookmarkexplorer/BookmarkNavigator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Lars Vogel <Lars.Vogel@gmail.com> - Bug 430694 + * Andrey Loskutov <loskutov@gmx.de> - generified interface, bug 461762 *******************************************************************************/ package org.eclipse.ui.views.bookmarkexplorer; @@ -369,29 +370,26 @@ public class BookmarkNavigator extends ViewPart { manager.add(editAction); } - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) - */ @Override - public Object getAdapter(Class adapter) { - if (adapter == IShowInSource.class) { - return new IShowInSource() { + public <T> T getAdapter(Class<T> adapterClass) { + if (adapterClass == IShowInSource.class) { + return adapterClass.cast(new IShowInSource() { @Override public ShowInContext getShowInContext() { return new ShowInContext(null, getViewer().getSelection()); } - }; + }); } - if (adapter == IShowInTargetList.class) { - return new IShowInTargetList() { + if (adapterClass == IShowInTargetList.class) { + return adapterClass.cast(new IShowInTargetList() { @Override public String[] getShowInTargetIds() { return new String[] { IPageLayout.ID_RES_NAV }; } - }; + }); } - return super.getAdapter(adapter); + return super.getAdapter(adapterClass); } /** diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/navigator/ResourceNavigator.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/navigator/ResourceNavigator.java index 3d3d621c283..472f4590002 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/navigator/ResourceNavigator.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/navigator/ResourceNavigator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,6 +10,7 @@ * Benjamin Muskalla - bug 105041 * Remy Chi Jian Suen - bug 144102 * Lars Vogel <Lars.Vogel@gmail.com> - Bug 440810 + * Andrey Loskutov <loskutov@gmx.de> - generified interface, bug 461762 *******************************************************************************/ package org.eclipse.ui.views.navigator; @@ -19,31 +20,14 @@ import java.util.Arrays; import java.util.Iterator; import java.util.List; -import org.eclipse.osgi.util.NLS; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.DND; -import org.eclipse.swt.dnd.FileTransfer; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.KeyListener; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IPath; - import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; - +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IPath; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; @@ -67,7 +51,19 @@ import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.ViewerComparator; import org.eclipse.jface.viewers.ViewerSorter; - +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.FileTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IMemento; @@ -1520,16 +1516,13 @@ public class ResourceNavigator extends ViewPart implements ISetSelectionTarget, this.actionGroup = actionGroup; } - /* - * @see IWorkbenchPart#getAdapter(Class) - */ @Override - public Object getAdapter(Class adapter) { + public <T> T getAdapter(Class<T> adapter) { if (adapter == IShowInSource.class) { - return getShowInSource(); + return adapter.cast(getShowInSource()); } if (adapter == IShowInTarget.class) { - return getShowInTarget(); + return adapter.cast(getShowInTarget()); } return null; } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/tasklist/TaskList.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/tasklist/TaskList.java index 14f10aef5c1..dc2fa54be7a 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/tasklist/TaskList.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/tasklist/TaskList.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * IBM Corporation - initial API and implementation * Cagatay Kavukcuoglu <cagatayk@acm.org> - Filter for markers in same project * Sebastian Davids <sdavids@gmx.de> - Reordered menu items + * Andrey Loskutov <loskutov@gmx.de> - generified interface, bug 461762 *******************************************************************************/ package org.eclipse.ui.views.tasklist; @@ -878,29 +879,26 @@ public class TaskList extends ViewPart { updateFocusResource(event.getSelection()); } - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) - */ @Override - public Object getAdapter(Class adapter) { - if (adapter == IShowInSource.class) { - return new IShowInSource() { + public <T> T getAdapter(Class<T> adapterType) { + if (adapterType == IShowInSource.class) { + return adapterType.cast(new IShowInSource() { @Override public ShowInContext getShowInContext() { return new ShowInContext(null, getSelection()); } - }; + }); } - if (adapter == IShowInTargetList.class) { - return new IShowInTargetList() { + if (adapterType == IShowInTargetList.class) { + return adapterType.cast(new IShowInTargetList() { @Override public String[] getShowInTargetIds() { return new String[] { IPageLayout.ID_RES_NAV }; } - }; + }); } - return super.getAdapter(adapter); + return super.getAdapter(adapterType); } /** |
