本文整理汇总了Java中com.squareup.javawriter.JavaWriter.emitSingleLineComment方法的典型用法代码示例。如果您正苦于以下问题:Java JavaWriter.emitSingleLineComment方法的具体用法?Java JavaWriter.emitSingleLineComment怎么用?Java JavaWriter.emitSingleLineComment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javawriter.JavaWriter
的用法示例。
在下文中一共展示了JavaWriter.emitSingleLineComment方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateTo
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
final void generateTo(final Writer out) throws IOException {
JavaWriter w = new JavaWriter(out);
w.emitSingleLineComment("Code generated by Enroscar. Do not edit. %s",
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US).format(new Date()));
w.emitPackage(packageName);
w.emitImports(imports);
w.emitEmptyLine();
classJavaDoc(w);
w.beginType(className, "class", modifiers(operationsClass), extendsClass);
w.emitEmptyLine();
writeClassBody(w);
w.endType();
}
示例2: generate
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
/**
* Generates the BuildConfig class.
*/
public void generate() throws IOException {
File pkgFolder = getFolderPath();
if (!pkgFolder.isDirectory()) {
if (!pkgFolder.mkdirs()) {
throw new RuntimeException("Failed to create " + pkgFolder.getAbsolutePath());
}
}
File buildConfigJava = new File(pkgFolder, BUILD_CONFIG_NAME);
Closer closer = Closer.create();
try {
FileOutputStream fos = closer.register(new FileOutputStream(buildConfigJava));
OutputStreamWriter out = closer.register(new OutputStreamWriter(fos, Charsets.UTF_8));
JavaWriter writer = closer.register(new JavaWriter(out));
writer.emitJavadoc("Automatically generated file. DO NOT MODIFY")
.emitPackage(mBuildConfigPackageName)
.beginType("BuildConfig", "class", PUBLIC_FINAL);
for (ClassField field : mFields) {
emitClassField(writer, field);
}
for (Object item : mItems) {
if (item instanceof ClassField) {
emitClassField(writer, (ClassField) item);
} else if (item instanceof String) {
writer.emitSingleLineComment((String) item);
}
}
writer.endType();
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}
示例3: writeParseChildrenMethod
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void writeParseChildrenMethod(TypeElement classElement, JavaWriter writer)
throws IOException {
List<String> parameters = new ArrayList<String>(4);
parameters.add(classElement.getSimpleName().toString());
parameters.add("object");
parameters.add(XmlStreamReader.class.getSimpleName());
parameters.add("reader");
List<String> throwsTypes = CollectionUtils.newArrayList(
ParseException.class.getSimpleName(),
UnknownElementException.class.getSimpleName(),
UnexpectedChildException.class.getSimpleName());
writer.beginMethod("void",
"parseChildren",
EnumSet.of(Modifier.PRIVATE),
parameters,
throwsTypes);
initializeSetters(writer);
writer.beginControlFlow("while (!reader.isEndElement())");
writer.emitStatement(
"Preconditions.checkState(reader.isStartElement(), \"Expected to be at a start "
+ "element\")");
writer.emitStatement("String name = reader.getName()");
writer.emitStatement("Object child = ParserUtils.parseCurrentElement(reader)");
boolean first = true;
first = writeChildIfStatements(writer, first);
String unexpectedChildStatement =
String.format("%s.handleUnexpectedChild(object, child, name)",
UnexpectedElementHandler.class.getSimpleName());
if (first) {
writer.emitStatement(unexpectedChildStatement);
} else {
writer.nextControlFlow("else if (child == null)");
writer.emitSingleLineComment("do nothing");
writer.nextControlFlow("else");
writer.emitStatement(unexpectedChildStatement);
writer.endControlFlow();
}
writer.endControlFlow();
writeSetterAssignments(writer);
writer.endMethod();
}
示例4: writeClassBody
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
protected void writeClassBody(JavaWriter w) throws IOException {
w.emitSingleLineComment("construction");
w.beginConstructor(EnumSet.of(PRIVATE), "final " + operatorContext(operationsClass), "context");
w.emitStatement("super(new %s(context), context)", loaderDescription(packageName, operationsClass));
w.endConstructor();
String buildClass = OPERATOR_BUILDER_CLASS
+ "<" + getFqcn() + ", " + operationsClass.getQualifiedName() + ">";
w.beginMethod(buildClass, "build", EnumSet.of(PUBLIC, STATIC));
w.emitStatement(
"return new " + simpleName(OPERATOR_BUILDER_BASE_CLASS)
+ "<" + getFqcn() + ", " + operationsClass.getQualifiedName() + ">() {\n"
+ " @Override\n"
+ " protected " + getFqcn() + " create(final " + operatorContext(operationsClass) + " context) {\n"
+ " return new " + getFqcn() + "(context);\n"
+ " }\n"
+ "}"
);
w.endMethod();
w.emitEmptyLine();
w.emitSingleLineComment("invocation");
for (MethodData data : methods) {
ExecutableElement m = data.method;
boolean load = isLoadMethod(m);
int loaderId = getLoaderId(m);
w.beginMethod("void", m.getSimpleName().toString(), EnumSet.of(PUBLIC), parameters(w, m), null);
w.emitStatement(data.operatorTypeSupport.asyncProvider(w, m));
w.emitStatement("%sLoader(%d, provider, %b)", load ? "init" : "restart", loaderId, !load);
w.endMethod();
w.emitEmptyLine();
if (load) {
// force method
w.beginMethod("void", "force" + capitalize(m.getSimpleName().toString()),
EnumSet.of(PUBLIC), parameters(w, m), null);
w.emitStatement(data.operatorTypeSupport.asyncProvider(w, m));
w.emitStatement("restartLoader(%d, provider, false)", loaderId);
w.endMethod();
w.emitEmptyLine();
}
w.beginMethod("void", "cancel" + capitalize(m.getSimpleName().toString()),
EnumSet.of(PUBLIC));
w.emitStatement("destroyLoader(%d)", loaderId);
w.endMethod();
w.emitEmptyLine();
}
}