1 /*
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package org.openjdk.asmtools.jasm;
24
25 /*
26 * Class File Version
27 */
28 public class CFVersion implements Cloneable{
29 /**
30 * Default versions of class file
31 */
32 public static final short DEFAULT_MAJOR_VERSION = 45;
33 public static final short DEFAULT_MINOR_VERSION = 3;
34 public static final short DEFAULT_MODULE_MAJOR_VERSION = 53;
35 public static final short DEFAULT_MODULE_MINOR_VERSION = 0;
36 public static final short UNDEFINED_VERSION = -1;
37
38 private short major_version;
39 private short minor_version;
40 private boolean frozen;
41 private boolean isSet;
42
43 public CFVersion() {
44 frozen = false;
45 isSet = false;
46 major_version = UNDEFINED_VERSION;
47 minor_version = UNDEFINED_VERSION;
48 }
49
50 public CFVersion(boolean frozenCFV, short major_version, short minor_version) {
51 isSet = true;
52 frozen = frozenCFV;
53 this.major_version = major_version;
54 this.minor_version = minor_version;
55 }
56
57 public void setMajorVersion(short major_version) {
58 if ( !frozen ) {
59 isSet = true;
60 this.major_version = major_version;
61 }
62 }
63
64 public void setMinorVersion(short minor_version) {
65 if (!frozen) {
66 isSet = true;
67 this.minor_version = minor_version;
68 }
69 }
70
71 public String asString() {
72 return (isSet) ? this.major_version + ":" +this.minor_version : "(undef):(undef)";
73 }
74
75 public void initModuleDefaults() {
76 if( ! isSet) {
77 major_version = DEFAULT_MODULE_MAJOR_VERSION;
78 minor_version = DEFAULT_MODULE_MINOR_VERSION;
79 }
80 }
81
82 public void initClassDefaults() {
83 if( !isSet ) {
84 major_version = DEFAULT_MAJOR_VERSION;
85 minor_version = DEFAULT_MINOR_VERSION;
86 }
87 }
88
89 public short minor_version() {
90 return this.minor_version;
91 }
92
93 public short major_version() {
94 return this.major_version;
95 }
96
97 public CFVersion clone() {
98 try {
99 return (CFVersion)super.clone();
100 } catch (CloneNotSupportedException e) {
101 throw new RuntimeException(e);
102 }
103 }
104 }