src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Constant.java
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Constant.java Tue Jun 25 18:46:51 2019 -0700
+++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Constant.java Wed Jun 26 05:49:59 2019 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -22,30 +22,33 @@
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.util.Objects;
import com.sun.org.apache.bcel.internal.Const;
import com.sun.org.apache.bcel.internal.util.BCELComparator;
/**
- * Abstract superclass for classes to represent the different constant types in
- * the constant pool of a class file. The classes keep closely to the JVM
- * specification.
+ * Abstract superclass for classes to represent the different constant types
+ * in the constant pool of a class file. The classes keep closely to
+ * the JVM specification.
*
- * @version $Id: Constant.java 1749603 2016-06-21 20:50:19Z ggregory $
+ * @version $Id$
+ * @LastModified: Jun 2019
*/
public abstract class Constant implements Cloneable, Node {
private static BCELComparator bcelComparator = new BCELComparator() {
@Override
- public boolean equals(final Object o1, final Object o2) {
+ public boolean equals( final Object o1, final Object o2 ) {
final Constant THIS = (Constant) o1;
final Constant THAT = (Constant) o2;
- return THIS.toString().equals(THAT.toString());
+ return Objects.equals(THIS.toString(), THAT.toString());
}
+
@Override
- public int hashCode(final Object o) {
+ public int hashCode( final Object o ) {
final Constant THIS = (Constant) o;
return THIS.toString().hashCode();
}
@@ -61,10 +64,12 @@
*/
private byte tag;
+
Constant(final byte tag) {
this.tag = tag;
}
+
/**
* 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,
@@ -73,9 +78,11 @@
* @param v Visitor object
*/
@Override
- public abstract void accept(Visitor v);
+ public abstract void accept( Visitor v );
+
- public abstract void dump(DataOutputStream file) throws IOException;
+ public abstract void dump( DataOutputStream file ) throws IOException;
+
/**
* @return Tag of constant, i.e., its type. No setTag() method to avoid
@@ -85,6 +92,7 @@
return tag;
}
+
/**
* @return String representation.
*/
@@ -93,6 +101,7 @@
return Const.getConstantName(tag) + "[" + tag + "]";
}
+
/**
* @return deep copy of this constant
*/
@@ -105,6 +114,7 @@
return null;
}
+
@Override
public Object clone() {
try {
@@ -114,47 +124,55 @@
}
}
+
/**
* Read one constant from the given input, the type depends on a tag byte.
*
- * @param input Input stream
+ * @param dataInput Input stream
* @return Constant object
+ * @throws IOException if an I/O error occurs reading from the given {@code dataInput}.
+ * @throws ClassFormatException if the next byte is not recognized
* @since 6.0 made public
*/
- public static Constant readConstant(final DataInput input) throws IOException,
- ClassFormatException {
- final byte b = input.readByte(); // Read tag byte
+ public static Constant readConstant(final DataInput dataInput) throws IOException, ClassFormatException {
+ final byte b = dataInput.readByte(); // Read tag byte
switch (b) {
- case Const.CONSTANT_Class:
- return new ConstantClass(input);
- case Const.CONSTANT_Fieldref:
- return new ConstantFieldref(input);
- case Const.CONSTANT_Methodref:
- return new ConstantMethodref(input);
- case Const.CONSTANT_InterfaceMethodref:
- return new ConstantInterfaceMethodref(input);
- case Const.CONSTANT_String:
- return new ConstantString(input);
- case Const.CONSTANT_Integer:
- return new ConstantInteger(input);
- case Const.CONSTANT_Float:
- return new ConstantFloat(input);
- case Const.CONSTANT_Long:
- return new ConstantLong(input);
- case Const.CONSTANT_Double:
- return new ConstantDouble(input);
- case Const.CONSTANT_NameAndType:
- return new ConstantNameAndType(input);
- case Const.CONSTANT_Utf8:
- return ConstantUtf8.getInstance(input);
- case Const.CONSTANT_MethodHandle:
- return new ConstantMethodHandle(input);
- case Const.CONSTANT_MethodType:
- return new ConstantMethodType(input);
- case Const.CONSTANT_InvokeDynamic:
- return new ConstantInvokeDynamic(input);
- default:
- throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
+ case Const.CONSTANT_Class:
+ return new ConstantClass(dataInput);
+ case Const.CONSTANT_Fieldref:
+ return new ConstantFieldref(dataInput);
+ case Const.CONSTANT_Methodref:
+ return new ConstantMethodref(dataInput);
+ case Const.CONSTANT_InterfaceMethodref:
+ return new ConstantInterfaceMethodref(dataInput);
+ case Const.CONSTANT_String:
+ return new ConstantString(dataInput);
+ case Const.CONSTANT_Integer:
+ return new ConstantInteger(dataInput);
+ case Const.CONSTANT_Float:
+ return new ConstantFloat(dataInput);
+ case Const.CONSTANT_Long:
+ return new ConstantLong(dataInput);
+ case Const.CONSTANT_Double:
+ return new ConstantDouble(dataInput);
+ case Const.CONSTANT_NameAndType:
+ return new ConstantNameAndType(dataInput);
+ case Const.CONSTANT_Utf8:
+ return ConstantUtf8.getInstance(dataInput);
+ case Const.CONSTANT_MethodHandle:
+ return new ConstantMethodHandle(dataInput);
+ case Const.CONSTANT_MethodType:
+ return new ConstantMethodType(dataInput);
+ case Const.CONSTANT_Dynamic:
+ return new ConstantDynamic(dataInput);
+ case Const.CONSTANT_InvokeDynamic:
+ return new ConstantInvokeDynamic(dataInput);
+ case Const.CONSTANT_Module:
+ return new ConstantModule(dataInput);
+ case Const.CONSTANT_Package:
+ return new ConstantPackage(dataInput);
+ default:
+ throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
}
}
@@ -165,28 +183,31 @@
return bcelComparator;
}
+
/**
* @param comparator Comparison strategy object
*/
- public static void setComparator(final BCELComparator comparator) {
+ public static void setComparator( final BCELComparator comparator ) {
bcelComparator = comparator;
}
+
/**
- * Return value as defined by given BCELComparator strategy. By default two
- * Constant objects are said to be equal when the result of toString() is
- * equal.
+ * Return value as defined by given BCELComparator strategy.
+ * By default two Constant objects are said to be equal when
+ * the result of toString() is equal.
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
- public boolean equals(final Object obj) {
+ public boolean equals( final Object obj ) {
return bcelComparator.equals(this, obj);
}
+
/**
- * Return value as defined by given BCELComparator strategy. By default
- * return the hashcode of the result of toString().
+ * Return value as defined by given BCELComparator strategy.
+ * By default return the hashcode of the result of toString().
*
* @see java.lang.Object#hashCode()
*/