本文整理汇总了Java中com.squareup.javawriter.JavaWriter.beginMethod方法的典型用法代码示例。如果您正苦于以下问题:Java JavaWriter.beginMethod方法的具体用法?Java JavaWriter.beginMethod怎么用?Java JavaWriter.beginMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javawriter.JavaWriter
的用法示例。
在下文中一共展示了JavaWriter.beginMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: emitGetExpectedObjectSchemaInfoMap
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitGetExpectedObjectSchemaInfoMap(JavaWriter writer) throws IOException {
writer.emitAnnotation("Override");
writer.beginMethod(
"Map<Class<? extends RealmModel>, OsObjectSchemaInfo>",
"getExpectedObjectSchemaInfoMap",
EnumSet.of(Modifier.PUBLIC));
writer.emitStatement(
"Map<Class<? extends RealmModel>, OsObjectSchemaInfo> infoMap = " +
"new HashMap<Class<? extends RealmModel>, OsObjectSchemaInfo>(%s)", qualifiedProxyClasses.size());
for (int i = 0; i < qualifiedProxyClasses.size(); i++) {
writer.emitStatement("infoMap.put(%s.class, %s.getExpectedObjectSchemaInfo())",
qualifiedModelClasses.get(i), qualifiedProxyClasses.get(i));
}
writer.emitStatement("return infoMap");
writer.endMethod();
writer.emitEmptyLine();
}
示例2: emitInjectContextMethod
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitInjectContextMethod(JavaWriter writer) throws IOException {
writer.emitAnnotation("Override");
writer.beginMethod(
"void", // Return type
"realm$injectObjectContext", // Method name
EnumSet.of(Modifier.PUBLIC) // Modifiers
); // Argument type & argument name
writer.beginControlFlow("if (this.proxyState != null)")
.emitStatement("return")
.endControlFlow()
.emitStatement("final BaseRealm.RealmObjectContext context = BaseRealm.objectContext.get()")
.emitStatement("this.columnInfo = (%1$s) context.getColumnInfo()", columnInfoClassName())
.emitStatement("this.proxyState = new ProxyState<%1$s>(this)", qualifiedClassName)
.emitStatement("proxyState.setRealm$realm(context.getRealm())")
.emitStatement("proxyState.setRow$realm(context.getRow())")
.emitStatement("proxyState.setAcceptDefaultValue$realm(context.getAcceptDefaultValue())")
.emitStatement("proxyState.setExcludeFields$realm(context.getExcludeFields())")
.endMethod()
.emitEmptyLine();
}
示例3: emitSetter
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitSetter(JavaWriter writer, Field field) throws IOException {
// Setter
writer.beginMethod(
"void", // Return type
"set" + field.name, // Method name
EnumSet.of(Modifier.PUBLIC), field.type, field.name); // Modifiers
writer.emitStatement("realmSet$" + field.name + "(" + field.name + ")");
writer.endMethod();
// Realm Setter
writer.beginMethod(
"void", // Return type
"realmSet$" + field.name, // Method name
EnumSet.of(Modifier.PUBLIC), field.type, field.name); // Modifiers
writer.emitStatement("this." + field.name + "=" + field.name);
writer.endMethod();
}
示例4: emitGetter
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitGetter(JavaWriter writer, Field field) throws IOException {
// Getter
writer.beginMethod(
field.type, // Return type
"get" + field.name, // Method name
EnumSet.of(Modifier.PUBLIC)); // Modifiers
writer.emitStatement("return realmGet$" + field.name + "()");
writer.endMethod();
// Realm Getter
writer.beginMethod(
field.type, // Return type
"realmGet$" + field.name, // Method name
EnumSet.of(Modifier.PUBLIC)); // Modifiers
writer.emitStatement("return " + field.name);
writer.endMethod();
}
示例5: writeWriteToParcelMethod
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeWriteToParcelMethod(JavaWriter writer) throws IOException {
List<String> parameters = new ArrayList<>(4);
parameters.add(elementCompressedName);
parameters.add("object");
parameters.add("Parcel");
parameters.add("dest");
writer.emitAnnotation(Override.class);
writer.beginMethod("void", "writeToParcel", Modifiers.PUBLIC, parameters, null);
writer.emitStatement("Bundle bundle = new Bundle()");
for (VariableElement field : parceledFields) {
getSaveStatementWriter(field).writeFieldWriteStatement(field, writer);
}
writer.emitStatement("dest.writeBundle(bundle)");
writer.endMethod();
}
示例6: writePostCreateMapMethod
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
public void writePostCreateMapMethod(JavaWriter writer) throws IOException {
String mapType = writer.compressType(JavaWriter.type(Map.class, "?", "?"));
writer.beginMethod("void",
"onPostCreateMap",
Modifiers.PRIVATE,
parentType,
"parent",
mapType,
"map");
writer.beginControlFlow("for (Object o : map.values())");
writeItemSwitch(writer, "parent", "o");
writer.endControlFlow();
writer.endMethod();
}
示例7: writeReadFromParcelMethod
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeReadFromParcelMethod(JavaWriter writer) throws IOException {
writer.emitAnnotation(Override.class);
writer.beginMethod(elementCompressedName, "readFromParcel", Modifiers.PUBLIC, "Parcel",
"parcel");
writer.emitStatement("%s object = new %s()", elementCompressedName, elementCompressedName);
writer.emitStatement("Bundle bundle = parcel.readBundle()");
writer.emitStatement("bundle.setClassLoader(%s.class.getClassLoader())",
elementCompressedName);
for (VariableElement field : parceledFields) {
getSaveStatementWriter(field).writeFieldReadStatement(field,
postCreateChildMethods,
writer);
}
writer.emitStatement("return object");
writer.endMethod();
}
示例8: writePostCreateCollectionMethod
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
public void writePostCreateCollectionMethod(JavaWriter writer) throws IOException {
String collectionType = writer.compressType(JavaWriter.type(Collection.class, "?"));
writer.beginMethod("void",
"onPostCreateCollection",
Modifiers.PRIVATE,
parentType,
"parent",
collectionType,
"collection");
writer.beginControlFlow("for (Object o : collection)");
writeItemSwitch(writer, "parent", "o");
writer.endControlFlow();
writer.endMethod();
}
示例9: emitGetClassModelList
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitGetClassModelList(JavaWriter writer) throws IOException {
writer.emitAnnotation("Override");
writer.beginMethod("Set<Class<? extends RealmModel>>", "getModelClasses", EnumSet.of(Modifier.PUBLIC));
writer.emitStatement("return MODEL_CLASSES");
writer.endMethod();
writer.emitEmptyLine();
}
示例10: emitGetExpectedObjectSchemaInfo
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitGetExpectedObjectSchemaInfo(JavaWriter writer) throws IOException {
writer.beginMethod(
"OsObjectSchemaInfo", // Return type
"getExpectedObjectSchemaInfo", // Method name
EnumSet.of(Modifier.PUBLIC, Modifier.STATIC)); // Modifiers
writer.emitStatement("return expectedObjectSchemaInfo");
writer.endMethod()
.emitEmptyLine();
}
示例11: emitCreateColumnInfoMethod
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitCreateColumnInfoMethod(JavaWriter writer) throws IOException {
writer.beginMethod(
columnInfoClassName(), // Return type
"createColumnInfo", // Method name
EnumSet.of(Modifier.PUBLIC, Modifier.STATIC), // Modifiers
"OsSchemaInfo", "schemaInfo"); // Argument type & argument name
// create an instance of ColumnInfo
writer.emitStatement("return new %1$s(schemaInfo)", columnInfoClassName());
writer.endMethod();
writer.emitEmptyLine();
}
示例12: 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();
}
示例13: writeParseAttributesMethod
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void writeParseAttributesMethod(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");
writer.beginMethod("void", "parseAttributes", EnumSet.of(Modifier.PRIVATE), parameters,
CollectionUtils.newArrayList(ParseException.class.getSimpleName()));
writer.emitStatement("Attributes attributes = new Attributes(reader)");
for (Map.Entry<List<String>, Element> entry : attributesAndElements.getAttributes()
.entrySet()) {
List<String> names = entry.getKey();
Element attributeElement = entry.getValue();
writeAttributeAssignment(names, attributeElement, writer);
}
Element textContent = attributesAndElements.getTextContentElement();
writer.emitField("String",
"contentString",
EnumSet.noneOf(Modifier.class),
"attributes.getContentString()");
writer.beginControlFlow("if (contentString != null)");
if (textContent instanceof ExecutableElement) {
writer.emitStatement("object.%s(contentString)", textContent.getSimpleName());
} else if (textContent instanceof VariableElement) {
writer.emitStatement("object.%s = contentString", textContent.getSimpleName());
}
writer.endControlFlow();
writer.endMethod();
}
示例14: writeGetter
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeGetter(JavaWriter writer) throws IOException {
writer.emitAnnotation(Override.class);
writer.beginMethod(JavaWriter.type(XmlElementParser.class, "?"),
"get",
EnumSet.of(Modifier.PUBLIC),
"String",
"name");
writer.emitStatement("return MAP.get(name)");
writer.endMethod();
}
示例15: writeNewArrayMethod
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeNewArrayMethod(JavaWriter writer) throws IOException {
writer.emitAnnotation(Override.class);
writer.beginMethod(String.format("%s[]", elementCompressedName),
"newArray",
Modifiers.PUBLIC,
"int",
"size");
writer.emitStatement("return new %s[size]", elementCompressedName);
writer.endMethod();
}