KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > heapwalking > JavaWatchExpressionFilter


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.heapwalking;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.debug.core.DebugException;
15 import org.eclipse.debug.core.model.IVariable;
16 import org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapterExtension;
17 import org.eclipse.jdt.internal.debug.core.model.JDIArrayEntryVariable;
18 import org.eclipse.jdt.internal.debug.core.model.JDIPlaceholderValue;
19 import org.eclipse.jdt.internal.debug.core.model.JDIReferenceListEntryVariable;
20 import org.eclipse.jdt.internal.debug.core.model.JDIReferenceListVariable;
21
22 /**
23  * Uses the <code>IWatchExpressionFactoryAdapterExtension</code> to filter when the watch expression
24  * action is available based on the variable selected.
25  *
26  * Currently removes the action from <code>JDIPlaceholderVariable</code>s and <code>JDIReferenceListVariable</code>s.
27  *
28  * @since 3.3
29  */

30 public class JavaWatchExpressionFilter implements IWatchExpressionFactoryAdapterExtension {
31
32     /* (non-Javadoc)
33      * @see org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapterExtension#canCreateWatchExpression(org.eclipse.debug.core.model.IVariable)
34      */

35     public boolean canCreateWatchExpression(IVariable variable) {
36         if (variable instanceof JDIReferenceListVariable || variable instanceof JDIReferenceListEntryVariable ||
37                 variable instanceof JDIArrayEntryVariable){
38             return false;
39         }
40         try{
41             if (variable.getValue() instanceof JDIPlaceholderValue){
42                 return false;
43             }
44         } catch (DebugException e) {}
45         return true;
46     }
47
48     /* (non-Javadoc)
49      * @see org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapter#createWatchExpression(org.eclipse.debug.core.model.IVariable)
50      */

51     public String JavaDoc createWatchExpression(IVariable variable)
52             throws CoreException {
53         return variable.getName();
54     }
55
56 }
57
Popular Tags