You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/10/01 14:22:19 UTC
[commons-bcel] branch master updated: Make some classes implement Iterable
This is an automated email from the ASF dual-hosted git repository.
ggregory 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 ca05d2e6 Make some classes implement Iterable
ca05d2e6 is described below
commit ca05d2e6a6eed2d3f137b78ff68546c4b206235b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Oct 1 10:22:13 2022 -0400
Make some classes implement Iterable
Make Annotations implement Iterable<AnnotationEntry>
Make BootstrapMethods implement Iterable<BootstrapMethod>
Make ConstantPool implement Iterable<Constant>
Make InnerClasses implement Iterable<InnerClass>
Make LineNumberTable implement Iterable<LineNumber>
Make LocalVariableTable implement Iterable<LocalVariable>
Make LocalVariableTypeTable implement Iterable<LocalVariable>
Make MethodParameters implement Iterable<MethodParameter>
Make ParameterAnnotations implement Iterable<ParameterAnnotationEntry>
---
src/changes/changes.xml | 11 ++++-
.../org/apache/bcel/classfile/Annotations.java | 56 +++++++++++++++-------
.../apache/bcel/classfile/BootstrapMethods.java | 9 +++-
.../org/apache/bcel/classfile/ConstantPool.java | 9 +++-
.../org/apache/bcel/classfile/InnerClasses.java | 9 +++-
.../java/org/apache/bcel/classfile/JavaClass.java | 9 ++--
.../org/apache/bcel/classfile/LineNumberTable.java | 9 +++-
.../apache/bcel/classfile/LocalVariableTable.java | 9 +++-
.../bcel/classfile/LocalVariableTypeTable.java | 9 +++-
.../apache/bcel/classfile/MethodParameters.java | 9 +++-
.../bcel/classfile/ParameterAnnotations.java | 9 +++-
.../java/org/apache/bcel/generic/ClassGen.java | 9 +---
.../java/org/apache/bcel/generic/FieldGen.java | 5 +-
.../java/org/apache/bcel/generic/MethodGen.java | 17 ++-----
.../java/org/apache/bcel/util/AttributeHTML.java | 21 ++++----
src/main/java/org/apache/bcel/util/CodeHTML.java | 9 ++--
.../bcel/verifier/statics/Pass2Verifier.java | 26 +++++-----
.../bcel/verifier/statics/Pass3aVerifier.java | 7 +--
18 files changed, 151 insertions(+), 91 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index e336ca49..60096c46 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -90,7 +90,16 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="BCEL-363" type="fix" dev="ggregory" due-to="Richard Atkins, Gary Gregory">Enforce MAX_CP_ENTRIES in ConstantPoolGen and ConstantPool.dump #147.</action>
<action type="fix" dev="ggregory" due-to="Arturo Bernal, Gary Gregory">Minor Changes #99.</action>
<!-- ADD -->
- <action type="fix" dev="ggregory">Add github/codeql-action.</action>
+ <action type="add" dev="ggregory">Add github/codeql-action.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Make Annotations implement Iterable<AnnotationEntry>.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Make BootstrapMethods implement Iterable<BootstrapMethod>.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Make ConstantPool implement Iterable<Constant>.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Make InnerClasses implement Iterable<InnerClass>.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Make LineNumberTable implement Iterable<LineNumber>.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Make LocalVariableTable implement Iterable<LocalVariable>.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Make LocalVariableTypeTable implement Iterable<LocalVariable>.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Make MethodParameters implement Iterable<MethodParameter>.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Make ParameterAnnotations implement Iterable<ParameterAnnotationEntry>.</action>
<!-- UPDATES -->
<action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump actions/cache from 2 to 3.0.9 #88, #93, #110, #119, #149.</action>
<action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump actions/checkout from 2.3.1 to 3.0.2 #59, #66, #73, #108, #115.</action>
diff --git a/src/main/java/org/apache/bcel/classfile/Annotations.java b/src/main/java/org/apache/bcel/classfile/Annotations.java
index f279963e..dca13b1e 100644
--- a/src/main/java/org/apache/bcel/classfile/Annotations.java
+++ b/src/main/java/org/apache/bcel/classfile/Annotations.java
@@ -20,6 +20,8 @@ package org.apache.bcel.classfile;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.util.Iterator;
+import java.util.stream.Stream;
import org.apache.bcel.Const;
@@ -28,37 +30,41 @@ import org.apache.bcel.Const;
*
* @since 6.0
*/
-public abstract class Annotations extends Attribute {
+public abstract class Annotations extends Attribute implements Iterable<AnnotationEntry> {
private AnnotationEntry[] annotationTable;
private final boolean isRuntimeVisible;
/**
- * @param annotationType the subclass type of the annotation
- * @param nameIndex Index pointing to the name <em>Code</em>
- * @param length Content length in bytes
- * @param annotationTable the actual annotations
- * @param constantPool Array of constants
+ * Constructs an instance.
+ *
+ * @param annotationType the subclass type of the annotation
+ * @param nameIndex Index pointing to the name <em>Code</em>
+ * @param length Content length in bytes
+ * @param annotationTable the actual annotations
+ * @param constantPool Array of constants
* @param isRuntimeVisible whether this Annotation visible at runtime
*/
public Annotations(final byte annotationType, final int nameIndex, final int length, final AnnotationEntry[] annotationTable,
- final ConstantPool constantPool, final boolean isRuntimeVisible) {
+ final ConstantPool constantPool, final boolean isRuntimeVisible) {
super(annotationType, nameIndex, length, constantPool);
this.annotationTable = annotationTable;
this.isRuntimeVisible = isRuntimeVisible;
}
/**
- * @param annotationType the subclass type of the annotation
- * @param nameIndex Index pointing to the name <em>Code</em>
- * @param length Content length in bytes
- * @param input Input stream
- * @param constantPool Array of constants
+ * Constructs an instance.
+ *
+ * @param annotationType the subclass type of the annotation
+ * @param nameIndex Index pointing to the name <em>Code</em>
+ * @param length Content length in bytes
+ * @param input Input stream
+ * @param constantPool Array of constants
* @param isRuntimeVisible whether this Annotation visible at runtime
* @throws IOException if an I/O error occurs.
*/
Annotations(final byte annotationType, final int nameIndex, final int length, final DataInput input, final ConstantPool constantPool,
- final boolean isRuntimeVisible) throws IOException {
+ final boolean isRuntimeVisible) throws IOException {
this(annotationType, nameIndex, length, (AnnotationEntry[]) null, constantPool, isRuntimeVisible);
final int annotation_table_length = input.readUnsignedShort();
annotationTable = new AnnotationEntry[annotation_table_length];
@@ -68,8 +74,9 @@ public abstract class Annotations extends Attribute {
}
/**
- * Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class.
- * I.e., the hierarchy of methods, fields, attributes, etc. spawns a tree of objects.
+ * Called by objects that are traversing the nodes of the tree implicitely
+ * defined by the contents of a Java class. I.e., the hierarchy of methods,
+ * fields, attributes, etc. spawns a tree of objects.
*
* @param v Visitor object
*/
@@ -78,14 +85,22 @@ public abstract class Annotations extends Attribute {
v.visitAnnotation(this);
}
+ @Override
+ public Attribute copy(ConstantPool constantPool) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
/**
- * returns the array of annotation entries in this annotation
+ * Gets the array of annotation entries in this annotation
*/
public AnnotationEntry[] getAnnotationEntries() {
return annotationTable;
}
/**
+ * Gets the number of annotation entries in this annotation.
+ *
* @return the number of annotation entries in this annotation
*/
public final int getNumAnnotations() {
@@ -99,7 +114,14 @@ public abstract class Annotations extends Attribute {
return isRuntimeVisible;
}
+ @Override
+ public Iterator<AnnotationEntry> iterator() {
+ return Stream.of(annotationTable).iterator();
+ }
+
/**
+ * Sets the entries to set in this annotation.
+ *
* @param annotationTable the entries to set in this annotation
*/
public final void setAnnotationTable(final AnnotationEntry[] annotationTable) {
@@ -107,6 +129,8 @@ public abstract class Annotations extends Attribute {
}
/**
+ * Converts to a String representation.
+ *
* @return String representation
*/
@Override
diff --git a/src/main/java/org/apache/bcel/classfile/BootstrapMethods.java b/src/main/java/org/apache/bcel/classfile/BootstrapMethods.java
index 087c83c6..40017d9d 100644
--- a/src/main/java/org/apache/bcel/classfile/BootstrapMethods.java
+++ b/src/main/java/org/apache/bcel/classfile/BootstrapMethods.java
@@ -20,6 +20,8 @@ package org.apache.bcel.classfile;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.util.Iterator;
+import java.util.stream.Stream;
import org.apache.bcel.Const;
@@ -30,7 +32,7 @@ import org.apache.bcel.Const;
* The BootstrapMethods Attribute</a>
* @since 6.0
*/
-public class BootstrapMethods extends Attribute {
+public class BootstrapMethods extends Attribute implements Iterable<BootstrapMethod> {
private BootstrapMethod[] bootstrapMethods; // TODO this could be made final (setter is not used)
@@ -118,6 +120,11 @@ public class BootstrapMethods extends Attribute {
return bootstrapMethods;
}
+ @Override
+ public Iterator<BootstrapMethod> iterator() {
+ return Stream.of(bootstrapMethods).iterator();
+ }
+
/**
* @param bootstrapMethods the array of bootstrap methods
*/
diff --git a/src/main/java/org/apache/bcel/classfile/ConstantPool.java b/src/main/java/org/apache/bcel/classfile/ConstantPool.java
index 8e8fddf7..90ee371f 100644
--- a/src/main/java/org/apache/bcel/classfile/ConstantPool.java
+++ b/src/main/java/org/apache/bcel/classfile/ConstantPool.java
@@ -20,6 +20,8 @@ package org.apache.bcel.classfile;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.util.Arrays;
+import java.util.Iterator;
import org.apache.bcel.Const;
@@ -32,7 +34,7 @@ import org.apache.bcel.Const;
* @see Constant
* @see org.apache.bcel.generic.ConstantPoolGen
*/
-public class ConstantPool implements Cloneable, Node {
+public class ConstantPool implements Cloneable, Node, Iterable<Constant> {
private static String escape(final String str) {
final int len = str.length();
@@ -341,6 +343,11 @@ public class ConstantPool implements Cloneable, Node {
return constantPool == null ? 0 : constantPool.length;
}
+ @Override
+ public Iterator<Constant> iterator() {
+ return Arrays.stream(constantPool).iterator();
+ }
+
/**
* @param constant Constant to set
*/
diff --git a/src/main/java/org/apache/bcel/classfile/InnerClasses.java b/src/main/java/org/apache/bcel/classfile/InnerClasses.java
index 300feca7..6fcc05de 100644
--- a/src/main/java/org/apache/bcel/classfile/InnerClasses.java
+++ b/src/main/java/org/apache/bcel/classfile/InnerClasses.java
@@ -20,6 +20,8 @@ package org.apache.bcel.classfile;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.util.Iterator;
+import java.util.stream.Stream;
import org.apache.bcel.Const;
@@ -29,7 +31,7 @@ import org.apache.bcel.Const;
*
* @see Attribute
*/
-public final class InnerClasses extends Attribute {
+public final class InnerClasses extends Attribute implements Iterable<InnerClass> {
/**
* Empty array.
@@ -123,6 +125,11 @@ public final class InnerClasses extends Attribute {
return innerClasses;
}
+ @Override
+ public Iterator<InnerClass> iterator() {
+ return Stream.of(innerClasses).iterator();
+ }
+
/**
* @param innerClasses the array of inner classes
*/
diff --git a/src/main/java/org/apache/bcel/classfile/JavaClass.java b/src/main/java/org/apache/bcel/classfile/JavaClass.java
index 72d20a8a..e098b051 100644
--- a/src/main/java/org/apache/bcel/classfile/JavaClass.java
+++ b/src/main/java/org/apache/bcel/classfile/JavaClass.java
@@ -255,21 +255,20 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
}
for (final Attribute attribute : this.attributes) {
if (attribute instanceof InnerClasses) {
- final InnerClass[] innerClasses = ((InnerClasses) attribute).getInnerClasses();
- for (final InnerClass innerClasse : innerClasses) {
+ ((InnerClasses) attribute).forEach(innerClass -> {
boolean innerClassAttributeRefersToMe = false;
- String innerClassName = constantPool.getConstantString(innerClasse.getInnerClassIndex(), Const.CONSTANT_Class);
+ String innerClassName = constantPool.getConstantString(innerClass.getInnerClassIndex(), Const.CONSTANT_Class);
innerClassName = Utility.compactClassName(innerClassName, false);
if (innerClassName.equals(getClassName())) {
innerClassAttributeRefersToMe = true;
}
if (innerClassAttributeRefersToMe) {
this.isNested = true;
- if (innerClasse.getInnerNameIndex() == 0) {
+ if (innerClass.getInnerNameIndex() == 0) {
this.isAnonymous = true;
}
}
- }
+ });
}
}
this.computedNestedTypeStatus = true;
diff --git a/src/main/java/org/apache/bcel/classfile/LineNumberTable.java b/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
index 87109d69..c350023f 100644
--- a/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
+++ b/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
@@ -20,6 +20,8 @@ package org.apache.bcel.classfile;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.util.Iterator;
+import java.util.stream.Stream;
import org.apache.bcel.Const;
@@ -30,7 +32,7 @@ import org.apache.bcel.Const;
* @see Code
* @see LineNumber
*/
-public final class LineNumberTable extends Attribute {
+public final class LineNumberTable extends Attribute implements Iterable<LineNumber> {
private static final int MAX_LINE_LENGTH = 72;
private LineNumber[] lineNumberTable; // Table of line/numbers pairs
@@ -174,6 +176,11 @@ public final class LineNumberTable extends Attribute {
return lineNumberTable == null ? 0 : lineNumberTable.length;
}
+ @Override
+ public Iterator<LineNumber> iterator() {
+ return Stream.of(lineNumberTable).iterator();
+ }
+
/**
* @param lineNumberTable the line number entries for this table
*/
diff --git a/src/main/java/org/apache/bcel/classfile/LocalVariableTable.java b/src/main/java/org/apache/bcel/classfile/LocalVariableTable.java
index 14667ee1..12154cf3 100644
--- a/src/main/java/org/apache/bcel/classfile/LocalVariableTable.java
+++ b/src/main/java/org/apache/bcel/classfile/LocalVariableTable.java
@@ -20,6 +20,8 @@ package org.apache.bcel.classfile;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.util.Iterator;
+import java.util.stream.Stream;
import org.apache.bcel.Const;
@@ -30,7 +32,7 @@ import org.apache.bcel.Const;
* @see Code
* @see LocalVariable
*/
-public class LocalVariableTable extends Attribute {
+public class LocalVariableTable extends Attribute implements Iterable<LocalVariable> {
private LocalVariable[] localVariableTable; // variables
@@ -161,6 +163,11 @@ public class LocalVariableTable extends Attribute {
return localVariableTable == null ? 0 : localVariableTable.length;
}
+ @Override
+ public Iterator<LocalVariable> iterator() {
+ return Stream.of(localVariableTable).iterator();
+ }
+
public final void setLocalVariableTable(final LocalVariable[] local_variable_table) {
this.localVariableTable = local_variable_table;
}
diff --git a/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java b/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java
index c3def9a3..4c74d09f 100644
--- a/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java
+++ b/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java
@@ -20,6 +20,8 @@ package org.apache.bcel.classfile;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.util.Iterator;
+import java.util.stream.Stream;
import org.apache.bcel.Const;
@@ -54,7 +56,7 @@ import org.apache.bcel.Const;
/**
* @since 6.0
*/
-public class LocalVariableTypeTable extends Attribute {
+public class LocalVariableTypeTable extends Attribute implements Iterable<LocalVariable> {
private LocalVariable[] localVariableTypeTable; // variables
@@ -126,6 +128,11 @@ public class LocalVariableTypeTable extends Attribute {
return localVariableTypeTable == null ? 0 : localVariableTypeTable.length;
}
+ @Override
+ public Iterator<LocalVariable> iterator() {
+ return Stream.of(localVariableTypeTable).iterator();
+ }
+
public final void setLocalVariableTable(final LocalVariable[] local_variable_table) {
this.localVariableTypeTable = local_variable_table;
}
diff --git a/src/main/java/org/apache/bcel/classfile/MethodParameters.java b/src/main/java/org/apache/bcel/classfile/MethodParameters.java
index 37c412b4..7c710b0c 100644
--- a/src/main/java/org/apache/bcel/classfile/MethodParameters.java
+++ b/src/main/java/org/apache/bcel/classfile/MethodParameters.java
@@ -20,6 +20,8 @@ package org.apache.bcel.classfile;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.util.Iterator;
+import java.util.stream.Stream;
import org.apache.bcel.Const;
@@ -30,7 +32,7 @@ import org.apache.bcel.Const;
* The MethodParameters Attribute</a>
* @since 6.0
*/
-public class MethodParameters extends Attribute {
+public class MethodParameters extends Attribute implements Iterable<MethodParameter> {
/**
* Empty array.
@@ -85,6 +87,11 @@ public class MethodParameters extends Attribute {
return parameters;
}
+ @Override
+ public Iterator<MethodParameter> iterator() {
+ return Stream.of(parameters).iterator();
+ }
+
public void setParameters(final MethodParameter[] parameters) {
this.parameters = parameters;
}
diff --git a/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java b/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java
index 76f58946..c73aef38 100644
--- a/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java
+++ b/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java
@@ -20,13 +20,15 @@ package org.apache.bcel.classfile;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.util.Iterator;
+import java.util.stream.Stream;
/**
* base class for parameter annotations
*
* @since 6.0
*/
-public abstract class ParameterAnnotations extends Attribute {
+public abstract class ParameterAnnotations extends Attribute implements Iterable<ParameterAnnotationEntry> {
/** Table of parameter annotations */
private ParameterAnnotationEntry[] parameterAnnotationTable;
@@ -105,6 +107,11 @@ public abstract class ParameterAnnotations extends Attribute {
return parameterAnnotationTable;
}
+ @Override
+ public Iterator<ParameterAnnotationEntry> iterator() {
+ return Stream.of(parameterAnnotationTable).iterator();
+ }
+
/**
* @param parameterAnnotationTable the entries to set in this parameter annotation
*/
diff --git a/src/main/java/org/apache/bcel/generic/ClassGen.java b/src/main/java/org/apache/bcel/generic/ClassGen.java
index 45a6cd75..dc0de419 100644
--- a/src/main/java/org/apache/bcel/generic/ClassGen.java
+++ b/src/main/java/org/apache/bcel/generic/ClassGen.java
@@ -23,7 +23,6 @@ import java.util.Objects;
import org.apache.bcel.Const;
import org.apache.bcel.classfile.AccessFlags;
-import org.apache.bcel.classfile.AnnotationEntry;
import org.apache.bcel.classfile.Annotations;
import org.apache.bcel.classfile.Attribute;
import org.apache.bcel.classfile.ConstantPool;
@@ -537,14 +536,10 @@ public class ClassGen extends AccessFlags implements Cloneable {
for (final Attribute attr : attrs) {
if (attr instanceof RuntimeVisibleAnnotations) {
final RuntimeVisibleAnnotations rva = (RuntimeVisibleAnnotations) attr;
- for (final AnnotationEntry a : rva.getAnnotationEntries()) {
- annotationGenObjs.add(new AnnotationEntryGen(a, getConstantPool(), false));
- }
+ rva.forEach(a -> annotationGenObjs.add(new AnnotationEntryGen(a, getConstantPool(), false)));
} else if (attr instanceof RuntimeInvisibleAnnotations) {
final RuntimeInvisibleAnnotations ria = (RuntimeInvisibleAnnotations) attr;
- for (final AnnotationEntry a : ria.getAnnotationEntries()) {
- annotationGenObjs.add(new AnnotationEntryGen(a, getConstantPool(), false));
- }
+ ria.forEach(a -> annotationGenObjs.add(new AnnotationEntryGen(a, getConstantPool(), false)));
}
}
return annotationGenObjs.toArray(AnnotationEntryGen.EMPTY_ARRAY);
diff --git a/src/main/java/org/apache/bcel/generic/FieldGen.java b/src/main/java/org/apache/bcel/generic/FieldGen.java
index 0c2f46d5..dd3a5ce7 100644
--- a/src/main/java/org/apache/bcel/generic/FieldGen.java
+++ b/src/main/java/org/apache/bcel/generic/FieldGen.java
@@ -23,7 +23,6 @@ import java.util.Objects;
import java.util.stream.Stream;
import org.apache.bcel.Const;
-import org.apache.bcel.classfile.AnnotationEntry;
import org.apache.bcel.classfile.Annotations;
import org.apache.bcel.classfile.Attribute;
import org.apache.bcel.classfile.Constant;
@@ -90,9 +89,7 @@ public class FieldGen extends FieldGenOrMethodGen {
setValue(((ConstantValue) attr).getConstantValueIndex());
} else if (attr instanceof Annotations) {
final Annotations runtimeAnnotations = (Annotations) attr;
- for (final AnnotationEntry element : runtimeAnnotations.getAnnotationEntries()) {
- addAnnotationEntry(new AnnotationEntryGen(element, cp, false));
- }
+ runtimeAnnotations.forEach(element -> addAnnotationEntry(new AnnotationEntryGen(element, cp, false)));
} else {
addAttribute(attr);
}
diff --git a/src/main/java/org/apache/bcel/generic/MethodGen.java b/src/main/java/org/apache/bcel/generic/MethodGen.java
index dd236bca..1ee37b78 100644
--- a/src/main/java/org/apache/bcel/generic/MethodGen.java
+++ b/src/main/java/org/apache/bcel/generic/MethodGen.java
@@ -345,13 +345,12 @@ public class MethodGen extends FieldGenOrMethodGen {
for (final Attribute c_attribute : c_attributes) {
a = c_attribute;
if (a instanceof LineNumberTable) {
- final LineNumber[] ln = ((LineNumberTable) a).getLineNumberTable();
- for (final LineNumber l : ln) {
+ ((LineNumberTable) a).forEach(l -> {
final InstructionHandle ih = il.findHandle(l.getStartPC());
if (ih != null) {
addLineNumber(ih, l.getLineNumber());
}
- }
+ });
} else if (a instanceof LocalVariableTable) {
updateLocalVariableTable((LocalVariableTable) a);
} else if (a instanceof LocalVariableTypeTable) {
@@ -367,10 +366,7 @@ public class MethodGen extends FieldGenOrMethodGen {
}
} else if (a instanceof Annotations) {
final Annotations runtimeAnnotations = (Annotations) a;
- final AnnotationEntry[] aes = runtimeAnnotations.getAnnotationEntries();
- for (final AnnotationEntry element : aes) {
- addAnnotationEntry(new AnnotationEntryGen(element, cp, false));
- }
+ runtimeAnnotations.forEach(element -> addAnnotationEntry(new AnnotationEntryGen(element, cp, false)));
} else {
addAttribute(a);
}
@@ -565,9 +561,7 @@ public class MethodGen extends FieldGenOrMethodGen {
private void adjustLocalVariableTypeTable(final LocalVariableTable lvt) {
final LocalVariable[] lv = lvt.getLocalVariableTable();
- final LocalVariable[] lvg = localVariableTypeTable.getLocalVariableTypeTable();
-
- for (final LocalVariable element : lvg) {
+ for (final LocalVariable element : localVariableTypeTable.getLocalVariableTypeTable()) {
for (final LocalVariable l : lv) {
if (element.getName().equals(l.getName()) && element.getIndex() == l.getOrigIndex()) {
element.setLength(l.getLength());
@@ -1198,9 +1192,8 @@ public class MethodGen extends FieldGenOrMethodGen {
}
private void updateLocalVariableTable(final LocalVariableTable a) {
- final LocalVariable[] lv = a.getLocalVariableTable();
removeLocalVariables();
- for (final LocalVariable l : lv) {
+ for (final LocalVariable l : a.getLocalVariableTable()) {
InstructionHandle start = il.findHandle(l.getStartPC());
final InstructionHandle end = il.findHandle(l.getStartPC() + l.getLength());
// Repair malformed handles
diff --git a/src/main/java/org/apache/bcel/util/AttributeHTML.java b/src/main/java/org/apache/bcel/util/AttributeHTML.java
index 53f56ec0..5fbd14d4 100644
--- a/src/main/java/org/apache/bcel/util/AttributeHTML.java
+++ b/src/main/java/org/apache/bcel/util/AttributeHTML.java
@@ -34,7 +34,6 @@ import org.apache.bcel.classfile.InnerClass;
import org.apache.bcel.classfile.InnerClasses;
import org.apache.bcel.classfile.LineNumber;
import org.apache.bcel.classfile.LineNumberTable;
-import org.apache.bcel.classfile.LocalVariable;
import org.apache.bcel.classfile.LocalVariableTable;
import org.apache.bcel.classfile.SourceFile;
import org.apache.bcel.classfile.Utility;
@@ -151,37 +150,35 @@ final class AttributeHTML implements Closeable {
}
break;
case Const.ATTR_LOCAL_VARIABLE_TABLE:
- final LocalVariable[] vars = ((LocalVariableTable) attribute).getLocalVariableTable();
// List name, range and type
printWriter.print("<UL>");
- for (final LocalVariable var : vars) {
- index = var.getSignatureIndex();
- String signature = ((ConstantUtf8) constantPool.getConstant(index, Const.CONSTANT_Utf8)).getBytes();
+ ((LocalVariableTable) attribute).forEach(var -> {
+ int sigIdx = var.getSignatureIndex();
+ String signature = ((ConstantUtf8) constantPool.getConstant(sigIdx, Const.CONSTANT_Utf8)).getBytes();
signature = Utility.signatureToString(signature, false);
final int start = var.getStartPC();
final int end = start + var.getLength();
printWriter.println("<LI>" + Class2HTML.referenceType(signature) + " <B>" + var.getName() + "</B> in slot %" + var.getIndex()
+ "<BR>Valid from lines " + "<A HREF=\"" + className + "_code.html#code" + method_number + "@" + start + "\" TARGET=Code>" + start
+ "</A> to " + "<A HREF=\"" + className + "_code.html#code" + method_number + "@" + end + "\" TARGET=Code>" + end + "</A></LI>");
- }
+ });
printWriter.print("</UL>\n");
break;
case Const.ATTR_INNER_CLASSES:
- final InnerClass[] classes = ((InnerClasses) attribute).getInnerClasses();
// List inner classes
printWriter.print("<UL>");
- for (final InnerClass classe : classes) {
+ for (final InnerClass clazz : ((InnerClasses) attribute).getInnerClasses()) {
final String name;
final String access;
- index = classe.getInnerNameIndex();
+ index = clazz.getInnerNameIndex();
if (index > 0) {
name = ((ConstantUtf8) constantPool.getConstant(index, Const.CONSTANT_Utf8)).getBytes();
} else {
name = "<anonymous>";
}
- access = Utility.accessToString(classe.getInnerAccessFlags());
- printWriter.print("<LI><FONT COLOR=\"#FF0000\">" + access + "</FONT> " + constantHtml.referenceConstant(classe.getInnerClassIndex())
- + " in class " + constantHtml.referenceConstant(classe.getOuterClassIndex()) + " named " + name + "</LI>\n");
+ access = Utility.accessToString(clazz.getInnerAccessFlags());
+ printWriter.print("<LI><FONT COLOR=\"#FF0000\">" + access + "</FONT> " + constantHtml.referenceConstant(clazz.getInnerClassIndex())
+ + " in class " + constantHtml.referenceConstant(clazz.getOuterClassIndex()) + " named " + name + "</LI>\n");
}
printWriter.print("</UL>\n");
break;
diff --git a/src/main/java/org/apache/bcel/util/CodeHTML.java b/src/main/java/org/apache/bcel/util/CodeHTML.java
index 2bf93608..5324e426 100644
--- a/src/main/java/org/apache/bcel/util/CodeHTML.java
+++ b/src/main/java/org/apache/bcel/util/CodeHTML.java
@@ -32,7 +32,6 @@ import org.apache.bcel.classfile.ConstantInvokeDynamic;
import org.apache.bcel.classfile.ConstantMethodref;
import org.apache.bcel.classfile.ConstantNameAndType;
import org.apache.bcel.classfile.ConstantPool;
-import org.apache.bcel.classfile.LocalVariable;
import org.apache.bcel.classfile.LocalVariableTable;
import org.apache.bcel.classfile.Method;
import org.apache.bcel.classfile.Utility;
@@ -388,13 +387,11 @@ final class CodeHTML {
final Attribute[] attributes = code.getAttributes();
for (final Attribute attribute : attributes) {
if (attribute.getTag() == Const.ATTR_LOCAL_VARIABLE_TABLE) {
- final LocalVariable[] vars = ((LocalVariableTable) attribute).getLocalVariableTable();
- for (final LocalVariable var : vars) {
+ ((LocalVariableTable) attribute).forEach(var -> {
final int start = var.getStartPC();
- final int end = start + var.getLength();
gotoSet.set(start);
- gotoSet.set(end);
- }
+ gotoSet.set(start + var.getLength());
+ });
break;
}
}
diff --git a/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java b/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
index 81616e52..8dd9de5b 100644
--- a/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
+++ b/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
@@ -273,9 +273,7 @@ public final class Pass2Verifier extends PassVerifier implements Constants {
}
// In JustIce, the check for correct offsets into the code array is delayed to Pass 3a.
- final LocalVariable[] localvariables = lvt.getLocalVariableTable();
-
- for (final LocalVariable localvariable : localvariables) {
+ for (final LocalVariable localvariable : lvt.getLocalVariableTable()) {
checkIndex(lvt, localvariable.getNameIndex(), CONST_Utf8);
final String localname = ((ConstantUtf8) cp.getConstant(localvariable.getNameIndex())).getBytes();
if (!validJavaIdentifier(localname)) {
@@ -642,37 +640,35 @@ public final class Pass2Verifier extends PassVerifier implements Constants {
}
@Override
- public void visitInnerClasses(final InnerClasses obj) {// vmspec2 4.7.5
+ public void visitInnerClasses(final InnerClasses innerClasses) {// vmspec2 4.7.5
// exactly one InnerClasses attr per ClassFile if some inner class is refernced: see visitJavaClass()
- checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
+ checkIndex(innerClasses, innerClasses.getNameIndex(), CONST_Utf8);
- final String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
+ final String name = ((ConstantUtf8) cp.getConstant(innerClasses.getNameIndex())).getBytes();
if (!name.equals("InnerClasses")) {
throw new ClassConstraintException(
- "The InnerClasses attribute '" + tostring(obj) + "' is not correctly named 'InnerClasses' but '" + name + "'.");
+ "The InnerClasses attribute '" + tostring(innerClasses) + "' is not correctly named 'InnerClasses' but '" + name + "'.");
}
- final InnerClass[] ics = obj.getInnerClasses();
-
- for (final InnerClass ic : ics) {
- checkIndex(obj, ic.getInnerClassIndex(), CONST_Class);
+ innerClasses.forEach(ic -> {
+ checkIndex(innerClasses, ic.getInnerClassIndex(), CONST_Class);
final int outer_idx = ic.getOuterClassIndex();
if (outer_idx != 0) {
- checkIndex(obj, outer_idx, CONST_Class);
+ checkIndex(innerClasses, outer_idx, CONST_Class);
}
final int innername_idx = ic.getInnerNameIndex();
if (innername_idx != 0) {
- checkIndex(obj, innername_idx, CONST_Utf8);
+ checkIndex(innerClasses, innername_idx, CONST_Utf8);
}
int acc = ic.getInnerAccessFlags();
acc = acc & ~(Const.ACC_PUBLIC | Const.ACC_PRIVATE | Const.ACC_PROTECTED | Const.ACC_STATIC | Const.ACC_FINAL | Const.ACC_INTERFACE |
Const.ACC_ABSTRACT);
if (acc != 0) {
- addMessage("Unknown access flag for inner class '" + tostring(ic) + "' set (InnerClasses attribute '" + tostring(obj) + "').");
+ addMessage("Unknown access flag for inner class '" + tostring(ic) + "' set (InnerClasses attribute '" + tostring(innerClasses) + "').");
}
- }
+ });
// Semantical consistency is not yet checked by Sun, see vmspec2 4.7.5.
// [marked TODO in JustIce]
}
diff --git a/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java b/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java
index d811f050..271d5e5f 100644
--- a/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java
+++ b/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java
@@ -39,7 +39,6 @@ import org.apache.bcel.classfile.Field;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.LineNumber;
import org.apache.bcel.classfile.LineNumberTable;
-import org.apache.bcel.classfile.LocalVariable;
import org.apache.bcel.classfile.LocalVariableTable;
import org.apache.bcel.classfile.Method;
import org.apache.bcel.generic.ALOAD;
@@ -1016,9 +1015,7 @@ public final class Pass3aVerifier extends PassVerifier {
final Attribute[] atts = code.getAttributes();
for (final Attribute att : atts) {
if (att instanceof LocalVariableTable) {
- final LocalVariableTable lvt = (LocalVariableTable) att;
- final LocalVariable[] localVariables = lvt.getLocalVariableTable();
- for (final LocalVariable localVariable : localVariables) {
+ ((LocalVariableTable) att).forEach(localVariable -> {
final int startpc = localVariable.getStartPC();
final int length = localVariable.getLength();
@@ -1031,7 +1028,7 @@ public final class Pass3aVerifier extends PassVerifier {
"Code attribute '" + tostring(code) + "' has a LocalVariableTable attribute '" + code.getLocalVariableTable()
+ "' referring to a code offset start_pc+length ('" + (startpc + length) + "') that does not exist.");
}
- }
+ });
}
}