summaryrefslogtreecommitdiff
path: root/dexgen/src/com/android/dexgen/dex/file/EncodedMember.java
blob: 6c317042b641e9fba0bcb7b95c34afd0881d4a02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.dexgen.dex.file;

import com.android.dexgen.rop.cst.CstUtf8;
import com.android.dexgen.util.AnnotatedOutput;
import com.android.dexgen.util.ToHuman;

import java.io.PrintWriter;

/**
 * Representation of a member (field or method) of a class, for the
 * purposes of encoding it inside a {@link ClassDataItem}.
 */
public abstract class EncodedMember implements ToHuman {
    /** access flags */
    private final int accessFlags;

    /**
     * Constructs an instance.
     *
     * @param accessFlags access flags for the member
     */
    public EncodedMember(int accessFlags) {
        this.accessFlags = accessFlags;
    }

    /**
     * Gets the access flags.
     *
     * @return the access flags
     */
    public final int getAccessFlags() {
        return accessFlags;
    }

    /**
     * Gets the name.
     *
     * @return {@code non-null;} the name
     */
    public abstract CstUtf8 getName();

    /**
     * Does a human-friendly dump of this instance.
     *
     * @param out {@code non-null;} where to dump
     * @param verbose whether to be verbose with the output
     */
    public abstract void debugPrint(PrintWriter out, boolean verbose);

    /**
     * Populates a {@link DexFile} with items from within this instance.
     *
     * @param file {@code non-null;} the file to populate
     */
    public abstract void addContents(DexFile file);

    /**
     * Encodes this instance to the given output.
     *
     * @param file {@code non-null;} file this instance is part of
     * @param out {@code non-null;} where to write to
     * @param lastIndex {@code >= 0;} the previous member index value encoded, or
     * {@code 0} if this is the first element to encode
     * @param dumpSeq {@code >= 0;} sequence number of this instance for
     * annotation purposes
     * @return {@code >= 0;} the member index value that was encoded
     */
    public abstract int encode(DexFile file, AnnotatedOutput out,
            int lastIndex, int dumpSeq);
}