Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/share/options/OptionDefinition.java
41155 views
1
/*
2
* Copyright (c) 2011, 2018, 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 vm.share.options;
24
25
import java.util.Map;
26
import java.util.HashMap;
27
import java.lang.reflect.Field;
28
import nsk.share.TestBug;
29
30
/**
31
* This is a "value" class for holding information about the defined options.
32
*/
33
public final class OptionDefinition {
34
private static final Map<String, OptionObjectFactory> factories = new HashMap<String, OptionObjectFactory>();
35
private String prefix;
36
private String name;
37
private String description;
38
private String defaultValue;
39
private Class<? extends OptionObjectFactory> factory;
40
private Field field;
41
private Object owner;
42
43
public OptionDefinition(String prefix, String name, String description, String defaultValue, Class<? extends OptionObjectFactory> factory, Field field, Object owner) {
44
this.prefix = prefix;
45
this.name = name;
46
this.description = description;
47
this.defaultValue = defaultValue;
48
this.factory = factory;
49
this.field = field;
50
this.owner = owner;
51
}
52
53
public String getPrefix() {
54
return prefix;
55
}
56
57
public String getName() {
58
return name;
59
}
60
61
public String getFullName() {
62
if (prefix != null)
63
return prefix + "." + name;
64
else
65
return name;
66
}
67
68
public Field getField() {
69
return field;
70
}
71
72
public Object getOwner() {
73
return owner;
74
}
75
76
public String getDescription() {
77
if (hasFactory())
78
if (description == null)
79
return getFactory().getDescription();
80
return description;
81
}
82
83
public String getDefaultValue() {
84
if (hasFactory())
85
if (defaultValue == null)
86
return getFactory().getDefaultValue();
87
return defaultValue;
88
}
89
90
public boolean hasFactory() {
91
return factory != null;
92
}
93
94
public String getPlaceHolder() {
95
if (hasFactory())
96
return getFactory().getPlaceholder();
97
else
98
return getField().getType().toString();
99
}
100
101
public synchronized OptionObjectFactory getFactory() {
102
if (factory == null)
103
throw new TestBug("Called getFactory() on OptionDefinition with unset factory");
104
OptionObjectFactory factory = factories.get(this.factory);
105
if (factory == null) {
106
try {
107
factory = this.factory.newInstance();
108
} catch (InstantiationException ex) {
109
throw new TestBug("Failed to instantiate factory " + this.factory, ex);
110
} catch (IllegalAccessException ex) {
111
throw new TestBug("Failed to instantiate factory " + this.factory, ex);
112
}
113
}
114
return factory;
115
}
116
117
public String toString() {
118
return "Option " + name + " field " + field + " object " + owner;
119
}
120
}
121
122