test/jdk/java/lang/annotation/typeAnnotations/TestObjectMethods.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 52317 3c981e581f93
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
     1 /*
     1 /*
     2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 8058202 8212081
    26  * @bug 8058202 8212081 8224012
    27  * @summary Test java.lang.Object methods on AnnotatedType objects.
    27  * @summary Test java.lang.Object methods on AnnotatedType objects.
    28  */
    28  */
    29 
    29 
    30 import java.lang.annotation.*;
    30 import java.lang.annotation.*;
    31 import java.lang.reflect.*;
    31 import java.lang.reflect.*;
    71         testGetAnnotations(TypeHost.class, false);
    71         testGetAnnotations(TypeHost.class, false);
    72         testGetAnnotations(AnnotatedTypeHost.class, true);
    72         testGetAnnotations(AnnotatedTypeHost.class, true);
    73 
    73 
    74         testWildcards();
    74         testWildcards();
    75 
    75 
       
    76         testFbounds();
       
    77 
    76         if (errors > 0) {
    78         if (errors > 0) {
    77             throw new RuntimeException(errors + " errors");
    79             throw new RuntimeException(errors + " errors");
    78         }
    80         }
    79     }
    81     }
    80 
    82 
   173                                    "\n\n");
   175                                    "\n\n");
   174             }
   176             }
   175         }
   177         }
   176     }
   178     }
   177 
   179 
   178     private static final Pattern annotationRegex = Pattern.compile("@TestObjectMethods\\$AnnotType\\(value=(\\p{Digit})+\\)");
   180     private static final Pattern annotationRegex = Pattern.compile("@TestObjectMethods\\$AnnotType\\((\\p{Digit})+\\)");
   179 
   181 
   180     static void testGetAnnotations(Class<?> clazz, boolean annotationsExpectedOnMethods) {
   182     static void testGetAnnotations(Class<?> clazz, boolean annotationsExpectedOnMethods) {
   181         System.err.println("Testing getAnnotations on methods of class " + clazz.getName());
   183         System.err.println("Testing getAnnotations on methods of class " + clazz.getName());
   182         Method[] methods = clazz.getDeclaredMethods();
   184         Method[] methods = clazz.getDeclaredMethods();
   183         for (Method m : methods) {
   185         for (Method m : methods) {
   312         } catch (Exception e) {
   314         } catch (Exception e) {
   313             throw new RuntimeException(e);
   315             throw new RuntimeException(e);
   314         }
   316         }
   315     }
   317     }
   316 
   318 
       
   319     static void testFbounds() {
       
   320         // Make sure equals and hashCode work fine for a type
       
   321         // involving an F-bound, in particular Comparable<E> in
       
   322         // java.lang.Enum:
       
   323         //
       
   324         // class Enum<E extends Enum<E>>
       
   325         // implements Constable, Comparable<E>, Serializable
       
   326 
       
   327         AnnotatedType[] types = Enum.class.getAnnotatedInterfaces();
       
   328 
       
   329         for (int i = 0; i < types.length; i ++) {
       
   330             for (int j = 0; j < types.length; j ++) {
       
   331                 checkTypesForEquality(types[i], types[j], i == j);
       
   332             }
       
   333         }
       
   334     }
       
   335 
   317     // The TypeHost and AnnotatedTypeHost classes declare methods with
   336     // The TypeHost and AnnotatedTypeHost classes declare methods with
   318     // the same name and signatures but with the AnnotatedTypeHost
   337     // the same name and signatures but with the AnnotatedTypeHost
   319     // methods having annotations on their return type, where
   338     // methods having annotations on their return type, where
   320     // possible.
   339     // possible.
   321 
   340