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