author | chegar |
Sun, 17 Aug 2014 15:54:13 +0100 | |
changeset 25859 | 3317bb8137f4 |
parent 24195 | jdk/src/share/classes/com/sun/tools/jdi/InterfaceTypeImpl.java@705325a63a58 |
child 30350 | c055af074935 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
11277
diff
changeset
|
2 |
* Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.jdi; |
|
27 |
||
28 |
import com.sun.jdi.*; |
|
29 |
||
30 |
import java.util.List; |
|
31 |
import java.util.ArrayList; |
|
32 |
import java.util.Collections; |
|
22049
15b9d7db4ad7
8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents:
14342
diff
changeset
|
33 |
import java.util.Set; |
2 | 34 |
import java.lang.ref.SoftReference; |
35 |
||
24195
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
36 |
final public class InterfaceTypeImpl extends InvokableTypeImpl |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
37 |
implements InterfaceType { |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
38 |
|
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
39 |
private static class IResult implements InvocationResult { |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
40 |
final private JDWP.InterfaceType.InvokeMethod rslt; |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
41 |
|
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
42 |
public IResult(JDWP.InterfaceType.InvokeMethod rslt) { |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
43 |
this.rslt = rslt; |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
44 |
} |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
45 |
|
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
46 |
@Override |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
47 |
public ObjectReferenceImpl getException() { |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
48 |
return rslt.exception; |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
49 |
} |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
50 |
|
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
51 |
@Override |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
52 |
public ValueImpl getResult() { |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
53 |
return rslt.returnValue; |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
54 |
} |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
55 |
|
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
56 |
} |
2 | 57 |
|
58 |
private SoftReference<List<InterfaceType>> superinterfacesRef = null; |
|
59 |
||
60 |
protected InterfaceTypeImpl(VirtualMachine aVm,long aRef) { |
|
61 |
super(aVm, aRef); |
|
62 |
} |
|
63 |
||
64 |
public List<InterfaceType> superinterfaces() { |
|
65 |
List<InterfaceType> superinterfaces = (superinterfacesRef == null) ? null : |
|
66 |
superinterfacesRef.get(); |
|
67 |
if (superinterfaces == null) { |
|
68 |
superinterfaces = getInterfaces(); |
|
69 |
superinterfaces = Collections.unmodifiableList(superinterfaces); |
|
70 |
superinterfacesRef = new SoftReference<List<InterfaceType>>(superinterfaces); |
|
71 |
} |
|
72 |
return superinterfaces; |
|
73 |
} |
|
74 |
||
75 |
public List<InterfaceType> subinterfaces() { |
|
76 |
List<InterfaceType> subs = new ArrayList<InterfaceType>(); |
|
77 |
for (ReferenceType refType : vm.allClasses()) { |
|
78 |
if (refType instanceof InterfaceType) { |
|
79 |
InterfaceType interfaze = (InterfaceType)refType; |
|
80 |
if (interfaze.isPrepared() && interfaze.superinterfaces().contains(this)) { |
|
81 |
subs.add(interfaze); |
|
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
return subs; |
|
86 |
} |
|
87 |
||
88 |
public List<ClassType> implementors() { |
|
89 |
List<ClassType> implementors = new ArrayList<ClassType>(); |
|
90 |
for (ReferenceType refType : vm.allClasses()) { |
|
91 |
if (refType instanceof ClassType) { |
|
92 |
ClassType clazz = (ClassType)refType; |
|
93 |
if (clazz.isPrepared() && clazz.interfaces().contains(this)) { |
|
94 |
implementors.add(clazz); |
|
95 |
} |
|
96 |
} |
|
97 |
} |
|
98 |
return implementors; |
|
99 |
} |
|
100 |
||
101 |
public boolean isInitialized() { |
|
102 |
return isPrepared(); |
|
103 |
} |
|
104 |
||
105 |
public String toString() { |
|
106 |
return "interface " + name() + " (" + loaderString() + ")"; |
|
107 |
} |
|
24195
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
108 |
|
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
109 |
@Override |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
110 |
InvocationResult waitForReply(PacketStream stream) throws JDWPException { |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
111 |
return new IResult(JDWP.InterfaceType.InvokeMethod.waitForReply(vm, stream)); |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
112 |
} |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
113 |
|
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
114 |
@Override |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
115 |
CommandSender getInvokeMethodSender(final ThreadReferenceImpl thread, |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
116 |
final MethodImpl method, |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
117 |
final ValueImpl[] args, |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
118 |
final int options) { |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
119 |
return () -> |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
120 |
JDWP.InterfaceType.InvokeMethod.enqueueCommand(vm, |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
121 |
InterfaceTypeImpl.this, |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
122 |
thread, |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
123 |
method.ref(), |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
124 |
args, |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
125 |
options); |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
126 |
} |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
127 |
|
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
128 |
@Override |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
129 |
ClassType superclass() { |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
130 |
return null; |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
131 |
} |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
132 |
|
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
133 |
@Override |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
134 |
List<InterfaceType> interfaces() { |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
135 |
return superinterfaces(); |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
136 |
} |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
137 |
|
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
138 |
@Override |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
139 |
boolean canInvoke(Method method) { |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
140 |
// method must be directly in this interface |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
141 |
return this.equals(method.declaringType()); |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
142 |
} |
705325a63a58
8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents:
24127
diff
changeset
|
143 |
} |