KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.aspectj.tools.ide.*;
27
28 import com.sun.jdi.*;
29 import com.sun.jdi.request.*;
30 import java.util.*;
31
32 /**
33  * ClassMethodBreakpointRequestAction.java
34  *
35  *
36  * Created: Wed Aug 23 11:36:26 2000
37  *
38  * @author <a HREF="mailto:palm@parc.xerox.com"Jeffrey Palm</a>
39  */

40
41 public abstract class ClassMethodBreakpointRequestAction extends ClassBreakpointRequestAction {
42
43     private String JavaDoc methodProto;
44
45     ClassMethodBreakpointRequestAction(Debugger debugger,
46                                        String JavaDoc className,
47                                        String JavaDoc methodProto) {
48         super(debugger, className);
49         this.methodProto = methodProto;
50     }
51
52     public String JavaDoc getMethodProto() {
53         return methodProto;
54     }
55
56     public String JavaDoc getErrorMessage() {
57         return "No method " + getMethodName() + " in " + getClassName();
58     }
59
60     public String JavaDoc getProto() {
61         return getClassName() + "." + getMethodProto();
62     }
63
64
65
66     public boolean equals(Object JavaDoc o) {
67         if (!(o instanceof ClassMethodBreakpointRequestAction)) {
68             return super.equals(o);
69         }
70         ClassMethodBreakpointRequestAction ra = (ClassMethodBreakpointRequestAction)o;
71         return (ra.getClassName().equals(getClassName()) &&
72                 ra.getMethodName().equals(getMethodName()) &&
73                 ra.argumentTypeNames().equals(argumentTypeNames()));
74     }
75
76     Location findLocation()
77         throws NoVMException,
78                MultipleLocationsException,
79                UnableToSetRequestException {
80         Location location = null;
81         Iterator iter = vm().classesByName(className).iterator();
82         while (iter.hasNext()) {
83             ReferenceType refType = (ReferenceType) iter.next();
84             if (refType.name().equals(className)) {
85                 List methods = refType.methodsByName(getMethodName());
86                 Iterator methodsIter = methods.iterator();
87                 List argumentTypeNames = argumentTypeNames();
88                 boolean justName = true;
89                 for (int i = 0; i < methodProto.length(); i++) {
90                     if (!Character.isJavaIdentifierPart(methodProto.charAt(i))) {
91                         justName = false;
92                         break;
93                     }
94                 }
95                 if (justName) {
96                     if (methods.size() == 1) {
97                         location = ((Method) methods.get(0)).location();
98                         return location;
99                     } else if (methods.size() == 0) {
100                         throw new UnableToSetRequestException(this);
101                     } else {
102                         throw new MultipleLocationsException(className + "." + methodProto, methods);
103                     }
104                 }
105                 while (methodsIter.hasNext()) {
106                     Method method = (Method) methodsIter.next();
107                     if (argumentTypeNames().equals(method.argumentTypeNames())) {
108                         location = method.location();
109                         return location;
110                     }
111                 }
112                 throw new UnableToSetRequestException(this);
113             }
114         }
115         return location;
116     }
117
118     String JavaDoc getMethodName() {
119         int iparen = methodProto.indexOf("(");
120         if (iparen != -1) {
121             return methodProto.substring(0, iparen);
122         }
123         return methodProto;
124     }
125
126     public List getArgumentTypeNames() {
127         return argumentTypeNames();
128     }
129
130     List argumentTypeNames() {
131         List argNames = new ArrayList();
132         int iparen = methodProto.indexOf("(");
133         if (iparen == -1) {
134             return argNames;
135         }
136         StringTokenizer tok = new StringTokenizer(methodProto, "(,;:)");
137         try {
138             String JavaDoc meth = tok.nextToken();
139             while (tok.hasMoreTokens()) {
140                 String JavaDoc token = tok.nextToken();
141                 argNames.add(token);
142             }
143         } catch (NoSuchElementException e) {
144         }
145         return argNames;
146     }
147
148     //!!! Mapping
149
public int getLine() {
150         SourceLine sl = sourceLine();
151         if (sl == null || sl.line < 0) {
152             return super.getLine();
153         }
154         return sl.line;
155     }
156
157     //!!! Mapping
158
public String JavaDoc getSourceName() {
159         SourceLine sl = sourceLine();
160         if (sl == null) {
161             return super.getSourceName();
162         }
163         return sl.filename;
164     }
165
166
167     public SourceLine sourceLine() {
168         String JavaDoc fullSrcPath = ajdbg().getFullSourcePathFromAJCClass(className);
169         Location loc = getLocation();
170         if (loc == null) {
171             return ajdbg().sourceLineOfMethodThatShouldMap(getClassName(),
172                                                            getMethodName(),
173                                                            fullSrcPath);
174         } else {
175             return ajdbg().sourceLineOfMethodThatShouldMap(loc, fullSrcPath);
176         }
177     }
178 }
179
Popular Tags