1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 14:12:10 +02:00

Move to new getAdapter() signature using generics

Change-Id: If51cc778c1b7e7dfea7a6fb3b7f39acea56aa330
Signed-off-by: Marc Khouzam <marc.khouzam@ericsson.com>
This commit is contained in:
Marc Khouzam 2015-04-15 13:54:53 -04:00 committed by Gerrit Code Review @ Eclipse.org
parent 9cc312e1fe
commit ecf21ca882
16 changed files with 99 additions and 106 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010, 2014 Nokia and others.
* Copyright (c) 2010, 2015 Nokia 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
@ -40,13 +40,13 @@ import com.ibm.icu.text.MessageFormat;
public class CSourceNotFoundDescriptionFactory implements IAdapterFactory {
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Object adaptableObject, Class adapterType) {
@SuppressWarnings("unchecked")
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
if (adapterType.equals(ICSourceNotFoundDescription.class) &&
adaptableObject instanceof IFrameDMContext)
{
final IFrameDMContext frameDMC = (IFrameDMContext) adaptableObject;
return new ICSourceNotFoundDescription() {
return (T)new ICSourceNotFoundDescription() {
@Override
public String getDescription() {
@ -84,8 +84,7 @@ public class CSourceNotFoundDescriptionFactory implements IAdapterFactory {
}
@Override
@SuppressWarnings("rawtypes")
public Class[] getAdapterList() {
public Class<?>[] getAdapterList() {
return new Class[] { ICSourceNotFoundDescription.class };
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010 Wind River Systems, Inc. and others.
* Copyright (c) 2010, 2015 Wind River Systems, Inc. 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
@ -28,28 +28,27 @@ public class DebugTextHoverAdapterFactory implements IAdapterFactory {
private static final Class<?>[] TYPES = { ICEditorTextHover.class };
private static final Object fDebugTextHover= new DsfDebugTextHover();
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Object adaptableObject, Class adapterType) {
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
if (adaptableObject instanceof IDMVMContext) {
IDMContext dmc = ((IDMVMContext) adaptableObject).getDMContext();
// try session specific hover
Object sessionHover = dmc.getAdapter(adapterType);
T sessionHover = dmc.getAdapter(adapterType);
if (sessionHover != null) {
return sessionHover;
}
// use default
IFrameDMContext frameDmc = DMContexts.getAncestorOfType(dmc, IFrameDMContext.class);
if (frameDmc != null) {
return fDebugTextHover;
return (T)fDebugTextHover;
}
}
return null;
}
@Override
@SuppressWarnings("rawtypes")
public Class[] getAdapterList() {
public Class<?>[] getAdapterList() {
return TYPES;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2010 Wind River Systems and others.
* Copyright (c) 2009, 2015 Wind River Systems 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
@ -43,17 +43,17 @@ public class SuspendResumeAdapterFactory implements IAdapterFactory {
fResumeAtLine = new ResumeAtLine(execCtx);
}
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Class adapter) {
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> adapter) {
if (adapter.isInstance(fRunToLine)) {
return fRunToLine;
return (T)fRunToLine;
}
if (adapter.isInstance(fMoveToLine)) {
return fMoveToLine;
return (T)fMoveToLine;
}
if (adapter.isInstance(fResumeAtLine)) {
return fResumeAtLine;
return (T)fResumeAtLine;
}
return null;
}
@ -73,9 +73,9 @@ public class SuspendResumeAdapterFactory implements IAdapterFactory {
public void suspend() throws DebugException {}
}
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Object adaptableObject, Class adapterType) {
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
if (ISuspendResume.class.equals(adapterType)) {
if (adaptableObject instanceof IDMVMContext) {
IExecutionDMContext execDmc = DMContexts.getAncestorOfType(
@ -84,7 +84,7 @@ public class SuspendResumeAdapterFactory implements IAdapterFactory {
// It only makes sense to RunToLine, MoveToLine or
// ResumeAtLine if we are dealing with a thread, not a container
if (execDmc != null && !(execDmc instanceof IContainerDMContext)) {
return new SuspendResume(execDmc);
return (T)new SuspendResume(execDmc);
}
}
}
@ -92,8 +92,7 @@ public class SuspendResumeAdapterFactory implements IAdapterFactory {
}
@Override
@SuppressWarnings("rawtypes")
public Class[] getAdapterList() {
public Class<?>[] getAdapterList() {
return new Class[] { ISuspendResume.class };
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010 Ericsson and others.
* Copyright (c) 2010, 2015 Ericsson 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
@ -26,16 +26,16 @@ public class RetargettableActionAdapterFactory implements IAdapterFactory {
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
*/
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Object adaptableObject, Class adapterType) {
@SuppressWarnings("unchecked")
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
if (adapterType == IRunToLineTarget.class) {
return new DisassemblyRunToLineAdapter();
return (T)new DisassemblyRunToLineAdapter();
}
if (adapterType == IMoveToLineTarget.class) {
return new DisassemblyMoveToLineAdapter();
return (T)new DisassemblyMoveToLineAdapter();
}
if (adapterType == IResumeAtLineTarget.class) {
return new DisassemblyResumeAtLineAdapter();
return (T)new DisassemblyResumeAtLineAdapter();
}
return null;
}
@ -44,8 +44,7 @@ public class RetargettableActionAdapterFactory implements IAdapterFactory {
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
*/
@Override
@SuppressWarnings("rawtypes")
public Class[] getAdapterList() {
public Class<?>[] getAdapterList() {
return new Class[]{ IRunToLineTarget.class, IResumeAtLineTarget.class, IMoveToLineTarget.class };
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010 Freescale Semiconductor, Inc. and others.
* Copyright (c) 2010, 2015 Freescale Semiconductor, Inc. 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
@ -24,8 +24,8 @@ public class DisassemblyBackendDsfFactory implements IAdapterFactory {
private static final Class<?>[] ADAPTERS = { IDisassemblyBackend.class };
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Object adaptableObject, Class adapterType) {
@SuppressWarnings("unchecked")
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
if (IDisassemblyBackend.class.equals(adapterType)) {
if (adaptableObject instanceof IAdaptable && DisassemblyBackendDsf.supportsDebugContext_((IAdaptable)adaptableObject)) {
String sessionId = ((IDMVMContext) adaptableObject).getDMContext().getSessionId();
@ -33,20 +33,19 @@ public class DisassemblyBackendDsfFactory implements IAdapterFactory {
if (session.isActive()) {
IAdapterFactory factory = (IAdapterFactory) session.getModelAdapter(IAdapterFactory.class);
if (factory != null) {
Object adapter = factory.getAdapter(adaptableObject, adapterType);
T adapter = factory.getAdapter(adaptableObject, adapterType);
if (adapter != null)
return adapter;
}
}
return new DisassemblyBackendDsf();
return (T)new DisassemblyBackendDsf();
}
}
return null;
}
@Override
@SuppressWarnings("rawtypes")
public Class[] getAdapterList() {
public Class<?>[] getAdapterList() {
return ADAPTERS;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2014 Wind River Systems and others.
* Copyright (c) 2007, 2015 Wind River Systems 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
@ -537,26 +537,26 @@ public abstract class DisassemblyPart extends WorkbenchPart implements IDisassem
/*
* @see IAdaptable#getAdapter(java.lang.Class)
*/
@SuppressWarnings("rawtypes")
@SuppressWarnings("unchecked")
@Override
public Object getAdapter(Class required) {
public <T> T getAdapter(Class<T> required) {
if (IVerticalRulerInfo.class.equals(required)) {
if (fVerticalRuler != null) {
return fVerticalRuler;
return (T)fVerticalRuler;
}
} else if (IDisassemblyPart.class.equals(required)) {
return this;
return (T)this;
} else if (IFindReplaceTarget.class.equals(required)) {
if (fFindReplaceTarget == null) {
fFindReplaceTarget = (fViewer == null ? null : fViewer.getFindReplaceTarget());
}
return fFindReplaceTarget;
return (T)fFindReplaceTarget;
} else if (ITextOperationTarget.class.equals(required)) {
return (fViewer == null ? null : fViewer.getTextOperationTarget());
return (fViewer == null ? null : (T)fViewer.getTextOperationTarget());
} else if (Control.class.equals(required)) {
return fViewer != null ? fViewer.getTextWidget() : null;
return fViewer != null ? (T)fViewer.getTextWidget() : null;
} else if (IGotoMarker.class.equals(required)) {
return new IGotoMarker() {
return (T)new IGotoMarker() {
@Override
public void gotoMarker(IMarker marker) {
DisassemblyPart.this.gotoMarker(marker);
@ -564,7 +564,7 @@ public abstract class DisassemblyPart extends WorkbenchPart implements IDisassem
} else if (IColumnSupport.class.equals(required)) {
if (fColumnSupport == null)
fColumnSupport= createColumnSupport();
return fColumnSupport;
return (T)fColumnSupport;
}
return super.getAdapter(required);
@ -577,7 +577,7 @@ public abstract class DisassemblyPart extends WorkbenchPart implements IDisassem
*/
private void addRulerContributionActions(IMenuManager menu) {
// store directly in generic editor preferences
final IColumnSupport support= (IColumnSupport) getAdapter(IColumnSupport.class);
final IColumnSupport support= getAdapter(IColumnSupport.class);
IPreferenceStore store= DsfUIPlugin.getDefault().getPreferenceStore();
final RulerColumnPreferenceAdapter adapter= new RulerColumnPreferenceAdapter(store, PREFERENCE_RULER_CONTRIBUTIONS);
List<RulerColumnDescriptor> descriptors= RulerColumnRegistry.getDefault().getColumnDescriptors();
@ -608,7 +608,7 @@ public abstract class DisassemblyPart extends WorkbenchPart implements IDisassem
* @param ruler the composite ruler to add contributions to
*/
protected void updateContributedRulerColumns(CompositeRuler ruler) {
IColumnSupport support= (IColumnSupport)getAdapter(IColumnSupport.class);
IColumnSupport support= getAdapter(IColumnSupport.class);
if (support == null)
return;
@ -689,7 +689,7 @@ public abstract class DisassemblyPart extends WorkbenchPart implements IDisassem
fPCHistorySizeMax = store.getInt(property);
} else if (PREFERENCE_RULER_CONTRIBUTIONS.equals(property)) {
String[] difference= StringSetSerializer.getDifference((String) event.getOldValue(), (String) event.getNewValue());
IColumnSupport support= (IColumnSupport) getAdapter(IColumnSupport.class);
IColumnSupport support= getAdapter(IColumnSupport.class);
for (int i= 0; i < difference.length; i++) {
RulerColumnDescriptor desc= RulerColumnRegistry.getDefault().getColumnDescriptor(difference[i]);
if (desc != null && support.isColumnSupported(desc)) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2010 Wind River Systems and others.
* Copyright (c) 2007, 2015 Wind River Systems 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
@ -108,8 +108,7 @@ abstract public class StorageEditorInput implements IStorageEditorInput {
}
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Class adapter) {
public <T> T getAdapter(Class<T> adapter) {
return null;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2010 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
@ -724,13 +724,13 @@ public class NumberFormatDetailPane implements IDetailPane2, IAdaptable, IProper
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
*/
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Class required) {
@SuppressWarnings("unchecked")
public <T> T getAdapter(Class<T> required) {
if (IFindReplaceTarget.class.equals(required)) {
return fTextViewer.getFindReplaceTarget();
return (T)fTextViewer.getFindReplaceTarget();
}
if (ITextViewer.class.equals(required)) {
return fTextViewer;
return (T)fTextViewer;
}
return null;
}

View file

@ -1,5 +1,5 @@
/*****************************************************************
* Copyright (c) 2011, 2014 Wind River Systems and others.
* Copyright (c) 2011, 2015 Wind River Systems 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
@ -138,10 +138,11 @@ public class SimpleMapPersistable<V> implements IPersistableElement, IAdaptable
return SimpleMapPersistableFactory.getFactoryId();
}
@SuppressWarnings("unchecked")
@Override
public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
public <T> T getAdapter(Class<T> adapter) {
if (adapter.isInstance(this)) {
return this;
return (T)this;
}
return null;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2010 Wind River Systems and others.
* Copyright (c) 2008, 2015 Wind River Systems 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
@ -29,11 +29,11 @@ public class BreakpointVMContext extends AbstractVMContext {
return fBreakpoint;
}
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Class adapter) {
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> adapter) {
if (adapter.isInstance(fBreakpoint)) {
return fBreakpoint;
return (T)fBreakpoint;
}
return super.getAdapter(adapter);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2010 Wind River Systems and others.
* Copyright (c) 2006, 2015 Wind River Systems 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
@ -73,8 +73,7 @@ public class ExpressionManagerVMNode extends AbstractVMNode
}
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Class adapter) {
public <T> T getAdapter(Class<T> adapter) {
return super.getAdapter(adapter);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2010 Wind River Systems, Inc. and others.
* Copyright (c) 2009, 2015 Wind River Systems, Inc. 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
@ -54,16 +54,16 @@ public class SingleExpressionVMNode extends AbstractVMNode implements IElementLa
public IDMContext getDMContext() {
return fDmc;
}
@SuppressWarnings("rawtypes")
@SuppressWarnings("unchecked")
@Override
public Object getAdapter(Class adapter) {
Object superAdapter = super.getAdapter(adapter);
public <T> T getAdapter(Class<T> adapter) {
T superAdapter = super.getAdapter(adapter);
if (superAdapter != null) {
return superAdapter;
} else {
// Delegate to the Data Model to find the context.
if (adapter.isInstance(fDmc)) {
return fDmc;
return (T)fDmc;
} else {
return fDmc.getAdapter(adapter);
}
@ -121,9 +121,8 @@ public class SingleExpressionVMNode extends AbstractVMNode implements IElementLa
public String getModelIdentifier() {
return null;
}
@SuppressWarnings("rawtypes")
@Override
public Object getAdapter(Class adapter) {
public <T> T getAdapter(Class<T> adapter) {
return null;
}
@Override

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2010 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
@ -181,11 +181,11 @@ public class ModuleDetailPane extends ModulesAbstractDetailPane implements IAdap
return false;
}
@SuppressWarnings("rawtypes")
@Override
public Object getAdapter(Class adapter) {
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> adapter) {
if (ITextViewer.class.equals(adapter)) {
return fSourceViewer;
return (T)fSourceViewer;
}
return null;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2014 Wind River Systems and others.
* Copyright (c) 2006, 2015 Wind River Systems 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
@ -236,16 +236,16 @@ public class RegisterVMProvider extends AbstractElementVMProvider
* The IAdaptable implementation. If the adapter is the DM context,
* return the context, otherwise delegate to IDMContext.getAdapter().
*/
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Class adapter) {
Object superAdapter = super.getAdapter(adapter);
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> adapter) {
T superAdapter = super.getAdapter(adapter);
if (superAdapter != null) {
return superAdapter;
} else {
// Delegate to the Data Model to find the context.
if (adapter.isInstance(fDMContext)) {
return fDMContext;
return (T)fDMContext;
} else {
return fDMContext.getAdapter(adapter);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2010 Wind River Systems and others.
* Copyright (c) 2006, 2015 Wind River Systems 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
@ -41,23 +41,23 @@ abstract public class AbstractVMContext implements IVMContext {
@Override
public IVMNode getVMNode() { return fNode; }
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Class adapter) {
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> adapter) {
// If the context implements the given adapter directly, it always takes
// precedence.
if (adapter.isInstance(this)) {
return this;
return (T)this;
}
IVMProvider vmProvider = getVMNode().getVMProvider();
IVMAdapter vmAdapter = vmProvider.getVMAdapter();
if (adapter.isInstance(vmAdapter)) {
return vmAdapter;
return (T)vmAdapter;
} else if (adapter.isInstance(vmProvider)) {
return vmProvider;
return (T)vmProvider;
} else if (adapter.isInstance(getVMNode())) {
return getVMNode();
return (T)getVMNode();
}
return Platform.getAdapterManager().getAdapter(this, adapter);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2010 Wind River Systems and others.
* Copyright (c) 2006, 2015 Wind River Systems 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
@ -66,16 +66,16 @@ abstract public class AbstractDMVMNode extends AbstractVMNode implements IVMNode
* The IAdaptable implementation. If the adapter is the DM context,
* return the context, otherwise delegate to IDMContext.getAdapter().
*/
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Class adapter) {
Object superAdapter = super.getAdapter(adapter);
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> adapter) {
T superAdapter = super.getAdapter(adapter);
if (superAdapter != null) {
return superAdapter;
} else {
// Delegate to the Data Model to find the context.
if (adapter.isInstance(fDmc)) {
return fDmc;
return (T)fDmc;
} else {
return fDmc.getAdapter(adapter);
}