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
17package com.android.dx.rop.cst;
18
19import com.android.dx.rop.type.Type;
20import com.android.dx.util.Hex;
21
22/**
23 * Constants of type {@code CONSTANT_Long_info}.
24 */
25public final class CstLong
26        extends CstLiteral64 {
27    /** {@code non-null;} instance representing {@code 0} */
28    public static final CstLong VALUE_0 = make(0);
29
30    /** {@code non-null;} instance representing {@code 1} */
31    public static final CstLong VALUE_1 = make(1);
32
33    /**
34     * Makes an instance for the given value. This may (but does not
35     * necessarily) return an already-allocated instance.
36     *
37     * @param value the {@code long} value
38     */
39    public static CstLong make(long value) {
40        /*
41         * Note: Javadoc notwithstanding, this implementation always
42         * allocates.
43         */
44        return new CstLong(value);
45    }
46
47    /**
48     * Constructs an instance. This constructor is private; use {@link #make}.
49     *
50     * @param value the {@code long} value
51     */
52    private CstLong(long value) {
53        super(value);
54    }
55
56    /** {@inheritDoc} */
57    @Override
58    public String toString() {
59        long value = getLongBits();
60        return "long{0x" + Hex.u8(value) + " / " + value + '}';
61    }
62
63    /** {@inheritDoc} */
64    public Type getType() {
65        return Type.LONG;
66    }
67
68    /** {@inheritDoc} */
69    @Override
70    public String typeName() {
71        return "long";
72    }
73
74    /** {@inheritDoc} */
75    public String toHuman() {
76        return Long.toString(getLongBits());
77    }
78
79    /**
80     * Gets the {@code long} value.
81     *
82     * @return the value
83     */
84    public long getValue() {
85        return getLongBits();
86    }
87}
88