Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javadoc/T4994049/T4994049.java
38813 views
/*1* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 499404926* @summary Unit test for SourcePosition.column with respect to tab expansion27* @author Peter von der Ah\u00e928* @run main T4994049 FileWithTabs.java29*/3031import com.sun.javadoc.*;32import java.io.*;33import static com.sun.tools.javadoc.Main.execute;3435public class T4994049 extends Doclet {3637public static boolean start(RootDoc root) {38for (ClassDoc klass : root.classes()) {39for (MethodDoc method : klass.methods()) {40if (method.name().equals("tabbedMethod")) {41if (method.position().column() == 21) {42System.out.println(method.position().column() + ": OK!");43return true;44} else {45System.err.println(method.position() + ": wrong tab expansion");46return false;47}48}49}50}51return false;52}5354public static void main(String... args) throws Exception {55File testSrc = new File(System.getProperty("test.src"));56File tmpSrc = new File("tmpSrc");57initTabs(testSrc, tmpSrc);5859for (String file : args) {60File source = new File(tmpSrc, file);61int rc = execute("javadoc", "T4994049", T4994049.class.getClassLoader(),62new String[]{ source.getPath() } );63if (rc != 0)64throw new Error("Unexpected return code from javadoc: " + rc);65}66}6768static void initTabs(File from, File to) throws IOException {69for (File f: from.listFiles()) {70File t = new File(to, f.getName());71if (f.isDirectory()) {72initTabs(f, t);73} else if (f.getName().endsWith(".java")) {74write(t, read(f).replace("\\t", "\t"));75}76}77}7879static String read(File f) throws IOException {80StringBuilder sb = new StringBuilder();81try (BufferedReader in = new BufferedReader(new FileReader(f))) {82String line;83while ((line = in.readLine()) != null) {84sb.append(line);85sb.append("\n");86}87}88return sb.toString();89}9091static void write(File f, String s) throws IOException {92f.getParentFile().mkdirs();93try (Writer out = new FileWriter(f)) {94out.write(s);95}96}9798}99100101