author | joehw |
Sun, 13 Aug 2017 21:10:40 -0700 | |
changeset 46174 | 5611d2529b49 |
parent 45853 | bfa06be36a17 |
permissions | -rw-r--r-- |
6 | 1 |
/* |
45853
bfa06be36a17
8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents:
44797
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
6 | 3 |
*/ |
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
4 |
/* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
5 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
6 |
* contributor license agreements. See the NOTICE file distributed with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
7 |
* this work for additional information regarding copyright ownership. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
8 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
9 |
* (the "License"); you may not use this file except in compliance with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
10 |
* the License. You may obtain a copy of the License at |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
11 |
* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
13 |
* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
14 |
* Unless required by applicable law or agreed to in writing, software |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS, |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
17 |
* See the License for the specific language governing permissions and |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
18 |
* limitations under the License. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
19 |
*/ |
6 | 20 |
|
21 |
package com.sun.org.apache.bcel.internal.classfile; |
|
22 |
||
46174 | 23 |
import java.io.DataInput; |
24 |
import java.io.DataOutputStream; |
|
25 |
import java.io.IOException; |
|
6 | 26 |
|
46174 | 27 |
import com.sun.org.apache.bcel.internal.Const; |
6 | 28 |
|
29 |
/** |
|
46174 | 30 |
* This class is derived from the abstract {@link Constant} |
6 | 31 |
* and represents a reference to an int object. |
32 |
* |
|
46174 | 33 |
* @version $Id: ConstantInteger.java 1747278 2016-06-07 17:28:43Z britter $ |
6 | 34 |
* @see Constant |
35 |
*/ |
|
36 |
public final class ConstantInteger extends Constant implements ConstantObject { |
|
46174 | 37 |
|
38 |
private int bytes; |
|
39 |
||
6 | 40 |
|
46174 | 41 |
/** |
42 |
* @param bytes Data |
|
43 |
*/ |
|
44 |
public ConstantInteger(final int bytes) { |
|
45 |
super(Const.CONSTANT_Integer); |
|
46 |
this.bytes = bytes; |
|
47 |
} |
|
48 |
||
49 |
||
50 |
/** |
|
51 |
* Initialize from another object. |
|
52 |
*/ |
|
53 |
public ConstantInteger(final ConstantInteger c) { |
|
54 |
this(c.getBytes()); |
|
55 |
} |
|
56 |
||
6 | 57 |
|
46174 | 58 |
/** |
59 |
* Initialize instance from file data. |
|
60 |
* |
|
61 |
* @param file Input stream |
|
62 |
* @throws IOException |
|
63 |
*/ |
|
64 |
ConstantInteger(final DataInput file) throws IOException { |
|
65 |
this(file.readInt()); |
|
66 |
} |
|
67 |
||
6 | 68 |
|
46174 | 69 |
/** |
70 |
* Called by objects that are traversing the nodes of the tree implicitely |
|
71 |
* defined by the contents of a Java class. I.e., the hierarchy of methods, |
|
72 |
* fields, attributes, etc. spawns a tree of objects. |
|
73 |
* |
|
74 |
* @param v Visitor object |
|
75 |
*/ |
|
76 |
@Override |
|
77 |
public void accept( final Visitor v ) { |
|
78 |
v.visitConstantInteger(this); |
|
79 |
} |
|
80 |
||
6 | 81 |
|
46174 | 82 |
/** |
83 |
* Dump constant integer to file stream in binary format. |
|
84 |
* |
|
85 |
* @param file Output file stream |
|
86 |
* @throws IOException |
|
87 |
*/ |
|
88 |
@Override |
|
89 |
public final void dump( final DataOutputStream file ) throws IOException { |
|
90 |
file.writeByte(super.getTag()); |
|
91 |
file.writeInt(bytes); |
|
92 |
} |
|
6 | 93 |
|
46174 | 94 |
|
95 |
/** |
|
96 |
* @return data, i.e., 4 bytes. |
|
97 |
*/ |
|
98 |
public final int getBytes() { |
|
99 |
return bytes; |
|
100 |
} |
|
101 |
||
6 | 102 |
|
46174 | 103 |
/** |
104 |
* @param bytes the raw bytes that represent this integer |
|
105 |
*/ |
|
106 |
public final void setBytes( final int bytes ) { |
|
107 |
this.bytes = bytes; |
|
108 |
} |
|
6 | 109 |
|
110 |
||
46174 | 111 |
/** |
112 |
* @return String representation. |
|
113 |
*/ |
|
114 |
@Override |
|
115 |
public final String toString() { |
|
116 |
return super.toString() + "(bytes = " + bytes + ")"; |
|
117 |
} |
|
6 | 118 |
|
46174 | 119 |
|
120 |
/** @return Integer object |
|
121 |
*/ |
|
122 |
@Override |
|
123 |
public Object getConstantValue( final ConstantPool cp ) { |
|
124 |
return Integer.valueOf(bytes); |
|
125 |
} |
|
6 | 126 |
} |