Home | History | Annotate | Download | only in attrib
      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.attrib;
     17 
     18 import com.android.dx.cf.code.BootstrapMethodsList;
     19 
     20 /**
     21  * Attribute class for standard {@code AttBootstrapMethods} attributes.
     22  */
     23 public class AttBootstrapMethods extends BaseAttribute {
     24     /** {@code non-null;} attribute name for attributes of this type */
     25     public static final String ATTRIBUTE_NAME = "BootstrapMethods";
     26 
     27     private static final int ATTRIBUTE_HEADER_BYTES = 8;
     28     private static final int BOOTSTRAP_METHOD_BYTES = 4;
     29     private static final int BOOTSTRAP_ARGUMENT_BYTES = 2;
     30 
     31     private final BootstrapMethodsList bootstrapMethods;
     32 
     33     private final int byteLength;
     34 
     35     public AttBootstrapMethods(BootstrapMethodsList bootstrapMethods) {
     36         super(ATTRIBUTE_NAME);
     37         this.bootstrapMethods = bootstrapMethods;
     38 
     39         int bytes = ATTRIBUTE_HEADER_BYTES + bootstrapMethods.size() * BOOTSTRAP_METHOD_BYTES;
     40         for (int i = 0; i < bootstrapMethods.size(); ++i) {
     41             int numberOfArguments = bootstrapMethods.get(i).getBootstrapMethodArguments().size();
     42             bytes += numberOfArguments * BOOTSTRAP_ARGUMENT_BYTES;
     43         }
     44         this.byteLength = bytes;
     45     }
     46 
     47     @Override
     48     public int byteLength() {
     49         return byteLength;
     50     }
     51 
     52     /**
     53      * Get the bootstrap methods present in attribute.
     54      * @return bootstrap methods list
     55      */
     56     public BootstrapMethodsList getBootstrapMethods() {
     57         return bootstrapMethods;
     58     }
     59 }
     60