OSDN Git Service

Fix up GWT javadocs/exceptions
[mikumikustudio/libgdx-mikumikustudio.git] / backends / gdx-backends-gwt / src / com / badlogic / gdx / backends / gwt / emu / com / badlogic / gdx / utils / reflect / Field.java
1 package com.badlogic.gdx.utils.reflect;
2
3 import java.lang.reflect.Modifier;
4 import java.lang.reflect.ParameterizedType;
5 import java.lang.reflect.Type;
6
7 /** Provides information about, and access to, a single field of a class or interface.
8  * @author nexsoftware */
9 public final class Field {
10         
11         private final com.badlogic.gwtref.client.Field field;
12         
13         Field(com.badlogic.gwtref.client.Field field) {
14                 this.field = field;
15         }
16         
17         /** Returns the name of the field. */
18         public String getName() {
19                 return field.getName();
20         }
21         
22         /** Returns a Class object that identifies the declared type for the field. */
23         public Class getType() {
24                 return field.getType().getClassOfType();
25         }
26         
27         /** Returns the Class object representing the class or interface that declares the field. */
28         public Class getDeclaringClass() {
29                 return field.getEnclosingType().getClassOfType();
30         }
31         
32         public boolean isAccessible() {
33                 return field.isAccessible();            
34         }
35         
36         public void setAccessible(boolean accessible) {
37                 field.setAccessible(accessible);
38         }
39
40         /** Return true if the field does not include any of the {@code private}, {@code protected}, or {@code public} modifiers. */
41         public boolean isDefaultAccess() {
42                 return !isPrivate() && ! isProtected() && ! isPublic();
43         }
44         
45         /** Return true if the field includes the {@code final} modifier. */
46         public boolean isFinal() {
47                 return field.isFinal();
48         }
49         
50         /** Return true if the field includes the {@code private} modifier. */
51         public boolean isPrivate() {
52                 return field.isPrivate();
53         }
54         
55         /** Return true if the field includes the {@code protected} modifier. */
56         public boolean isProtected() {
57                 return field.isProtected();
58         }
59         
60         /** Return true if the field includes the {@code public} modifier. */
61         public boolean isPublic() {
62                 return field.isPublic();
63         }
64         
65         /** Return true if the field includes the {@code static} modifier. */
66         public boolean isStatic() {
67                 return field.isStatic();
68         }
69
70         /** Return true if the field includes the {@code transient} modifier. */
71         public boolean isTransient() {
72                 return field.isTransient();
73         }
74         
75         /** Return true if the field includes the {@code volatile} modifier. */
76         public boolean isVolatile() {
77                 return field.isVolatile();
78         }
79
80         /** Return true if the field is a synthetic field. */
81         public boolean isSynthetic() {
82                 return field.isSynthetic();
83         }
84         
85         /** If the type of the field is parameterized, returns the Class object representing the parameter type, null otherwise. */
86         public Class getElementType() {
87                 return null;
88         }
89         
90         /** Returns the value of the field on the supplied object. */
91         public Object get(Object obj) throws ReflectionException {
92                 try {
93                         return field.get(obj);
94                 } catch (IllegalArgumentException e) {
95                         throw new ReflectionException("Object is not an instance of " + getDeclaringClass(), e);
96                 } catch (IllegalAccessException e) {
97                         throw new ReflectionException("Illegal access to field: " + getName(), e);
98                 }       
99         }
100         
101         /** Sets the value of the field on the supplied object. */
102         public void set(Object obj, Object value) throws ReflectionException {
103                 try {
104                         field.set(obj, value);
105                 } catch (IllegalArgumentException e) {
106                         throw new ReflectionException("Argument not valid for field: " + getName(), e);
107                 } catch (IllegalAccessException e) {
108                         throw new ReflectionException("Illegal access to field: " + getName(), e);
109                 }
110         }
111         
112 }