/
ClassFlags.java
213 lines (191 loc) · 4.42 KB
/
ClassFlags.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// -*- 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;
import java.util.ArrayList;
import java.util.List;
/**
* This represents the flags which a class may be.
*
* @since 2016/04/23
*/
public class ClassFlags
extends Flags<ClassFlag>
implements AccessibleFlags
{
/**
* Initializes the class flags decoding from the specified bit field.
*
* @param __i The bit field to decode flags from.
* @since 2017/06/13
*/
public ClassFlags(int __i)
{
this(Flags.<ClassFlag>__decode(__i, ClassFlag.values()));
}
/**
* Initializes the class flags.
*
* @param __fl The class flags.
* @since 2016/04/23
*/
public ClassFlags(ClassFlag... __fl)
{
super(ClassFlag.class, __fl);
__checkFlags();
}
/**
* Initializes the class flags.
*
* @param __fl The class flags.
* @since 2016/04/23
*/
public ClassFlags(Iterable<ClassFlag> __fl)
{
super(ClassFlag.class, __fl);
__checkFlags();
}
/**
* Is this class abstract?
*
* @return {@code true} if it is abstract.
* @since 2016/03/15
*/
public final boolean isAbstract()
{
return contains(ClassFlag.ABSTRACT);
}
/**
* Is this an annotation?
*
* @return {@code true} if it is an annotation.
* @since 2016/03/15
*/
public final boolean isAnnotation()
{
return contains(ClassFlag.ANNOTATION);
}
/**
* Is this an enumeration?
*
* @return {@code true} if it is an enumeration.
* @since 2016/03/15
*/
public final boolean isEnum()
{
return contains(ClassFlag.ENUM);
}
/**
* Is this class final?
*
* @return {@code true} if it is final.
* @since 2016/03/15
*/
public final boolean isFinal()
{
return contains(ClassFlag.FINAL);
}
/**
* Is this an interface?
*
* @return {@code true} if an interface.
* @since 2016/03/15
*/
public final boolean isInterface()
{
return contains(ClassFlag.INTERFACE);
}
/**
* {@inheritDoc}
* @since 2016/03/15
*/
@Override
public final boolean isPackagePrivate()
{
return !isPublic();
}
/**
* {@inheritDoc}
* @since 2016/05/12
*/
@Override
public final boolean isPrivate()
{
// Classes are never private
return false;
}
/**
* {@inheritDoc}
* @since 2016/05/12
*/
@Override
public final boolean isProtected()
{
// Classes are never protected
return false;
}
/**
* {@inheritDoc}
* @since 2016/03/15
*/
@Override
public final boolean isPublic()
{
return contains(ClassFlag.PUBLIC);
}
/**
* Is there special handling for super-class method calls?
*
* @return {@code true} if the super-class invocation special flag is set.
* @since 2016/03/15
*/
public final boolean isSpecialInvokeSpecial()
{
return contains(ClassFlag.SUPER);
}
/**
* Checks that the given flags are valid.
*
* @throws InvalidClassFormatException If they are not valid.
* @since 2016/04/23
*/
private final void __checkFlags()
throws InvalidClassFormatException
{
// Interface?
if (isInterface())
{
// {@squirreljme.error JC0i An interface must also be abstract.
// (The class flags)}
if (!isAbstract())
throw new InvalidClassFormatException(
String.format("JC0i %s", this));
// {@squirreljme.error JC0j An interface cannot be {@code final} or
// {@code enum} and it must not have the special flag set. (The
// class flags)}
if (isFinal() || isSpecialInvokeSpecial() || isEnum())
throw new InvalidClassFormatException(
String.format("JC0j %s", this));
}
// Normal class
else
{
// {@squirreljme.error JC0k Annotations must be interfaces. (The
// class flags)}
if (isAnnotation())
throw new InvalidClassFormatException(
String.format("JC0k %s", this));
// {@squirreljme.error JC0l A class cannot be both {@code abstract}
// and {@code final}. (The class flags)}
if (isAbstract() && isFinal())
throw new InvalidClassFormatException(
String.format("JC0l %s", this));
}
}
}