garydgregory commented on code in PR #290:
URL: https://github.com/apache/commons-bcel/pull/290#discussion_r1531140604


##########
src/main/java/org/apache/bcel/classfile/Record.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.bcel.classfile;
+
+import java.io.DataInput;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.apache.bcel.Const;
+import org.apache.bcel.util.Args;
+import org.apache.commons.lang3.ArrayUtils;
+
+/**
+ * This class is derived from <em>Attribute</em> and records the classes and 
interfaces that are authorized to claim
+ * membership in the nest hosted by the current class or interface. There may 
be at most one Record attribute in a
+ * ClassFile structure.
+ *
+ * @see Attribute
+ * @since 6.9.0
+ */
+public final class Record extends Attribute {
+
+    private static final RecordComponentInfo[] EMPTY_RCI_ARRAY = new 
RecordComponentInfo[] {};
+
+    private RecordComponentInfo[] components;
+
+    /**
+     * Constructs object from input stream.
+     *
+     * @param nameIndex Index in constant pool
+     * @param length Content length in bytes
+     * @param input Input stream
+     * @param constantPool Array of constants
+     * @throws IOException if an I/O error occurs.
+     */
+    Record(final int nameIndex, final int length, final DataInput input, final 
ConstantPool constantPool) throws IOException {
+        this(nameIndex, length, (RecordComponentInfo[]) null, constantPool);
+        final int classCount = input.readUnsignedShort();
+        components = new RecordComponentInfo[classCount];
+        for (int i = 0; i < classCount; i++) {
+            final int index = input.readUnsignedShort();
+            final int descriptorIndex =input.readUnsignedShort();
+            final int attributesCount = input.readUnsignedShort();
+            final Attribute[] attributes = new Attribute[attributesCount];
+            for (int j = 0 ; j< attributesCount; j++)
+                attributes[j] = Attribute.readAttribute(input, constantPool);
+            components[i] = new RecordComponentInfo(
+                    index,
+                    descriptorIndex,
+                    attributes,input,constantPool);
+        }
+    }
+
+    /**
+     * @param nameIndex Index in constant pool

Review Comment:
   Javadoc's first sentence is missing.



##########
src/main/java/org/apache/bcel/classfile/RecordComponentInfo.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.bcel.classfile;
+
+import java.io.DataInput;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.bcel.Const;
+
+public class RecordComponentInfo implements Cloneable, Node {

Review Comment:
   Must the class be public. Let's not make it `Cloneable` if we can. In 
general, we want to move away from Cloneable and toward serialization proxies 
instead.



##########
src/test/java/org/apache/bcel/CounterVisitorTestCase.java:
##########
@@ -217,4 +217,8 @@ public void testSyntheticCount() {
     public void testUnknownCount() {
         assertEquals(0, getVisitor().unknownCount, "unknownCount");
     }
+    @Test

Review Comment:
   Please add a blank line to separate methods (watch out for trailing 
whitespace).



##########
src/main/java/org/apache/bcel/classfile/Visitor.java:
##########
@@ -207,6 +207,14 @@ default void visitNestMembers(final NestMembers obj) {
         // empty
     }
 
+    /**
+     * @since 6.5.0

Review Comment:
   The next version will be 6.9.0.



##########
src/main/java/org/apache/bcel/classfile/JavaClass.java:
##########
@@ -906,4 +910,22 @@ public String toString() {
         }
         return buf.toString();
     }
+
+    public boolean isRecord() {

Review Comment:
   Javadoc missing, the next version will be 6.9.0 since this is a PR for a new 
feature.



##########
src/main/java/org/apache/bcel/classfile/RecordComponentInfo.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.bcel.classfile;
+
+import java.io.DataInput;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.bcel.Const;
+
+public class RecordComponentInfo implements Cloneable, Node {
+
+    private final int index;
+    private final int descriptorIndex;
+    private final Attribute[] attributes; 
+    private final ConstantPool constantPool;
+    
+    public RecordComponentInfo(int index, int descriptorIndex, Attribute[] 
attributes, DataInput input,
+            ConstantPool constantPool) {
+        this.index=index;
+        this.descriptorIndex=descriptorIndex;
+        this.attributes=attributes;
+        this.constantPool=constantPool;
+    }
+
+    public void write(DataOutputStream file) throws IOException {

Review Comment:
   Javadoc missing.



##########
src/main/java/org/apache/bcel/classfile/RecordComponentInfo.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.bcel.classfile;
+
+import java.io.DataInput;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.bcel.Const;
+
+public class RecordComponentInfo implements Cloneable, Node {
+
+    private final int index;
+    private final int descriptorIndex;
+    private final Attribute[] attributes; 
+    private final ConstantPool constantPool;
+    
+    public RecordComponentInfo(int index, int descriptorIndex, Attribute[] 
attributes, DataInput input,

Review Comment:
   Javadoc missing.
   



##########
src/main/java/org/apache/bcel/classfile/Record.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.bcel.classfile;
+
+import java.io.DataInput;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.apache.bcel.Const;
+import org.apache.bcel.util.Args;
+import org.apache.commons.lang3.ArrayUtils;
+
+/**
+ * This class is derived from <em>Attribute</em> and records the classes and 
interfaces that are authorized to claim
+ * membership in the nest hosted by the current class or interface. There may 
be at most one Record attribute in a
+ * ClassFile structure.
+ *
+ * @see Attribute
+ * @since 6.9.0
+ */
+public final class Record extends Attribute {
+
+    private static final RecordComponentInfo[] EMPTY_RCI_ARRAY = new 
RecordComponentInfo[] {};
+
+    private RecordComponentInfo[] components;
+
+    /**
+     * Constructs object from input stream.
+     *
+     * @param nameIndex Index in constant pool
+     * @param length Content length in bytes
+     * @param input Input stream
+     * @param constantPool Array of constants
+     * @throws IOException if an I/O error occurs.
+     */
+    Record(final int nameIndex, final int length, final DataInput input, final 
ConstantPool constantPool) throws IOException {
+        this(nameIndex, length, (RecordComponentInfo[]) null, constantPool);
+        final int classCount = input.readUnsignedShort();
+        components = new RecordComponentInfo[classCount];
+        for (int i = 0; i < classCount; i++) {
+            final int index = input.readUnsignedShort();
+            final int descriptorIndex =input.readUnsignedShort();
+            final int attributesCount = input.readUnsignedShort();
+            final Attribute[] attributes = new Attribute[attributesCount];
+            for (int j = 0 ; j< attributesCount; j++)
+                attributes[j] = Attribute.readAttribute(input, constantPool);
+            components[i] = new RecordComponentInfo(
+                    index,
+                    descriptorIndex,
+                    attributes,input,constantPool);
+        }
+    }
+
+    /**
+     * @param nameIndex Index in constant pool
+     * @param length Content length in bytes
+     * @param classes Table of Record component info
+     * @param constantPool Array of constants
+     */
+    public Record(final int nameIndex, final int length, final 
RecordComponentInfo[] classes, final ConstantPool constantPool) {
+        super(Const.ATTR_RECORD, nameIndex, length, constantPool);
+        this.components = classes != null ? classes : EMPTY_RCI_ARRAY;
+        Args.requireU2(this.components.length, "attributes.length");
+    }
+
+    /**
+     * Initialize from another object. Note that both objects use the same 
references (shallow copy). Use copy() for a
+     * physical copy.
+     *
+     * @param c Source to copy.
+     */
+    public Record(final Record c) {
+        this(c.getNameIndex(), c.getLength(), c.getComponents(), 
c.getConstantPool());
+    }
+
+    /**
+     * Called by objects that are traversing the nodes of the tree implicitly 
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
+     */
+    @Override
+    public void accept(final Visitor v) {
+        v.visitRecord(this);
+    }
+
+    /**
+     * @return deep copy of this attribute

Review Comment:
   Javadoc's first sentence is missing.



##########
src/main/java/org/apache/bcel/classfile/Record.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.bcel.classfile;
+
+import java.io.DataInput;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.apache.bcel.Const;
+import org.apache.bcel.util.Args;
+import org.apache.commons.lang3.ArrayUtils;
+
+/**
+ * This class is derived from <em>Attribute</em> and records the classes and 
interfaces that are authorized to claim
+ * membership in the nest hosted by the current class or interface. There may 
be at most one Record attribute in a
+ * ClassFile structure.
+ *
+ * @see Attribute
+ * @since 6.9.0
+ */
+public final class Record extends Attribute {
+
+    private static final RecordComponentInfo[] EMPTY_RCI_ARRAY = new 
RecordComponentInfo[] {};
+
+    private RecordComponentInfo[] components;
+
+    /**
+     * Constructs object from input stream.
+     *
+     * @param nameIndex Index in constant pool
+     * @param length Content length in bytes
+     * @param input Input stream
+     * @param constantPool Array of constants
+     * @throws IOException if an I/O error occurs.
+     */
+    Record(final int nameIndex, final int length, final DataInput input, final 
ConstantPool constantPool) throws IOException {
+        this(nameIndex, length, (RecordComponentInfo[]) null, constantPool);
+        final int classCount = input.readUnsignedShort();
+        components = new RecordComponentInfo[classCount];
+        for (int i = 0; i < classCount; i++) {
+            final int index = input.readUnsignedShort();
+            final int descriptorIndex =input.readUnsignedShort();
+            final int attributesCount = input.readUnsignedShort();
+            final Attribute[] attributes = new Attribute[attributesCount];
+            for (int j = 0 ; j< attributesCount; j++)
+                attributes[j] = Attribute.readAttribute(input, constantPool);

Review Comment:
   Always use `{` and `}`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to