< prev index next >

src/java.base/share/classes/java/lang/constant/ReferenceClassDescImpl.java

Print this page




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.lang.constant;
  26 
  27 import java.lang.invoke.MethodHandles;
  28 




  29 import static java.lang.constant.ConstantUtils.dropFirstAndLastChar;
  30 import static java.lang.constant.ConstantUtils.internalToBinary;
  31 import static java.util.Objects.requireNonNull;
  32 
  33 /**
  34  * A <a href="package-summary.html#nominal">nominal descriptor</a> for a class,
  35  * interface, or array type.  A {@linkplain ReferenceClassDescImpl} corresponds to a
  36  * {@code Constant_Class_info} entry in the constant pool of a classfile.
  37  */
  38 final class ReferenceClassDescImpl implements ClassDesc {
  39     private final String descriptor;
  40 
  41     /**
  42      * Creates a {@linkplain ClassDesc} from a descriptor string for a class or
  43      * interface type
  44      *
  45      * @param descriptor a field descriptor string for a class or interface type
  46      * @throws IllegalArgumentException if the descriptor string is not a valid
  47      * field descriptor string, or does not describe a class or interface type
  48      * @jvms 4.3.2 Field Descriptors


  90      * @return {@code true} if the specified {@code ClassDesc} is
  91      *      equals to this {@code ClassDesc}.
  92      */
  93     @Override
  94     public boolean equals(Object o) {
  95         if (this == o) return true;
  96         if (o == null || getClass() != o.getClass()) return false;
  97 
  98         ClassDesc constant = (ClassDesc) o;
  99         return descriptor.equals(constant.descriptorString());
 100     }
 101 
 102     @Override
 103     public int hashCode() {
 104         return descriptor.hashCode();
 105     }
 106 
 107     @Override
 108     public String toString() {
 109         return String.format("ClassDesc[%s]", displayName());





 110     }
 111 }


   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.lang.constant;
  26 
  27 import java.lang.invoke.MethodHandles;
  28 
  29 import java.lang.invoke.MethodHandles;
  30 import java.util.Optional;
  31 
  32 import static java.lang.constant.ConstantDescs.BSM_INVOKE;
  33 import static java.lang.constant.ConstantUtils.dropFirstAndLastChar;
  34 import static java.lang.constant.ConstantUtils.internalToBinary;
  35 import static java.util.Objects.requireNonNull;
  36 
  37 /**
  38  * A <a href="package-summary.html#nominal">nominal descriptor</a> for a class,
  39  * interface, or array type.  A {@linkplain ReferenceClassDescImpl} corresponds to a
  40  * {@code Constant_Class_info} entry in the constant pool of a classfile.
  41  */
  42 final class ReferenceClassDescImpl implements ClassDesc {
  43     private final String descriptor;
  44 
  45     /**
  46      * Creates a {@linkplain ClassDesc} from a descriptor string for a class or
  47      * interface type
  48      *
  49      * @param descriptor a field descriptor string for a class or interface type
  50      * @throws IllegalArgumentException if the descriptor string is not a valid
  51      * field descriptor string, or does not describe a class or interface type
  52      * @jvms 4.3.2 Field Descriptors


  94      * @return {@code true} if the specified {@code ClassDesc} is
  95      *      equals to this {@code ClassDesc}.
  96      */
  97     @Override
  98     public boolean equals(Object o) {
  99         if (this == o) return true;
 100         if (o == null || getClass() != o.getClass()) return false;
 101 
 102         ClassDesc constant = (ClassDesc) o;
 103         return descriptor.equals(constant.descriptorString());
 104     }
 105 
 106     @Override
 107     public int hashCode() {
 108         return descriptor.hashCode();
 109     }
 110 
 111     @Override
 112     public String toString() {
 113         return String.format("ClassDesc[%s]", displayName());
 114     }
 115 
 116     @Override
 117     public Optional<? extends ConstantDesc> describeConstable() {
 118         return Optional.empty();
 119     }
 120 }
< prev index next >