本文整理汇总了Java中com.squareup.javawriter.JavaWriter.endMethod方法的典型用法代码示例。如果您正苦于以下问题:Java JavaWriter.endMethod方法的具体用法?Java JavaWriter.endMethod怎么用?Java JavaWriter.endMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javawriter.JavaWriter
的用法示例。
在下文中一共展示了JavaWriter.endMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: 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();
}
示例4: 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();
}
示例5: 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();
}
示例6: 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();
}
示例7: 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();
}
示例8: 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();
}
示例9: 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();
}
示例10: 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();
}
示例11: 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();
}
示例12: 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();
}
示例13: writeKeySet
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeKeySet(JavaWriter writer) throws IOException {
writer.emitAnnotation(Override.class);
writer.beginMethod(JavaWriter.type(Set.class, "String"), "keySet", Modifiers.PUBLIC);
writer.emitStatement("return MAP.keySet()");
writer.endMethod();
}
示例14: writeClassBody
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
protected void writeClassBody(final JavaWriter w) throws IOException {
w.beginConstructor(constructorModifiers(), "final " + operatorContext(operationsClass), "context");
w.emitStatement("super(context)");
w.endConstructor();
w.emitEmptyLine();
for (MethodData data : methods) {
ExecutableElement m = data.method;
String operationName = m.getSimpleName().toString();
w.beginMethod(
data.loaderDescriptionTypeSupport.loaderDescriptionReturnType(w, m, this),
operationName.concat("IsFinished"),
EnumSet.of(PUBLIC)
);
w.emitStatement(data.loaderDescriptionTypeSupport.loaderDescriptionMethodBody(w, m, this));
w.endMethod();
w.beginMethod(
w.compressType(getFqcn()),
operationName.concat("IsStartedDo"),
EnumSet.of(PUBLIC),
"final Runnable", "action"
);
w.emitStatement("addStartAction(%d, action)", getLoaderId(m));
w.emitStatement("return this");
w.endMethod();
}
}
示例15: writeUpdateFromMapMethod
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeUpdateFromMapMethod(JavaWriter writer) throws IOException {
writer.emitAnnotation(Override.class);
writer.emitAnnotation(SuppressWarnings.class, JavaWriter.stringLiteral("rawtypes"));
List<String> parameters = CollectionUtils.newArrayList(parsedClassName, "instance",
JavaWriter.type(Map.class, "String", "Object"), "map",
JsonParserContext.class.getSimpleName(), "context");
writer.beginMethod("void", "updateInstanceFromMap", Modifiers.PUBLIC, parameters, null);
writeUpdateAssignmentsBlock(writer);
if (selfValueAssignmentInfo != null) {
writeUpdateSelfValuesBlock(writer);
}
writer.endMethod();
}