本文整理汇总了Java中com.squareup.javawriter.JavaWriter.emitPackage方法的典型用法代码示例。如果您正苦于以下问题:Java JavaWriter.emitPackage方法的具体用法?Java JavaWriter.emitPackage怎么用?Java JavaWriter.emitPackage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javawriter.JavaWriter
的用法示例。
在下文中一共展示了JavaWriter.emitPackage方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
示例7: 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();
}
示例8: 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();
}
示例9: 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();
}
示例10: 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();
}
示例11: 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();
}