481N/A/*
553N/A * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
481N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
481N/A *
481N/A * This code is free software; you can redistribute it and/or modify it
481N/A * under the terms of the GNU General Public License version 2 only, as
481N/A * published by the Free Software Foundation.
481N/A *
481N/A * This code is distributed in the hope that it will be useful, but WITHOUT
481N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
481N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
481N/A * version 2 for more details (a copy is included in the LICENSE file that
481N/A * accompanied this code).
481N/A *
481N/A * You should have received a copy of the GNU General Public License version
481N/A * 2 along with this work; if not, write to the Free Software Foundation,
481N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
481N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
481N/A */
481N/A
481N/A/*
481N/A * @test
481N/A * @bug 6654037
481N/A * @summary JCTree.pos may be incorrect for BinaryTrees
481N/A */
481N/A
481N/Aimport com.sun.source.tree.BinaryTree;
481N/Aimport com.sun.source.tree.ClassTree;
481N/Aimport com.sun.source.tree.CompilationUnitTree;
481N/Aimport com.sun.source.tree.MethodTree;
481N/Aimport com.sun.source.tree.VariableTree;
481N/Aimport com.sun.tools.javac.api.JavacTaskImpl;
481N/Aimport com.sun.tools.javac.tree.JCTree;
481N/Aimport java.net.URI;
481N/Aimport java.util.Arrays;
481N/Aimport javax.tools.JavaCompiler;
481N/Aimport javax.tools.JavaFileObject;
481N/Aimport javax.tools.SimpleJavaFileObject;
481N/Aimport javax.tools.ToolProvider;
481N/A
481N/Apublic class T6654037 {
481N/A
481N/A public static void main(String[] args) throws Exception {
481N/A final String bootPath = System.getProperty("sun.boot.class.path"); //NOI18N
481N/A final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
481N/A assert tool != null;
481N/A
481N/A String code = "package test; public class Test {private void test() {Object o = null; boolean b = o != null && o instanceof String;} private Test() {}}";
481N/A
481N/A JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, Arrays.asList("-bootclasspath", bootPath, "-Xjcov"), null, Arrays.asList(new MyFileObject(code)));
481N/A CompilationUnitTree cut = ct.parse().iterator().next();
481N/A ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
481N/A MethodTree method = (MethodTree) clazz.getMembers().get(0);
481N/A VariableTree condSt = (VariableTree) method.getBody().getStatements().get(1);
481N/A BinaryTree cond = (BinaryTree) condSt.getInitializer();
481N/A JCTree condJC = (JCTree) cond;
481N/A
481N/A if (condJC.pos != 93)
481N/A throw new IllegalStateException("Unexpected position=" + condJC.pos);
481N/A }
481N/A
481N/A static class MyFileObject extends SimpleJavaFileObject {
481N/A private String text;
481N/A public MyFileObject(String text) {
481N/A super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
481N/A this.text = text;
481N/A }
481N/A @Override
481N/A public CharSequence getCharContent(boolean ignoreEncodingErrors) {
481N/A return text;
481N/A }
481N/A }
481N/A}