本文整理汇总了Java中com.squareup.javawriter.JavaWriter.endType方法的典型用法代码示例。如果您正苦于以下问题:Java JavaWriter.endType方法的具体用法?Java JavaWriter.endType怎么用?Java JavaWriter.endType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javawriter.JavaWriter
的用法示例。
在下文中一共展示了JavaWriter.endType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generate
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generate() throws IOException {
String qualifiedGeneratedClassName = String.format(Locale.US, "%s.%s", Constants.REALM_PACKAGE_NAME, Constants.DEFAULT_MODULE_CLASS_NAME);
JavaFileObject sourceFile = env.getFiler().createSourceFile(qualifiedGeneratedClassName);
JavaWriter writer = new JavaWriter(new BufferedWriter(sourceFile.openWriter()));
writer.setIndent(" ");
writer.emitPackage(Constants.REALM_PACKAGE_NAME);
writer.emitEmptyLine();
Map<String, Boolean> attributes = new HashMap<String, Boolean>();
attributes.put("allClasses", Boolean.TRUE);
writer.emitAnnotation(RealmModule.class, attributes);
writer.beginType(
qualifiedGeneratedClassName, // full qualified name of the item to generate
"class", // the type of the item
Collections.<Modifier>emptySet(), // modifiers to apply
null); // class to extend
writer.emitEmptyLine();
writer.endType();
writer.close();
}
示例2: build
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public RealmSyntheticTestClass build() throws IOException {
StringWriter stringWriter = new StringWriter();
JavaWriter writer = new JavaWriter(stringWriter);
// Package name
writer.emitPackage("some.test");
// Import Realm classes
writer.emitImports("io.realm.*");
writer.emitImports("io.realm.annotations.*");
// Begin the class definition
writer.beginType(
name, // full qualified name of the item to generate
"class", // the type of the item
EnumSet.of(Modifier.PUBLIC), // modifiers to apply
"RealmObject") // class to extend
.emitEmptyLine();
for (Field field : fields) { generateField(writer, field); }
writer.endType();
return new RealmSyntheticTestClass(stringWriter, name);
}
示例3: 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();
}
示例4: generateParceler
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generateParceler() throws IOException {
JavaFileObject sourceFile = processingEnv.getFiler().createSourceFile(parcelerName);
JavaWriter writer = new JavaWriter(sourceFile.openWriter());
writer.emitPackage(processingEnv.getElementUtils().getPackageOf(
elementToParcel).getQualifiedName().toString());
writer.emitImports(getImports());
writer.emitEmptyLine();
elementCompressedName = writer.compressType(elementToParcel.getQualifiedName().toString());
writer.beginType(parcelerName, "class", EnumSet.of(Modifier.PUBLIC, Modifier.FINAL), null,
JavaWriter.type(Parceler.class, elementCompressedName));
writer.emitEmptyLine();
writeWriteToParcelMethod(writer);
writer.emitEmptyLine();
writeReadFromParcelMethod(writer);
writer.emitEmptyLine();
writeNewArrayMethod(writer);
writer.emitEmptyLine();
writer.endType();
writer.close();
}
示例5: generateCode
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generateCode(Elements elementUtils, Filer filer) throws IOException {
TypeElement superClassName = elementUtils.getTypeElement(qualifiedClassName);
String factoryClassName = superClassName.getSimpleName() + SUFFIX;
JavaFileObject jfo = filer.createSourceFile(qualifiedClassName + SUFFIX);
Writer writer = jfo.openWriter();
JavaWriter jw = new JavaWriter(writer);
// 写包名
PackageElement pkg = elementUtils.getPackageOf(superClassName);
if (!pkg.isUnnamed()) {
jw.emitPackage(pkg.getQualifiedName().toString());
jw.emitEmptyLine();
} else {
jw.emitPackage("");
}
jw.beginType(factoryClassName, "class", EnumSet.of(Modifier.PUBLIC));
jw.emitEmptyLine();
jw.beginMethod(qualifiedClassName, "create", EnumSet.of(Modifier.PUBLIC), "String", "id");
jw.beginControlFlow("if (id == null)");
jw.emitStatement("throw new IllegalArgumentException(\"id is null!\")");
jw.endControlFlow();
for (FactoryAnnotatedClass item : itemsMap.values()) {
jw.beginControlFlow(String.format("if (\"%s\".equals(id))", item.getId()));
jw.emitStatement("return new %s()", item.getTypeElement().getQualifiedName().toString());
jw.endControlFlow();
jw.emitEmptyLine();
}
jw.emitStatement("throw new IllegalArgumentException(\"Unknown id = \" + id)");
jw.endMethod();
jw.endType();
jw.close();
}
示例6: 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();
}
}
示例7: generateParseMap
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generateParseMap() throws IOException {
String packageName = packageElement != null
? packageElement.getQualifiedName().toString()
: XmlParserSettingsBuilder.DEFAULT_PACKAGE;
String parserMapClassName = GeneratedClassNames.CLASS_GENERATED_PARSER_MAP;
String qualifiedClassName = GeneratedClassNames.getQualifiedName(packageName,
parserMapClassName);
JavaFileObject sourceFile = processingEnv.getFiler().createSourceFile(qualifiedClassName);
JavaWriter writer = new JavaWriter(sourceFile.openWriter());
writer.emitPackage(packageName);
writer.emitImports(getParsableClassImports());
writer.emitEmptyLine();
writer.emitImports(getJavaImports());
writer.emitEmptyLine();
writer.beginType(GeneratedClassNames.CLASS_GENERATED_PARSER_MAP,
"class",
EnumSet.of(Modifier.PUBLIC, Modifier.FINAL),
null,
ParserMap.class.getCanonicalName());
writer.emitEmptyLine();
writeMapField(writer);
writer.emitEmptyLine();
writeGetter(writer);
writer.emitEmptyLine();
writeKeySet(writer);
writer.endType();
writer.close();
}
示例8: generateParserMap
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generateParserMap() throws IOException {
String packageName = packageElement != null
? packageElement.getQualifiedName().toString()
: JsonParserSettingsBuilder.DEFAULT_OBJECT_PARSER_PACKAGE;
String qualifiedClassName = GeneratedClassNames.getQualifiedName(packageName,
GeneratedClassNames
.CLASS_JSON_OBJECT_PARSER_TABLE);
JavaFileObject sourceFile = processingEnv.getFiler().createSourceFile(qualifiedClassName);
JavaWriter writer = new JavaWriter(sourceFile.openWriter());
writer.emitPackage(packageName);
writer.emitEmptyLine();
writer.emitImports(getImports());
writer.emitEmptyLine();
writer.beginType(GeneratedClassNames.CLASS_JSON_OBJECT_PARSER_TABLE, "class",
EnumSet.of(Modifier.PUBLIC, Modifier.FINAL), null,
JsonObjectParserTable.class.getCanonicalName());
writer.emitEmptyLine();
writeMapField(writer);
writer.emitEmptyLine();
writeGetter(writer);
writer.emitEmptyLine();
writeKeySet(writer);
writer.endType();
writer.close();
}
示例9: generateTable
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generateTable() throws IOException {
String packageName = packageElement != null
? packageElement.getQualifiedName().toString()
: JsonParserSettingsBuilder.DEFAULT_INSTANCE_UPDATER_PACKAGE;
String qualifiedClassName = GeneratedClassNames.getQualifiedName(packageName,
GeneratedClassNames
.CLASS_INSTANCE_UPDATER_TABLE);
JavaFileObject sourceFile = processingEnv.getFiler().createSourceFile(qualifiedClassName);
JavaWriter writer = new JavaWriter(sourceFile.openWriter());
writer.emitPackage(packageName);
writer.emitEmptyLine();
writer.emitImports(getImports());
writer.emitEmptyLine();
writer.beginType(GeneratedClassNames.CLASS_INSTANCE_UPDATER_TABLE, "class",
EnumSet.of(Modifier.PUBLIC, Modifier.FINAL),
null, InstanceUpdaterTable.class.getCanonicalName());
writer.emitEmptyLine();
writeMapField(writer);
writer.emitEmptyLine();
writeGetter(writer);
writer.endType();
writer.close();
}
示例10: generate
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generate() throws IOException {
String qualifiedGeneratedClassName = String.format(Locale.US, "%s.%sMediator", REALM_PACKAGE_NAME, className);
JavaFileObject sourceFile = processingEnvironment.getFiler().createSourceFile(qualifiedGeneratedClassName);
JavaWriter writer = new JavaWriter(new BufferedWriter(sourceFile.openWriter()));
writer.setIndent(" ");
writer.emitPackage(REALM_PACKAGE_NAME);
writer.emitEmptyLine();
writer.emitImports(
"android.util.JsonReader",
"java.io.IOException",
"java.util.Collections",
"java.util.HashSet",
"java.util.List",
"java.util.Map",
"java.util.HashMap",
"java.util.Set",
"java.util.Iterator",
"java.util.Collection",
"io.realm.internal.ColumnInfo",
"io.realm.internal.RealmObjectProxy",
"io.realm.internal.RealmProxyMediator",
"io.realm.internal.Row",
"io.realm.internal.OsSchemaInfo",
"io.realm.internal.OsObjectSchemaInfo",
"org.json.JSONException",
"org.json.JSONObject"
);
writer.emitEmptyLine();
writer.emitAnnotation(RealmModule.class);
writer.beginType(
qualifiedGeneratedClassName, // full qualified name of the item to generate
"class", // the type of the item
Collections.<Modifier>emptySet(), // modifiers to apply
"RealmProxyMediator"); // class to extend
writer.emitEmptyLine();
emitFields(writer);
emitGetExpectedObjectSchemaInfoMap(writer);
emitCreateColumnInfoMethod(writer);
emitGetFieldNamesMethod(writer);
emitGetSimpleClassNameMethod(writer);
emitNewInstanceMethod(writer);
emitGetClassModelList(writer);
emitCopyToRealmMethod(writer);
emitInsertObjectToRealmMethod(writer);
emitInsertListToRealmMethod(writer);
emitInsertOrUpdateObjectToRealmMethod(writer);
emitInsertOrUpdateListToRealmMethod(writer);
emitCreteOrUpdateUsingJsonObject(writer);
emitCreateUsingJsonStream(writer);
emitCreateDetachedCopyMethod(writer);
writer.endType();
writer.close();
}
示例11: generate
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generate() throws IOException, UnsupportedOperationException {
JavaFileObject sourceFile = processingEnvironment.getFiler().createSourceFile(qualifiedGeneratedClassName);
JavaWriter writer = new JavaWriter(new BufferedWriter(sourceFile.openWriter()));
// Set source code indent
writer.setIndent(Constants.INDENT);
writer.emitPackage(Constants.REALM_PACKAGE_NAME)
.emitEmptyLine();
List<String> imports = new ArrayList<String>(IMPORTS);
if (!metadata.getBacklinkFields().isEmpty()) {
imports.add("io.realm.internal.UncheckedRow");
}
writer.emitImports(imports)
.emitEmptyLine();
// Begin the class definition
if (suppressWarnings) {
writer.emitAnnotation("SuppressWarnings(\"all\")");
}
writer
.beginType(
qualifiedGeneratedClassName, // full qualified name of the item to generate
"class", // the type of the item
EnumSet.of(Modifier.PUBLIC), // modifiers to apply
qualifiedClassName, // class to extend
"RealmObjectProxy", // interfaces to implement
interfaceName)
.emitEmptyLine();
emitColumnInfoClass(writer);
emitClassFields(writer);
emitInstanceFields(writer);
emitConstructor(writer);
emitInjectContextMethod(writer);
emitPersistedFieldAccessors(writer);
emitBacklinkFieldAccessors(writer);
emitCreateExpectedObjectSchemaInfo(writer);
emitGetExpectedObjectSchemaInfo(writer);
emitCreateColumnInfoMethod(writer);
emitGetSimpleClassNameMethod(writer);
emitGetFieldNamesMethod(writer);
emitCreateOrUpdateUsingJsonObject(writer);
emitCreateUsingJsonStream(writer);
emitCopyOrUpdateMethod(writer);
emitCopyMethod(writer);
emitInsertMethod(writer);
emitInsertListMethod(writer);
emitInsertOrUpdateMethod(writer);
emitInsertOrUpdateListMethod(writer);
emitCreateDetachedCopyMethod(writer);
emitUpdateMethod(writer);
emitToStringMethod(writer);
emitRealmObjectProxyImplementation(writer);
emitHashcodeMethod(writer);
emitEqualsMethod(writer);
// End the class definition
writer.endType();
writer.close();
}
示例12: generate
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generate() throws IOException {
String qualifiedGeneratedInterfaceName =
String.format(Locale.US, "%s.%s", Constants.REALM_PACKAGE_NAME, Utils.getProxyInterfaceName(className));
JavaFileObject sourceFile = processingEnvironment.getFiler().createSourceFile(qualifiedGeneratedInterfaceName);
JavaWriter writer = new JavaWriter(new BufferedWriter(sourceFile.openWriter()));
writer.setIndent(Constants.INDENT);
writer
.emitPackage(Constants.REALM_PACKAGE_NAME)
.emitEmptyLine()
.beginType(qualifiedGeneratedInterfaceName, "interface", EnumSet.of(Modifier.PUBLIC));
for (VariableElement field : metaData.getFields()) {
if (field.getModifiers().contains(Modifier.STATIC) || (field.getAnnotation(Ignore.class) != null)) {
continue;
}
// The field is neither static nor ignored
String fieldName = field.getSimpleName().toString();
String fieldTypeCanonicalName = field.asType().toString();
writer
.beginMethod(
fieldTypeCanonicalName,
metaData.getInternalGetter(fieldName),
EnumSet.of(Modifier.PUBLIC))
.endMethod();
// MutableRealmIntegers do not have setters.
if (Utils.isMutableRealmInteger(field)) { continue; }
writer
.beginMethod(
"void",
metaData.getInternalSetter(fieldName),
EnumSet.of(Modifier.PUBLIC),
fieldTypeCanonicalName,
"value")
.endMethod();
}
// backlinks are final and have only a getter.
for (Backlink backlink : metaData.getBacklinkFields()) {
writer
.beginMethod(
backlink.getTargetFieldType(),
metaData.getInternalGetter(backlink.getTargetField()),
EnumSet.of(Modifier.PUBLIC))
.endMethod();
}
writer.endType();
writer.close();
}
示例13: generateParser
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generateParser()
throws IOException {
String parserName =
classElement.getQualifiedName().toString() + GeneratedClassNames.PARSER_SUFFIX;
JavaFileObject sourceFile = processingEnv.getFiler().createSourceFile(parserName);
JavaWriter writer = new JavaWriter(sourceFile.openWriter());
writer.emitPackage(processingEnv.getElementUtils()
.getPackageOf(classElement)
.getQualifiedName()
.toString());
writer.emitImports(getStandardImports());
writer.emitEmptyLine();
String xmlElementParserName =
JavaWriter.type(XmlElementParser.class, classElement.getSimpleName().toString());
writer.beginType(parserName,
"class",
EnumSet.of(Modifier.PUBLIC, Modifier.FINAL),
null,
xmlElementParserName);
writer.emitEmptyLine();
writer.emitField(parserName,
"INSTANCE",
EnumSet.of(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL),
String.format("new %s()", writer.compressType(parserName)));
writer.emitEmptyLine();
// Constructor
writer.beginMethod(null, parserName, EnumSet.of(Modifier.PRIVATE));
writer.endMethod();
writer.emitEmptyLine();
writeParseElementMethod(writer);
writer.emitEmptyLine();
parseAttributesMethodWriter.writeParseAttributesMethod(classElement, writer);
writer.emitEmptyLine();
parseChildrenMethodWriter.writeParseChildrenMethod(classElement, writer);
writer.emitEmptyLine();
writer.endType();
writer.close();
}
示例14: generateParser
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generateParser() throws IOException {
String parserName = MetaTypeNames.constructTypeName(classElement, GeneratedClassNames.PARSER_SUFFIX);
JavaFileObject sourceFile = processingEnv.getFiler().createSourceFile(parserName);
JavaWriter writer = new JavaWriter(sourceFile.openWriter());
writer.setIndent(" ");
writer.emitPackage(processingEnv.getElementUtils().getPackageOf(classElement).getQualifiedName().toString());
writer.emitImports(getStandardImports());
writer.emitEmptyLine();
parsedClassName = writer.compressType(classElement.getQualifiedName().toString());
String jsonObjectParserInterfaceName = JavaWriter.type(JsonObjectParser.class, parsedClassName);
String fromMapUpdaterInterfaceName = JavaWriter.type(InstanceUpdater.class, parsedClassName);
writer.beginType(parserName, "class", EnumSet.of(Modifier.PUBLIC, Modifier.FINAL), null,
jsonObjectParserInterfaceName, fromMapUpdaterInterfaceName);
writer.emitEmptyLine();
writer.emitField(parserName, "INSTANCE", Modifiers.PUBLIC_CONSTANT,
String.format("new %s()", writer.compressType(parserName)));
writer.emitEmptyLine();
// Constructor
writer.beginMethod(null, parserName, Modifiers.PRIVATE);
writer.endMethod();
writer.emitEmptyLine();
initializeAssignments(writer);
writePublicParseJsonObjectMethod(writer);
writer.emitEmptyLine();
writeParseFromJsonObjectMethod(writer);
writer.emitEmptyLine();
writeParseFromReaderMethod(writer);
writer.emitEmptyLine();
writeUpdateFromMapMethod(writer);
writer.emitEmptyLine();
writeGetFieldMethod(writer);
writer.emitEmptyLine();
writeInitializeAndGetFieldMethod(writer);
writer.emitEmptyLine();
writeDoInitializeAndGetFieldMethod(writer);
if (!postCreateChildMethods.isEmpty()) {
// TODO: Only write the methods that we need.
// TODO: Tell block writer whether to write the map or collection parts.
writer.emitEmptyLine();
postCreateChildBlockWriter.writePostCreateChildMethod(writer);
writer.emitEmptyLine();
postCreateChildBlockWriter.writePostCreateCollectionMethod(writer);
writer.emitEmptyLine();
postCreateChildBlockWriter.writePostCreateMapMethod(writer);
}
writer.endType();
writer.close();
}