com.squareup.javawriter.JavaWriter.emitStaticImports()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(2.0k)|赞(0)|评价(0)|浏览(63)

本文整理了Java中com.squareup.javawriter.JavaWriter.emitStaticImports()方法的一些代码示例,展示了JavaWriter.emitStaticImports()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JavaWriter.emitStaticImports()方法的具体详情如下:
包路径:com.squareup.javawriter.JavaWriter
类名称:JavaWriter
方法名:emitStaticImports

JavaWriter.emitStaticImports介绍

[英]Emit a static import for each type in the provided Collection. For the duration of the file, all references to these classes will be automatically shortened.
[中]为提供的集合中的每个类型发出静态导入。在文件期间,对这些类的所有引用都将自动缩短。

代码示例

代码示例来源:origin: com.squareup/javawriter

/**
 * Emit a static import for each {@code type} provided. For the duration of the file,
 * all references to these classes will be automatically shortened.
 */
public JavaWriter emitStaticImports(String... types) throws IOException {
 return emitStaticImports(Arrays.asList(types));
}

代码示例来源:origin: com.stanfy.helium/helium

protected void startTest(final JavaWriter java, final Service service, final Project project) throws IOException {
 java.emitPackage(getPackageName())
   .emitImports(
     Test.class.getName(),
     MethodType.class.getName(), RestApiMethods.class.getName(), URI.class.getName(),
     Request.class.getName(), Response.class.getName(), OkHttpClient.class.getName(),
     RequestBody.class.getName(), MediaType.class.getName(),
     Helium.class.getName()
   )
   .emitStaticImports(Assertions.class.getName() + ".assertThat")
   .beginType(getClassName(service), "class", PUBLIC, RestApiMethods.class.getSimpleName());
 java.emitAnnotation(Override.class);
 java.beginMethod("void", "prepareVariables", PROTECTED, "final Helium", "helium");
 if (project instanceof ProjectDsl) {
  Map<?, ?> varMap = ((ProjectDsl) project).getVariablesBinding().getVariables();
  for (Map.Entry entry : varMap.entrySet()) {
   String name = String.valueOf(entry.getKey());
   if ("baseDir".equals(name)) {
    continue;
   }
   String value = String.valueOf(entry.getValue());
   java.emitStatement("helium.set(%1$s, %2$s)", stringLiteral(name), stringLiteral(value));
  }
 }
 java.endMethod();
 java.emitEmptyLine();
}

相关文章