當前位置: 首頁>>代碼示例>>Java>>正文


Java ToolProvider.getSystemDocumentationTool方法代碼示例

本文整理匯總了Java中javax.tools.ToolProvider.getSystemDocumentationTool方法的典型用法代碼示例。如果您正苦於以下問題:Java ToolProvider.getSystemDocumentationTool方法的具體用法?Java ToolProvider.getSystemDocumentationTool怎麽用?Java ToolProvider.getSystemDocumentationTool使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.tools.ToolProvider的用法示例。


在下文中一共展示了ToolProvider.getSystemDocumentationTool方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testMemoryFileObject

import javax.tools.ToolProvider; //導入方法依賴的package包/類
/**
 * Verify that expected output files are written via the file manager,
 * for an in-memory file object.
 */
@Test
public void testMemoryFileObject() throws Exception {
    JavaFileObject srcFile = createSimpleJavaFileObject();
    DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
        File outDir = getOutDir();
        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
        DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
        if (t.call()) {
            System.err.println("task succeeded");
            checkFiles(outDir, standardExpectFiles);
        } else {
            throw new Exception("task failed");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:GetTask_FileObjectsTest.java

示例2: testDoclet

import javax.tools.ToolProvider; //導入方法依賴的package包/類
/**
 * Verify that an alternate doclet can be specified.
 *
 * There is no standard interface or superclass for a doclet;
 * the only requirement is that it provides static methods that
 * can be invoked via reflection. So, for now, the doclet is
 * specified as a class.
 * Because we cannot create and use a unique instance of the class,
 * we verify that the doclet has been called by having it record
 * (in a static field!) the comment from the last time it was invoked,
 * which is randomly generated each time the test is run.
 */
@Test
public void testDoclet() throws Exception {
    Random r = new Random();
    int key = r.nextInt();
    JavaFileObject srcFile = createSimpleJavaFileObject(
            "pkg/C",
            "package pkg; /** " + key + "*/ public class C { }");
    DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
        File outDir = getOutDir();
        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
        DocumentationTask t = tool.getTask(null, fm, null, TestDoclet.class, null, files);
        if (t.call()) {
            System.err.println("task succeeded");
            if (TestDoclet.lastCaller.equals(String.valueOf(key)))
                System.err.println("found expected key: " + key);
            else
                error("Expected key not found");
            checkFiles(outDir, Collections.<String>emptySet());
        } else {
            throw new Exception("task failed");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:38,代碼來源:GetTask_DocletClassTest.java

示例3: testRawCall

import javax.tools.ToolProvider; //導入方法依賴的package包/類
@Test
public void testRawCall() throws Exception {
    JavaFileObject srcFile = createSimpleJavaFileObject();
    DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
        File outDir = getOutDir();
        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);

        @SuppressWarnings("rawtypes")
        Callable t = tool.getTask(null, fm, null, null, null, files);

        if (t.call() == Boolean.TRUE) {
            System.err.println("task succeeded");
        } else {
            throw new Exception("task failed");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:JavadocTaskImplTest.java

示例4: testStandardFileObject

import javax.tools.ToolProvider; //導入方法依賴的package包/類
/**
 * Verify that expected output files are written via the file manager,
 * for a source file read from the file system with StandardJavaFileManager.
 */
@Test
public void testStandardFileObject() throws Exception {
    File testSrc = new File(System.getProperty("test.src"));
    File srcFile = new File(testSrc, "pkg/C.java");
    DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
        File outDir = getOutDir();
        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile);
        DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
        if (t.call()) {
            System.err.println("task succeeded");
            checkFiles(outDir, standardExpectFiles);
        } else {
            throw new Exception("task failed");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:GetTask_FileObjectsTest.java

示例5: testNoIndex

import javax.tools.ToolProvider; //導入方法依賴的package包/類
/**
 * Verify that expected output files are written for given options.
 */
@Test
public void testNoIndex() throws Exception {
    JavaFileObject srcFile = createSimpleJavaFileObject();
    DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
        File outDir = getOutDir();
        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
        Iterable<String> options = Arrays.asList("-noindex");
        DocumentationTask t = tool.getTask(null, fm, null, null, options, files);
        if (t.call()) {
            System.err.println("task succeeded");
            Set<String> expectFiles = new TreeSet<String>(noIndexFiles);
            checkFiles(outDir, expectFiles);
        } else {
            error("task failed");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:GetTask_OptionsTest.java

示例6: testNull

import javax.tools.ToolProvider; //導入方法依賴的package包/類
/**
 * Verify null is handled correctly.
 */
@Test
public void testNull() throws Exception {
    DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
        File outDir = getOutDir();
        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
        Iterable<? extends JavaFileObject> files = Arrays.asList((JavaFileObject) null);
        try {
            DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
            error("getTask succeeded, no exception thrown");
        } catch (NullPointerException e) {
            System.err.println("exception caught as expected: " + e);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:GetTask_FileObjectsTest.java

示例7: testBadFileObject

import javax.tools.ToolProvider; //導入方法依賴的package包/類
/**
 * Verify bad file object is handled correctly.
 */
@Test
public void testBadFileObject() throws Exception {
    File testSrc = new File(System.getProperty("test.src"));
    File srcFile = new File(testSrc, "pkg/C.class");  // unacceptable file kind
    DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
        File outDir = getOutDir();
        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile);
        try {
            DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
            error("getTask succeeded, no exception thrown");
        } catch (IllegalArgumentException e) {
            System.err.println("exception caught as expected: " + e);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:GetTask_FileObjectsTest.java

示例8: getAndRunTask

import javax.tools.ToolProvider; //導入方法依賴的package包/類
private DocumentationTask getAndRunTask() throws Exception {
    JavaFileObject srcFile = createSimpleJavaFileObject();
    DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
        File outDir = getOutDir();
        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
        DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
        if (t.call()) {
            System.err.println("task succeeded");
            return t;
        } else {
            throw new Exception("task failed");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:Task_reuseTest.java

示例9: testNull

import javax.tools.ToolProvider; //導入方法依賴的package包/類
/**
 * Verify null is handled correctly.
 */
@Test
public void testNull() throws Exception {
    JavaFileObject srcFile = createSimpleJavaFileObject();
    DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
        File outDir = getOutDir();
        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
        Iterable<String> options = Arrays.asList((String) null);
        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
        try {
            DocumentationTask t = tool.getTask(null, fm, null, null, options, files);
            error("getTask succeeded, no exception thrown");
        } catch (NullPointerException e) {
            System.err.println("exception caught as expected: " + e);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:GetTask_OptionsTest.java

示例10: testRun

import javax.tools.ToolProvider; //導入方法依賴的package包/類
/**
 * Verify getSourceVersions.
 */
@Test
public void testRun() throws Exception {
    DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    Set<SourceVersion> found = tool.getSourceVersions();
    Set<SourceVersion> expect = EnumSet.range(SourceVersion.RELEASE_3, SourceVersion.latest());
    if (!expect.equals(found)) {
        System.err.println("expect: " + expect);
        System.err.println(" found: " + expect);
        error("unexpected versions");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:GetSourceVersionsTest.java

示例11: testDiagListener

import javax.tools.ToolProvider; //導入方法依賴的package包/類
/**
 * Verify that a diagnostic listener can be specified.
 * Note that messages from the tool and doclet are imperfectly modeled
 * because the DocErrorReporter API works in terms of localized strings
 * and file:line positions. Therefore, messages reported via DocErrorReporter
 * and simply wrapped and passed through.
 */
@Test
public void testDiagListener() throws Exception {
    JavaFileObject srcFile = createSimpleJavaFileObject("pkg/C", "package pkg; public error { }");
    DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
        File outDir = getOutDir();
        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
        DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();
        DocumentationTask t = tool.getTask(null, fm, dc, null, null, files);
        if (t.call()) {
            throw new Exception("task succeeded unexpectedly");
        } else {
            List<String> diagCodes = new ArrayList<String>();
            for (Diagnostic d: dc.getDiagnostics()) {
                System.err.println(d);
                diagCodes.add(d.getCode());
            }
            List<String> expect = Arrays.asList(
                    "javadoc.note.msg",         // Loading source file
                    "compiler.err.expected3",   // class, interface, or enum expected
                    "javadoc.note.msg");        // 1 error
            if (!diagCodes.equals(expect))
                throw new Exception("unexpected diagnostics occurred");
            System.err.println("diagnostics received as expected");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:GetTask_DiagListenerTest.java

示例12: testRunOK

import javax.tools.ToolProvider; //導入方法依賴的package包/類
/**
     * Verify that run method can be invoked.
     */
//    @Test
    public void testRunOK() throws Exception {
        File testSrc = new File(System.getProperty("test.src"));
        File srcFile = new File(testSrc, "pkg/C.java");
        File outDir = getOutDir();
        String[] args = { "-d", outDir.getPath(), srcFile.getPath() };

        ByteArrayOutputStream stdout = new ByteArrayOutputStream();
        ByteArrayOutputStream stderr = new ByteArrayOutputStream();
        DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
        int rc = tool.run(null, stdout, stderr, args);
        System.err.println("stdout >>" + stdout.toString() + "<<");
        System.err.println("stderr >>" + stderr.toString() + "<<");

        if (rc == 0) {
            System.err.println("call succeeded");
            checkFiles(outDir, standardExpectFiles);
            String out = stdout.toString();
            for (String f: standardExpectFiles) {
                String f1 = f.replace('/', File.separatorChar);
                if (f1.endsWith(".html") && !out.contains(f1))
                    error("expected string not found: " + f1);
            }
        } else {
            error("call failed");
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:31,代碼來源:RunTest.java

示例13: test

import javax.tools.ToolProvider; //導入方法依賴的package包/類
/**
 * Verify that isSupportedOption method can be invoked.
 */
@Test
public void test() throws Exception {
    DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    check(tool, "-sourcepath", 1);
    check(tool, "-verbose", 0);
    check(tool, "-ZZZ", -1);

    try {
        check(tool, null, -1);
        error("null was accepted without exception");
    } catch (NullPointerException e) {
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:IsSupportedOptionTest.java

示例14: runAPI

import javax.tools.ToolProvider; //導入方法依賴的package包/類
private int runAPI(PrintWriter pw) throws IOException {
    try {
        jdtool = (JavadocTool) ToolProvider.getSystemDocumentationTool();
        jdtool = new JavadocTool();

        if (fileManager == null)
            fileManager = internalFileManager = jdtool.getStandardFileManager(null, null, null);
        if (outdir != null)
            setLocationFromPaths(DocumentationTool.Location.DOCUMENTATION_OUTPUT,
                    Collections.singletonList(outdir));
        if (classpath != null)
            setLocationFromPaths(StandardLocation.CLASS_PATH, classpath);
        if (sourcepath != null)
            setLocationFromPaths(StandardLocation.SOURCE_PATH, sourcepath);
        List<String> allOpts = new ArrayList<>();
        if (options != null)
            allOpts.addAll(options);

        Iterable<? extends JavaFileObject> allFiles = joinFiles(files, fileObjects);
        DocumentationTask task = jdtool.getTask(pw,
                fileManager,
                null,  // diagnostic listener; should optionally collect diags
                docletClass,
                allOpts,
                allFiles);
        return ((DocumentationTask) task).call() ? 0 : 1;
    } finally {
        if (internalFileManager != null)
            internalFileManager.close();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:32,代碼來源:JavadocTask.java

示例15: testTagletPath

import javax.tools.ToolProvider; //導入方法依賴的package包/類
/**
 * Verify that a taglet can be specified, and located via
 * the file manager's TAGLET_PATH.
 */
@Test
public void testTagletPath() throws Exception {
    File testSrc = new File(System.getProperty("test.src"));
    File tagletSrcFile = new File(testSrc, "taglets/UnderlineTaglet.java");
    File tagletDir = getOutDir("classes");
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    try (StandardJavaFileManager cfm = compiler.getStandardFileManager(null, null, null)) {
        cfm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(tagletDir));
        Iterable<? extends JavaFileObject> cfiles = cfm.getJavaFileObjects(tagletSrcFile);
        if (!compiler.getTask(null, cfm, null, null, null, cfiles).call())
            throw new Exception("cannot compile taglet");
    }

    JavaFileObject srcFile = createSimpleJavaFileObject("pkg/C", testSrcText);
    DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
        File outDir = getOutDir("api");
        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
        fm.setLocation(DocumentationTool.Location.TAGLET_PATH, Arrays.asList(tagletDir));
        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
        Iterable<String> options = Arrays.asList("-taglet", "UnderlineTaglet");
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        DocumentationTask t = tool.getTask(pw, fm, null, null, options, files);
        boolean ok = t.call();
        String out = sw.toString();
        System.err.println(">>" + out + "<<");
        if (ok) {
            File f = new File(outDir, "pkg/C.html");
            List<String> doc = Files.readAllLines(f.toPath(), Charset.defaultCharset());
            for (String line: doc) {
                if (line.contains("<u>" + TEST_STRING + "</u>")) {
                    System.err.println("taglet executed as expected");
                    return;
                }
            }
            error("expected text not found in output " + f);
        } else {
            error("task failed");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:47,代碼來源:TagletPathTest.java


注:本文中的javax.tools.ToolProvider.getSystemDocumentationTool方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。