UnsafeStaticIntegerFieldAccessorImpl.java revision 14176:8606d027b2c2
1289177Speter/*
2289177Speter * Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
3289177Speter * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4289177Speter *
5289177Speter * This code is free software; you can redistribute it and/or modify it
6289177Speter * under the terms of the GNU General Public License version 2 only, as
7289177Speter * published by the Free Software Foundation.  Oracle designates this
8289177Speter * particular file as subject to the "Classpath" exception as provided
9289177Speter * by Oracle in the LICENSE file that accompanied this code.
10289177Speter *
11289177Speter * This code is distributed in the hope that it will be useful, but WITHOUT
12289177Speter * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13289177Speter * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14289177Speter * version 2 for more details (a copy is included in the LICENSE file that
15289177Speter * accompanied this code).
16289177Speter *
17289177Speter * You should have received a copy of the GNU General Public License version
18289177Speter * 2 along with this work; if not, write to the Free Software Foundation,
19289177Speter * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20289177Speter *
21289177Speter * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22289177Speter * or visit www.oracle.com if you need additional information or have any
23289177Speter * questions.
24289177Speter */
25289177Speter
26289177Speterpackage jdk.internal.reflect;
27289177Speter
28289177Speterimport java.lang.reflect.Field;
29289177Speter
30289177Speterclass UnsafeStaticIntegerFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
31289177Speter    UnsafeStaticIntegerFieldAccessorImpl(Field field) {
32289177Speter        super(field);
33289177Speter    }
34289177Speter
35289177Speter    public Object get(Object obj) throws IllegalArgumentException {
36289177Speter        return Integer.valueOf(getInt(obj));
37289177Speter    }
38289177Speter
39289177Speter    public boolean getBoolean(Object obj) throws IllegalArgumentException {
40289177Speter        throw newGetBooleanIllegalArgumentException();
41289177Speter    }
42289177Speter
43289177Speter    public byte getByte(Object obj) throws IllegalArgumentException {
44289177Speter        throw newGetByteIllegalArgumentException();
45289177Speter    }
46289177Speter
47289177Speter    public char getChar(Object obj) throws IllegalArgumentException {
48289177Speter        throw newGetCharIllegalArgumentException();
49289177Speter    }
50289177Speter
51289177Speter    public short getShort(Object obj) throws IllegalArgumentException {
52289177Speter        throw newGetShortIllegalArgumentException();
53289177Speter    }
54289177Speter
55289177Speter    public int getInt(Object obj) throws IllegalArgumentException {
56289177Speter        return unsafe.getInt(base, fieldOffset);
57289177Speter    }
58289177Speter
59289177Speter    public long getLong(Object obj) throws IllegalArgumentException {
60289177Speter        return getInt(obj);
61289177Speter    }
62289177Speter
63289177Speter    public float getFloat(Object obj) throws IllegalArgumentException {
64289177Speter        return getInt(obj);
65289177Speter    }
66289177Speter
67289177Speter    public double getDouble(Object obj) throws IllegalArgumentException {
68289177Speter        return getInt(obj);
69289177Speter    }
70289177Speter
71289177Speter    public void set(Object obj, Object value)
72289177Speter        throws IllegalArgumentException, IllegalAccessException
73289177Speter    {
74289177Speter        if (isFinal) {
75289177Speter            throwFinalFieldIllegalAccessException(value);
76289177Speter        }
77289177Speter        if (value == null) {
78289177Speter            throwSetIllegalArgumentException(value);
79289177Speter        }
80289177Speter        if (value instanceof Byte) {
81289177Speter            unsafe.putInt(base, fieldOffset, ((Byte) value).byteValue());
82289177Speter            return;
83289177Speter        }
84289177Speter        if (value instanceof Short) {
85289177Speter            unsafe.putInt(base, fieldOffset, ((Short) value).shortValue());
86289177Speter            return;
87289177Speter        }
88289177Speter        if (value instanceof Character) {
89289177Speter            unsafe.putInt(base, fieldOffset, ((Character) value).charValue());
90289177Speter            return;
91289177Speter        }
92289177Speter        if (value instanceof Integer) {
93289177Speter            unsafe.putInt(base, fieldOffset, ((Integer) value).intValue());
94289177Speter            return;
95289177Speter        }
96289177Speter        throwSetIllegalArgumentException(value);
97289177Speter    }
98289177Speter
99289177Speter    public void setBoolean(Object obj, boolean z)
100289177Speter        throws IllegalArgumentException, IllegalAccessException
101289177Speter    {
102289177Speter        throwSetIllegalArgumentException(z);
103289177Speter    }
104289177Speter
105289177Speter    public void setByte(Object obj, byte b)
106289177Speter        throws IllegalArgumentException, IllegalAccessException
107289177Speter    {
108289177Speter        setInt(obj, b);
109289177Speter    }
110289177Speter
111289177Speter    public void setChar(Object obj, char c)
112289177Speter        throws IllegalArgumentException, IllegalAccessException
113289177Speter    {
114289177Speter        setInt(obj, c);
115289177Speter    }
116289177Speter
117289177Speter    public void setShort(Object obj, short s)
118289177Speter        throws IllegalArgumentException, IllegalAccessException
119289177Speter    {
120289177Speter        setInt(obj, s);
121289177Speter    }
122289177Speter
123289177Speter    public void setInt(Object obj, int i)
124289177Speter        throws IllegalArgumentException, IllegalAccessException
125289177Speter    {
126289177Speter        if (isFinal) {
127289177Speter            throwFinalFieldIllegalAccessException(i);
128289177Speter        }
129289177Speter        unsafe.putInt(base, fieldOffset, i);
130289177Speter    }
131289177Speter
132289177Speter    public void setLong(Object obj, long l)
133289177Speter        throws IllegalArgumentException, IllegalAccessException
134289177Speter    {
135289177Speter        throwSetIllegalArgumentException(l);
136289177Speter    }
137289177Speter
138289177Speter    public void setFloat(Object obj, float f)
139289177Speter        throws IllegalArgumentException, IllegalAccessException
140289177Speter    {
141289177Speter        throwSetIllegalArgumentException(f);
142289177Speter    }
143289177Speter
144289177Speter    public void setDouble(Object obj, double d)
145289177Speter        throws IllegalArgumentException, IllegalAccessException
146289177Speter    {
147289177Speter        throwSetIllegalArgumentException(d);
148289177Speter    }
149289177Speter}
150289177Speter