From d692d9d650f8c6aa7cb0e396bfd846cd0a03a53d Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Tue, 13 Feb 2007 23:42:50 +0000 Subject: Bug 173253: Create Watch Expression of member variable or struct. --- .../eclipse/cdt/debug/core/model/ICVariable.java | 8 +++++ .../internal/core/model/AbstractCVariable.java | 8 ----- .../adapters/CDebugElementAdapterFactory.java | 1 - .../adapters/CWatchExpressionFactoryAdapter.java | 33 +++++++++++++++++ .../CWatchExpressionFactoryAdapterFactory.java | 41 ++++++++++++++++++++++ .../org/eclipse/cdt/debug/ui/CDebugUIPlugin.java | 10 ++++-- 6 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/elements/adapters/CWatchExpressionFactoryAdapter.java create mode 100644 debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/elements/adapters/CWatchExpressionFactoryAdapterFactory.java (limited to 'debug') diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java index 603499c1f21..db1e75e843c 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java @@ -33,4 +33,12 @@ public interface ICVariable extends IVariable, ICDebugElement, IFormatSupport, I * @return whether this variable is an argument */ boolean isArgument(); + + /** + * Returns the text presentation of this variable as an expression. + * + * @return the text presentation of this variable as an expression + * @throws DebugException + */ + public String getExpressionString() throws DebugException; } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCVariable.java index 0cc49db3c16..62bbc718ba6 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCVariable.java @@ -62,14 +62,6 @@ public abstract class AbstractCVariable extends CDebugElement implements ICVaria return super.getAdapter( adapter ); } - /** - * Returns the text presentation of this variable as an expression. - * - * @return the text presentation of this variable as an expression - * @throws DebugException - */ - public abstract String getExpressionString() throws DebugException; - public abstract void dispose(); protected abstract void resetValue(); diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/elements/adapters/CDebugElementAdapterFactory.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/elements/adapters/CDebugElementAdapterFactory.java index b7fbc32a2b7..49d9e3b972c 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/elements/adapters/CDebugElementAdapterFactory.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/elements/adapters/CDebugElementAdapterFactory.java @@ -18,7 +18,6 @@ import org.eclipse.cdt.debug.internal.ui.views.modules.ModuleLabelProvider; import org.eclipse.cdt.debug.internal.ui.views.modules.ModuleMementoProvider; import org.eclipse.cdt.debug.internal.ui.views.modules.ModuleProxyFactory; import org.eclipse.core.runtime.IAdapterFactory; -import org.eclipse.debug.core.model.IStackFrame; import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider; import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementLabelProvider; import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementMementoProvider; diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/elements/adapters/CWatchExpressionFactoryAdapter.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/elements/adapters/CWatchExpressionFactoryAdapter.java new file mode 100644 index 00000000000..8f8258ee97b --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/elements/adapters/CWatchExpressionFactoryAdapter.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2007 ARM 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * ARM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.debug.internal.ui.elements.adapters; + +import org.eclipse.cdt.debug.core.model.ICVariable; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.model.IVariable; +import org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapterExtension; + +public class CWatchExpressionFactoryAdapter implements IWatchExpressionFactoryAdapterExtension { + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapterExtension#canCreateWatchExpression(org.eclipse.debug.core.model.IVariable) + */ + public boolean canCreateWatchExpression( IVariable variable ) { + return ( variable instanceof ICVariable ); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapter#createWatchExpression(org.eclipse.debug.core.model.IVariable) + */ + public String createWatchExpression( IVariable variable ) throws CoreException { + return ( variable instanceof ICVariable ) ? ((ICVariable)variable).getExpressionString() : null; + } +} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/elements/adapters/CWatchExpressionFactoryAdapterFactory.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/elements/adapters/CWatchExpressionFactoryAdapterFactory.java new file mode 100644 index 00000000000..256f9f97eca --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/elements/adapters/CWatchExpressionFactoryAdapterFactory.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007 ARM 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * ARM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.debug.internal.ui.elements.adapters; + +import org.eclipse.cdt.debug.core.model.ICVariable; +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapter; + +public class CWatchExpressionFactoryAdapterFactory implements IAdapterFactory { + + private static IWatchExpressionFactoryAdapter fgWatchExpressionFactoryAdapter = new CWatchExpressionFactoryAdapter(); + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class) + */ + public Object getAdapter( Object adaptableObject, Class adapterType ) { + if ( adapterType.equals( IWatchExpressionFactoryAdapter.class ) ) { + if ( adaptableObject instanceof ICVariable ) { + return fgWatchExpressionFactoryAdapter; + } + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() + */ + public Class[] getAdapterList() { + return new Class[] { + IWatchExpressionFactoryAdapter.class, + }; + } +} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/CDebugUIPlugin.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/CDebugUIPlugin.java index 413350ed3b0..aff58cc6290 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/CDebugUIPlugin.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/CDebugUIPlugin.java @@ -12,9 +12,11 @@ package org.eclipse.cdt.debug.ui; import java.util.HashMap; import java.util.Map; + import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.model.ICModule; +import org.eclipse.cdt.debug.core.model.ICVariable; import org.eclipse.cdt.debug.core.model.IModuleRetrieval; import org.eclipse.cdt.debug.internal.ui.CBreakpointUpdater; import org.eclipse.cdt.debug.internal.ui.CDebugImageDescriptorRegistry; @@ -25,9 +27,10 @@ import org.eclipse.cdt.debug.internal.ui.EvaluationContextManager; import org.eclipse.cdt.debug.internal.ui.IInternalCDebugUIConstants; import org.eclipse.cdt.debug.internal.ui.elements.adapters.CDebugElementAdapterFactory; import org.eclipse.cdt.debug.internal.ui.elements.adapters.CMemoryAdapterFactory; +import org.eclipse.cdt.debug.internal.ui.elements.adapters.CWatchExpressionFactoryAdapterFactory; import org.eclipse.cdt.debug.ui.sourcelookup.DefaultSourceLocator; import org.eclipse.cdt.debug.ui.sourcelookup.OldDefaultSourceLocator; -import org.eclipse.cdt.internal.ui.editor.SharedTextColors; +import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -277,6 +280,9 @@ public class CDebugUIPlugin extends AbstractUIPlugin { manager.registerAdapters( elementAdapterFactory, IModuleRetrieval.class ); manager.registerAdapters( elementAdapterFactory, ICModule.class ); manager.registerAdapters( elementAdapterFactory, ICElement.class ); + + CWatchExpressionFactoryAdapterFactory watchExpressionAdapterFactory = new CWatchExpressionFactoryAdapterFactory(); + manager.registerAdapters( watchExpressionAdapterFactory, ICVariable.class ); CMemoryAdapterFactory memoryAdapterFactory = new CMemoryAdapterFactory(); manager.registerAdapters( memoryAdapterFactory, IMemoryBlockRetrievalExtension.class ); @@ -308,7 +314,7 @@ public class CDebugUIPlugin extends AbstractUIPlugin { */ public ISharedTextColors getSharedTextColors() { if ( fSharedTextColors == null ) - fSharedTextColors = new SharedTextColors(); + fSharedTextColors = CUIPlugin.getDefault().getSharedTextColors(); return fSharedTextColors; } } -- cgit v1.2.3