9 * (the "License"); you may not use this file except in compliance with
10 * the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21 package com.sun.org.apache.bcel.internal.generic;
22
23 /**
24 * DCONST - Push 0.0 or 1.0, other values cause an exception
25 *
26 * <PRE>Stack: ... -> ..., </PRE>
27 *
28 * @version $Id: DCONST.java 1747278 2016-06-07 17:28:43Z britter $
29 */
30 public class DCONST extends Instruction implements ConstantPushInstruction {
31
32 private double value;
33
34
35 /**
36 * Empty constructor needed for the Class.newInstance() statement in
37 * Instruction.readInstruction(). Not to be used otherwise.
38 */
39 DCONST() {
40 }
41
42
43 public DCONST(final double f) {
44 super(com.sun.org.apache.bcel.internal.Const.DCONST_0, (short) 1);
45 if (f == 0.0) {
46 super.setOpcode(com.sun.org.apache.bcel.internal.Const.DCONST_0);
47 } else if (f == 1.0) {
48 super.setOpcode(com.sun.org.apache.bcel.internal.Const.DCONST_1);
49 } else {
50 throw new ClassGenException("DCONST can be used only for 0.0 and 1.0: " + f);
51 }
52 value = f;
53 }
54
55
56 @Override
57 public Number getValue() {
58 return new Double(value);
59 }
60
61
62 /** @return Type.DOUBLE
63 */
64 @Override
65 public Type getType( final ConstantPoolGen cp ) {
66 return Type.DOUBLE;
67 }
68
69
70 /**
71 * Call corresponding visitor method(s). The order is:
72 * Call visitor methods of implemented interfaces first, then
73 * call methods according to the class hierarchy in descending order,
74 * i.e., the most specific visitXXX() call comes last.
75 *
76 * @param v Visitor object
77 */
78 @Override
|
9 * (the "License"); you may not use this file except in compliance with
10 * the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21 package com.sun.org.apache.bcel.internal.generic;
22
23 /**
24 * DCONST - Push 0.0 or 1.0, other values cause an exception
25 *
26 * <PRE>Stack: ... -> ..., </PRE>
27 *
28 * @version $Id: DCONST.java 1747278 2016-06-07 17:28:43Z britter $
29 * @LastModified: Nov 2017
30 */
31 public class DCONST extends Instruction implements ConstantPushInstruction {
32
33 private double value;
34
35
36 /**
37 * Empty constructor needed for the Class.newInstance() statement in
38 * Instruction.readInstruction(). Not to be used otherwise.
39 */
40 DCONST() {
41 }
42
43
44 public DCONST(final double f) {
45 super(com.sun.org.apache.bcel.internal.Const.DCONST_0, (short) 1);
46 if (f == 0.0) {
47 super.setOpcode(com.sun.org.apache.bcel.internal.Const.DCONST_0);
48 } else if (f == 1.0) {
49 super.setOpcode(com.sun.org.apache.bcel.internal.Const.DCONST_1);
50 } else {
51 throw new ClassGenException("DCONST can be used only for 0.0 and 1.0: " + f);
52 }
53 value = f;
54 }
55
56
57 @Override
58 public Number getValue() {
59 return value;
60 }
61
62
63 /** @return Type.DOUBLE
64 */
65 @Override
66 public Type getType( final ConstantPoolGen cp ) {
67 return Type.DOUBLE;
68 }
69
70
71 /**
72 * Call corresponding visitor method(s). The order is:
73 * Call visitor methods of implemented interfaces first, then
74 * call methods according to the class hierarchy in descending order,
75 * i.e., the most specific visitXXX() call comes last.
76 *
77 * @param v Visitor object
78 */
79 @Override
|