Home | History | Annotate | Download | only in cst
      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 /**
     20  * Interface for constant pools, which are, more or less, just lists of
     21  * {@link Constant} objects.
     22  */
     23 public interface ConstantPool {
     24     /**
     25      * Get the "size" of the constant pool. This corresponds to the
     26      * class file field {@code constant_pool_count}, and is in fact
     27      * always at least one more than the actual size of the constant pool,
     28      * as element {@code 0} is always invalid.
     29      *
     30      * @return {@code >= 1;} the size
     31      */
     32     public int size();
     33 
     34     /**
     35      * Get the {@code n}th entry in the constant pool, which must
     36      * be valid.
     37      *
     38      * @param n {@code n >= 0, n < size();} the constant pool index
     39      * @return {@code non-null;} the corresponding entry
     40      * @throws IllegalArgumentException thrown if {@code n} is
     41      * in-range but invalid
     42      */
     43     public Constant get(int n);
     44 
     45     /**
     46      * Get the {@code n}th entry in the constant pool, which must
     47      * be valid unless {@code n == 0}, in which case {@code null}
     48      * is returned.
     49      *
     50      * @param n {@code n >= 0, n < size();} the constant pool index
     51      * @return {@code null-ok;} the corresponding entry, if {@code n != 0}
     52      * @throws IllegalArgumentException thrown if {@code n} is
     53      * in-range and non-zero but invalid
     54      */
     55     public Constant get0Ok(int n);
     56 
     57     /**
     58      * Get the {@code n}th entry in the constant pool, or
     59      * {@code null} if the index is in-range but invalid. In
     60      * particular, {@code null} is returned for index {@code 0}
     61      * as well as the index after any entry which is defined to take up
     62      * two slots (that is, {@code Long} and {@code Double}
     63      * entries).
     64      *
     65      * @param n {@code n >= 0, n < size();} the constant pool index
     66      * @return {@code null-ok;} the corresponding entry, or {@code null} if
     67      * the index is in-range but invalid
     68      */
     69     public Constant getOrNull(int n);
     70 
     71     /**
     72      * Get all entries in this constant pool.
     73      *
     74      * @return the returned array may contain null entries.
     75      */
     76     public Constant[] getEntries();
     77 }
     78