Source Code Cross Referenced for Field5Test.java in  » Apache-Harmony-Java-SE » java-package » java » lang » reflect » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » java package » java.lang.reflect 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        /**
019:         * @author Alexey V. Varlamov
020:         * @version $Revision$
021:         */package java.lang.reflect;
022:
023:        import org.apache.harmony.lang.AnnotatedElementTestFrame;
024:        import org.apache.harmony.lang.AnnotatedElementTestFrame.MissingClassValAntn;
025:        import org.apache.harmony.lang.AnnotatedElementTestFrame.MissingTypeAntn;
026:        import org.apache.harmony.lang.AnnotatedElementTestFrame.TagAntn;
027:        import org.apache.harmony.lang.AnnotatedElementTestFrame.ValAntn;
028:
029:        class AnnotatedField {
030:            @TagAntn
031:            public Object foo;
032:            @TagAntn
033:            @ValAntn
034:            public Object[] bar;
035:            public static transient volatile TwoParamType<String, ?> buz;
036:            @notfound.MissingAntn
037:            public int i;
038:            @MissingClassValAntn
039:            public long l;
040:            @MissingTypeAntn
041:            public char ch;
042:        }
043:
044:        class TwoParamType<K, V> {
045:        }
046:
047:        class OneParamType<U> {
048:        }
049:
050:        public class Field5Test extends AnnotatedElementTestFrame {
051:
052:            protected @Override
053:            AnnotatedElement getElement1() throws Throwable {
054:                return AnnotatedField.class.getField("foo");
055:            }
056:
057:            protected @Override
058:            AnnotatedElement getElement2() throws Throwable {
059:                return AnnotatedField.class.getField("bar");
060:            }
061:
062:            protected @Override
063:            AnnotatedElement getElement3() throws Throwable {
064:                return AnnotatedField.class.getField("buz");
065:            }
066:
067:            /**
068:             * Provides an instance to be tested. The instance must be annotated
069:             * by the notfound.MissingAntn.
070:             */
071:            protected @Override
072:            AnnotatedElement getElement4() throws Throwable {
073:                return AnnotatedField.class.getField("i");
074:            }
075:
076:            /**
077:             * Provides an instance to be tested. The instance must be annotated
078:             * by the MissingClassValAntn.
079:             */
080:            protected @Override
081:            AnnotatedElement getElement5() throws Throwable {
082:                return AnnotatedField.class.getField("l");
083:            }
084:
085:            /** 
086:             * Provides an instance to be tested. The instance must be annotated
087:             * by the MissingTypeAntn.
088:             */
089:            protected @Override
090:            AnnotatedElement getElement6() throws Throwable {
091:                return AnnotatedField.class.getField("ch");
092:            }
093:
094:            public static void main(String[] args) {
095:                junit.textui.TestRunner.run(Field5Test.class);
096:            }
097:
098:            class A {
099:                {
100:                    assert true;
101:                }
102:            }
103:
104:            enum E {
105:                E1, E2, E3
106:            }
107:
108:            static class B {
109:                public E foo;
110:            }
111:
112:            /**
113:             * isSynthetic() should return true if and only if
114:             * the target field does not appear in the source code. 
115:             */
116:            public void testIsSynthetic() throws Exception {
117:                assertFalse("case1.1: ordinary field", AnnotatedField.class
118:                        .getField("foo").isSynthetic());
119:                assertFalse("case1.2: ordinary field", B.class.getField("foo")
120:                        .isSynthetic());
121:
122:                Field[] fs = A.class.getDeclaredFields();
123:                assertTrue(fs != null && fs.length > 0);
124:                for (Field f : fs) {
125:                    assertTrue("case2: " + f.getName(), f.isSynthetic());
126:                }
127:
128:                fs = E.class.getFields();
129:                assertTrue(fs != null && fs.length > 0);
130:                for (Field f : fs) {
131:                    assertFalse("case3: " + f.getName(), f.isSynthetic());
132:                }
133:            }
134:
135:            /**
136:             * isEnumConstant() should return true if and only if
137:             * the target field is an element of an enumeration. 
138:             */
139:            public void testIsEnumConstant() throws Exception {
140:                assertFalse("case1: ordinary field", AnnotatedField.class
141:                        .getField("foo").isEnumConstant());
142:
143:                Field[] fs = E.class.getFields();
144:                assertTrue(fs != null && fs.length > 0);
145:                for (Field f : fs) {
146:                    assertTrue("case2: " + f.getName(), f.isEnumConstant());
147:                }
148:
149:                assertFalse("case3: enum-typed member field", B.class.getField(
150:                        "foo").isEnumConstant());
151:            }
152:
153:            enum E2 {
154:                E1;
155:                public int i;
156:            }
157:
158:            /**
159:             * isEnumConstant() should not return true 
160:             * for ordinary members (not elements) of an enumeration. 
161:             */
162:            public void testIsEnumConstant2() throws Exception {
163:                assertFalse(E2.class.getField("i").isEnumConstant());
164:            }
165:
166:            /**
167:             * toGenericString() should return a string exactly matching
168:             * the API specification.
169:             */
170:            public void testToGenericString() throws Exception {
171:                String s = AnnotatedField.class.getField("buz")
172:                        .toGenericString();
173:                System.out.println(s);
174:                assertEquals(
175:                        "public static transient volatile"
176:                                + " java.lang.reflect.TwoParamType<java.lang.String, ?>"
177:                                + " java.lang.reflect.AnnotatedField.buz", s);
178:            }
179:
180:            public final int INSTANCE_I = 10;
181:
182:            /**
183:             * Regression test for HARMONY-4927
184:             */
185:            public void testAccessFinalInstance() throws Throwable {
186:                Field fi = this .getClass().getField("INSTANCE_I");
187:                final Object oldVal = fi.get(this );
188:                final Object newVal = new Integer(2134523);
189:
190:                try {
191:                    fi.set(this , newVal);
192:                    fail("Should not modify final field");
193:                } catch (IllegalAccessException expected) {
194:                    assertEquals(oldVal, fi.get(this ));
195:                }
196:
197:                fi.setAccessible(true);
198:                fi.set(this , newVal);
199:                assertEquals(newVal, fi.get(this ));
200:            }
201:
202:            public static final int STATIC_I = 10;
203:
204:            public void testAccessFinalStatic() throws Throwable {
205:                Field fi = this .getClass().getField("STATIC_I");
206:                final Object oldVal = fi.get(null);
207:                final Object newVal = new Integer(2134523);
208:
209:                try {
210:                    fi.set(null, newVal);
211:                    fail("Should not modify final field");
212:                } catch (IllegalAccessException expected) {
213:                    assertEquals(oldVal, fi.get(null));
214:                }
215:
216:                try {
217:                    fi.setAccessible(true);
218:                    fi.set(this , newVal);
219:                    fail("Should not modify final field");
220:                } catch (IllegalAccessException expected) {
221:                    assertEquals(oldVal, fi.get(null));
222:                }
223:            }
224:
225:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.