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.LocalVariableList; 20 import com.android.dx.util.MutabilityException; 21 22 /** 23 * Base attribute class for standard {@code LocalVariableTable} 24 * and {@code LocalVariableTypeTable} attributes. 25 */ 26 public abstract class BaseLocalVariables extends BaseAttribute { 27 /** {@code non-null;} list of local variable entries */ 28 private final LocalVariableList localVariables; 29 30 /** 31 * Constructs an instance. 32 * 33 * @param name {@code non-null;} attribute name 34 * @param localVariables {@code non-null;} list of local variable entries 35 */ BaseLocalVariables(String name, LocalVariableList localVariables)36 public BaseLocalVariables(String name, 37 LocalVariableList localVariables) { 38 super(name); 39 40 try { 41 if (localVariables.isMutable()) { 42 throw new MutabilityException("localVariables.isMutable()"); 43 } 44 } catch (NullPointerException ex) { 45 // Translate the exception. 46 throw new NullPointerException("localVariables == null"); 47 } 48 49 this.localVariables = localVariables; 50 } 51 52 /** {@inheritDoc} */ byteLength()53 public final int byteLength() { 54 return 8 + localVariables.size() * 10; 55 } 56 57 /** 58 * Gets the list of "local variable" entries associated with this instance. 59 * 60 * @return {@code non-null;} the list 61 */ getLocalVariables()62 public final LocalVariableList getLocalVariables() { 63 return localVariables; 64 } 65 } 66