test/tools/javac/processing/model/util/TestIntersectionTypeVisitors.java

Thu, 31 Aug 2017 15:17:03 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:17:03 +0800
changeset 2525
2eb010b6cb22
parent 0
959103a6100f
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     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
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /*
    25  * @test
    26  * @bug     8027730
    27  * @summary Test visitor support for intersection types
    28  */
    30 import java.lang.annotation.Annotation;
    31 import java.util.List;
    32 import javax.lang.model.element.*;
    33 import javax.lang.model.type.*;
    34 import javax.lang.model.util.*;
    36 public class TestIntersectionTypeVisitors {
    37     public static void main(String... args) throws Exception {
    38         IntersectionType it = new TestIntersectionType();
    40         boolean result = it.accept(new TypeKindVisitor8Child(), null) &&
    41             it.accept(new SimpleTypeVisitor8Child(), null) &&
    42             it.accept(new SimpleTypeVisitor6Child(), null);
    44         if (!result)
    45             throw new RuntimeException();
    46     }
    48     static class TestIntersectionType implements IntersectionType {
    49         TestIntersectionType() {}
    51         @Override
    52         public List<? extends TypeMirror> getBounds() {
    53             throw new UnsupportedOperationException();
    54         }
    56         @Override
    57         public <R,P> R accept(TypeVisitor<R,P> v,
    58                        P p) {
    59             return v.visitIntersection(this, p);
    60         }
    62         @Override
    63         public TypeKind getKind() {
    64             return TypeKind.INTERSECTION;
    65         }
    67         @Override
    68         public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
    69             throw new UnsupportedOperationException();
    70         }
    72         @Override
    73         public List<? extends AnnotationMirror> getAnnotationMirrors() {
    74             throw new UnsupportedOperationException();
    75         }
    77         @Override
    78         public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType) {
    79             throw new UnsupportedOperationException();
    80         }
    81     }
    83     static class TypeKindVisitor8Child extends TypeKindVisitor8<Boolean, Void> {
    84         TypeKindVisitor8Child() {
    85             super(false);
    86         }
    88         @Override
    89         public Boolean visitIntersection(IntersectionType t, Void p) {
    90             super.visitIntersection(t, p); // Make sure overridden method doesn't throw an exception
    91             return true;
    92         }
    93     }
    95     static class SimpleTypeVisitor8Child extends SimpleTypeVisitor8<Boolean, Void> {
    96         SimpleTypeVisitor8Child() {
    97             super(false);
    98         }
   100         @Override
   101         public Boolean visitIntersection(IntersectionType t, Void p) {
   102             super.visitIntersection(t, p);  // Make sure overridden method doesn't throw an exception
   103             return true;
   104         }
   105     }
   107     static class SimpleTypeVisitor6Child extends SimpleTypeVisitor6<Boolean, Void> {
   108         SimpleTypeVisitor6Child() {
   109             super(false);
   110         }
   112         @Override
   113         public Boolean visitIntersection(IntersectionType t, Void p) {
   114             try {
   115                 super.visitIntersection(t, p);
   116                 return false;
   117             } catch (UnknownTypeException ute) {
   118                 return true; // Expected
   119             }
   120         }
   121     }
   122 }

mercurial