0N/A/*
797N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/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.
0N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 4994049
0N/A * @summary Unit test for SourcePosition.column with respect to tab expansion
0N/A * @author Peter von der Ah\u00e9
0N/A * @run main T4994049 FileWithTabs.java
0N/A */
0N/A
0N/Aimport com.sun.javadoc.*;
709N/Aimport java.io.*;
0N/Aimport static com.sun.tools.javadoc.Main.execute;
0N/A
0N/Apublic class T4994049 extends Doclet {
0N/A
0N/A public static boolean start(RootDoc root) {
0N/A for (ClassDoc klass : root.classes()) {
0N/A for (MethodDoc method : klass.methods()) {
0N/A if (method.name().equals("tabbedMethod")) {
0N/A if (method.position().column() == 21) {
0N/A System.out.println(method.position().column() + ": OK!");
0N/A return true;
0N/A } else {
0N/A System.err.println(method.position() + ": wrong tab expansion");
0N/A return false;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A return false;
0N/A }
0N/A
709N/A public static void main(String... args) throws Exception {
709N/A File testSrc = new File(System.getProperty("test.src"));
709N/A File tmpSrc = new File("tmpSrc");
709N/A initTabs(testSrc, tmpSrc);
709N/A
0N/A for (String file : args) {
709N/A File source = new File(tmpSrc, file);
709N/A int rc = execute("javadoc", "T4994049", T4994049.class.getClassLoader(),
709N/A new String[]{ source.getPath() } );
709N/A if (rc != 0)
709N/A throw new Error("Unexpected return code from javadoc: " + rc);
709N/A }
709N/A }
709N/A
709N/A static void initTabs(File from, File to) throws IOException {
709N/A for (File f: from.listFiles()) {
709N/A File t = new File(to, f.getName());
709N/A if (f.isDirectory()) {
709N/A initTabs(f, t);
709N/A } else if (f.getName().endsWith(".java")) {
709N/A write(t, read(f).replace("\\t", "\t"));
709N/A }
709N/A }
709N/A }
709N/A
709N/A static String read(File f) throws IOException {
709N/A StringBuilder sb = new StringBuilder();
709N/A try (BufferedReader in = new BufferedReader(new FileReader(f))) {
709N/A String line;
709N/A while ((line = in.readLine()) != null) {
709N/A sb.append(line);
709N/A sb.append("\n");
709N/A }
709N/A }
709N/A return sb.toString();
709N/A }
709N/A
709N/A static void write(File f, String s) throws IOException {
709N/A f.getParentFile().mkdirs();
709N/A try (Writer out = new FileWriter(f)) {
709N/A out.write(s);
0N/A }
0N/A }
0N/A
0N/A}