KickJava   Java API By Example, From Geeks To Geeks.

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


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
14 import java.util.Map JavaDoc;
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.jdt.debug.core.IJavaMethodEntryBreakpoint;
21 import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
22 import com.sun.jdi.ClassType;
23 import com.sun.jdi.Location;
24 import com.sun.jdi.Method;
25 import com.sun.jdi.ReferenceType;
26 import com.sun.jdi.request.BreakpointRequest;
27 import com.sun.jdi.request.EventRequest;
28
29 /**
30  * A line breakpoint at the first executable location in a specific method.
31  */

32
33 public class JavaMethodEntryBreakpoint extends JavaLineBreakpoint implements IJavaMethodEntryBreakpoint {
34     
35     private static final String JavaDoc JAVA_METHOD_ENTRY_BREAKPOINT = "org.eclipse.jdt.debug.javaMethodEntryBreakpointMarker"; //$NON-NLS-1$
36

37     /**
38      * Breakpoint attribute storing the name of the method
39      * in which a breakpoint is contained.
40      * (value <code>"org.eclipse.jdt.debug.core.methodName"</code>). This attribute is a <code>String</code>.
41      */

42     private static final String JavaDoc METHOD_NAME = "org.eclipse.jdt.debug.core.methodName"; //$NON-NLS-1$
43

44     /**
45      * Breakpoint attribute storing the signature of the method
46      * in which a breakpoint is contained.
47      * (value <code>"org.eclipse.jdt.debug.core.methodSignature"</code>). This attribute is a <code>String</code>.
48      */

49     private static final String JavaDoc METHOD_SIGNATURE = "org.eclipse.jdt.debug.core.methodSignature"; //$NON-NLS-1$
50

51     /**
52      * Cache of method name attribute
53      */

54     private String JavaDoc fMethodName = null;
55     
56     /**
57      * Cache of method signature attribute
58      */

59     private String JavaDoc fMethodSignature = null;
60         
61     /**
62      * Constructs a new unconfigured method breakpoint
63      */

64     public JavaMethodEntryBreakpoint() {
65     }
66     
67     public JavaMethodEntryBreakpoint(final IResource resource, final String JavaDoc typeName, final String JavaDoc methodName, final String JavaDoc methodSignature, final int lineNumber, final int charStart, final int charEnd, final int hitCount, final boolean register, final Map JavaDoc attributes) throws CoreException {
68         IWorkspaceRunnable wr= new IWorkspaceRunnable() {
69             public void run(IProgressMonitor monitor) throws CoreException {
70                 // create the marker
71
setMarker(resource.createMarker(JAVA_METHOD_ENTRY_BREAKPOINT));
72                 
73                 // add attributes
74
addLineBreakpointAttributes(attributes, getModelIdentifier(), true, lineNumber, charStart, charEnd);
75                 addMethodNameAndSignature(attributes, methodName, methodSignature);
76                 addTypeNameAndHitCount(attributes, typeName, hitCount);
77                 //set attributes
78
attributes.put(SUSPEND_POLICY, new Integer JavaDoc(getDefaultSuspendPolicy()));
79                 ensureMarker().setAttributes(attributes);
80                 
81                 register(register);
82             }
83
84         };
85         run(getMarkerRule(resource), wr);
86     }
87         
88     /**
89      * Adds the method name and signature attributes to the
90      * given attribute map, and intializes the local cache
91      * of method name and signature.
92      */

93     private void addMethodNameAndSignature(Map JavaDoc attributes, String JavaDoc methodName, String JavaDoc methodSignature) {
94         if (methodName != null) {
95             attributes.put(METHOD_NAME, methodName);
96         }
97         if (methodSignature != null) {
98             attributes.put(METHOD_SIGNATURE, methodSignature);
99         }
100         fMethodName= methodName;
101         fMethodSignature= methodSignature;
102     }
103                 
104     /**
105      * @see IJavaMethodEntryBreakpoint#getMethodName()
106      */

107     public String JavaDoc getMethodName() {
108         return fMethodName;
109     }
110     
111     /**
112      * @see IJavaMethodEntryBreakpoint#getMethodSignature()
113      */

114     public String JavaDoc getMethodSignature() {
115         return fMethodSignature;
116     }
117                 
118     /**
119      * Initialize cache of attributes
120      *
121      * @see IBreakpoint#setMarker(IMarker)
122      */

123     public void setMarker(IMarker marker) throws CoreException {
124         super.setMarker(marker);
125         fMethodName = marker.getAttribute(METHOD_NAME, null);
126         fMethodSignature = marker.getAttribute(METHOD_SIGNATURE, null);
127     }
128     
129     /**
130      * @see IJavaLineBreakpoint#supportsCondition()
131      */

132     public boolean supportsCondition() {
133         return false;
134     }
135         
136     /**
137      * @see JavaBreakpoint#newRequests(JDIDebugTarget, ReferenceType)
138      */

139     protected EventRequest[] newRequests(JDIDebugTarget target, ReferenceType type) throws CoreException {
140         try {
141             if (type instanceof ClassType) {
142                 ClassType clazz = (ClassType)type;
143                 Method method = clazz.concreteMethodByName(getMethodName(), getMethodSignature());
144                 if (method == null) {
145                     return null;
146                 }
147                 Location location = method.location();
148                 if (location == null || location.codeIndex() == -1) {
149                     return null;
150                 }
151                 BreakpointRequest req = type.virtualMachine().eventRequestManager().createBreakpointRequest(location);
152                 configureRequest(req, target);
153                 return new EventRequest[]{req};
154             }
155             return null;
156         } catch (RuntimeException JavaDoc e) {
157             target.internalError(e);
158             return null;
159         }
160     }
161 }
162
Popular Tags