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


Java Tool类代码示例

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


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

示例1: main

import javax.tools.Tool; //导入依赖的package包/类
public static void main(String... args) {
    Tool compiler = ToolProvider.getSystemJavaCompiler();
    Set<SourceVersion> expected = EnumSet.noneOf(SourceVersion.class);
    for (String arg : args)
        expected.add(SourceVersion.valueOf(arg));
    Set<SourceVersion> found = compiler.getSourceVersions();
    Set<SourceVersion> notExpected = EnumSet.copyOf(found);
    for (SourceVersion version : expected) {
        if (!found.contains(version))
            throw new AssertionError("Expected source version not found: " + version);
        else
            notExpected.remove(version);
    }
    if (!notExpected.isEmpty())
        throw new AssertionError("Unexpected source versions: " + notExpected);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:T6395981.java

示例2: run

import javax.tools.Tool; //导入依赖的package包/类
public void run() throws Exception {
    Optional<Tool> opt = findFirst("javadoc");
    if (!opt.isPresent()) {
        throw new Exception("tool not found");
    }
    if (!(opt.get() instanceof JavadocTool)) {
        throw new Exception("unexpected tool found");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:TestName.java

示例3: findFirst

import javax.tools.Tool; //导入依赖的package包/类
Optional<Tool> findFirst(String name) {
    getClass().getModule().addUses(Tool.class);
    for (Tool p : ServiceLoader.load(Tool.class,
            ClassLoader.getSystemClassLoader())) {
        if (p.name().equals(name)) {
            return Optional.of(p);
        }
    }
    return Optional.empty();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:TestName.java

示例4: runShellServiceLoader

import javax.tools.Tool; //导入依赖的package包/类
private int runShellServiceLoader(String... args) {
    ServiceLoader<Tool> sl = ServiceLoader.load(Tool.class);
    for (Tool provider : sl) {
        if (provider.name().equals("jshell")) {
            return provider.run(cmdInStream, cmdout, cmderr, args);
        }
    }
    throw new AssertionError("Repl tool not found by ServiceLoader: " + sl);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:ToolProviderTest.java

示例5: compile

import javax.tools.Tool; //导入依赖的package包/类
static void compile(String... args) {
    StringBuffer sb = new StringBuffer("compile:");
    for (String a: args)
        sb.append(' ').append(a);
    System.err.println(sb);

    Tool t = ToolProvider.getSystemJavaCompiler();
    int rc = t.run(System.in, System.out, System.err, args);
    System.out.flush();
    System.err.flush();
    if (rc != 0)
        throw new Error("compilation failed");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:T6350124.java

示例6: run

import javax.tools.Tool; //导入依赖的package包/类
public void run() throws Exception {
    Optional<Tool> opt = findFirst("javac");
    if (!opt.isPresent()) {
        throw new Exception("tool not found");
    }
    if (!(opt.get() instanceof JavacTool)) {
        throw new Exception("unexpected tool found");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:TestName.java

示例7: compileJava

import javax.tools.Tool; //导入依赖的package包/类
public void compileJava(List<JavacOption> options, List<File> sourceFiles)
{
    List<String> args = ImmutableList.<String>builder()
            .addAll(options.stream().map(JavacOption::getArgs).flatMap(List::stream).iterator())
            .addAll(sourceFiles.stream().map(File::getPath).iterator())
            .build();
    Tool javac = ToolProvider.getSystemJavaCompiler();
    javac.run(null, null, null, args.toArray(new String[args.size()]));
}
 
开发者ID:wrmsr,项目名称:wava,代码行数:10,代码来源:InProcJavaCompiler.java

示例8: run

import javax.tools.Tool; //导入依赖的package包/类
static int run(InputStream in, OutputStream out, OutputStream err, String... arguments) {
  ServiceLoader<Tool> loader = ServiceLoader.load(Tool.class, JShellConfigRunner.class.getClassLoader());
  Tool jshell = loader.stream()
      .map(provider -> provider.get())
      .filter(tool -> tool.name().equals("jshell"))
      .findFirst()
      .orElseThrow(() -> new IllegalStateException("can not find jshell"));
  return jshell.run(in, out, err, arguments);
}
 
开发者ID:forax,项目名称:pro,代码行数:10,代码来源:JShellWrapper.java

示例9: doCompile

import javax.tools.Tool; //导入依赖的package包/类
protected static int doCompile(String dir, String classpath, List<String> files, OutputStream out, OutputStream err) {
    List<String> args = new ArrayList<String>();
    args.add("-target");
    args.add("1.5");
    args.add("-d");
    args.add(dir);
    args.add("-cp");
    args.add(classpath);
    Tool compiler = null;
    for (String f : files) {
        Tool ftool;
        if (f.endsWith(".f3"))
            ftool = f3c;
        else if (f.endsWith(".java"))
            ftool = javac;
        else
            ftool = null;
        if (compiler != null && ftool != null && ftool != compiler) {
            throw new IllegalArgumentException("cannot compile both .java and .f3 with same compiler");
        }
        compiler = ftool;
        args.add(f);
    }
    if (compiler == null)
      compiler = f3c;
    return compiler.run(null, out, err, args.toArray(new String[args.size()]));
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:28,代码来源:TestHelper.java


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