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.rop.cst.CstNat; 20 import com.android.dx.rop.cst.CstType; 21 22 /** 23 * Attribute class for standards-track {@code EnclosingMethod} 24 * attributes. 25 */ 26 public final class AttEnclosingMethod extends BaseAttribute { 27 /** {@code non-null;} attribute name for attributes of this type */ 28 public static final String ATTRIBUTE_NAME = "EnclosingMethod"; 29 30 /** {@code non-null;} the innermost enclosing class */ 31 private final CstType type; 32 33 /** {@code null-ok;} the name-and-type of the innermost enclosing method, if any */ 34 private final CstNat method; 35 36 /** 37 * Constructs an instance. 38 * 39 * @param type {@code non-null;} the innermost enclosing class 40 * @param method {@code null-ok;} the name-and-type of the innermost enclosing 41 * method, if any 42 */ 43 public AttEnclosingMethod(CstType type, CstNat method) { 44 super(ATTRIBUTE_NAME); 45 46 if (type == null) { 47 throw new NullPointerException("type == null"); 48 } 49 50 this.type = type; 51 this.method = method; 52 } 53 54 /** {@inheritDoc} */ 55 @Override 56 public int byteLength() { 57 return 10; 58 } 59 60 /** 61 * Gets the innermost enclosing class. 62 * 63 * @return {@code non-null;} the innermost enclosing class 64 */ 65 public CstType getEnclosingClass() { 66 return type; 67 } 68 69 /** 70 * Gets the name-and-type of the innermost enclosing method, if 71 * any. 72 * 73 * @return {@code null-ok;} the name-and-type of the innermost enclosing 74 * method, if any 75 */ 76 public CstNat getMethod() { 77 return method; 78 } 79 } 80