< prev index next >

test/jdk/java/lang/annotation/typeAnnotations/TestObjectMethods.java

Print this page




 160                         System.err.println("\tExpected annotation not found: " + annotTypeString);
 161                     }
 162                 }
 163             }
 164 
 165             boolean found = matcher.find();
 166             if (found) {
 167                 errors++;
 168                 System.err.println("\tAnnotation found unexpectedly: " + annotTypeString);
 169             }
 170 
 171             if (!valid) {
 172                 errors++;
 173                 System.err.println(typeString + "\n" + annotTypeString +
 174                                    "\n " + valid  +
 175                                    "\n\n");
 176             }
 177         }
 178     }
 179 
 180     private static final Pattern annotationRegex = Pattern.compile("@TestObjectMethods\\$AnnotType\\(value=(\\p{Digit})+\\)");
 181 
 182     static void testGetAnnotations(Class<?> clazz, boolean annotationsExpectedOnMethods) {
 183         System.err.println("Testing getAnnotations on methods of class " + clazz.getName());
 184         Method[] methods = clazz.getDeclaredMethods();
 185         for (Method m : methods) {
 186             Type type = m.getGenericReturnType();
 187             AnnotatedType annotType = m.getAnnotatedReturnType();
 188             Annotation[] annotations = annotType.getAnnotations();
 189 
 190             boolean isVoid = "void".equals(type.toString());
 191 
 192             if (annotationsExpectedOnMethods && !isVoid) {
 193                 if (annotations.length == 0 ) {
 194                     errors++;
 195                     System.err.println("Expected annotations missing on " + annotType);
 196                 }
 197             } else {
 198                 if (annotations.length > 0 ) {
 199                     errors++;
 200                     System.err.println("Unexpected annotations present on " + annotType);




 160                         System.err.println("\tExpected annotation not found: " + annotTypeString);
 161                     }
 162                 }
 163             }
 164 
 165             boolean found = matcher.find();
 166             if (found) {
 167                 errors++;
 168                 System.err.println("\tAnnotation found unexpectedly: " + annotTypeString);
 169             }
 170 
 171             if (!valid) {
 172                 errors++;
 173                 System.err.println(typeString + "\n" + annotTypeString +
 174                                    "\n " + valid  +
 175                                    "\n\n");
 176             }
 177         }
 178     }
 179 
 180     private static final Pattern annotationRegex = Pattern.compile("@TestObjectMethods\\$AnnotType\\((\\p{Digit})+\\)");
 181 
 182     static void testGetAnnotations(Class<?> clazz, boolean annotationsExpectedOnMethods) {
 183         System.err.println("Testing getAnnotations on methods of class " + clazz.getName());
 184         Method[] methods = clazz.getDeclaredMethods();
 185         for (Method m : methods) {
 186             Type type = m.getGenericReturnType();
 187             AnnotatedType annotType = m.getAnnotatedReturnType();
 188             Annotation[] annotations = annotType.getAnnotations();
 189 
 190             boolean isVoid = "void".equals(type.toString());
 191 
 192             if (annotationsExpectedOnMethods && !isVoid) {
 193                 if (annotations.length == 0 ) {
 194                     errors++;
 195                     System.err.println("Expected annotations missing on " + annotType);
 196                 }
 197             } else {
 198                 if (annotations.length > 0 ) {
 199                     errors++;
 200                     System.err.println("Unexpected annotations present on " + annotType);


< prev index next >