Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.jdi/share/classes/com/sun/tools/jdi/PrimitiveValueImpl.java
41161 views
1
/*
2
* Copyright (c) 1998, 2020, 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package com.sun.tools.jdi;
27
28
import com.sun.jdi.BooleanValue;
29
import com.sun.jdi.ClassNotLoadedException;
30
import com.sun.jdi.InternalException;
31
import com.sun.jdi.InvalidTypeException;
32
import com.sun.jdi.PrimitiveValue;
33
import com.sun.jdi.VirtualMachine;
34
35
public abstract class PrimitiveValueImpl extends ValueImpl
36
implements PrimitiveValue
37
{
38
PrimitiveValueImpl(VirtualMachine aVm) {
39
super(aVm);
40
}
41
42
abstract public boolean booleanValue();
43
abstract public byte byteValue();
44
abstract public char charValue();
45
abstract public short shortValue();
46
abstract public int intValue();
47
abstract public long longValue();
48
abstract public float floatValue();
49
abstract public double doubleValue();
50
51
/*
52
* The checked versions of the value accessors throw
53
* InvalidTypeException if the required conversion is
54
* narrowing and would result in the loss of information
55
* (either magnitude or precision).
56
*
57
* Default implementations here do no checking; subclasses
58
* override as necessary to do the proper checking.
59
*/
60
byte checkedByteValue() throws InvalidTypeException {
61
return byteValue();
62
}
63
char checkedCharValue() throws InvalidTypeException {
64
return charValue();
65
}
66
short checkedShortValue() throws InvalidTypeException {
67
return shortValue();
68
}
69
int checkedIntValue() throws InvalidTypeException {
70
return intValue();
71
}
72
long checkedLongValue() throws InvalidTypeException {
73
return longValue();
74
}
75
float checkedFloatValue() throws InvalidTypeException {
76
return floatValue();
77
}
78
79
final boolean checkedBooleanValue() throws InvalidTypeException {
80
/*
81
* Always disallow a conversion to boolean from any other
82
* primitive
83
*/
84
if (this instanceof BooleanValue) {
85
return booleanValue();
86
} else {
87
throw new InvalidTypeException("Can't convert non-boolean value to boolean");
88
}
89
}
90
91
final double checkedDoubleValue() throws InvalidTypeException {
92
/*
93
* Can't overflow by converting to double, so this method
94
* is never overridden
95
*/
96
return doubleValue();
97
}
98
99
ValueImpl prepareForAssignmentTo(ValueContainer destination)
100
throws InvalidTypeException
101
{
102
return convertForAssignmentTo(destination);
103
}
104
105
ValueImpl convertForAssignmentTo(ValueContainer destination)
106
throws InvalidTypeException
107
{
108
JNITypeParser destSig = new JNITypeParser(destination.signature());
109
JNITypeParser sourceSig = new JNITypeParser(type().signature());
110
111
if (destSig.isReference()) {
112
throw new InvalidTypeException("Can't assign primitive value to object");
113
}
114
115
if (destSig.isBoolean() && !sourceSig.isBoolean()) {
116
throw new InvalidTypeException("Can't assign non-boolean value to a boolean");
117
}
118
119
if (!destSig.isBoolean() && sourceSig.isBoolean()) {
120
throw new InvalidTypeException("Can't assign boolean value to an non-boolean");
121
}
122
123
if (destSig.isVoid()) {
124
throw new InvalidTypeException("Can't assign primitive value to a void");
125
}
126
127
try {
128
PrimitiveTypeImpl primitiveType = (PrimitiveTypeImpl)destination.type();
129
return (ValueImpl)(primitiveType.convert(this));
130
} catch (ClassNotLoadedException e) {
131
throw new InternalException("Signature and type inconsistent for: " +
132
destination.typeName());
133
}
134
}
135
}
136
137