UninitializedObjectType.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  *  Unless required by applicable law or agreed to in writing, software
  12.  *  distributed under the License is distributed on an "AS IS" BASIS,
  13.  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  *  See the License for the specific language governing permissions and
  15.  *  limitations under the License.
  16.  */
  17. package org.apache.bcel.verifier.structurals;

  18. import org.apache.bcel.Const;
  19. import org.apache.bcel.Constants;
  20. import org.apache.bcel.generic.ObjectType;
  21. import org.apache.bcel.generic.ReferenceType;

  22. /**
  23.  * This class represents an uninitialized object type; see The Java Virtual Machine Specification, Second Edition, page
  24.  * 147: 4.9.4 for more details.
  25.  */
  26. public class UninitializedObjectType extends ReferenceType implements Constants {

  27.     /** The "initialized" version. */
  28.     private final ObjectType initialized;

  29.     /**
  30.      * Creates a new instance.
  31.      *
  32.      * @param objectType uninitialized object type.
  33.      */
  34.     public UninitializedObjectType(final ObjectType objectType) {
  35.         super(Const.T_UNKNOWN, "<UNINITIALIZED OBJECT OF TYPE '" + objectType.getClassName() + "'>");
  36.         initialized = objectType;
  37.     }

  38.     /**
  39.      * Returns true on equality of this and o. Equality means the ObjectType instances of "initialized" equal one another in
  40.      * this and the o instance.
  41.      */
  42.     @Override
  43.     public boolean equals(final Object o) {
  44.         if (!(o instanceof UninitializedObjectType)) {
  45.             return false;
  46.         }
  47.         return initialized.equals(((UninitializedObjectType) o).initialized);
  48.     }

  49.     /**
  50.      * Returns the ObjectType of the same class as the one of the uninitialized object represented by this
  51.      * UninitializedObjectType instance.
  52.      *
  53.      * @return the ObjectType.
  54.      */
  55.     public ObjectType getInitialized() {
  56.         return initialized;
  57.     }

  58.     /**
  59.      * @return a hash code value for the object.
  60.      */
  61.     @Override
  62.     public int hashCode() {
  63.         return initialized.hashCode();
  64.     }
  65. }