KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > JavaInspectExpressionActionFilter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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;
12
13  
14 import java.util.HashSet JavaDoc;
15 import java.util.Set JavaDoc;
16
17 import org.eclipse.debug.core.DebugException;
18 import org.eclipse.debug.core.model.IValue;
19 import org.eclipse.jdt.debug.core.IJavaObject;
20 import org.eclipse.jdt.internal.debug.ui.actions.OpenVariableTypeAction;
21 import org.eclipse.jdt.internal.debug.ui.display.JavaInspectExpression;
22 import org.eclipse.ui.IActionFilter;
23
24 public class JavaInspectExpressionActionFilter implements IActionFilter {
25
26     private static final Set JavaDoc fgPrimitiveTypes = initPrimitiveTypes();
27
28     private static Set JavaDoc initPrimitiveTypes() {
29         HashSet JavaDoc set = new HashSet JavaDoc(8);
30         set.add("short"); //$NON-NLS-1$
31
set.add("int"); //$NON-NLS-1$
32
set.add("long"); //$NON-NLS-1$
33
set.add("float"); //$NON-NLS-1$
34
set.add("double"); //$NON-NLS-1$
35
set.add("boolean"); //$NON-NLS-1$
36
set.add("byte"); //$NON-NLS-1$
37
set.add("char"); //$NON-NLS-1$
38
set.add("null"); //$NON-NLS-1$
39
return set;
40     }
41
42     /**
43      * @see org.eclipse.ui.IActionFilter#testAttribute(java.lang.Object, java.lang.String, java.lang.String)
44      */

45     public boolean testAttribute(Object JavaDoc target, String JavaDoc name, String JavaDoc value) {
46         if (target instanceof JavaInspectExpression) {
47             JavaInspectExpression exp= (JavaInspectExpression) target;
48             if (name.equals("PrimitiveVariableActionFilter") && value.equals("isNotPrimitive")) { //$NON-NLS-1$ //$NON-NLS-2$
49
return !isPrimitiveType(exp);
50             } else if (name.equals("DetailFormatterFilter") && value.equals("isDefined")) { //$NON-NLS-1$ //$NON-NLS-2$
51
try {
52                     IValue varValue= exp.getValue();
53                     return (varValue instanceof IJavaObject) && (JavaDetailFormattersManager.getDefault().hasAssociatedDetailFormatter(((IJavaObject)varValue).getJavaType()));
54                 } catch (DebugException exception) {
55                     JDIDebugUIPlugin.log(exception);
56                 }
57             }
58         }
59         return false;
60     }
61     
62     private boolean isPrimitiveType(JavaInspectExpression exp) {
63         if (exp == null) {
64             return false;
65         }
66         try {
67             IValue value = exp.getValue();
68             if (value != null) {
69                 String JavaDoc refType = OpenVariableTypeAction.removeArray(value.getReferenceTypeName());
70                 return fgPrimitiveTypes.contains(refType);
71             }
72         } catch (DebugException e) {
73         }
74         return false;
75     }
76
77 }
78
Popular Tags