You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by eb...@apache.org on 2014/12/19 14:32:32 UTC
svn commit: r1646706 -
/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValue.java
Author: ebourg
Date: Fri Dec 19 13:32:32 2014
New Revision: 1646706
URL: http://svn.apache.org/r1646706
Log:
Simplified the switch block in ElementValue
Modified:
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValue.java
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValue.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValue.java?rev=1646706&r1=1646705&r2=1646706&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValue.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValue.java Fri Dec 19 13:32:32 2014
@@ -13,8 +13,8 @@
* 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;
@@ -53,85 +53,57 @@ public abstract class ElementValue
public abstract void dump(DataOutputStream dos) throws IOException;
- public static final int STRING = 's';
-
- public static final int ENUM_CONSTANT = 'e';
-
- public static final int CLASS = 'c';
-
- public static final int ANNOTATION = '@';
-
- public static final int ARRAY = '[';
-
- public static final int PRIMITIVE_INT = 'I';
-
- public static final int PRIMITIVE_BYTE = 'B';
+ public static final byte STRING = 's';
+ public static final byte ENUM_CONSTANT = 'e';
+ public static final byte CLASS = 'c';
+ public static final byte ANNOTATION = '@';
+ public static final byte ARRAY = '[';
+ public static final byte PRIMITIVE_INT = 'I';
+ public static final byte PRIMITIVE_BYTE = 'B';
+ public static final byte PRIMITIVE_CHAR = 'C';
+ public static final byte PRIMITIVE_DOUBLE = 'D';
+ public static final byte PRIMITIVE_FLOAT = 'F';
+ public static final byte PRIMITIVE_LONG = 'J';
+ public static final byte PRIMITIVE_SHORT = 'S';
+ public static final byte PRIMITIVE_BOOLEAN = 'Z';
- public static final int PRIMITIVE_CHAR = 'C';
-
- public static final int PRIMITIVE_DOUBLE = 'D';
-
- public static final int PRIMITIVE_FLOAT = 'F';
-
- public static final int PRIMITIVE_LONG = 'J';
-
- public static final int PRIMITIVE_SHORT = 'S';
-
- public static final int PRIMITIVE_BOOLEAN = 'Z';
-
- public static ElementValue readElementValue(DataInput input,
- ConstantPool cpool) throws IOException
+ public static ElementValue readElementValue(DataInput input, ConstantPool cpool) throws IOException
{
byte type = input.readByte();
switch (type)
{
- case 'B': // byte
- return new SimpleElementValue(PRIMITIVE_BYTE, input
- .readUnsignedShort(), cpool);
- case 'C': // char
- return new SimpleElementValue(PRIMITIVE_CHAR, input
- .readUnsignedShort(), cpool);
- case 'D': // double
- return new SimpleElementValue(PRIMITIVE_DOUBLE, input
- .readUnsignedShort(), cpool);
- case 'F': // float
- return new SimpleElementValue(PRIMITIVE_FLOAT, input
- .readUnsignedShort(), cpool);
- case 'I': // int
- return new SimpleElementValue(PRIMITIVE_INT, input
- .readUnsignedShort(), cpool);
- case 'J': // long
- return new SimpleElementValue(PRIMITIVE_LONG, input
- .readUnsignedShort(), cpool);
- case 'S': // short
- return new SimpleElementValue(PRIMITIVE_SHORT, input
- .readUnsignedShort(), cpool);
- case 'Z': // boolean
- return new SimpleElementValue(PRIMITIVE_BOOLEAN, input
- .readUnsignedShort(), cpool);
- case 's': // String
- return new SimpleElementValue(STRING, input.readUnsignedShort(),
- cpool);
- case 'e': // Enum constant
- return new EnumElementValue(ENUM_CONSTANT, input.readUnsignedShort(),
- input.readUnsignedShort(), cpool);
- case 'c': // Class
- return new ClassElementValue(CLASS, input.readUnsignedShort(), cpool);
- case '@': // Annotation
- // TODO isRuntimeVisible
- return new AnnotationElementValue(ANNOTATION, AnnotationEntry.read(
- input, cpool, false), cpool);
- case '[': // Array
- int numArrayVals = input.readUnsignedShort();
- ElementValue[] evalues = new ElementValue[numArrayVals];
- for (int j = 0; j < numArrayVals; j++)
- {
- evalues[j] = ElementValue.readElementValue(input, cpool);
- }
- return new ArrayElementValue(ARRAY, evalues, cpool);
- default:
- throw new RuntimeException(
- "Unexpected element value kind in annotation: " + type);
+ case PRIMITIVE_BYTE:
+ case PRIMITIVE_CHAR:
+ case PRIMITIVE_DOUBLE:
+ case PRIMITIVE_FLOAT:
+ case PRIMITIVE_INT:
+ case PRIMITIVE_LONG:
+ case PRIMITIVE_SHORT:
+ case PRIMITIVE_BOOLEAN:
+ case STRING:
+ return new SimpleElementValue(type, input.readUnsignedShort(), cpool);
+
+ case ENUM_CONSTANT:
+ return new EnumElementValue(ENUM_CONSTANT, input.readUnsignedShort(), input.readUnsignedShort(), cpool);
+
+ case CLASS:
+ return new ClassElementValue(CLASS, input.readUnsignedShort(), cpool);
+
+ case ANNOTATION:
+ // TODO isRuntimeVisible
+ return new AnnotationElementValue(ANNOTATION, AnnotationEntry.read(input, cpool, false), cpool);
+
+ case ARRAY:
+ int numArrayVals = input.readUnsignedShort();
+ ElementValue[] evalues = new ElementValue[numArrayVals];
+ for (int j = 0; j < numArrayVals; j++)
+ {
+ evalues[j] = ElementValue.readElementValue(input, cpool);
+ }
+ return new ArrayElementValue(ARRAY, evalues, cpool);
+
+ default:
+ throw new RuntimeException("Unexpected element value kind in annotation: " + type);
}
}