/
FieldFlags.java
198 lines (176 loc) · 4.19 KB
/
FieldFlags.java
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// Copyright (C) Multi-Phasic Applications <multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
package net.multiphasicapps.classfile;
/**
* This represent the set of flags for fields.
*
* @since 2016/04/23
*/
public final class FieldFlags
extends MemberFlags<FieldFlag>
implements AccessibleFlags
{
/**
* Initializes the field flags.
*
* @param __oc The outer class.
* @param __fl The field flags.
* @since 2016/04/23
*/
public FieldFlags(ClassFlags __oc, FieldFlag... __fl)
{
super(FieldFlag.class, __fl);
__checkFlags(__oc);
}
/**
* Initializes the field flags.
*
* @param __oc The outer class.
* @param __fl The field flags.
* @since 2016/04/23
*/
public FieldFlags(ClassFlags __oc, Iterable<FieldFlag> __fl)
{
super(FieldFlag.class, __fl);
__checkFlags(__oc);
}
/**
* Decodes field flags from the bit field.
*
* @param __oc The outer class flags.
* @param __i The bitfield to decode.
* @since 2017/07/07
*/
public FieldFlags(ClassFlags __oc, int __i)
{
this(__oc, Flags.<FieldFlag>__decode(__i, FieldFlag.values()));
}
/**
* Returns {@code true} if this is an enumeration.
*
* @return {@code true} if an enumeration.
* @since 2016/03/20
*/
public boolean isEnum()
{
return contains(FieldFlag.ENUM);
}
/**
* {@inheritDoc}
* @since 2016/03/20
*/
@Override
public boolean isFinal()
{
return contains(FieldFlag.FINAL);
}
/**
* {@inheritDoc}
* @since 2016/03/20
*/
@Override
public boolean isPrivate()
{
return contains(FieldFlag.PRIVATE);
}
/**
* {@inheritDoc}
* @since 2016/03/20
*/
@Override
public boolean isProtected()
{
return contains(FieldFlag.PROTECTED);
}
/**
* {@inheritDoc}
* @since 2016/03/20
*/
@Override
public boolean isPublic()
{
return contains(FieldFlag.PUBLIC);
}
/**
* {@inheritDoc}
* @since 2016/03/20
*/
@Override
public boolean isStatic()
{
return contains(FieldFlag.STATIC);
}
/**
* {@inheritDoc}
* @since 2016/03/20
*/
@Override
public boolean isSynthetic()
{
return contains(FieldFlag.SYNTHETIC);
}
/**
* Returns {@code true} if this is transient.
*
* @return {@code true} if transient.
* @since 2016/03/20
*/
public boolean isTransient()
{
return contains(FieldFlag.TRANSIENT);
}
/**
* Returns {@code true} if this is volatile.
*
* @return {@code true} if volatile.
* @since 2016/03/20
*/
public boolean isVolatile()
{
return contains(FieldFlag.VOLATILE);
}
/**
* Checks that the given flags are valid.
*
* @param __oc The outer class.
* @throws InvalidClassFormatException If they are not valid.
* @throws NullPointerException On null arguments.
* @since 2016/04/23
*/
private final void __checkFlags(ClassFlags __oc)
throws InvalidClassFormatException, NullPointerException
{
// Check
if (__oc == null)
throw new NullPointerException("NARG");
// {@squirreljme.error JC0v A field cannot be both {@code final} and
// {@code volatile}. (The field flags)}
if (isFinal() && isVolatile())
throw new InvalidClassFormatException(
String.format("JC0v %s", this));
// If the class is an interface, some flags cannot be set
if (__oc.isInterface())
for (FieldFlag f : FieldFlag.values())
{
// Must have these
boolean must = (f == FieldFlag.PUBLIC ||
f == FieldFlag.STATIC || f == FieldFlag.FINAL);
// Could have these
boolean maybe = (f == FieldFlag.SYNTHETIC);
// Is it set?
boolean has = contains(f);
// {@squirreljme.error JC0w Flags for interface field has an
// incorrect set of flags. (The field flags)}
if (must != has && !maybe)
throw new InvalidClassFormatException(
String.format("JC0w %s", this));
}
}
}