Initial Commit
[packages] / xemacs-packages / jde / java / src / jde / debugger / spec / LineBreakpointSpec.java
1 package jde.debugger.spec;
2
3 import com.sun.jdi.*;
4 import com.sun.jdi.request.*;
5
6 import java.util.*;
7 import jde.debugger.JDEException;
8
9 /**
10  * LineBreakpointSpec.java
11  * <p>
12  *
13  * <p>
14  * Created: Thu Jul 15 13:00:34 1999
15  *
16  * @author Amit Kumar
17  * @since 0.1
18  * @version $Revision: 1.4 $
19  */
20
21 public class LineBreakpointSpec extends BreakpointSpec {
22
23   private int lineNumber;
24
25   public LineBreakpointSpec(ReferenceTypeSpec refSpec,
26                             int line) {
27     super(refSpec);
28     this.lineNumber = line;
29   }
30
31   boolean resolve(ReferenceType refType) throws JDEException {
32     if (!(refType instanceof ClassType)) {
33       // remove spec from list of current specs
34       throw new JDEException("'"+refType+"' is not a Class");
35     }
36     Location location = getLocation((ClassType)refType);
37     BreakpointRequest br = refType.virtualMachine().eventRequestManager().createBreakpointRequest(location);
38         
39     setRequest(br);
40     return true;
41   }
42
43   private Location getLocation(ClassType clazz) throws JDEException {
44     Location location = null;
45     try {
46       List locs = null;
47       try {
48         locs = clazz.locationsOfLine(lineNumber);
49       } catch (InvalidLineNumberException ex) {
50         throw new JDEException("Line #"+lineNumber+" does not exist in "+clazz+".");
51       }         
52       if (locs.size() == 0) {
53         // remove spec from list of current specs
54         throw new JDEException("Line #"+lineNumber+" does not exist int "+clazz+".");
55       }
56       // XXX handle multiple locations
57       location = (Location)locs.get(0);
58       if (location.method() == null) {
59         // remove spec from list of current specs
60         throw new JDEException("Line #"+lineNumber+" does not correspond to a method in "+
61                                clazz + ".");
62       } 
63     } catch (AbsentInformationException e) {
64       // remove spec from list of current specs
65       throw new JDEException("Line Information missing for Class '"+clazz+"'");
66     }
67     return location;
68   }
69
70   public int getLineNumber() {
71     return lineNumber;
72   }
73
74 } // LineBreakpointSpec
75
76 /*
77  * $Log: LineBreakpointSpec.java,v $
78  * Revision 1.4  2003/01/15 06:06:15  paulk
79  * Petter Mahlen's changes.
80  *
81  */
82
83 // End of LineBreakpointSpec.java