summaryrefslogtreecommitdiff
path: root/src/fjbg/ch/epfl/lamp/fjbg/JField.java
blob: 314ed708051946456b27035652ec8c3389d1fb86 (plain) (blame)
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
/* FJBG -- Fast Java Bytecode Generator
 * Copyright 2002-2012 LAMP/EPFL
 * @author  Michel Schinz
 */

package ch.epfl.lamp.fjbg;

import java.io.DataInputStream;
import java.io.IOException;

/**
 * Java class field.
 *
 * @author Michel Schinz
 * @version 1.0
 */

public class JField extends JFieldOrMethod {

    protected JField(FJBGContext context,
                     JClass owner,
                     int accessFlags,
                     String name,
                     JType type) {
        super(context, owner, accessFlags, name, type);
    }

    protected JField(FJBGContext context,
                     JClass owner,
                     DataInputStream stream)
        throws IOException {
        super(context, owner, stream);
    }

    // Follows javap output format for fields.
    /*@Override*/ public String toString() {
        StringBuffer buf = new StringBuffer(flagsToString());
        buf.append(toExternalName(getType()));
        buf.append(" ");
        buf.append(getName());
        buf.append(";\n");
        java.util.Iterator attrsIt = attributes.iterator();
        while (attrsIt.hasNext()) {
            JAttribute attrs = (JAttribute)attrsIt.next();
            buf.append(attrs);
        }
        return buf.toString();
    }

    private String flagsToString() {
        StringBuffer buf = new StringBuffer();
        if (isPublic()) buf.append("public ");
        else if (isProtected()) buf.append("protected ");
        else if (isPrivate()) buf.append("private ");
        if (isStatic()) buf.append("static ");
        else if (isTransient()) buf.append("transient ");
        else if (isVolatile()) buf.append("volatile ");
        if (isAbstract()) buf.append("abstract ");
        else if (isFinal()) buf.append("final ");
        return buf.toString();
    }
}