Remove exported everywhere.
[SquirrelJME.git] / modules / tool-classfile / src / main / java / net / multiphasicapps / classfile / ClassVersion.java
blob39766b9cc24ac14607fca828834f38c6a3929646
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 /**
13 * This represents the class version that a class may be.
15 * @since 2016/06/29
17 public enum ClassVersion
19 /** CLDC 1.0 (JSR 30). */
20 CLDC_1((45 << 16) + 3, (47 << 16) - 1, false, false, false),
22 /** CLDC 1.1 (JSR 139). */
23 CLDC_1_1((47 << 16), (51 << 16) - 1, true, false, false),
25 /** CLDC 8 (aka Java 7). */
26 CLDC_8((51 << 16), (52 << 16), true, false, true),
28 /* End. */
31 /** The minimum supported version. */
32 public static final ClassVersion MIN_VERSION = ClassVersion.CLDC_1;
34 /** The maximum supported version. */
35 public static final ClassVersion MAX_VERSION = ClassVersion.CLDC_8;
37 /** The version ID. */
38 protected final int version;
40 /** The maximum range of the version. */
41 protected final int maxversion;
43 /** Has floating point support? */
44 protected final boolean hasfloat;
46 /** Supports invokedynamic? */
47 protected final boolean hasinvokedynamic;
49 /** Use StackMapTable? */
50 protected final boolean usestackmaptable;
52 /**
53 * Initializes the version data.
55 * @param __vid The version ID.
56 * @param __vmx The max version identifier.
57 * @param __float Is floating point supported?
58 * @param __hasid Has invoke dynamic support?
59 * @param __usesmt Should the StackMapTable attribute be used?
60 * @since 2016/03/13
62 ClassVersion(int __vid, int __vmx, boolean __float, boolean __hasid,
63 boolean __usesmt)
65 // Set
66 this.version = __vid;
67 this.maxversion = __vmx;
68 this.hasfloat = __float;
69 this.hasinvokedynamic = __hasid;
70 this.usestackmaptable = __usesmt;
73 /**
74 * Returns {@code true} if floating point is supported by the virtual
75 * machine.
77 * @return {@code true} if it is.
78 * @since 2016/03/13
80 public boolean hasFloatingPoint()
82 return this.hasfloat;
85 /**
86 * Returns {@code true} if invokedynamic is supported by the virtual
87 * machine.
89 * @return {@code true} if it is.
90 * @since 2016/03/15
92 public boolean hasInvokeDynamic()
94 return this.hasinvokedynamic;
97 /**
98 * Should the new StackMapTable attribute be used when veryifying the byte
99 * code of a class?
101 * @return {@code true} if the "StackMapTable" attribute should be parsed
102 * instead of "StackMap".
103 * @since 2016/03/20
105 public boolean useStackMapTable()
107 return this.usestackmaptable;
111 * Finds the best matching version with the given ID.
113 * @param __vid The version ID to get a match for.
114 * @return The matching class version or {@code null} if not found.
115 * @since 2016/03/13
117 public static ClassVersion findVersion(int __vid)
119 // Go through all versions, find the best
120 ClassVersion best = null;
121 for (ClassVersion v : ClassVersion.values())
122 if (__vid >= v.version && __vid <= v.maxversion)
123 if (best == null || v.version > best.version)
124 best = v;
126 // Use the best (if any)
127 return best;