1 /* 2 * Copyright (C) 2008 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 * Utility for turning types into zeroes. 23 */ 24 public final class Zeroes { 25 /** 26 * This class is uninstantiable. 27 */ 28 private Zeroes() { 29 // This space intentionally left blank. 30 } 31 32 /** 33 * Gets the "zero" (or {@code null}) value for the given type. 34 * 35 * @param type {@code non-null;} the type in question 36 * @return {@code non-null;} its "zero" value 37 */ 38 public static Constant zeroFor(Type type) { 39 switch (type.getBasicType()) { 40 case Type.BT_BOOLEAN: return CstBoolean.VALUE_FALSE; 41 case Type.BT_BYTE: return CstByte.VALUE_0; 42 case Type.BT_CHAR: return CstChar.VALUE_0; 43 case Type.BT_DOUBLE: return CstDouble.VALUE_0; 44 case Type.BT_FLOAT: return CstFloat.VALUE_0; 45 case Type.BT_INT: return CstInteger.VALUE_0; 46 case Type.BT_LONG: return CstLong.VALUE_0; 47 case Type.BT_SHORT: return CstShort.VALUE_0; 48 case Type.BT_OBJECT: return CstKnownNull.THE_ONE; 49 default: { 50 throw new UnsupportedOperationException("no zero for type: " + 51 type.toHuman()); 52 } 53 } 54 } 55 } 56