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.dex.file;
18
19import com.android.dx.rop.cst.CstString;
20import com.android.dx.util.AnnotatedOutput;
21import com.android.dx.util.ToHuman;
22
23import java.io.PrintWriter;
24
25/**
26 * Representation of a member (field or method) of a class, for the
27 * purposes of encoding it inside a {@link ClassDataItem}.
28 */
29public abstract class EncodedMember implements ToHuman {
30    /** access flags */
31    private final int accessFlags;
32
33    /**
34     * Constructs an instance.
35     *
36     * @param accessFlags access flags for the member
37     */
38    public EncodedMember(int accessFlags) {
39        this.accessFlags = accessFlags;
40    }
41
42    /**
43     * Gets the access flags.
44     *
45     * @return the access flags
46     */
47    public final int getAccessFlags() {
48        return accessFlags;
49    }
50
51    /**
52     * Gets the name.
53     *
54     * @return {@code non-null;} the name
55     */
56    public abstract CstString getName();
57
58    /**
59     * Does a human-friendly dump of this instance.
60     *
61     * @param out {@code non-null;} where to dump
62     * @param verbose whether to be verbose with the output
63     */
64    public abstract void debugPrint(PrintWriter out, boolean verbose);
65
66    /**
67     * Populates a {@link DexFile} with items from within this instance.
68     *
69     * @param file {@code non-null;} the file to populate
70     */
71    public abstract void addContents(DexFile file);
72
73    /**
74     * Encodes this instance to the given output.
75     *
76     * @param file {@code non-null;} file this instance is part of
77     * @param out {@code non-null;} where to write to
78     * @param lastIndex {@code >= 0;} the previous member index value encoded, or
79     * {@code 0} if this is the first element to encode
80     * @param dumpSeq {@code >= 0;} sequence number of this instance for
81     * annotation purposes
82     * @return {@code >= 0;} the member index value that was encoded
83     */
84    public abstract int encode(DexFile file, AnnotatedOutput out,
85            int lastIndex, int dumpSeq);
86}
87