Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/tools/jdi/PrimitiveValueImpl.java
38920 views
/*1* Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.tools.jdi;2627import com.sun.jdi.*;2829public abstract class PrimitiveValueImpl extends ValueImpl30implements PrimitiveValue {3132PrimitiveValueImpl(VirtualMachine aVm) {33super(aVm);34}3536abstract public boolean booleanValue();37abstract public byte byteValue();38abstract public char charValue();39abstract public short shortValue();40abstract public int intValue();41abstract public long longValue();42abstract public float floatValue();43abstract public double doubleValue();4445/*46* The checked versions of the value accessors throw47* InvalidTypeException if the required conversion is48* narrowing and would result in the loss of information49* (either magnitude or precision).50*51* Default implementations here do no checking; subclasses52* override as necessary to do the proper checking.53*/54byte checkedByteValue() throws InvalidTypeException {55return byteValue();56}57char checkedCharValue() throws InvalidTypeException {58return charValue();59}60short checkedShortValue() throws InvalidTypeException {61return shortValue();62}63int checkedIntValue() throws InvalidTypeException {64return intValue();65}66long checkedLongValue() throws InvalidTypeException {67return longValue();68}69float checkedFloatValue() throws InvalidTypeException {70return floatValue();71}7273final boolean checkedBooleanValue() throws InvalidTypeException {74/*75* Always disallow a conversion to boolean from any other76* primitive77*/78if (this instanceof BooleanValue) {79return booleanValue();80} else {81throw new InvalidTypeException("Can't convert non-boolean value to boolean");82}83}8485final double checkedDoubleValue() throws InvalidTypeException {86/*87* Can't overflow by converting to double, so this method88* is never overridden89*/90return doubleValue();91}9293ValueImpl prepareForAssignmentTo(ValueContainer destination)94throws InvalidTypeException {9596return convertForAssignmentTo(destination);97}9899ValueImpl convertForAssignmentTo(ValueContainer destination)100throws InvalidTypeException {101102/*103* TO DO: Centralize JNI signature knowledge104*/105if (destination.signature().length() > 1) {106throw new InvalidTypeException("Can't assign primitive value to object");107}108109if ((destination.signature().charAt(0) == 'Z') &&110(type().signature().charAt(0) != 'Z')) {111throw new InvalidTypeException("Can't assign non-boolean value to a boolean");112}113114if ((destination.signature().charAt(0) != 'Z') &&115(type().signature().charAt(0) == 'Z')) {116throw new InvalidTypeException("Can't assign boolean value to an non-boolean");117}118119if ("void".equals(destination.typeName())) {120throw new InvalidTypeException("Can't assign primitive value to a void");121}122123try {124PrimitiveTypeImpl primitiveType = (PrimitiveTypeImpl)destination.type();125return (ValueImpl)(primitiveType.convert(this));126} catch (ClassNotLoadedException e) {127throw new InternalException("Signature and type inconsistent for: " +128destination.typeName());129}130}131}132133134