summaryrefslogtreecommitdiff
path: root/src/msil/ch/epfl/lamp/compiler/msil/FieldInfo.java
blob: bd08e4a3e1a3d1a9e64485d55edd6ad5bb4a6540 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
 */

// $Id$

package ch.epfl.lamp.compiler.msil;

/**
 * Discovers the attributes of a field and provides access to field metadata.
 *
 * @author Nikolay Mihaylov
 * @version 1.0
 */
public class FieldInfo extends MemberInfo {

    //##########################################################################
    // public interface

    public final int MemberType() { return MemberTypes.Field; }

    /** Attributes associated with this field. */
    public final short Attributes;

    /** Type of the field represented by this FieldInfo object. */
    public final Type FieldType;

    protected final Object value;

    public final boolean IsStatic() {
	return (Attributes & FieldAttributes.Static)   != 0;
    }

    public final boolean IsInitOnly() {
	return (Attributes & FieldAttributes.InitOnly) != 0;
    }

    public final boolean IsLiteral() {
 	return (Attributes & FieldAttributes.Literal) != 0;

    }

    public final boolean IsPublic() {
	return (Attributes & FieldAttributes.FieldAccessMask)
	    == FieldAttributes.Public;
    }

    public final boolean IsPrivate() {
	return (Attributes & FieldAttributes.FieldAccessMask)
	    == FieldAttributes.Private;
    }

    public final boolean IsFamily() {
	return (Attributes & FieldAttributes.FieldAccessMask)
	    == FieldAttributes.Family;
    }

    public final boolean IsAssembly() {
	return (Attributes & FieldAttributes.FieldAccessMask)
	    == FieldAttributes.Assembly;
    }

    public final boolean IsFamilyOrAssembly() {
	return (Attributes & FieldAttributes.FieldAccessMask)
	    == FieldAttributes.FamORAssem;
    }

    public final boolean IsFamilyAndAssembly() {
	return (Attributes & FieldAttributes.FieldAccessMask)
	    == FieldAttributes.FamANDAssem;
    }
    public final boolean IsSpecialName() {
 	return (Attributes & FieldAttributes.SpecialName) != 0;
    }

    public final boolean IsPinvokeImpl() {
 	return (Attributes & FieldAttributes.PinvokeImpl) != 0;
    }

    public final boolean IsNotSerialized() {
 	return (Attributes & FieldAttributes.NotSerialized) != 0;
    }

    public String toString() {
	return FieldAttributes.toString(Attributes) + " " +
	    FieldType + " " + DeclaringType.FullName + "::" +  Name;
    }

    //##########################################################################

    protected static final FieldInfo[] EMPTY_ARRAY = new FieldInfo[0];

    /** Initializes a new instance of the FieldInfo class. */
    protected FieldInfo(String name, Type declType, int attrs, Type fieldType) {
	this(name, declType, attrs, fieldType, null);
    }

    protected FieldInfo(String name, Type declType,
			int attrs, Type fieldType, Object value)
    {
	super(name, declType);
	FieldType = fieldType;
	Attributes = (short) attrs;
	this.value = value;
    }

    /**
     */
    public Object getValue() { return value; }

    //##########################################################################

}  // class FieldInfo