History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/com/sun/tools/jdi/ArrayTypeImpl.java (1 of 18352 files). Show all

Unified · Split

java/pkg/com/sun/tools/jdi/ArrayTypeImpl.java+201−0
@@ -0,0 +1,201 @@
1+/*
2+ * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
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
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
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+ *
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.
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.Iterator;
33+import java.util.Map;
34+
35+public class ArrayTypeImpl extends ReferenceTypeImpl
36+ implements ArrayType
37+{
38+ protected ArrayTypeImpl(VirtualMachine aVm, long aRef) {
39+ super(aVm, aRef);
40+ }
41+
42+ public ArrayReference newInstance(int length) {
43+ try {
44+ return (ArrayReference)JDWP.ArrayType.NewInstance.
45+ process(vm, this, length).newArray;
46+ } catch (JDWPException exc) {
47+ throw exc.toJDIException();
48+ }
49+ }
50+
51+ public String componentSignature() {
52+ return signature().substring(1); // Just skip the leading '['
53+ }
54+
55+ public String componentTypeName() {
56+ JNITypeParser parser = new JNITypeParser(componentSignature());
57+ return parser.typeName();
58+ }
59+
60+ Type type() throws ClassNotLoadedException {
61+ return findType(componentSignature());
62+ }
63+
64+ void addVisibleMethods(Map map) {
65+ // arrays don't have methods
66+ }
67+
68+ public List<Method> allMethods() {
69+ return new ArrayList<Method>(0); // arrays don't have methods
70+ }
71+
72+ /*
73+ * Find the type object, if any, of a component type of this array.
74+ * The component type does not have to be immediate; e.g. this method
75+ * can be used to find the component Foo of Foo[][]. This method takes
76+ * advantage of the property that an array and its component must have
77+ * the same class loader. Since array set operations don't have an
78+ * implicit enclosing type like field and variable set operations,
79+ * this method is sometimes needed for proper type checking.
80+ */
81+ Type findComponentType(String signature) throws ClassNotLoadedException {
82+ byte tag = (byte)signature.charAt(0);
83+ if (PacketStream.isObjectTag(tag)) {
84+ // It's a reference type
85+ JNITypeParser parser = new JNITypeParser(componentSignature());
86+ List list = vm.classesByName(parser.typeName());
87+ Iterator iter = list.iterator();
88+ while (iter.hasNext()) {
89+ ReferenceType type = (ReferenceType)iter.next();
90+ ClassLoaderReference cl = type.classLoader();
91+ if ((cl == null)?
92+ (classLoader() == null) :
93+ (cl.equals(classLoader()))) {
94+ return type;
95+ }
96+ }
97+ // Component class has not yet been loaded
98+ throw new ClassNotLoadedException(componentTypeName());
99+ } else {
100+ // It's a primitive type
101+ return vm.primitiveTypeMirror(tag);
102+ }
103+ }
104+
105+ public Type componentType() throws ClassNotLoadedException {
106+ return findComponentType(componentSignature());
107+ }
108+
109+ static boolean isComponentAssignable(Type destination, Type source) {
110+ if (source instanceof PrimitiveType) {
111+ // Assignment of primitive arrays requires identical
112+ // component types.
113+ return source.equals(destination);
114+ } else {
115+ if (destination instanceof PrimitiveType) {
116+ return false;
117+ }
118+
119+ ReferenceTypeImpl refSource = (ReferenceTypeImpl)source;
120+ ReferenceTypeImpl refDestination = (ReferenceTypeImpl)destination;
121+ // Assignment of object arrays requires availability
122+ // of widening conversion of component types
123+ return refSource.isAssignableTo(refDestination);
124+ }
125+ }
126+
127+ /*
128+ * Return true if an instance of the given reference type
129+ * can be assigned to a variable of this type
130+ */
131+ boolean isAssignableTo(ReferenceType destType) {
132+ if (destType instanceof ArrayType) {
133+ try {
134+ Type destComponentType = ((ArrayType)destType).componentType();
135+ return isComponentAssignable(destComponentType, componentType());
136+ } catch (ClassNotLoadedException e) {
137+ // One or both component types has not yet been
138+ // loaded => can't assign
139+ return false;
140+ }
141+ } else if (destType instanceof InterfaceType) {
142+ // Only valid InterfaceType assignee is Cloneable
143+ return destType.name().equals("java.lang.Cloneable");
144+ } else {
145+ // Only valid ClassType assignee is Object
146+ return destType.name().equals("java.lang.Object");
147+ }
148+ }
149+
150+ List<ReferenceType> inheritedTypes() {
151+ return new ArrayList<ReferenceType>(0);
152+ }
153+
154+ void getModifiers() {
155+ if (modifiers != -1) {
156+ return;
157+ }
158+ /*
159+ * For object arrays, the return values for Interface
160+ * Accessible.isPrivate(), Accessible.isProtected(),
161+ * etc... are the same as would be returned for the
162+ * component type. Fetch the modifier bits from the
163+ * component type and use those.
164+ *
165+ * For primitive arrays, the modifiers are always
166+ * VMModifiers.FINAL | VMModifiers.PUBLIC
167+ *
168+ * Reference com.sun.jdi.Accessible.java.
169+ */
170+ try {
171+ Type t = componentType();
172+ if (t instanceof PrimitiveType) {
173+ modifiers = VMModifiers.FINAL | VMModifiers.PUBLIC;
174+ } else {
175+ ReferenceType rt = (ReferenceType)t;
176+ modifiers = rt.modifiers();
177+ }
178+ } catch (ClassNotLoadedException cnle) {
179+ cnle.printStackTrace();
180+ }
181+ }
182+
183+ public String toString() {
184+ return "array class " + name() + " (" + loaderString() + ")";
185+ }
186+
187+ /*
188+ * Save a pointless trip over the wire for these methods
189+ * which have undefined results for arrays.
190+ */
191+ public boolean isPrepared() { return true; }
192+ public boolean isVerified() { return true; }
193+ public boolean isInitialized() { return true; }
194+ public boolean failedToInitialize() { return false; }
195+ public boolean isAbstract() { return false; }
196+
197+ /*
198+ * Defined always to be true for arrays
199+ */
200+ public boolean isFinal() { return true; }
201+}