1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.dexgen.rop.cst; 18 19 import com.android.dexgen.rop.type.Type; 20 21 /** 22 * Constant type to represent a known-{@code null} value. 23 */ 24 public final class CstKnownNull extends CstLiteralBits { 25 /** {@code non-null;} unique instance of this class */ 26 public static final CstKnownNull THE_ONE = new CstKnownNull(); 27 28 /** 29 * Constructs an instance. This class is not publicly instantiable. Use 30 * {@link #THE_ONE}. 31 */ CstKnownNull()32 private CstKnownNull() { 33 // This space intentionally left blank. 34 } 35 36 /** {@inheritDoc} */ 37 @Override equals(Object other)38 public boolean equals(Object other) { 39 return (other instanceof CstKnownNull); 40 } 41 42 /** {@inheritDoc} */ 43 @Override hashCode()44 public int hashCode() { 45 return 0x4466757a; 46 } 47 48 /** {@inheritDoc} */ 49 @Override compareTo0(Constant other)50 protected int compareTo0(Constant other) { 51 return 0; 52 } 53 54 /** {@inheritDoc} */ 55 @Override toString()56 public String toString() { 57 return "known-null"; 58 } 59 60 /** {@inheritDoc} */ getType()61 public Type getType() { 62 return Type.KNOWN_NULL; 63 } 64 65 /** {@inheritDoc} */ 66 @Override typeName()67 public String typeName() { 68 return "known-null"; 69 } 70 71 /** {@inheritDoc} */ 72 @Override isCategory2()73 public boolean isCategory2() { 74 return false; 75 } 76 77 /** {@inheritDoc} */ toHuman()78 public String toHuman() { 79 return "null"; 80 } 81 82 /** {@inheritDoc} */ 83 @Override fitsInInt()84 public boolean fitsInInt() { 85 // See comment in getIntBits(). 86 return true; 87 } 88 89 /** 90 * {@inheritDoc} 91 * 92 * As "literal bits," a known-null is always represented as the 93 * number zero. 94 */ 95 @Override getIntBits()96 public int getIntBits() { 97 return 0; 98 } 99 100 /** 101 * {@inheritDoc} 102 * 103 * As "literal bits," a known-null is always represented as the 104 * number zero. 105 */ 106 @Override getLongBits()107 public long getLongBits() { 108 return 0; 109 } 110 } 111