Home | History | Annotate | Download | only in attrib
      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.cf.attrib;
     18 
     19 import com.android.dx.cf.code.LineNumberList;
     20 import com.android.dx.util.MutabilityException;
     21 
     22 /**
     23  * Attribute class for standard {@code LineNumberTable} attributes.
     24  */
     25 public final class AttLineNumberTable extends BaseAttribute {
     26     /** {@code non-null;} attribute name for attributes of this type */
     27     public static final String ATTRIBUTE_NAME = "LineNumberTable";
     28 
     29     /** {@code non-null;} list of line number entries */
     30     private final LineNumberList lineNumbers;
     31 
     32     /**
     33      * Constructs an instance.
     34      *
     35      * @param lineNumbers {@code non-null;} list of line number entries
     36      */
     37     public AttLineNumberTable(LineNumberList lineNumbers) {
     38         super(ATTRIBUTE_NAME);
     39 
     40         try {
     41             if (lineNumbers.isMutable()) {
     42                 throw new MutabilityException("lineNumbers.isMutable()");
     43             }
     44         } catch (NullPointerException ex) {
     45             // Translate the exception.
     46             throw new NullPointerException("lineNumbers == null");
     47         }
     48 
     49         this.lineNumbers = lineNumbers;
     50     }
     51 
     52     /** {@inheritDoc} */
     53     public int byteLength() {
     54         return 8 + 4 * lineNumbers.size();
     55     }
     56 
     57     /**
     58      * Gets the list of "line number" entries associated with this instance.
     59      *
     60      * @return {@code non-null;} the list
     61      */
     62     public LineNumberList getLineNumbers() {
     63         return lineNumbers;
     64     }
     65 }
     66