author | joehw |
Wed, 26 Jun 2019 05:49:59 +0000 | |
changeset 55496 | 8e0ae3830fca |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
12005 | 1 |
/* |
2 |
* reserved comment block |
|
3 |
* DO NOT REMOVE OR ALTER! |
|
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 | 21 |
package com.sun.org.apache.bcel.internal.generic; |
22 |
||
46174 | 23 |
import com.sun.org.apache.bcel.internal.Const; |
12005 | 24 |
|
25 |
/** |
|
26 |
* Denotes array type, such as int[][] |
|
27 |
* |
|
55496 | 28 |
* @version $Id$ |
12005 | 29 |
*/ |
30 |
public final class ArrayType extends ReferenceType { |
|
31 |
||
46174 | 32 |
private int dimensions; |
33 |
private Type basic_type; |
|
12005 | 34 |
|
55496 | 35 |
|
46174 | 36 |
/** |
37 |
* Convenience constructor for array type, e.g. int[] |
|
38 |
* |
|
39 |
* @param type array type, e.g. T_INT |
|
40 |
*/ |
|
41 |
public ArrayType(final byte type, final int dimensions) { |
|
42 |
this(BasicType.getType(type), dimensions); |
|
43 |
} |
|
12005 | 44 |
|
55496 | 45 |
|
46174 | 46 |
/** |
47 |
* Convenience constructor for reference array type, e.g. Object[] |
|
48 |
* |
|
49 |
* @param class_name complete name of class (java.lang.String, e.g.) |
|
50 |
*/ |
|
51 |
public ArrayType(final String class_name, final int dimensions) { |
|
52 |
this(ObjectType.getInstance(class_name), dimensions); |
|
12005 | 53 |
} |
54 |
||
55496 | 55 |
|
46174 | 56 |
/** |
57 |
* Constructor for array of given type |
|
58 |
* |
|
59 |
* @param type type of array (may be an array itself) |
|
60 |
*/ |
|
61 |
public ArrayType(final Type type, final int dimensions) { |
|
62 |
super(Const.T_ARRAY, "<dummy>"); |
|
63 |
if ((dimensions < 1) || (dimensions > Const.MAX_BYTE)) { |
|
64 |
throw new ClassGenException("Invalid number of dimensions: " + dimensions); |
|
65 |
} |
|
66 |
switch (type.getType()) { |
|
67 |
case Const.T_ARRAY: |
|
68 |
final ArrayType array = (ArrayType) type; |
|
69 |
this.dimensions = dimensions + array.dimensions; |
|
70 |
basic_type = array.basic_type; |
|
71 |
break; |
|
72 |
case Const.T_VOID: |
|
73 |
throw new ClassGenException("Invalid type: void[]"); |
|
74 |
default: // Basic type or reference |
|
75 |
this.dimensions = dimensions; |
|
76 |
basic_type = type; |
|
77 |
break; |
|
78 |
} |
|
79 |
final StringBuilder buf = new StringBuilder(); |
|
80 |
for (int i = 0; i < this.dimensions; i++) { |
|
81 |
buf.append('['); |
|
82 |
} |
|
83 |
buf.append(basic_type.getSignature()); |
|
84 |
super.setSignature(buf.toString()); |
|
85 |
} |
|
12005 | 86 |
|
55496 | 87 |
|
46174 | 88 |
/** |
89 |
* @return basic type of array, i.e., for int[][][] the basic type is int |
|
90 |
*/ |
|
91 |
public Type getBasicType() { |
|
92 |
return basic_type; |
|
93 |
} |
|
12005 | 94 |
|
55496 | 95 |
|
46174 | 96 |
/** |
55496 | 97 |
* @return element type of array, i.e., for int[][][] the element type is int[][] |
46174 | 98 |
*/ |
99 |
public Type getElementType() { |
|
100 |
if (dimensions == 1) { |
|
101 |
return basic_type; |
|
102 |
} |
|
103 |
return new ArrayType(basic_type, dimensions - 1); |
|
104 |
} |
|
12005 | 105 |
|
55496 | 106 |
|
107 |
/** @return number of dimensions of array |
|
46174 | 108 |
*/ |
109 |
public int getDimensions() { |
|
110 |
return dimensions; |
|
111 |
} |
|
12005 | 112 |
|
55496 | 113 |
|
114 |
/** @return a hash code value for the object. |
|
46174 | 115 |
*/ |
116 |
@Override |
|
117 |
public int hashCode() { |
|
118 |
return basic_type.hashCode() ^ dimensions; |
|
119 |
} |
|
12005 | 120 |
|
55496 | 121 |
|
122 |
/** @return true if both type objects refer to the same array type. |
|
46174 | 123 |
*/ |
124 |
@Override |
|
55496 | 125 |
public boolean equals( final Object _type ) { |
46174 | 126 |
if (_type instanceof ArrayType) { |
127 |
final ArrayType array = (ArrayType) _type; |
|
128 |
return (array.dimensions == dimensions) && array.basic_type.equals(basic_type); |
|
129 |
} |
|
130 |
return false; |
|
131 |
} |
|
12005 | 132 |
} |