KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > contentassist > CurrentFrameContext


1 /*******************************************************************************
2  * Copyright (c) 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.contentassist;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.eclipse.debug.core.model.IVariable;
16 import org.eclipse.debug.ui.DebugUITools;
17 import org.eclipse.jdt.core.IType;
18 import org.eclipse.jdt.debug.core.IJavaStackFrame;
19 import org.eclipse.jdt.debug.core.IJavaVariable;
20 import org.eclipse.jdt.internal.debug.core.JavaDebugUtils;
21
22
23 /**
24  * Provides a completion context for the active stack frame.
25  *
26  * @since 3.2
27  */

28 public class CurrentFrameContext extends TypeContext {
29
30     /**
31      * Constructs a new completion context for the currently selected
32      * stack frame.
33      */

34     public CurrentFrameContext() {
35         super(null, -1);
36     }
37
38     /* (non-Javadoc)
39      * @see org.eclipse.jdt.internal.debug.ui.contentassist.IJavaDebugContentAssistContext#getType()
40      */

41     public IType getType() throws CoreException {
42         IJavaStackFrame frame = getStackFrame();
43         if (frame != null) {
44             IType type = JavaDebugUtils.resolveDeclaringType(frame);
45             if (type != null) {
46                 return type;
47             }
48         }
49         return super.getType();
50     }
51
52     /* (non-Javadoc)
53      * @see org.eclipse.jdt.internal.debug.ui.contentassist.IJavaDebugContentAssistContext#getLocalVariables()
54      */

55     public String JavaDoc[][] getLocalVariables() throws CoreException {
56         IJavaStackFrame frame = getStackFrame();
57         if (frame != null) {
58             IVariable[] variables = frame.getVariables();
59             int index = 0;
60             if (!frame.isStatic()) {
61                 index = 1;
62             }
63             String JavaDoc[][] locals = new String JavaDoc[2][variables.length - index];
64             for (int i = 0; i < locals[0].length; i++) {
65                 IJavaVariable var = (IJavaVariable) variables[index];
66                 locals[0][i] = var.getName();
67                 locals[1][i] = var.getJavaType().getName();
68                 index++;
69             }
70             return locals;
71         }
72         return super.getLocalVariables();
73     }
74     
75     /* (non-Javadoc)
76      * @see org.eclipse.jdt.internal.debug.ui.contentassist.IJavaDebugContentAssistContext#isStatic()
77      */

78     public boolean isStatic() throws CoreException {
79         IJavaStackFrame frame = getStackFrame();
80         if (frame != null) {
81             return frame.isStatic();
82         }
83         return false;
84     }
85
86     /**
87      * Returns the currently active stack frame, or <code>null</code>
88      * if none.
89      *
90      * @return the currently active stack frame, or <code>null</code>
91      */

92     protected IJavaStackFrame getStackFrame() {
93         IAdaptable debugContext = DebugUITools.getDebugContext();
94         IJavaStackFrame frame = null;
95         if (debugContext != null) {
96             frame = (IJavaStackFrame) debugContext.getAdapter(IJavaStackFrame.class);
97         }
98         return frame;
99     }
100
101     
102 }
103
Popular Tags