KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.*;
29
30 /**
31  * ListRequest.java
32  *
33  *
34  * Created: Tue Aug 29 12:53:17 2000
35  *
36  * @author <a HREF="mailto:palm@parc.xerox.com"Jeffrey Palm</a>
37  */

38
39 public class ListRequest extends Request {
40
41     private String JavaDoc sourceName = null;
42     private int startLineNumber = -1;
43     private int endLineNumber = -1;
44
45     public ListRequest(Debugger debugger) {
46         this(debugger, null, -1, -1);
47     }
48
49     public ListRequest(Debugger debugger, String JavaDoc sourceName) {
50         this(debugger, sourceName, -1, -1);
51     }
52
53     public ListRequest(Debugger debugger, String JavaDoc sourceName, int startLineNumber) {
54         this(debugger, sourceName, startLineNumber, -1);
55     }
56
57     public ListRequest(Debugger debugger, String JavaDoc sourceName, int startLineNumber, int endLineNumber) {
58         super(debugger);
59         this.sourceName = sourceName;
60         this.startLineNumber = startLineNumber;
61         this.endLineNumber = endLineNumber;
62     }
63
64     private SourceAndLines empty(String JavaDoc sourceName) {
65         Vector v = new Vector();
66         v.add(ajdbg().emptySourceLine());
67         return new SourceAndLines(sourceName, v);
68     }
69
70     public static class SourceAndLines {
71         private String JavaDoc sourceName;
72         public String JavaDoc getSourceName() { return sourceName; }
73         private List lines;
74         public List getLines() { return lines; }
75         public SourceAndLines(String JavaDoc sourceName, List lines) {
76             this.sourceName = sourceName;
77             this.lines = lines;
78         }
79         public String JavaDoc toString() {
80             return sourceName + ":" + lines;
81         }
82     }
83
84     public Object JavaDoc go() throws NoVMException, DebuggerException {
85         SourceManager sm = debugger.getSourceManager();
86         if (sourceName == null) {
87             try {
88                 StackFrame frame = dbg().getDefaultFrame();
89                 if (frame == null) {
90                     return empty(sn());
91                 }
92                 int line = ajdbg().lineNumber(frame.location());
93                 int start = line;
94                 int end = line;
95                 if (line > 0) {
96                     for (int i = 0; i < 4; i++) {
97                         end++;
98                         if (start > 1) {
99                             start--;
100                         }
101                     }
102                     sourceName = ajdbg().sourceName(frame.location());
103                     if (sourceName == null) {
104                         return empty(sn());
105                     }
106                 }
107                 startLineNumber = start;
108                 endLineNumber = end + 2;
109             } catch (AbsentInformationException aie) {
110                 return empty(sn());
111             }
112         }
113         if (startLineNumber == -1) {
114             return sal(sm.getSourceLines(sourceName));
115         } else if (endLineNumber == -1) {
116             return sal(sm.getSourceLine(sourceName, startLineNumber-1));
117         } else {
118             return sal(sm.getSourceLines(sourceName, startLineNumber-1, endLineNumber));
119         }
120     }
121
122     private String JavaDoc sn() {
123         return sourceName == null ? "<not found>" : sourceName;
124     }
125
126     private SourceAndLines sal(SourceManager.SourceLine line) {
127         List lines = new Vector();
128         lines.add(line);
129         return sal(lines);
130     }
131
132     private SourceAndLines sal(List lines) {
133         return new SourceAndLines(sourceName, lines);
134     }
135 }
136
Popular Tags