KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > core > breakpoints > JavaClassPrepareBreakpoint


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.core.breakpoints;
12
13 import java.util.Map JavaDoc;
14
15 import org.eclipse.core.resources.IMarker;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.resources.IWorkspaceRunnable;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.IStatus;
21 import org.eclipse.core.runtime.Status;
22 import org.eclipse.debug.core.DebugException;
23 import org.eclipse.debug.core.model.IBreakpoint;
24 import org.eclipse.jdt.debug.core.IJavaClassPrepareBreakpoint;
25 import org.eclipse.jdt.debug.core.IJavaObject;
26 import org.eclipse.jdt.debug.core.IJavaThread;
27 import org.eclipse.jdt.debug.core.JDIDebugModel;
28 import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
29 import org.eclipse.jdt.internal.debug.core.model.JDIThread;
30
31 import com.sun.jdi.ObjectReference;
32 import com.sun.jdi.ReferenceType;
33 import com.sun.jdi.ThreadReference;
34 import com.sun.jdi.event.ClassPrepareEvent;
35 import com.sun.jdi.request.ClassPrepareRequest;
36 import com.sun.jdi.request.EventRequest;
37
38 /**
39  * Class prepare breakpoint.
40  *
41  * @since 3.0
42  */

43 public class JavaClassPrepareBreakpoint extends JavaBreakpoint implements IJavaClassPrepareBreakpoint {
44     
45     private static final String JavaDoc JAVA_CLASS_PREPARE_BREAKPOINT= "org.eclipse.jdt.debug.javaClassPrepareBreakpointMarker"; //$NON-NLS-1$
46

47     /**
48      * Class prepare breakpoint attribute storing the type of member this
49      * breakpoint is associated with
50      * (value <code>"org.eclipse.jdt.debug.core.memberType"</code>), encoded
51      * as an integer.
52      */

53     protected static final String JavaDoc MEMBER_TYPE = "org.eclipse.jdt.debug.core.memberType"; //$NON-NLS-1$
54

55     /**
56      * Creates and returns a Java class prepare breakpoint for the
57      * given type.
58      * @param resource the resource on which to create the associated
59      * breakpoint marker
60      * @param typeName the fully qualified name of the type for
61      * which to create the breakpoint
62      * @param memberType one of <code>TYPE_CLASS</code> or <code>TYPE_INTERFACE</code>
63      * @param charStart the first character index associated with the breakpoint,
64      * or -1 if unspecified, in the source file in which the breakpoint is set
65      * @param charEnd the last character index associated with the breakpoint,
66      * or -1 if unspecified, in the source file in which the breakpoint is set
67      * @param add whether to add this breakpoint to the breakpoint manager
68      * @return a Java class prepare breakpoint
69      * @exception DebugException if unable to create the associated marker due
70      * to a lower level exception.
71      */

72     public JavaClassPrepareBreakpoint(final IResource resource, final String JavaDoc typeName, final int memberType, final int charStart, final int charEnd, final boolean add, final Map JavaDoc attributes) throws DebugException {
73         IWorkspaceRunnable wr= new IWorkspaceRunnable() {
74
75             public void run(IProgressMonitor monitor) throws CoreException {
76                 // create the marker
77
setMarker(resource.createMarker(JAVA_CLASS_PREPARE_BREAKPOINT));
78                 
79                 // add attributes
80
attributes.put(IBreakpoint.ID, getModelIdentifier());
81                 attributes.put(IMarker.CHAR_START, new Integer JavaDoc(charStart));
82                 attributes.put(IMarker.CHAR_END, new Integer JavaDoc(charEnd));
83                 attributes.put(TYPE_NAME, typeName);
84                 attributes.put(MEMBER_TYPE, new Integer JavaDoc(memberType));
85                 attributes.put(ENABLED, Boolean.TRUE);
86                 attributes.put(SUSPEND_POLICY, new Integer JavaDoc(getDefaultSuspendPolicy()));
87                 
88                 ensureMarker().setAttributes(attributes);
89                 
90                 register(add);
91             }
92
93         };
94         run(getMarkerRule(resource), wr);
95     }
96     
97     public JavaClassPrepareBreakpoint() {
98     }
99     
100     /**
101      * Creates event requests for the given target
102      */

103     protected void createRequests(JDIDebugTarget target) throws CoreException {
104         if (target.isTerminated() || shouldSkipBreakpoint()) {
105             return;
106         }
107         String JavaDoc referenceTypeName= getTypeName();
108         if (referenceTypeName == null) {
109             return;
110         }
111
112         ClassPrepareRequest request = target.createClassPrepareRequest(referenceTypeName, null, false);
113         configureRequestHitCount(request);
114         updateEnabledState(request, target);
115         registerRequest(request, target);
116         // TODO: do we show anything for types already loaded?
117
incrementInstallCount();
118     }
119     
120     /**
121      * Remove the given request from the given target. If the request
122      * is the breakpoint request associated with this breakpoint,
123      * decrement the install count.
124      */

125     protected void deregisterRequest(EventRequest request, JDIDebugTarget target) throws CoreException {
126         target.removeJDIEventListener(this, request);
127         // A request may be getting deregistered because the breakpoint has
128
// been deleted. It may be that this occurred because of a marker deletion.
129
// Don't try updating the marker (decrementing the install count) if
130
// it no longer exists.
131
if (getMarker().exists()) {
132             decrementInstallCount();
133         }
134     }
135     
136     /* (non-Javadoc)
137      *
138      * Not supported for class prepare breakpoints.
139      *
140      * @see org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint#addInstanceFilter(com.sun.jdi.request.EventRequest, com.sun.jdi.ObjectReference)
141      */

142     protected void addInstanceFilter(EventRequest request, ObjectReference object) {
143     }
144     /* (non-Javadoc)
145      *
146      * This method not used for class prepare breakpoints.
147      *
148      * @see org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint#newRequest(org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget, com.sun.jdi.ReferenceType)
149      */

150     protected EventRequest[] newRequests(JDIDebugTarget target, ReferenceType type) throws CoreException {
151         return null;
152     }
153     /* (non-Javadoc)
154      *
155      * Not supported for class prepare breakpoints.
156      *
157      * @see org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint#setRequestThreadFilter(com.sun.jdi.request.EventRequest, com.sun.jdi.ThreadReference)
158      */

159     protected void setRequestThreadFilter(EventRequest request, ThreadReference thread) {
160     }
161     /* (non-Javadoc)
162      * @see org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint#handleClassPrepareEvent(com.sun.jdi.event.ClassPrepareEvent, org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget)
163      */

164     public boolean handleClassPrepareEvent(ClassPrepareEvent event, JDIDebugTarget target) {
165         try {
166             if (isEnabled() && event.referenceType().name().equals(getTypeName())) {
167                 ThreadReference threadRef= event.thread();
168                 JDIThread thread= target.findThread(threadRef);
169                 if (thread == null || thread.isIgnoringBreakpoints()) {
170                     return true;
171                 }
172                 return handleBreakpointEvent(event, target, thread);
173             }
174         } catch (CoreException e) {
175         }
176         return true;
177     }
178     /* (non-Javadoc)
179      * @see org.eclipse.jdt.debug.core.IJavaClassPrepareBreakpoint#getMemberType()
180      */

181     public int getMemberType() throws CoreException {
182         return ensureMarker().getAttribute(MEMBER_TYPE, IJavaClassPrepareBreakpoint.TYPE_CLASS);
183     }
184     
185     /* (non-Javadoc)
186      * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#supportsInstanceFilters()
187      */

188     public boolean supportsInstanceFilters() {
189         return false;
190     }
191     /* (non-Javadoc)
192      * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#addInstanceFilter(org.eclipse.jdt.debug.core.IJavaObject)
193      */

194     public void addInstanceFilter(IJavaObject object) throws CoreException {
195         throw new CoreException(new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), DebugException.REQUEST_FAILED, JDIDebugBreakpointMessages.JavaClassPrepareBreakpoint_2, null));
196     }
197     /* (non-Javadoc)
198      * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#setThreadFilter(org.eclipse.jdt.debug.core.IJavaThread)
199      */

200     public void setThreadFilter(IJavaThread thread) throws CoreException {
201         throw new CoreException(new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), DebugException.REQUEST_FAILED, JDIDebugBreakpointMessages.JavaClassPrepareBreakpoint_3, null));
202     }
203     /* (non-Javadoc)
204      * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#supportsThreadFilters()
205      */

206     public boolean supportsThreadFilters() {
207         return false;
208     }
209 }
210
Popular Tags