equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package com.sun.tools.jdi; |
26 package com.sun.tools.jdi; |
27 |
27 |
28 import com.sun.jdi.*; |
28 import java.util.ArrayList; |
29 |
29 import java.util.List; |
30 import java.util.*; |
30 |
|
31 import com.sun.jdi.ClassNotLoadedException; |
|
32 import com.sun.jdi.ClassType; |
|
33 import com.sun.jdi.Field; |
|
34 import com.sun.jdi.IncompatibleThreadStateException; |
|
35 import com.sun.jdi.InterfaceType; |
|
36 import com.sun.jdi.InvalidTypeException; |
|
37 import com.sun.jdi.InvocationException; |
|
38 import com.sun.jdi.Method; |
|
39 import com.sun.jdi.ObjectReference; |
|
40 import com.sun.jdi.ReferenceType; |
|
41 import com.sun.jdi.ThreadReference; |
|
42 import com.sun.jdi.Value; |
|
43 import com.sun.jdi.VirtualMachine; |
31 |
44 |
32 final public class ClassTypeImpl extends InvokableTypeImpl |
45 final public class ClassTypeImpl extends InvokableTypeImpl |
33 implements ClassType |
46 implements ClassType |
34 { |
47 { |
35 private static class IResult implements InvocationResult { |
48 private static class IResult implements InvocationResult { |
36 final private JDWP.ClassType.InvokeMethod rslt; |
49 final private JDWP.ClassType.InvokeMethod rslt; |
37 |
50 |
38 public IResult(JDWP.ClassType.InvokeMethod rslt) { |
51 public IResult(JDWP.ClassType.InvokeMethod rslt) { |
50 } |
63 } |
51 } |
64 } |
52 |
65 |
53 private boolean cachedSuperclass = false; |
66 private boolean cachedSuperclass = false; |
54 private ClassType superclass = null; |
67 private ClassType superclass = null; |
55 private int lastLine = -1; |
|
56 private List<InterfaceType> interfaces = null; |
68 private List<InterfaceType> interfaces = null; |
57 |
69 |
58 protected ClassTypeImpl(VirtualMachine aVm,long aRef) { |
70 protected ClassTypeImpl(VirtualMachine aVm, long aRef) { |
59 super(aVm, aRef); |
71 super(aVm, aRef); |
60 } |
72 } |
61 |
73 |
62 public ClassType superclass() { |
74 public ClassType superclass() { |
63 if(!cachedSuperclass) { |
75 if (!cachedSuperclass) { |
64 ClassTypeImpl sup = null; |
76 ClassTypeImpl sup = null; |
65 try { |
77 try { |
66 sup = JDWP.ClassType.Superclass. |
78 sup = JDWP.ClassType.Superclass. |
67 process(vm, this).superclass; |
79 process(vm, this).superclass; |
68 } catch (JDWPException exc) { |
80 } catch (JDWPException exc) { |
95 public List<InterfaceType> allInterfaces() { |
107 public List<InterfaceType> allInterfaces() { |
96 return getAllInterfaces(); |
108 return getAllInterfaces(); |
97 } |
109 } |
98 |
110 |
99 public List<ClassType> subclasses() { |
111 public List<ClassType> subclasses() { |
100 List<ClassType> subs = new ArrayList<ClassType>(); |
112 List<ClassType> subs = new ArrayList<>(); |
101 for (ReferenceType refType : vm.allClasses()) { |
113 for (ReferenceType refType : vm.allClasses()) { |
102 if (refType instanceof ClassType) { |
114 if (refType instanceof ClassType) { |
103 ClassType clazz = (ClassType)refType; |
115 ClassType clazz = (ClassType)refType; |
104 ClassType superclass = clazz.superclass(); |
116 ClassType superclass = clazz.superclass(); |
105 if ((superclass != null) && superclass.equals(this)) { |
117 if ((superclass != null) && superclass.equals(this)) { |
160 } |
172 } |
161 } |
173 } |
162 } |
174 } |
163 |
175 |
164 PacketStream sendNewInstanceCommand(final ThreadReferenceImpl thread, |
176 PacketStream sendNewInstanceCommand(final ThreadReferenceImpl thread, |
165 final MethodImpl method, |
177 final MethodImpl method, |
166 final ValueImpl[] args, |
178 final ValueImpl[] args, |
167 final int options) { |
179 final int options) { |
168 CommandSender sender = |
180 CommandSender sender = |
169 new CommandSender() { |
181 new CommandSender() { |
170 public PacketStream send() { |
182 public PacketStream send() { |
171 return JDWP.ClassType.NewInstance.enqueueCommand( |
183 return JDWP.ClassType.NewInstance.enqueueCommand( |
172 vm, ClassTypeImpl.this, thread, |
184 vm, ClassTypeImpl.this, thread, |
230 return ret.newObject; |
242 return ret.newObject; |
231 } |
243 } |
232 } |
244 } |
233 |
245 |
234 public Method concreteMethodByName(String name, String signature) { |
246 public Method concreteMethodByName(String name, String signature) { |
235 Method method = null; |
247 Method method = null; |
236 for (Method candidate : visibleMethods()) { |
248 for (Method candidate : visibleMethods()) { |
237 if (candidate.name().equals(name) && |
249 if (candidate.name().equals(name) && |
238 candidate.signature().equals(signature) && |
250 candidate.signature().equals(signature) && |
239 !candidate.isAbstract()) { |
251 !candidate.isAbstract()) { |
240 |
252 |
241 method = candidate; |
253 method = candidate; |
242 break; |
254 break; |
243 } |
255 } |
244 } |
256 } |
245 return method; |
257 return method; |
246 } |
258 } |
247 |
259 |
248 void validateConstructorInvocation(Method method) |
260 void validateConstructorInvocation(Method method) |
249 throws InvalidTypeException, |
261 throws InvalidTypeException, |
250 InvocationException { |
262 InvocationException { |
251 /* |
263 /* |
261 */ |
273 */ |
262 if (!method.isConstructor()) { |
274 if (!method.isConstructor()) { |
263 throw new IllegalArgumentException("Cannot create instance with non-constructor"); |
275 throw new IllegalArgumentException("Cannot create instance with non-constructor"); |
264 } |
276 } |
265 } |
277 } |
266 |
|
267 |
278 |
268 public String toString() { |
279 public String toString() { |
269 return "class " + name() + " (" + loaderString() + ")"; |
280 return "class " + name() + " (" + loaderString() + ")"; |
270 } |
281 } |
271 |
282 |