jjg@1455: /* vromero@1774: * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. jjg@1455: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@1455: * jjg@1455: * This code is free software; you can redistribute it and/or modify it jjg@1455: * under the terms of the GNU General Public License version 2 only, as jjg@1455: * published by the Free Software Foundation. jjg@1455: * jjg@1455: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@1455: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@1455: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@1455: * version 2 for more details (a copy is included in the LICENSE file that jjg@1455: * accompanied this code). jjg@1455: * jjg@1455: * You should have received a copy of the GNU General Public License version jjg@1455: * 2 along with this work; if not, write to the Free Software Foundation, jjg@1455: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@1455: * jjg@1455: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jjg@1455: * or visit www.oracle.com if you need additional information or have any jjg@1455: * questions. jjg@1455: */ jjg@1455: jjg@1455: /* @test vromero@1774: * @bug 8004832 8000103 jjg@1465: * @summary Add new doclint package jjg@1455: * @summary Create doclint utility jjg@1455: */ jjg@1455: jjg@1455: import java.io.File; jjg@1455: import java.io.IOException; jjg@1455: import java.io.PrintWriter; jjg@1455: import java.io.StringWriter; jjg@1455: import java.lang.annotation.Annotation; jjg@1455: import java.lang.annotation.Retention; jjg@1455: import java.lang.annotation.RetentionPolicy; jjg@1455: import java.lang.reflect.InvocationTargetException; jjg@1455: import java.lang.reflect.Method; jjg@1455: vromero@1774: import com.sun.tools.doclint.DocLint; vromero@1774: import com.sun.tools.doclint.DocLint.BadArgs; vromero@1774: jjg@1455: /** javadoc error on toplevel: a & b. */ jjg@1455: public class RunTest { jjg@1455: /** javadoc error on member: a < b */ jjg@1455: public static void main(String... args) throws Exception { jjg@1455: new RunTest().run(); jjg@1455: } jjg@1455: jjg@1455: jjg@1455: File testSrc = new File(System.getProperty("test.src")); jjg@1455: File thisFile = new File(testSrc, RunTest.class.getSimpleName() + ".java"); jjg@1455: jjg@1455: void run() throws Exception { jjg@1455: for (Method m: getClass().getDeclaredMethods()) { jjg@1455: Annotation a = m.getAnnotation(Test.class); jjg@1455: if (a != null) { jjg@1455: System.err.println("test: " + m.getName()); jjg@1455: try { jjg@1455: StringWriter sw = new StringWriter(); jjg@1455: PrintWriter pw = new PrintWriter(sw);; jjg@1455: m.invoke(this, new Object[] { pw }); jjg@1455: String out = sw.toString(); jjg@1455: System.err.println(">>> " + out.replace("\n", "\n>>> ")); jjg@1455: if (!out.contains("a < b")) jjg@1455: error("\"a < b\" not found"); jjg@1455: if (!out.contains("a & b")) jjg@1455: error("\"a & b\" not found"); jjg@1455: } catch (InvocationTargetException e) { jjg@1455: Throwable cause = e.getCause(); jjg@1455: throw (cause instanceof Exception) ? ((Exception) cause) : e; jjg@1455: } jjg@1455: System.err.println(); jjg@1455: } jjg@1455: } jjg@1455: jjg@1455: if (errors > 0) jjg@1455: throw new Exception(errors + " errors occurred"); jjg@1455: } jjg@1455: jjg@1455: jjg@1455: void error(String msg) { jjg@1455: System.err.println("Error: " + msg); jjg@1455: errors++; jjg@1455: } jjg@1455: jjg@1455: int errors; jjg@1455: jjg@1455: /** Marker annotation for test cases. */ jjg@1455: @Retention(RetentionPolicy.RUNTIME) jjg@1455: @interface Test { } jjg@1455: jjg@1455: @Test jjg@1455: void testMain(PrintWriter pw) throws BadArgs, IOException { jjg@1455: String[] args = { "-Xmsgs", thisFile.getPath() }; jjg@1455: DocLint d = new DocLint(); jjg@1455: d.run(pw, args); jjg@1455: } jjg@1455: } jjg@1455: jjg@1455: