test/tools/javac/annotations/typeAnnotations/newlocations/BasicTest.java

changeset 0
959103a6100f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/annotations/typeAnnotations/newlocations/BasicTest.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,81 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
     1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8 + *
     1.9 + * This code is free software; you can redistribute it and/or modify it
    1.10 + * under the terms of the GNU General Public License version 2 only, as
    1.11 + * published by the Free Software Foundation.
    1.12 + *
    1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.16 + * version 2 for more details (a copy is included in the LICENSE file that
    1.17 + * accompanied this code).
    1.18 + *
    1.19 + * You should have received a copy of the GNU General Public License version
    1.20 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.22 + *
    1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.24 + * or visit www.oracle.com if you need additional information or have any
    1.25 + * questions.
    1.26 + */
    1.27 +
    1.28 +/*
    1.29 + * @test
    1.30 + * @bug 6843077 8006775
    1.31 + * @summary random tests for new locations
    1.32 + * @author Matt Papi
    1.33 + * @compile BasicTest.java
    1.34 + */
    1.35 +
    1.36 +import java.lang.annotation.*;
    1.37 +import java.util.*;
    1.38 +import java.io.*;
    1.39 +
    1.40 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
    1.41 +@interface A {}
    1.42 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
    1.43 +@interface B {}
    1.44 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
    1.45 +@interface C {}
    1.46 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
    1.47 +@interface D {}
    1.48 +
    1.49 +/**
    1.50 + * Tests basic JSR 308 parser functionality. We don't really care about what
    1.51 + * the parse tree looks like, just that these annotations can be parsed.
    1.52 + */
    1.53 +class BasicTest<T extends @A Object> extends @B LinkedList<T> implements @C List<T> {
    1.54 +
    1.55 +    void test() {
    1.56 +
    1.57 +        // Handle annotated cast types
    1.58 +        Object o = (@A Object) "foo";
    1.59 +
    1.60 +        // Handle annotated "new" expressions (except arrays; see ArrayTest)
    1.61 +        String s = new @A String("bar");
    1.62 +
    1.63 +        boolean b = o instanceof @A Object;
    1.64 +
    1.65 +        @A Map<@B List<@C String>, @D String> map =
    1.66 +            new @A HashMap<@B List<@C String>, @D String>();
    1.67 +
    1.68 +        Class<? extends @A String> c2 = null;
    1.69 +    }
    1.70 +
    1.71 +    // Handle receiver annotations
    1.72 +    // Handle annotations on a qualified identifier list
    1.73 +    void test2(@C @D BasicTest<T> this) throws @A IllegalArgumentException, @B IOException {
    1.74 +
    1.75 +    }
    1.76 +
    1.77 +    // Handle annotations on a varargs element type
    1.78 +    void test3(@B Object @A... objs) { }
    1.79 +
    1.80 +    void test4(@B Class<@C ?> @A ... clz) { }
    1.81 +
    1.82 +
    1.83 +    // TODO: add more tests... nested classes, etc.
    1.84 +}

mercurial