Fri, 02 Nov 2012 14:35:57 -0700
7169362: JDK8: Write compiler tests for repeating annotations for JDK8
Reviewed-by: darcy, jjg
Contributed-by: sonali.goel@oracle.com
mcimadamore@303 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. |
mcimadamore@303 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
mcimadamore@303 | 4 | * |
mcimadamore@303 | 5 | * This code is free software; you can redistribute it and/or modify it |
mcimadamore@303 | 6 | * under the terms of the GNU General Public License version 2 only, as |
mcimadamore@303 | 7 | * published by the Free Software Foundation. |
mcimadamore@303 | 8 | * |
mcimadamore@303 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
mcimadamore@303 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mcimadamore@303 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
mcimadamore@303 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
mcimadamore@303 | 13 | * accompanied this code). |
mcimadamore@303 | 14 | * |
mcimadamore@303 | 15 | * You should have received a copy of the GNU General Public License version |
mcimadamore@303 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
mcimadamore@303 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
mcimadamore@303 | 18 | * |
ohair@554 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 21 | * questions. |
mcimadamore@303 | 22 | */ |
mcimadamore@303 | 23 | |
mcimadamore@303 | 24 | /* |
mcimadamore@303 | 25 | * @test |
mcimadamore@303 | 26 | * @bug 6852595 |
mcimadamore@303 | 27 | * @summary Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception |
mcimadamore@303 | 28 | * @author mcimadamore |
mcimadamore@303 | 29 | */ |
mcimadamore@303 | 30 | |
mcimadamore@303 | 31 | import java.io.IOException; |
mcimadamore@303 | 32 | import java.net.URI; |
mcimadamore@303 | 33 | import java.util.Arrays; |
mcimadamore@303 | 34 | import java.util.List; |
mcimadamore@303 | 35 | import javax.tools.JavaCompiler; |
mcimadamore@303 | 36 | import javax.tools.JavaFileObject; |
mcimadamore@303 | 37 | import javax.tools.SimpleJavaFileObject; |
mcimadamore@303 | 38 | import javax.tools.ToolProvider; |
mcimadamore@303 | 39 | |
mcimadamore@303 | 40 | import com.sun.source.util.JavacTask; |
mcimadamore@303 | 41 | import com.sun.source.tree.*; |
mcimadamore@303 | 42 | import com.sun.source.util.TreePath; |
mcimadamore@303 | 43 | import com.sun.source.util.Trees; |
mcimadamore@303 | 44 | import com.sun.tools.javac.api.JavacTrees; |
mcimadamore@303 | 45 | import com.sun.tools.javac.tree.JCTree.*; |
mcimadamore@303 | 46 | |
mcimadamore@303 | 47 | import static javax.tools.JavaFileObject.Kind; |
mcimadamore@303 | 48 | |
mcimadamore@303 | 49 | public class T6852595 { |
mcimadamore@303 | 50 | public static void main(String[] args) throws IOException { |
mcimadamore@303 | 51 | JavaFileObject sfo = new SimpleJavaFileObject(URI.create("myfo:/Test.java"),Kind.SOURCE) { |
mcimadamore@303 | 52 | public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
mcimadamore@303 | 53 | return "class BadName { Object o = j; }"; |
mcimadamore@303 | 54 | } |
mcimadamore@303 | 55 | }; |
mcimadamore@303 | 56 | List<? extends JavaFileObject> files = Arrays.asList(sfo); |
mcimadamore@303 | 57 | JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); |
mcimadamore@303 | 58 | JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, files); |
mcimadamore@303 | 59 | Iterable<? extends CompilationUnitTree> compUnits = ct.parse(); |
mcimadamore@303 | 60 | CompilationUnitTree cu = compUnits.iterator().next(); |
mcimadamore@303 | 61 | ClassTree cdef = (ClassTree)cu.getTypeDecls().get(0); |
mcimadamore@303 | 62 | JCVariableDecl vdef = (JCVariableDecl)cdef.getMembers().get(0); |
mcimadamore@303 | 63 | TreePath path = TreePath.getPath(cu, vdef.init); |
mcimadamore@303 | 64 | Trees.instance(ct).getScope(path); |
mcimadamore@303 | 65 | } |
mcimadamore@303 | 66 | } |