This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-bcel.git
The following commit(s) were added to refs/heads/master by this push:
new 5203f930 Add and use ArrayType.isElementType(Type).
5203f930 is described below
commit 5203f930dc6f49969cf945c712e9ba417550e67f
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Jul 14 17:54:13 2026 -0400
Add and use ArrayType.isElementType(Type).
---
src/changes/changes.xml | 1 +
.../java/org/apache/bcel/generic/ArrayType.java | 19 ++++++++---
.../structurals/InstConstraintVisitor.java | 38 ++++++++--------------
3 files changed, 30 insertions(+), 28 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 64edb72c..f0757f43 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -88,6 +88,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="add" dev="ggregory" due-to="nbauma109,
Gary Gregory">Add RecordComponentInfo.getAttribute(byte tag)#494.</action>
<action type="add" dev="ggregory" due-to="Gary
Gregory">Add Const.MAJOR_27.</action>
<action type="add" dev="ggregory" due-to="Gary
Gregory">Add Const.MINOR_27.</action>
+ <action type="add" dev="ggregory" due-to="Gary
Gregory">Add and use ArrayType.isElementType(Type).</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Gary
Gregory">Bump org.apache.commons:commons-parent from 95 to 102.</action>
<action type="update" dev="ggregory" due-to="Gary
Gregory, Dependabot">Bump org.jetbrains.kotlin:kotlin-stdlib from 2.3.0 to
2.4.20 (#497, #519).</action>
diff --git a/src/main/java/org/apache/bcel/generic/ArrayType.java
b/src/main/java/org/apache/bcel/generic/ArrayType.java
index 93627173..b0f1bdcd 100644
--- a/src/main/java/org/apache/bcel/generic/ArrayType.java
+++ b/src/main/java/org/apache/bcel/generic/ArrayType.java
@@ -93,9 +93,9 @@ public final class ArrayType extends ReferenceType {
}
/**
- * Gets the basic type of array, that is, for int[][][] the basic type is
int.
+ * Gets the basic type of array, that is, for {@code int[][][]} the basic
type is int.
*
- * @return basic type of array, that is, for int[][][] the basic type is
int.
+ * @return basic type of array, that is, for {@code int[][][]} the basic
type is int.
*/
public Type getBasicType() {
return basicType;
@@ -122,9 +122,9 @@ public final class ArrayType extends ReferenceType {
}
/**
- * Gets the element type of array, that is, for int[][][] the element type
is int[][].
+ * Gets the element type of array, that is, for {@code int[][][]} the
element type is {@code int[][]}.
*
- * @return element type of array, that is, for int[][][] the element type
is int[][].
+ * @return element type of array, that is, for {@code int[][][]} the
element type is {@code int[][]}.
*/
public Type getElementType() {
if (dimensions == 1) {
@@ -140,4 +140,15 @@ public final class ArrayType extends ReferenceType {
public int hashCode() {
return basicType.hashCode() ^ dimensions;
}
+
+ /**
+ * Tests whether the given type is the element type of this array type,
that is, for {@code int[][][]} the element type is {@code int[][]}.
+ *
+ * @param type the type to test.
+ * @return true if the given type is the element type of this array type,
that is, for {@code int[][][]} the element type is {@code int[][]}.
+ * @since 6.13.0
+ */
+ public boolean isElementType(final Type type) {
+ return getElementType().equals(type);
+ }
}
diff --git
a/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java
b/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java
index e27ac7dc..44fb86d1 100644
---
a/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java
+++
b/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java
@@ -351,7 +351,7 @@ public class InstConstraintVisitor extends EmptyVisitor {
final Type index = stack().peek(0);
indexOfInt(o, index);
if (arrayrefOfArrayType(o, arrayref)
- && !(((ArrayType) arrayref).getElementType().equals(Type.BOOLEAN)
|| ((ArrayType) arrayref).getElementType().equals(Type.BYTE))) {
+ && !(((ArrayType) arrayref).isElementType(Type.BOOLEAN) ||
((ArrayType) arrayref).isElementType(Type.BYTE))) {
constraintViolated(o, "The 'arrayref' does not refer to an array
with elements of a Type.BYTE or Type.BOOLEAN but to an array of '"
+ ((ArrayType) arrayref).getElementType() + "'.");
}
@@ -369,7 +369,7 @@ public class InstConstraintVisitor extends EmptyVisitor {
indexOfInt(o, index);
valueOfInt(o, value);
if (arrayrefOfArrayType(o, arrayref)
- && !(((ArrayType) arrayref).getElementType().equals(Type.BOOLEAN)
|| ((ArrayType) arrayref).getElementType().equals(Type.BYTE))) {
+ && !(((ArrayType) arrayref).isElementType(Type.BOOLEAN) ||
((ArrayType) arrayref).isElementType(Type.BYTE))) {
constraintViolated(o, "The 'arrayref' does not refer to an array
with elements of a Type.BYTE or Type.BOOLEAN but to an array of '"
+ ((ArrayType) arrayref).getElementType() + "'.");
}
@@ -404,7 +404,7 @@ public class InstConstraintVisitor extends EmptyVisitor {
final Type index = stack().peek(0);
indexOfInt(o, index);
- if (arrayrefOfArrayType(o, arrayref) && !((ArrayType)
arrayref).getElementType().equals(Type.CHAR)) {
+ if (arrayrefOfArrayType(o, arrayref) && !((ArrayType)
arrayref).isElementType(Type.CHAR)) {
constraintViolated(o, "The 'arrayref' does not refer to an array
with elements of type char but to an array of type "
+ ((ArrayType) arrayref).getElementType() + ".");
}
@@ -421,7 +421,7 @@ public class InstConstraintVisitor extends EmptyVisitor {
indexOfInt(o, index);
valueOfInt(o, value);
- if (arrayrefOfArrayType(o, arrayref) && !((ArrayType)
arrayref).getElementType().equals(Type.CHAR)) {
+ if (arrayrefOfArrayType(o, arrayref) && !((ArrayType)
arrayref).isElementType(Type.CHAR)) {
constraintViolated(o, "The 'arrayref' does not refer to an array
with elements of type char but to an array of type "
+ ((ArrayType) arrayref).getElementType() + ".");
}
@@ -521,8 +521,7 @@ public class InstConstraintVisitor extends EmptyVisitor {
if (!(stack().peek(1) instanceof ArrayType)) {
constraintViolated(o, "Stack next-to-top must be of type double[]
but is '" + stack().peek(1) + "'.");
}
- final Type t = ((ArrayType) stack().peek(1)).getElementType();
- if (t != Type.DOUBLE) {
+ if (!((ArrayType) stack().peek(1)).isElementType(Type.DOUBLE)) {
constraintViolated(o, "Stack next-to-top must be of type double[]
but is '" + stack().peek(1) + "'.");
}
}
@@ -542,8 +541,7 @@ public class InstConstraintVisitor extends EmptyVisitor {
if (!(stack().peek(2) instanceof ArrayType)) {
constraintViolated(o, "Stack next-to-next-to-top must be of type
double[] but is '" + stack().peek(2) + "'.");
}
- final Type t = ((ArrayType) stack().peek(2)).getElementType();
- if (t != Type.DOUBLE) {
+ if (!((ArrayType) stack().peek(2)).isElementType(Type.DOUBLE)) {
constraintViolated(o, "Stack next-to-next-to-top must be of type
double[] but is '" + stack().peek(2) + "'.");
}
}
@@ -828,8 +826,7 @@ public class InstConstraintVisitor extends EmptyVisitor {
if (!(stack().peek(1) instanceof ArrayType)) {
constraintViolated(o, "Stack next-to-top must be of type float[]
but is '" + stack().peek(1) + "'.");
}
- final Type t = ((ArrayType) stack().peek(1)).getElementType();
- if (t != Type.FLOAT) {
+ if (!((ArrayType) stack().peek(1)).isElementType(Type.FLOAT)) {
constraintViolated(o, "Stack next-to-top must be of type float[]
but is '" + stack().peek(1) + "'.");
}
}
@@ -849,8 +846,7 @@ public class InstConstraintVisitor extends EmptyVisitor {
if (!(stack().peek(2) instanceof ArrayType)) {
constraintViolated(o, "Stack next-to-next-to-top must be of type
float[] but is '" + stack().peek(2) + "'.");
}
- final Type t = ((ArrayType) stack().peek(2)).getElementType();
- if (t != Type.FLOAT) {
+ if (!((ArrayType) stack().peek(2)).isElementType(Type.FLOAT)) {
constraintViolated(o, "Stack next-to-next-to-top must be of type
float[] but is '" + stack().peek(2) + "'.");
}
}
@@ -1202,8 +1198,7 @@ public class InstConstraintVisitor extends EmptyVisitor {
if (!(stack().peek(1) instanceof ArrayType)) {
constraintViolated(o, "Stack next-to-top must be of type int[] but
is '" + stack().peek(1) + "'.");
}
- final Type t = ((ArrayType) stack().peek(1)).getElementType();
- if (t != Type.INT) {
+ if (!((ArrayType) stack().peek(1)).isElementType(Type.INT)) {
constraintViolated(o, "Stack next-to-top must be of type int[] but
is '" + stack().peek(1) + "'.");
}
}
@@ -1236,8 +1231,7 @@ public class InstConstraintVisitor extends EmptyVisitor {
if (!(stack().peek(2) instanceof ArrayType)) {
constraintViolated(o, "Stack next-to-next-to-top must be of type
int[] but is '" + stack().peek(2) + "'.");
}
- final Type t = ((ArrayType) stack().peek(2)).getElementType();
- if (t != Type.INT) {
+ if (!((ArrayType) stack().peek(2)).isElementType(Type.INT)) {
constraintViolated(o, "Stack next-to-next-to-top must be of type
int[] but is '" + stack().peek(2) + "'.");
}
}
@@ -1973,8 +1967,7 @@ public class InstConstraintVisitor extends EmptyVisitor {
if (!(stack().peek(1) instanceof ArrayType)) {
constraintViolated(o, "Stack next-to-top must be of type long[]
but is '" + stack().peek(1) + "'.");
}
- final Type t = ((ArrayType) stack().peek(1)).getElementType();
- if (t != Type.LONG) {
+ if (!((ArrayType) stack().peek(1)).isElementType(Type.LONG)) {
constraintViolated(o, "Stack next-to-top must be of type long[]
but is '" + stack().peek(1) + "'.");
}
}
@@ -2007,8 +2000,7 @@ public class InstConstraintVisitor extends EmptyVisitor {
if (!(stack().peek(2) instanceof ArrayType)) {
constraintViolated(o, "Stack next-to-next-to-top must be of type
long[] but is '" + stack().peek(2) + "'.");
}
- final Type t = ((ArrayType) stack().peek(2)).getElementType();
- if (t != Type.LONG) {
+ if (!((ArrayType) stack().peek(2)).isElementType(Type.LONG)) {
constraintViolated(o, "Stack next-to-next-to-top must be of type
long[] but is '" + stack().peek(2) + "'.");
}
}
@@ -2555,8 +2547,7 @@ public class InstConstraintVisitor extends EmptyVisitor {
if (!(stack().peek(1) instanceof ArrayType)) {
constraintViolated(o, "Stack next-to-top must be of type short[]
but is '" + stack().peek(1) + "'.");
}
- final Type t = ((ArrayType) stack().peek(1)).getElementType();
- if (t != Type.SHORT) {
+ if (!((ArrayType) stack().peek(1)).isElementType(Type.SHORT)) {
constraintViolated(o, "Stack next-to-top must be of type short[]
but is '" + stack().peek(1) + "'.");
}
}
@@ -2576,8 +2567,7 @@ public class InstConstraintVisitor extends EmptyVisitor {
if (!(stack().peek(2) instanceof ArrayType)) {
constraintViolated(o, "Stack next-to-next-to-top must be of type
short[] but is '" + stack().peek(2) + "'.");
}
- final Type t = ((ArrayType) stack().peek(2)).getElementType();
- if (t != Type.SHORT) {
+ if (!((ArrayType) stack().peek(2)).isElementType(Type.SHORT)) {
constraintViolated(o, "Stack next-to-next-to-top must be of type
short[] but is '" + stack().peek(2) + "'.");
}
}