KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > debugger > gui > AJUtil


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.gui;
24
25 import org.aspectj.debugger.base.*;
26
27 import java.awt.Frame JavaDoc;
28 import java.io.*;
29 import javax.swing.JOptionPane JavaDoc;
30
31 import com.sun.jdi.*;
32 import com.sun.jdi.event.*;
33 import com.sun.jdi.request.*;
34
35 public class AJUtil {
36
37     private final static Frame JavaDoc FRAME = null; //Main.gui;
38

39     public static void info(Object JavaDoc o) {
40         Object JavaDoc msg = check(o);
41         JOptionPane.showMessageDialog
42             (FRAME, msg, "Info", JOptionPane.INFORMATION_MESSAGE);
43     }
44
45     public static void warn(Object JavaDoc o) {
46         Object JavaDoc msg = check(o);
47         JOptionPane.showMessageDialog
48             (FRAME, msg, "Warning", JOptionPane.WARNING_MESSAGE);
49     }
50
51     public static void error(Object JavaDoc o) {
52         Object JavaDoc msg = check(o);
53         JOptionPane.showMessageDialog
54             (FRAME, msg, "Error", JOptionPane.ERROR_MESSAGE);
55     }
56
57     public static void question(Object JavaDoc o) {
58         Object JavaDoc msg = check(o);
59         JOptionPane.showMessageDialog
60             (FRAME, msg, "Huh?", JOptionPane.QUESTION_MESSAGE);
61     }
62
63     public static void popup(Object JavaDoc o) {
64         Object JavaDoc msg = check(o);
65         JOptionPane.showMessageDialog
66             (FRAME, msg, "Error", JOptionPane.PLAIN_MESSAGE);
67     }
68
69     public static void ex(Throwable JavaDoc o) {
70         if (o == null) return;
71         o.printStackTrace(System.err);
72         JOptionPane.showMessageDialog
73             (FRAME, o.getMessage(), "Exception", JOptionPane.ERROR_MESSAGE);
74     }
75
76 // public static String getStringFromSpec(BreakpointSpec spec) {
77
// String specString = spec + "";
78
// String strip = "breakpoint ";
79
// if (specString.indexOf(strip) != -1) {
80
// return specString.substring(strip.length());
81
// }
82
// return specString;
83
// }
84

85     public static String JavaDoc getStringFromRequest(BreakpointRequest request) {
86         String JavaDoc specString = request + "";
87         String JavaDoc strip = "breakpoint request ";
88         if (specString.indexOf(strip) != -1) {
89             return specString.substring(strip.length() - 1);
90         }
91         return specString;
92     }
93
94     public static String JavaDoc stripParens(Method method) {
95         return stripParens(method + "");
96     }
97
98     public static String JavaDoc stripParens(String JavaDoc method) {
99         int index = method.indexOf("(");
100         if (index < 0) {
101             return method;
102         }
103         String JavaDoc noParens = method.substring(0, index);
104         return noParens.trim();
105     }
106
107     public static String JavaDoc getParams(Method method) {
108         return getParams(method + "");
109     }
110
111     public static String JavaDoc getParams(String JavaDoc method) {
112         int lparen = method.indexOf("(");
113         int rparen = method.indexOf(")");
114         if (lparen < 0 || rparen < 0) {
115             return method;
116         }
117         return method.substring(lparen+1, rparen).trim();
118     }
119
120     public static String JavaDoc removePathFromSource(String JavaDoc source) {
121         int isep = source.lastIndexOf(File.separatorChar);
122         if (isep == -1) {
123             return source;
124         }
125         return source.substring(isep + 1);
126     }
127
128     public static String JavaDoc stripTypeFromMethod(String JavaDoc name) {
129         int iDot = locateFirstDotBeforeLParen(name);
130         if (iDot != -1) {
131             return name.substring(iDot + 1, name.length());
132         }
133         return name;
134     }
135
136     public static String JavaDoc getParamsFromMethod(Method method) {
137         return getParamsFromMethod(method + "");
138     }
139
140     public static String JavaDoc getParamsFromMethod(String JavaDoc name) {
141         int iLParen = name.indexOf("(");
142         int iRParen = name.indexOf(")");
143         if (iLParen == -1 || iRParen == -1) {
144             return "";
145         }
146         return name.substring(iLParen + 1, iRParen);
147     }
148
149     public static String JavaDoc getTypeFromMethod(String JavaDoc name) {
150         int iDot = locateFirstDotBeforeLParen(name);
151         if (iDot != -1) {
152             return name.substring(0, iDot);
153         }
154         return name;
155     }
156
157     public static String JavaDoc getNameFromMethod(String JavaDoc name) {
158         int iDot = locateFirstDotBeforeLParen(name);
159         int lParen = name.indexOf("(");
160         if (iDot != -1 && lParen != -1) {
161             return name.substring(iDot, lParen);
162         }
163         return name;
164     }
165
166     public static String JavaDoc safeIndex(String JavaDoc str, String JavaDoc pat) {
167         int index = str.indexOf(pat);
168         if (index != -1) {
169             return str.substring(index + pat.length() + 1).trim();
170         }
171         return str;
172     }
173
174     private static int locateFirstDotBeforeLParen(String JavaDoc name) {
175         int iDot = -1;
176         for (int i = 0; i < name.length(); i++) {
177             char c = name.charAt(i);
178             if (c == '(') {
179                 break;
180             }
181             if (c == '.') {
182                 iDot = i;
183             }
184         }
185         return iDot;
186     }
187
188     private static Object JavaDoc check(Object JavaDoc o) {
189         if (o == null) {
190             return "<NULL MESSAGE>";
191         }
192         return o;
193     }
194 }
195
Popular Tags