AttEnclosingMethod.java revision 99409883d9c4c0ffb49b070ce307bb33a9dfe9f1
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
17package com.android.dx.cf.attrib;
18
19import com.android.dx.rop.cst.CstNat;
20import com.android.dx.rop.cst.CstType;
21
22/**
23 * Attribute class for standards-track {@code EnclosingMethod}
24 * attributes.
25 */
26public 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    public int byteLength() {
56        return 10;
57    }
58
59    /**
60     * Gets the innermost enclosing class.
61     *
62     * @return {@code non-null;} the innermost enclosing class
63     */
64    public CstType getEnclosingClass() {
65        return type;
66    }
67
68    /**
69     * Gets the name-and-type of the innermost enclosing method, if
70     * any.
71     *
72     * @return {@code null-ok;} the name-and-type of the innermost enclosing
73     * method, if any
74     */
75    public CstNat getMethod() {
76        return method;
77    }
78}
79