Author: kkolinko Date: Fri Sep 12 17:15:31 2014 New Revision: 1624594 URL: http://svn.apache.org/r1624594 Log: Move stream reading logic into AnnotationEntry and ElementValue constructors.
Modified: tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/AnnotationEntry.java tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Annotations.java tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ElementValue.java tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ElementValuePair.java tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotationEntry.java Modified: tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/AnnotationEntry.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/AnnotationEntry.java?rev=1624594&r1=1624593&r2=1624594&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/AnnotationEntry.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/AnnotationEntry.java Fri Sep 12 17:15:31 2014 @@ -35,32 +35,26 @@ public class AnnotationEntry implements private final int type_index; private final ConstantPool constant_pool; - // FIXME: add 'final' - private List<ElementValuePair> element_value_pairs; + private final List<ElementValuePair> element_value_pairs; /** - * Factory method to create an AnnotionEntry from a DataInputStream + * Creates an AnnotationEntry from a DataInputStream * * @param file * @param constant_pool - * @return the entry * @throws IOException */ - public static AnnotationEntry read(DataInputStream file, ConstantPool constant_pool) throws IOException { + AnnotationEntry(DataInputStream file, ConstantPool constant_pool) throws IOException { - final AnnotationEntry annotationEntry = new AnnotationEntry(file.readUnsignedShort(), constant_pool); - final int num_element_value_pairs = (file.readUnsignedShort()); - annotationEntry.element_value_pairs = new ArrayList<>(); + this.constant_pool = constant_pool; + + type_index = file.readUnsignedShort(); + int num_element_value_pairs = file.readUnsignedShort(); + + element_value_pairs = new ArrayList<>(num_element_value_pairs); for (int i = 0; i < num_element_value_pairs; i++) { - annotationEntry.element_value_pairs.add(new ElementValuePair(file.readUnsignedShort(), ElementValue.readElementValue(file, constant_pool), - constant_pool)); + element_value_pairs.add(new ElementValuePair(file, constant_pool)); } - return annotationEntry; - } - - AnnotationEntry(int type_index, ConstantPool constant_pool) { - this.type_index = type_index; - this.constant_pool = constant_pool; } /** Modified: tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Annotations.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Annotations.java?rev=1624594&r1=1624593&r2=1624594&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Annotations.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Annotations.java Fri Sep 12 17:15:31 2014 @@ -39,7 +39,7 @@ public abstract class Annotations extend final int annotation_table_length = (file.readUnsignedShort()); annotation_table = new AnnotationEntry[annotation_table_length]; for (int i = 0; i < annotation_table_length; i++) { - annotation_table[i] = AnnotationEntry.read(file, constant_pool); + annotation_table[i] = new AnnotationEntry(file, constant_pool); } } Modified: tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ElementValue.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ElementValue.java?rev=1624594&r1=1624593&r2=1624594&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ElementValue.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ElementValue.java Fri Sep 12 17:15:31 2014 @@ -105,7 +105,7 @@ public abstract class ElementValue return new ClassElementValue(CLASS, dis.readUnsignedShort(), cpool); case '@': // Annotation // TODO isRuntimeVisible - return new AnnotationElementValue(ANNOTATION, AnnotationEntry.read( + return new AnnotationElementValue(ANNOTATION, new AnnotationEntry( dis, cpool), cpool); case '[': // Array int numArrayVals = dis.readUnsignedShort(); Modified: tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ElementValuePair.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ElementValuePair.java?rev=1624594&r1=1624593&r2=1624594&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ElementValuePair.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ElementValuePair.java Fri Sep 12 17:15:31 2014 @@ -17,6 +17,9 @@ */ package org.apache.tomcat.util.bcel.classfile; +import java.io.DataInputStream; +import java.io.IOException; + import org.apache.tomcat.util.bcel.Constants; /** @@ -33,11 +36,10 @@ public class ElementValuePair private final int elementNameIndex; - ElementValuePair(int elementNameIndex, ElementValue elementValue, - ConstantPool constantPool) { - this.elementValue = elementValue; - this.elementNameIndex = elementNameIndex; + ElementValuePair(DataInputStream file, ConstantPool constantPool) throws IOException { this.constantPool = constantPool; + this.elementNameIndex = file.readUnsignedShort(); + this.elementValue = ElementValue.readElementValue(file, constantPool); } public String getNameString() Modified: tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotationEntry.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotationEntry.java?rev=1624594&r1=1624593&r2=1624594&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotationEntry.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotationEntry.java Fri Sep 12 17:15:31 2014 @@ -42,7 +42,7 @@ public class ParameterAnnotationEntry im int annotation_table_length = file.readUnsignedShort(); annotation_table = new AnnotationEntry[annotation_table_length]; for (int i = 0; i < annotation_table_length; i++) { - annotation_table[i] = AnnotationEntry.read(file, constant_pool); + annotation_table[i] = new AnnotationEntry(file, constant_pool); } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org