1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package net
.multiphasicapps
.classfile
;
12 import java
.lang
.ref
.Reference
;
13 import java
.lang
.ref
.SoftReference
;
16 * This represents a set of flags which are used as modifiers to inner classes.
20 public final class InnerClassFlags
21 extends Flags
<InnerClassFlag
>
22 implements AccessibleFlags
24 /** Standard class flag representation. */
25 private Reference
<ClassFlags
> _cflags
;
28 * Initializes the inner class flags decoding from the specified bit field.
30 * @param __i The bit field to decode flags from.
33 public InnerClassFlags(int __i
)
35 this(Flags
.<InnerClassFlag
>__decode(__i
, InnerClassFlag
.values()));
39 * Initializes the inner class flags.
41 * @param __fl The inner class flags.
44 public InnerClassFlags(InnerClassFlag
... __fl
)
46 super(InnerClassFlag
.class, __fl
);
52 * Initializes the inner class flags.
54 * @param __fl The inner class flags.
57 public InnerClassFlags(Iterable
<InnerClassFlag
> __fl
)
59 super(InnerClassFlag
.class, __fl
);
65 * Returns the outer class representation for these flags.
67 * @return The outer class flag representation.
70 public final ClassFlags
asClassFlags()
72 Reference
<ClassFlags
> ref
= this._cflags
;
75 if (ref
== null || null == (rv
= ref
.get()))
78 for (InnerClassFlag i
: this)
92 v
= ClassFlag
.INTERFACE
;
96 v
= ClassFlag
.ABSTRACT
;
100 v
= ClassFlag
.SYNTHETIC
;
104 v
= ClassFlag
.ANNOTATION
;
116 mask
|= v
.javaBitMask();
119 this._cflags
= new SoftReference
<>((rv
= new ClassFlags(mask
)));
130 public final boolean isPackagePrivate()
132 return !this.isPrivate() && !this.isProtected() && !this.isPublic();
140 public final boolean isPrivate()
142 return this.contains(InnerClassFlag
.PRIVATE
);
150 public final boolean isProtected()
152 return this.contains(InnerClassFlag
.PROTECTED
);
160 public final boolean isPublic()
162 return this.contains(InnerClassFlag
.PUBLIC
);
166 * Checks that the inner class flags are valid.
168 * @throws InvalidClassFormatException If the inner class flags are not
172 private void __checkFlags()
173 throws InvalidClassFormatException
175 // Construct class flags which checks if they are valid
180 catch (InvalidClassFormatException e
)
182 // {@squirreljme.error JC2y Inner class flags are not valid
183 // because they would produce invalid standard outer class
184 // flags. (The flags)}
185 throw new InvalidClassFormatException(String
.format("JC2y %s",
189 // {@squirreljme.error JC2z Multiple access modifiers, inner classes
190 // can only be one or none of private, protected, or public.
192 int count
= (this.isPublic() ?
1 : 0) +
193 (this.isProtected() ?
1 : 0) +
194 (this.isPrivate() ?
1 : 0);
196 throw new InvalidClassFormatException(String
.format("JC2z %s",