Remove exported everywhere.
[SquirrelJME.git] / modules / tool-classfile / src / main / java / net / multiphasicapps / classfile / InnerClassFlags.java
blob1b95d464e4a0d7084ae4fd93a2e714bc667a3caa
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
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;
15 /**
16 * This represents a set of flags which are used as modifiers to inner classes.
18 * @since 2018/05/15
20 public final class InnerClassFlags
21 extends Flags<InnerClassFlag>
22 implements AccessibleFlags
24 /** Standard class flag representation. */
25 private Reference<ClassFlags> _cflags;
27 /**
28 * Initializes the inner class flags decoding from the specified bit field.
30 * @param __i The bit field to decode flags from.
31 * @since 2018/05/15
33 public InnerClassFlags(int __i)
35 this(Flags.<InnerClassFlag>__decode(__i, InnerClassFlag.values()));
38 /**
39 * Initializes the inner class flags.
41 * @param __fl The inner class flags.
42 * @since 2018/05/15
44 public InnerClassFlags(InnerClassFlag... __fl)
46 super(InnerClassFlag.class, __fl);
48 this.__checkFlags();
51 /**
52 * Initializes the inner class flags.
54 * @param __fl The inner class flags.
55 * @since 2018/05/15
57 public InnerClassFlags(Iterable<InnerClassFlag> __fl)
59 super(InnerClassFlag.class, __fl);
61 this.__checkFlags();
64 /**
65 * Returns the outer class representation for these flags.
67 * @return The outer class flag representation.
68 * @since 2018/05/21
70 public final ClassFlags asClassFlags()
72 Reference<ClassFlags> ref = this._cflags;
73 ClassFlags rv;
75 if (ref == null || null == (rv = ref.get()))
77 int mask = 0;
78 for (InnerClassFlag i : this)
80 ClassFlag v;
81 switch (i)
83 case PUBLIC:
84 v = ClassFlag.PUBLIC;
85 break;
87 case FINAL:
88 v = ClassFlag.FINAL;
89 break;
91 case INTERFACE:
92 v = ClassFlag.INTERFACE;
93 break;
95 case ABSTRACT:
96 v = ClassFlag.ABSTRACT;
97 break;
99 case SYNTHETIC:
100 v = ClassFlag.SYNTHETIC;
101 break;
103 case ANNOTATION:
104 v = ClassFlag.ANNOTATION;
105 break;
107 case ENUM:
108 v = ClassFlag.ENUM;
109 break;
111 default:
112 continue;
115 if (v != null)
116 mask |= v.javaBitMask();
119 this._cflags = new SoftReference<>((rv = new ClassFlags(mask)));
122 return rv;
126 * {@inheritDoc}
127 * @since 2018/05/15
129 @Override
130 public final boolean isPackagePrivate()
132 return !this.isPrivate() && !this.isProtected() && !this.isPublic();
136 * {@inheritDoc}
137 * @since 2018/05/15
139 @Override
140 public final boolean isPrivate()
142 return this.contains(InnerClassFlag.PRIVATE);
146 * {@inheritDoc}
147 * @since 2018/05/15
149 @Override
150 public final boolean isProtected()
152 return this.contains(InnerClassFlag.PROTECTED);
156 * {@inheritDoc}
157 * @since 2018/05/15
159 @Override
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
169 * valid.
170 * @since 2018/05/15
172 private void __checkFlags()
173 throws InvalidClassFormatException
175 // Construct class flags which checks if they are valid
178 this.asClassFlags();
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",
186 this), e);
189 // {@squirreljme.error JC2z Multiple access modifiers, inner classes
190 // can only be one or none of private, protected, or public.
191 // (The flags)}
192 int count = (this.isPublic() ? 1 : 0) +
193 (this.isProtected() ? 1 : 0) +
194 (this.isPrivate() ? 1 : 0);
195 if (count > 1)
196 throw new InvalidClassFormatException(String.format("JC2z %s",
197 this));