当前位置: 首页>>代码示例>>Java>>正文


Java DocumentationTool类代码示例

本文整理汇总了Java中javax.tools.DocumentationTool的典型用法代码示例。如果您正苦于以下问题:Java DocumentationTool类的具体用法?Java DocumentationTool怎么用?Java DocumentationTool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DocumentationTool类属于javax.tools包,在下文中一共展示了DocumentationTool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testBadFileObject

import javax.tools.DocumentationTool; //导入依赖的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

示例2: testNull

import javax.tools.DocumentationTool; //导入依赖的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

示例3: testDirectAccess1

import javax.tools.DocumentationTool; //导入依赖的package包/类
@Test
public void testDirectAccess1() throws Exception {
    JavaFileObject srcFile = createSimpleJavaFileObject();
    Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
    Context c = new Context();
    Messager.preRegister(c, "javadoc");
    try (StandardJavaFileManager fm = new JavacFileManager(c, true, null)) {
        File outDir = getOutDir();
        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
        DocumentationTask t = new JavadocTaskImpl(c, null, null, files);
        if (t.call()) {
            System.err.println("task succeeded");
        } else {
            throw new Exception("task failed");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:JavadocTaskImplTest.java

示例4: testMemoryFileObject

import javax.tools.DocumentationTool; //导入依赖的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

示例5: testNull

import javax.tools.DocumentationTool; //导入依赖的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

示例6: testDoclet

import javax.tools.DocumentationTool; //导入依赖的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

示例7: testRawCall

import javax.tools.DocumentationTool; //导入依赖的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

示例8: testDirectAccess2

import javax.tools.DocumentationTool; //导入依赖的package包/类
@Test
public void testDirectAccess2() throws Exception {
    JavaFileObject srcFile = null; // error, provokes NPE
    Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
    Context c = new Context();
    Messager.preRegister(c, "javadoc");
    try (StandardJavaFileManager fm = new JavacFileManager(c, true, null)) {
        File outDir = getOutDir();
        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
        try {
            DocumentationTask t = new JavadocTaskImpl(c, null, null, files);;
            error("getTask succeeded, no exception thrown");
        } catch (NullPointerException e) {
            System.err.println("exception caught as expected: " + e);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:JavadocTaskImplTest.java

示例9: testStandardFileObject

import javax.tools.DocumentationTool; //导入依赖的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

示例10: testNoIndex

import javax.tools.DocumentationTool; //导入依赖的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

示例11: readPackageListFromFile

import javax.tools.DocumentationTool; //导入依赖的package包/类
/**
 * Read the "package-list" file which is available locally.
 *
 * @param path URL or directory path to the packages.
 * @param pkgListPath Path to the local "package-list" file.
 */
private void readPackageListFromFile(String path, DocFile pkgListPath)
        throws Fault {
    DocFile file = pkgListPath.resolve(DocPaths.PACKAGE_LIST);
    if (! (file.isAbsolute() || linkoffline)){
        file = file.resolveAgainst(DocumentationTool.Location.DOCUMENTATION_OUTPUT);
    }
    try {
        if (file.exists() && file.canRead()) {
            boolean pathIsRelative =
                    !DocFile.createFileForInput(configuration, path).isAbsolute()
                    && !isUrl(path);
            readPackageList(file.openInputStream(), path, pathIsRelative);
        } else {
            throw new Fault(configuration.getText("doclet.File_error", file.getPath()), null);
        }
    } catch (IOException exc) {
       throw new Fault(configuration.getText("doclet.File_error", file.getPath()), exc);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:Extern.java

示例12: PathDocFileFactory

import javax.tools.DocumentationTool; //导入依赖的package包/类
public PathDocFileFactory(Configuration configuration) {
    super(configuration);
    fileManager = (PathFileManager) configuration.getFileManager();

    if (!configuration.destDirName.isEmpty()
            || !fileManager.hasLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT)) {
        try {
            String dirName = configuration.destDirName.isEmpty() ? "." : configuration.destDirName;
            Path dir = fileManager.getDefaultFileSystem().getPath(dirName);
            fileManager.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(dir));
        } catch (IOException e) {
            throw new DocletAbortException(e);
        }
    }

    destDir = fileManager.getLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT).iterator().next();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:PathDocFileFactory.java

示例13: getDestDir

import javax.tools.DocumentationTool; //导入依赖的package包/类
private File getDestDir() {
    if (destDir == null) {
        if (!configuration.destDirName.isEmpty()
                || !fileManager.hasLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT)) {
            try {
                String dirName = configuration.destDirName.isEmpty() ? "." : configuration.destDirName;
                File dir = new File(dirName);
                fileManager.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(dir));
            } catch (IOException e) {
                throw new DocletAbortException(e);
            }
        }

        destDir = fileManager.getLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT).iterator().next();
    }
    return destDir;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:StandardDocFileFactory.java

示例14: readPackageListFromFile

import javax.tools.DocumentationTool; //导入依赖的package包/类
/**
 * Read the "package-list" file which is available locally.
 *
 * @param path URL or directory path to the packages.
 * @param pkgListPath Path to the local "package-list" file.
 * @throws Fault if an error occurs that can be treated as a warning
 * @throws DocFileIOException if there is a problem opening the package list file
 */
private void readPackageListFromFile(String path, DocFile pkgListPath)
        throws Fault, DocFileIOException {
    DocFile file = pkgListPath.resolve(DocPaths.PACKAGE_LIST);
    if (! (file.isAbsolute() || linkoffline)){
        file = file.resolveAgainst(DocumentationTool.Location.DOCUMENTATION_OUTPUT);
    }
    try {
        if (file.exists() && file.canRead()) {
            boolean pathIsRelative =
                    !isUrl(path)
                    && !DocFile.createFileForInput(configuration, path).isAbsolute();
            readPackageList(file.openInputStream(), path, pathIsRelative);
        } else {
            throw new Fault(configuration.getText("doclet.File_error", file.getPath()), null);
        }
    } catch (IOException exc) {
       throw new Fault(configuration.getText("doclet.File_error", file.getPath()), exc);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:Extern.java

示例15: setDestDir

import javax.tools.DocumentationTool; //导入依赖的package包/类
@Override
public void setDestDir(String destDirName) throws SimpleDocletException {
    if (destDir != null)
        throw new AssertionError("destDir already initialized: " + destDir);

    if (!destDirName.isEmpty()
            || !fileManager.hasLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT)) {
        try {
            String dirName = destDirName.isEmpty() ? "." : destDirName;
            Path dir = Paths.get(dirName);
            fileManager.setLocationFromPaths(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(dir));
        } catch (IOException e) {
            // generic IOException from file manager, setting location, e.g. file not a directory
            String message = configuration.getResources().getText("doclet.error.initializing.dest.dir", e);
            throw new SimpleDocletException(message, e);
        }
    }

    destDir = fileManager.getLocationAsPaths(DocumentationTool.Location.DOCUMENTATION_OUTPUT).iterator().next();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:StandardDocFileFactory.java


注:本文中的javax.tools.DocumentationTool类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。