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.dx.rop.cst; 18 19 import com.android.dx.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} */ 61 @Override getType()62 public Type getType() { 63 return Type.KNOWN_NULL; 64 } 65 66 /** {@inheritDoc} */ 67 @Override typeName()68 public String typeName() { 69 return "known-null"; 70 } 71 72 /** {@inheritDoc} */ 73 @Override isCategory2()74 public boolean isCategory2() { 75 return false; 76 } 77 78 /** {@inheritDoc} */ 79 @Override toHuman()80 public String toHuman() { 81 return "null"; 82 } 83 84 /** {@inheritDoc} */ 85 @Override fitsInInt()86 public boolean fitsInInt() { 87 // See comment in getIntBits(). 88 return true; 89 } 90 91 /** 92 * {@inheritDoc} 93 * 94 * As "literal bits," a known-null is always represented as the 95 * number zero. 96 */ 97 @Override getIntBits()98 public int getIntBits() { 99 return 0; 100 } 101 102 /** 103 * {@inheritDoc} 104 * 105 * As "literal bits," a known-null is always represented as the 106 * number zero. 107 */ 108 @Override getLongBits()109 public long getLongBits() { 110 return 0; 111 } 112 } 113