1579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson/*
2579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * Copyright (C) 2007 The Android Open Source Project
3579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson *
4579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * Licensed under the Apache License, Version 2.0 (the "License");
5579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * you may not use this file except in compliance with the License.
6579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * You may obtain a copy of the License at
7579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson *
8579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson *      http://www.apache.org/licenses/LICENSE-2.0
9579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson *
10579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * Unless required by applicable law or agreed to in writing, software
11579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS,
12579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * See the License for the specific language governing permissions and
14579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * limitations under the License.
15579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */
16579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson
17579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilsonpackage com.android.dx.rop.cst;
18579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson
19579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson/**
20579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * Interface for constant pools, which are, more or less, just lists of
21579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@link Constant} objects.
22579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */
23579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilsonpublic interface ConstantPool {
24579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson    /**
25579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * Get the "size" of the constant pool. This corresponds to the
26579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * class file field {@code constant_pool_count}, and is in fact
27579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * always at least one more than the actual size of the constant pool,
28579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * as element {@code 0} is always invalid.
29579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     *
30579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * @return {@code >= 1;} the size
31579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     */
32579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson    public int size();
33579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson
34579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson    /**
35579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * Get the {@code n}th entry in the constant pool, which must
36579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * be valid.
37579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     *
38579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * @param n {@code n >= 0, n < size();} the constant pool index
39579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * @return {@code non-null;} the corresponding entry
40579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * @throws IllegalArgumentException thrown if {@code n} is
41579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * in-range but invalid
42579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     */
43579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson    public Constant get(int n);
44579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson
45579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson    /**
46579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * Get the {@code n}th entry in the constant pool, which must
47579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * be valid unless {@code n == 0}, in which case {@code null}
48579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * is returned.
49579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     *
50579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * @param n {@code n >= 0, n < size();} the constant pool index
51579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * @return {@code null-ok;} the corresponding entry, if {@code n != 0}
52579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * @throws IllegalArgumentException thrown if {@code n} is
53579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * in-range and non-zero but invalid
54579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     */
55579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson    public Constant get0Ok(int n);
56579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson
57579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson    /**
58579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * Get the {@code n}th entry in the constant pool, or
59579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * {@code null} if the index is in-range but invalid. In
60579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * particular, {@code null} is returned for index {@code 0}
61579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * as well as the index after any entry which is defined to take up
62579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * two slots (that is, {@code Long} and {@code Double}
63579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * entries).
64579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     *
65579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * @param n {@code n >= 0, n < size();} the constant pool index
66579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * @return {@code null-ok;} the corresponding entry, or {@code null} if
67579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     * the index is in-range but invalid
68579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson     */
69579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson    public Constant getOrNull(int n);
70579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson}
71