KickJava   Java API By Example, From Geeks To Geeks.

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


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.IJavaClassType;
20 import org.eclipse.jdt.debug.core.IJavaDebugTarget;
21 import org.eclipse.jdt.debug.core.IJavaObject;
22 import org.eclipse.jdt.debug.core.IJavaVariable;
23 import org.eclipse.jdt.internal.debug.core.logicalstructures.JavaStructureErrorValue;
24 import org.eclipse.jdt.internal.debug.core.model.JDINullValue;
25 import org.eclipse.jdt.internal.debug.ui.actions.EditVariableLogicalStructureAction;
26 import org.eclipse.jdt.internal.debug.ui.actions.OpenVariableTypeAction;
27 import org.eclipse.ui.IActionFilter;
28
29 public class JavaVariableActionFilter implements IActionFilter {
30
31     private static final Set JavaDoc fgPrimitiveTypes = initPrimitiveTypes();
32
33     private static Set JavaDoc initPrimitiveTypes() {
34         HashSet JavaDoc set = new HashSet JavaDoc(8);
35         set.add("short"); //$NON-NLS-1$
36
set.add("int"); //$NON-NLS-1$
37
set.add("long"); //$NON-NLS-1$
38
set.add("float"); //$NON-NLS-1$
39
set.add("double"); //$NON-NLS-1$
40
set.add("boolean"); //$NON-NLS-1$
41
set.add("byte"); //$NON-NLS-1$
42
set.add("char"); //$NON-NLS-1$
43
set.add("null"); //$NON-NLS-1$
44
return set;
45     }
46
47     /**
48      * @see org.eclipse.ui.IActionFilter#testAttribute(Object, String, String)
49      */

50     public boolean testAttribute(Object JavaDoc target, String JavaDoc name, String JavaDoc value) {
51         if (target instanceof IJavaVariable) {
52             IJavaVariable var = (IJavaVariable) target;
53             IValue varValue;
54             try {
55                 varValue= var.getValue();
56                 if (name.equals("PrimitiveVariableActionFilter")) { //$NON-NLS-1$ //$NON-NLS-2$
57
if (value.equals("isPrimitive")) { //$NON-NLS-1$
58
return isPrimitiveType(var);
59                     } else if (value.equals("isValuePrimitive")) { //$NON-NLS-1$
60
return isValuePrimitiveType(var);
61                     }
62                 } else if (name.equals("ConcreteVariableActionFilter") && value.equals("isConcrete")) { //$NON-NLS-1$ //$NON-NLS-2$
63
return isDeclaredSameAsConcrete(var);
64                 } else if (name.equals("JavaVariableActionFilter") && value.equals("instanceFilter")) { //$NON-NLS-1$ //$NON-NLS-2$
65
return !var.isStatic() && (varValue instanceof IJavaObject) && (((IJavaObject)varValue).getJavaType() instanceof IJavaClassType) && ((IJavaDebugTarget)var.getDebugTarget()).supportsInstanceBreakpoints();
66                 } else if (name.equals("DetailFormatterFilter") && value.equals("isDefined")) { //$NON-NLS-1$ //$NON-NLS-2$
67
return (varValue instanceof IJavaObject) && (JavaDetailFormattersManager.getDefault().hasAssociatedDetailFormatter(((IJavaObject)varValue).getJavaType()));
68                 } else if (name.equals("JavaLogicalStructureFilter") && value.equals("canEditLogicalStructure")) { //$NON-NLS-1$ //$NON-NLS-2$
69
return varValue instanceof JavaStructureErrorValue || EditVariableLogicalStructureAction.getLogicalStructure(varValue) != null;
70                 }
71             } catch (DebugException e) {
72                 JDIDebugUIPlugin.log(e);
73             }
74         }
75
76         return false;
77     }
78
79     protected boolean isDeclaredSameAsConcrete(IJavaVariable var) throws DebugException {
80         IValue value= var.getValue();
81         if (value instanceof JDINullValue) {
82             return false;
83         }
84         return !var.getReferenceTypeName().equals(value.getReferenceTypeName());
85     }
86     protected String JavaDoc getTypeNameToOpen(String JavaDoc refType) {
87         refType = OpenVariableTypeAction.removeArray(refType);
88         if (fgPrimitiveTypes.contains(refType)) {
89             return null;
90         }
91         return refType;
92     }
93
94
95     protected boolean isPrimitiveType(IJavaVariable var) {
96         try {
97             return getTypeNameToOpen(var.getReferenceTypeName()) != null;
98         } catch (DebugException e) {
99             JDIDebugUIPlugin.log(e);
100             // fall through
101
}
102         return false;
103     }
104     
105     protected boolean isValuePrimitiveType(IJavaVariable var) {
106         try {
107             return getTypeNameToOpen(var.getValue().getReferenceTypeName()) != null;
108         } catch (DebugException e) {
109             JDIDebugUIPlugin.log(e);
110             // fall through
111
}
112         return false;
113     }
114 }
115
Popular Tags