Home | History | Annotate | Download | only in code
      1 /*
      2  * Copyright (C) 2017 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 package com.android.dx.cf.code;
     17 
     18 import com.android.dx.rop.cst.Constant;
     19 import com.android.dx.rop.cst.CstDouble;
     20 import com.android.dx.rop.cst.CstFloat;
     21 import com.android.dx.rop.cst.CstInteger;
     22 import com.android.dx.rop.cst.CstLong;
     23 import com.android.dx.rop.cst.CstMethodHandle;
     24 import com.android.dx.rop.cst.CstProtoRef;
     25 import com.android.dx.rop.cst.CstString;
     26 import com.android.dx.rop.cst.CstType;
     27 import com.android.dx.util.FixedSizeList;
     28 
     29 /**
     30  * List of bootstrap method arguments, which are part of the contents of
     31  * {@code BootstrapMethods} attributes.
     32  */
     33 public class BootstrapMethodArgumentsList extends FixedSizeList {
     34     /**
     35      * Constructs an instance.
     36      *
     37      * @param count the number of elements to be in the list
     38      */
     39     public BootstrapMethodArgumentsList(int count) {
     40         super(count);
     41     }
     42 
     43     /**
     44      * Gets the bootstrap argument from the indicated position.
     45      *
     46      * @param n position of argument to get
     47      * @return {@code Constant} instance
     48      */
     49     public Constant get(int n) {
     50         return (Constant) get0(n);
     51     }
     52 
     53     /**
     54      * Sets the bootstrap argument at the indicated position.
     55      *
     56      * @param n position of argument to set
     57      * @param cst {@code Constant} instance
     58      */
     59     public void set(int n, Constant cst) {
     60         // The set of permitted types is defined by the JVMS 8, section 4.7.23.
     61         if (cst instanceof CstString ||
     62             cst instanceof CstType ||
     63             cst instanceof CstInteger ||
     64             cst instanceof CstLong ||
     65             cst instanceof CstFloat ||
     66             cst instanceof CstDouble ||
     67             cst instanceof CstMethodHandle ||
     68             cst instanceof CstProtoRef) {
     69             set0(n, cst);
     70         } else {
     71             Class<?> klass = cst.getClass();
     72             throw new IllegalArgumentException("bad type for bootstrap argument: " + klass);
     73         }
     74     }
     75 }
     76