KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > debugger > request > ClassLineBreakpointRequestAction


1 /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the debugger and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  */

22
23 package org.aspectj.debugger.request;
24
25 import org.aspectj.debugger.base.*;
26
27 import com.sun.jdi.*;
28 import com.sun.jdi.request.*;
29 import com.sun.jdi.event.*;
30 import org.aspectj.tools.ide.SourceLine;
31 import java.util.*;
32
33 import org.aspectj.util.LineNumberTableMapper;
34 import java.io.File JavaDoc;
35
36 /**
37  * ClassLineBreakpointRequestAction.java
38  *
39  *
40  * Created: Wed Aug 23 11:27:47 2000
41  *
42  * @author <a HREF="mailto:palm@parc.xerox.com"Jeffrey Palm</a>
43  */

44
45 public abstract class ClassLineBreakpointRequestAction extends ClassBreakpointRequestAction {
46
47     private int line;
48
49     ClassLineBreakpointRequestAction(Debugger debugger, String JavaDoc className, int line) {
50         super(debugger, className);
51         System.err.println(">> breakpoint request, class: " + className + ", line: " + line);
52         this.line = line;
53     }
54
55     public String JavaDoc getProto() {
56         SourceLine sl = ajdbg().getSourceLineFromClass(getClassName(), getLine());
57         int newLine = line;
58         if (sl == null) {
59             System.err.println("sl is null for " + getClassName() + ":" + line);
60         } else {
61             newLine = sl.line;
62         }
63         return getClassName() + ":" + newLine;
64     }
65
66     public String JavaDoc getErrorMessage() {
67         return "No code at line " + line + " in " + getClassName();
68     }
69
70     Location findLocation()
71         throws NoVMException,
72                MultipleLocationsException,
73                UnableToSetRequestException {
74
75         System.err.println(">>> resolving class-line breakpoint, class: " + className);
76
77 // String fullName = loc.declaringType().name();
78
// System.err.println(">>> pkg: " + pkg + ",);
79

80
81 // System.err.println(">>>> " + vm().classesByName(className));
82

83         try {
84
85             Iterator it = vm().classesByName(className).iterator();
86             ReferenceType refType = null;
87             while (it.hasNext()) {
88                 refType = (ReferenceType) it.next(); // HACK
89
System.err.println(">> refType: " + refType.sourceName());
90             }
91             if (refType != null) {
92                 String JavaDoc attrib = refType.sourceName();
93                 String JavaDoc pkg = className.substring(0, className.lastIndexOf('.')).replace('.', '/');
94                 String JavaDoc srcPath = org.aspectj.debugger.base.AJDebugger.INSTANCE.getSourcePath();
95                 File JavaDoc srcRoot = new File JavaDoc(srcPath);
96
97                 System.err.println(">> findMethod attrib: " + attrib + ", pkg: " + pkg + ", src: " + srcPath);
98
99                 LineNumberTableMapper mapper = new LineNumberTableMapper(attrib, pkg, srcRoot);
100                 System.err.println(">>> mapper: " + mapper.toString());
101                 System.err.println(">> mapped: " + mapper.getCorrespondingFile(line).getPath() + " : " + mapper.getCorrespondingLineNumber(line));
102
103                 Iterator linesIter = refType.allLineLocations().iterator();
104                 //System.err.println("line: " + line + " -> " + );
105
// List lines = refType.locationsOfLine(mapper.getCorrespondingLineNumber(line));
106
// Iterator linesIter = lines.iterator();
107
while (linesIter.hasNext()) {
108                     Location loc = (Location)linesIter.next();
109                     if (loc.lineNumber() == mapper.getCorrespondingLineNumber(line)) {
110                         return loc;
111                     }
112                 }
113 // return (Location) linesIter.next();
114
// } else {
115
// System.err.println("> ERROR: no lines");
116
// throw new AbsentInformationException();
117
// }
118
} else {
119                 throw new AbsentInformationException();
120             }
121         } catch (AbsentInformationException aie) {
122             System.err.println("> ERROR: in class line breakpoint request");
123             aie.printStackTrace();
124         }
125         return null;
126 // Location location = null;
127
// Iterator iter = vm().classesByName(getClassName()).iterator();
128
// while (iter.hasNext()) {
129
// ReferenceType refType = (ReferenceType) iter.next();
130
// if (refType.name().equals(getClassName())) {
131
// try {
132
// List lines = refType.locationsOfLine(getLine());
133
// Iterator linesIter = lines.iterator();
134
// while (linesIter.hasNext()) {
135
// return (Location) linesIter.next();
136
// }
137
// } catch (AbsentInformationException e) {
138
// return null;
139
// }
140
// throw new UnableToSetRequestException(this);
141
// }
142
// } System.out.println(this + ".location=" + location);
143
// return location;
144
}
145
146     public int getLine() {
147         return line;
148     }
149
150     public boolean equals(Object JavaDoc other) {
151         if (other == null || !(other instanceof ClassLineBreakpointRequestAction)) {
152             return super.equals(other);
153         }
154         ClassLineBreakpointRequestAction ra = (ClassLineBreakpointRequestAction) other;
155         return (getClassName().equals(ra.getClassName()) &&
156                 getLine() == ra.getLine());
157     }
158 }
159
Popular Tags