jdk/src/share/classes/com/sun/tools/jdi/ArrayReferenceImpl.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2004 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.jdi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
public class ArrayReferenceImpl extends ObjectReferenceImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    implements ArrayReference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    int length = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    ArrayReferenceImpl(VirtualMachine aVm,long aRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        super(aVm,aRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    protected ClassTypeImpl invokableReferenceType(Method method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        // The method has to be a method on Object since
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        // arrays don't have methods nor any other 'superclasses'
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        // So, use the ClassTypeImpl for Object instead of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        // the ArrayTypeImpl for the array itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        return (ClassTypeImpl)method.declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    ArrayTypeImpl arrayType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        return (ArrayTypeImpl)type();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * Return array length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Need not be synchronized since it cannot be provably stale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public int length() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        if(length == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                length = JDWP.ArrayReference.Length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                    process(vm, this).arrayLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        return length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public Value getValue(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        List list = getValues(index, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        return (Value)list.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public List<Value> getValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        return getValues(0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Validate that the range to set/get is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * length of -1 (meaning rest of array) has been converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * before entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private void validateArrayAccess(int index, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        // because length can be computed from index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        // index must be tested first for correct error message
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        if ((index < 0) || (index > length())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            throw new IndexOutOfBoundsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                        "Invalid array index: " + index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if (length < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            throw new IndexOutOfBoundsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                        "Invalid array range length: " + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        if (index + length > length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            throw new IndexOutOfBoundsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                        "Invalid array range: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                        index + " to " + (index + length - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    @SuppressWarnings("unchecked")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private static <T> T cast(Object x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return (T)x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public List<Value> getValues(int index, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (length == -1) { // -1 means the rest of the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
           length = length() - index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        validateArrayAccess(index, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        if (length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            return new ArrayList<Value>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        List<Value> vals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            vals = cast(JDWP.ArrayReference.GetValues.process(vm, this, index, length).values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        return vals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public void setValue(int index, Value value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            throws InvalidTypeException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                   ClassNotLoadedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        List<Value> list = new ArrayList<Value>(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        list.add(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        setValues(index, list, 0, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public void setValues(List<? extends Value> values)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            throws InvalidTypeException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                   ClassNotLoadedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        setValues(0, values, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public void setValues(int index, List<? extends Value> values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                          int srcIndex, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            throws InvalidTypeException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                   ClassNotLoadedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (length == -1) { // -1 means the rest of the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            // shorter of, the rest of the array and rest of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            // the source values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            length = Math.min(length() - index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                              values.size() - srcIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        validateMirrorsOrNulls(values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        validateArrayAccess(index, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if ((srcIndex < 0) || (srcIndex > values.size())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            throw new IndexOutOfBoundsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                        "Invalid source index: " + srcIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (srcIndex + length > values.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            throw new IndexOutOfBoundsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                        "Invalid source range: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                        srcIndex + " to " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                        (srcIndex + length - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        boolean somethingToSet = false;;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        ValueImpl[] setValues = new ValueImpl[length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        for (int i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            ValueImpl value = (ValueImpl)values.get(srcIndex + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                // Validate and convert if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                setValues[i] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                  ValueImpl.prepareForAssignment(value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                                 new Component());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                somethingToSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            } catch (ClassNotLoadedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                 * Since we got this exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                 * the component must be a reference type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                 * This means the class has not yet been loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                 * through the defining class's class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                 * If the value we're trying to set is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                 * then setting to null is essentially a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                 * no-op, and we should allow it without an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                 * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (somethingToSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                JDWP.ArrayReference.SetValues.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    process(vm, this, index, setValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return "instance of " + arrayType().componentTypeName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
               "[" + length() + "] (id=" + uniqueID() + ")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    byte typeValueKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        return JDWP.Tag.ARRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    void validateAssignment(ValueContainer destination)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                            throws InvalidTypeException, ClassNotLoadedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            super.validateAssignment(destination);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        } catch (ClassNotLoadedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
             * An array can be used extensively without the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
             * enclosing loader being recorded by the VM as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
             * initiating loader of the array type. In addition, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
             * load of an array class is fairly harmless as long as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
             * the component class is already loaded. So we relax the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
             * rules a bit and allow the assignment as long as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
             * ultimate component types are assignable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            boolean valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            JNITypeParser destParser = new JNITypeParser(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                                       destination.signature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            JNITypeParser srcParser = new JNITypeParser(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                                       arrayType().signature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            int destDims = destParser.dimensionCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            if (destDims <= srcParser.dimensionCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                 * Remove all dimensions from the destination. Remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                 * the same number of dimensions from the source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                 * Get types for both and check to see if they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                 * compatible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                String destComponentSignature =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    destParser.componentSignature(destDims);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                Type destComponentType =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    destination.findType(destComponentSignature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                String srcComponentSignature =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    srcParser.componentSignature(destDims);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                Type srcComponentType =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    arrayType().findComponentType(srcComponentSignature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                valid = ArrayTypeImpl.isComponentAssignable(destComponentType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                                                          srcComponentType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            if (!valid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                throw new InvalidTypeException("Cannot assign " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                                               arrayType().name() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                                               " to " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                                               destination.typeName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Represents an array component to other internal parts of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * implementation. This is not exposed at the JDI level. Currently,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * this class is needed only for type checking so it does not even
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * reference a particular component - just a generic component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * of this array. In the future we may need to expand its use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    class Component implements ValueContainer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        public Type type() throws ClassNotLoadedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            return arrayType().componentType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        public String typeName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            return arrayType().componentTypeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        public String signature() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            return arrayType().componentSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        public Type findType(String signature) throws ClassNotLoadedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            return arrayType().findComponentType(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
}