src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/ArrayType.java
author joehw
Wed, 26 Jun 2019 05:49:59 +0000
changeset 55496 8e0ae3830fca
parent 47216 71c04702a3d5
permissions -rw-r--r--
8224157: BCEL: update to version 6.3.1 Reviewed-by: dfuchs, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     1
/*
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     2
 * reserved comment block
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     4
 */
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     5
/*
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    12
 *
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    14
 *
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    18
 * See the License for the specific language governing permissions and
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    19
 * limitations under the License.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    20
 */
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    21
package com.sun.org.apache.bcel.internal.generic;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    22
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    23
import com.sun.org.apache.bcel.internal.Const;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    24
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    25
/**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    26
 * Denotes array type, such as int[][]
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    27
 *
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    28
 * @version $Id$
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    29
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    30
public final class ArrayType extends ReferenceType {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    31
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    32
    private int dimensions;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    33
    private Type basic_type;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    34
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    35
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    36
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    37
     * Convenience constructor for array type, e.g. int[]
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    38
     *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    39
     * @param type array type, e.g. T_INT
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    40
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    41
    public ArrayType(final byte type, final int dimensions) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    42
        this(BasicType.getType(type), dimensions);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    43
    }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    44
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    45
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    46
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    47
     * Convenience constructor for reference array type, e.g. Object[]
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    48
     *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    49
     * @param class_name complete name of class (java.lang.String, e.g.)
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    50
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    51
    public ArrayType(final String class_name, final int dimensions) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    52
        this(ObjectType.getInstance(class_name), dimensions);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    53
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    54
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    55
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    56
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    57
     * Constructor for array of given type
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    58
     *
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    59
     * @param type type of array (may be an array itself)
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    60
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    61
    public ArrayType(final Type type, final int dimensions) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    62
        super(Const.T_ARRAY, "<dummy>");
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    63
        if ((dimensions < 1) || (dimensions > Const.MAX_BYTE)) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    64
            throw new ClassGenException("Invalid number of dimensions: " + dimensions);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    65
        }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    66
        switch (type.getType()) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    67
            case Const.T_ARRAY:
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    68
                final ArrayType array = (ArrayType) type;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    69
                this.dimensions = dimensions + array.dimensions;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    70
                basic_type = array.basic_type;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    71
                break;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    72
            case Const.T_VOID:
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    73
                throw new ClassGenException("Invalid type: void[]");
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    74
            default: // Basic type or reference
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    75
                this.dimensions = dimensions;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    76
                basic_type = type;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    77
                break;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    78
        }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    79
        final StringBuilder buf = new StringBuilder();
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    80
        for (int i = 0; i < this.dimensions; i++) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    81
            buf.append('[');
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    82
        }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    83
        buf.append(basic_type.getSignature());
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    84
        super.setSignature(buf.toString());
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    85
    }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    86
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    87
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    88
    /**
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    89
     * @return basic type of array, i.e., for int[][][] the basic type is int
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    90
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    91
    public Type getBasicType() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    92
        return basic_type;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    93
    }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    94
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    95
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    96
    /**
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
    97
     * @return element type of array, i.e., for int[][][] the element type is int[][]
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    98
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
    99
    public Type getElementType() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   100
        if (dimensions == 1) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   101
            return basic_type;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   102
        }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   103
        return new ArrayType(basic_type, dimensions - 1);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   104
    }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   105
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   106
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   107
    /** @return number of dimensions of array
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   108
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   109
    public int getDimensions() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   110
        return dimensions;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   111
    }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   112
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   113
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   114
    /** @return a hash code value for the object.
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   115
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   116
    @Override
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   117
    public int hashCode() {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   118
        return basic_type.hashCode() ^ dimensions;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   119
    }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   120
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   121
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   122
    /** @return true if both type objects refer to the same array type.
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   123
     */
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   124
    @Override
55496
8e0ae3830fca 8224157: BCEL: update to version 6.3.1
joehw
parents: 47216
diff changeset
   125
    public boolean equals( final Object _type ) {
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   126
        if (_type instanceof ArrayType) {
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   127
            final ArrayType array = (ArrayType) _type;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   128
            return (array.dimensions == dimensions) && array.basic_type.equals(basic_type);
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   129
        }
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   130
        return false;
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 44797
diff changeset
   131
    }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   132
}