Showing the changes to java/pkg/com/sun/tools/example/debug/bdi/LineBreakpointSpec.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,121 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.tools.example.debug.bdi; | |
| 27 | + | |
| 28 | +import com.sun.jdi.*; | |
| 29 | +import java.util.List; | |
| 30 | + | |
| 31 | +public class LineBreakpointSpec extends BreakpointSpec { | |
| 32 | + int lineNumber; | |
| 33 | + | |
| 34 | + LineBreakpointSpec(EventRequestSpecList specs, | |
| 35 | + ReferenceTypeSpec refSpec, int lineNumber) { | |
| 36 | + super(specs, refSpec); | |
| 37 | + this.lineNumber = lineNumber; | |
| 38 | + } | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * The 'refType' is known to match. | |
| 42 | + */ | |
| 43 | + @Override | |
| 44 | + void resolve(ReferenceType refType) throws InvalidTypeException, | |
| 45 | + LineNotFoundException { | |
| 46 | + if (!(refType instanceof ClassType)) { | |
| 47 | + throw new InvalidTypeException(); | |
| 48 | + } | |
| 49 | + Location location = location((ClassType)refType); | |
| 50 | + setRequest(refType.virtualMachine().eventRequestManager() | |
| 51 | + .createBreakpointRequest(location)); | |
| 52 | + } | |
| 53 | + | |
| 54 | + private Location location(ClassType clazz) throws | |
| 55 | + LineNotFoundException { | |
| 56 | + Location location = null; | |
| 57 | + try { | |
| 58 | + List<Location> locs = clazz.locationsOfLine(lineNumber()); | |
| 59 | + if (locs.size() == 0) { | |
| 60 | + throw new LineNotFoundException(); | |
| 61 | + } | |
| 62 | + // TODO handle multiple locations | |
| 63 | + location = locs.get(0); | |
| 64 | + if (location.method() == null) { | |
| 65 | + throw new LineNotFoundException(); | |
| 66 | + } | |
| 67 | + } catch (AbsentInformationException e) { | |
| 68 | + /* | |
| 69 | + * TO DO: throw something more specific, or allow | |
| 70 | + * AbsentInfo exception to pass through. | |
| 71 | + */ | |
| 72 | + throw new LineNotFoundException(); | |
| 73 | + } | |
| 74 | + return location; | |
| 75 | + } | |
| 76 | + | |
| 77 | + public int lineNumber() { | |
| 78 | + return lineNumber; | |
| 79 | + } | |
| 80 | + | |
| 81 | + @Override | |
| 82 | + public int hashCode() { | |
| 83 | + return refSpec.hashCode() + lineNumber; | |
| 84 | + } | |
| 85 | + | |
| 86 | + @Override | |
| 87 | + public boolean equals(Object obj) { | |
| 88 | + if (obj instanceof LineBreakpointSpec) { | |
| 89 | + LineBreakpointSpec breakpoint = (LineBreakpointSpec)obj; | |
| 90 | + | |
| 91 | + return refSpec.equals(breakpoint.refSpec) && | |
| 92 | + (lineNumber == breakpoint.lineNumber); | |
| 93 | + } else { | |
| 94 | + return false; | |
| 95 | + } | |
| 96 | + } | |
| 97 | + | |
| 98 | + @Override | |
| 99 | + public String errorMessageFor(Exception e) { | |
| 100 | + if (e instanceof LineNotFoundException) { | |
| 101 | + return ("No code at line " + lineNumber() + " in " + refSpec); | |
| 102 | + } else if (e instanceof InvalidTypeException) { | |
| 103 | + return ("Breakpoints can be located only in classes. " + | |
| 104 | + refSpec + " is an interface or array"); | |
| 105 | + } else { | |
| 106 | + return super.errorMessageFor( e); | |
| 107 | + } | |
| 108 | + } | |
| 109 | + | |
| 110 | + @Override | |
| 111 | + public String toString() { | |
| 112 | + StringBuffer buffer = new StringBuffer("breakpoint "); | |
| 113 | + buffer.append(refSpec.toString()); | |
| 114 | + buffer.append(':'); | |
| 115 | + buffer.append(lineNumber); | |
| 116 | + buffer.append(" ("); | |
| 117 | + buffer.append(getStatusString()); | |
| 118 | + buffer.append(')'); | |
| 119 | + return buffer.toString(); | |
| 120 | + } | |
| 121 | +} | |