Tue, 21 May 2013 13:50:56 +0100
8005207: test has 2 @bug tags
Reviewed-by: mcimadamore
jjg@482 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. |
jjg@482 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@482 | 4 | * |
jjg@482 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@482 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@482 | 7 | * published by the Free Software Foundation. |
jjg@482 | 8 | * |
jjg@482 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@482 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@482 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@482 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@482 | 13 | * accompanied this code). |
jjg@482 | 14 | * |
jjg@482 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@482 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@482 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@482 | 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. |
jjg@482 | 22 | */ |
jjg@482 | 23 | |
jjg@482 | 24 | /* |
jjg@482 | 25 | * @test |
jjg@482 | 26 | * @bug 6654037 |
jjg@482 | 27 | * @summary JCTree.pos may be incorrect for BinaryTrees |
jjg@482 | 28 | */ |
jjg@482 | 29 | |
jjg@482 | 30 | import com.sun.source.tree.BinaryTree; |
jjg@482 | 31 | import com.sun.source.tree.ClassTree; |
jjg@482 | 32 | import com.sun.source.tree.CompilationUnitTree; |
jjg@482 | 33 | import com.sun.source.tree.MethodTree; |
jjg@482 | 34 | import com.sun.source.tree.VariableTree; |
jjg@482 | 35 | import com.sun.tools.javac.api.JavacTaskImpl; |
jjg@482 | 36 | import com.sun.tools.javac.tree.JCTree; |
jjg@482 | 37 | import java.net.URI; |
jjg@482 | 38 | import java.util.Arrays; |
jjg@482 | 39 | import javax.tools.JavaCompiler; |
jjg@482 | 40 | import javax.tools.JavaFileObject; |
jjg@482 | 41 | import javax.tools.SimpleJavaFileObject; |
jjg@482 | 42 | import javax.tools.ToolProvider; |
jjg@482 | 43 | |
jjg@482 | 44 | public class T6654037 { |
jjg@482 | 45 | |
jjg@482 | 46 | public static void main(String[] args) throws Exception { |
jjg@482 | 47 | final String bootPath = System.getProperty("sun.boot.class.path"); //NOI18N |
jjg@482 | 48 | final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); |
jjg@482 | 49 | assert tool != null; |
jjg@482 | 50 | |
jjg@482 | 51 | String code = "package test; public class Test {private void test() {Object o = null; boolean b = o != null && o instanceof String;} private Test() {}}"; |
jjg@482 | 52 | |
jjg@482 | 53 | JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, Arrays.asList("-bootclasspath", bootPath, "-Xjcov"), null, Arrays.asList(new MyFileObject(code))); |
jjg@482 | 54 | CompilationUnitTree cut = ct.parse().iterator().next(); |
jjg@482 | 55 | ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); |
jjg@482 | 56 | MethodTree method = (MethodTree) clazz.getMembers().get(0); |
jjg@482 | 57 | VariableTree condSt = (VariableTree) method.getBody().getStatements().get(1); |
jjg@482 | 58 | BinaryTree cond = (BinaryTree) condSt.getInitializer(); |
jjg@482 | 59 | JCTree condJC = (JCTree) cond; |
jjg@482 | 60 | |
jjg@482 | 61 | if (condJC.pos != 93) |
jjg@482 | 62 | throw new IllegalStateException("Unexpected position=" + condJC.pos); |
jjg@482 | 63 | } |
jjg@482 | 64 | |
jjg@482 | 65 | static class MyFileObject extends SimpleJavaFileObject { |
jjg@482 | 66 | private String text; |
jjg@482 | 67 | public MyFileObject(String text) { |
jjg@482 | 68 | super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); |
jjg@482 | 69 | this.text = text; |
jjg@482 | 70 | } |
jjg@482 | 71 | @Override |
jjg@482 | 72 | public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
jjg@482 | 73 | return text; |
jjg@482 | 74 | } |
jjg@482 | 75 | } |
jjg@482 | 76 | } |