private MethodSpec createBindingViewDelegateConstructor() { return MethodSpec.constructorBuilder() .addJavadoc("@deprecated Use {@link #$T($T, $T)} for direct creation.\n " + "Only present for runtime invocation through {@code ButterKnife.bind()}.\n", bindingClassName, targetTypeName, CONTEXT) .addAnnotation(Deprecated.class) .addAnnotation(UI_THREAD) .addModifiers(PUBLIC) .addParameter(targetTypeName, "target") .addParameter(VIEW, "source") .addStatement(("this(target, source.getContext())")) .build(); }
@Override public void configureSetter(@NonNull MethodSpec.Builder builder) { if (javadoc != null) { final String name = builder.build().parameters.get(0).name; builder.addJavadoc(javadoc.replaceAll("(\n|^) ", "$1").replaceAll("@return ((.|\n)*)$", "@param " + name + " $1@return this instance\n")); } }
private MethodSpec staticInjectMethod(List<Element> fields, ClassName typeName) { MethodSpec.Builder result = MethodSpec.methodBuilder("inject") .addJavadoc(AdapterJavadocs.STATIC_INJECT_METHOD, ObjectGraph.class) .addAnnotation(Override.class) .addModifiers(PUBLIC); for (Element field : fields) { result.addStatement("$T.$N = $N.get()", typeName, field.getSimpleName().toString(), fieldName(false, field)); } return result.build(); }
private MethodSpec renderNamedDeleteColumn(NamedColumnDescription col) { MethodSpec.Builder deleteColumnBuilder = MethodSpec.methodBuilder("delete" + VarName(col)) .addModifiers(Modifier.PUBLIC) .addJavadoc("Delete the value at column $L (if it exists) for the specified row-key.", VarName(col)); deleteColumnBuilder = addParametersFromRowComponents(deleteColumnBuilder, tableMetadata); return deleteColumnBuilder .addStatement("$T row = $T.of($L)", rowType, rowType, getArgumentsFromRowComponents(tableMetadata)) .addStatement("byte[] rowBytes = row.persistToBytes()", Persistables.class) .addStatement("$T<$T> cells = $T.of($T.create(rowBytes, $T.toCachedBytes($L)))", Set.class, Cell.class, ImmutableSet.class, Cell.class, PtBytes.class, ColumnRenderers.short_name(col)) .addStatement("t.delete(tableRef, cells)") .build(); }
private MethodSpec renderNamedPutColumn(NamedColumnDescription col) { MethodSpec.Builder putColumnBuilder = MethodSpec.methodBuilder("put" + VarName(col)) .addJavadoc("Takes the row-keys and a value to be inserted at column $L.", VarName(col)) .addModifiers(Modifier.PUBLIC); putColumnBuilder = addParametersFromRowComponents(putColumnBuilder, tableMetadata); TypeName columnValueType = tableType.nestedClass(VarName(col)); putColumnBuilder.addParameter(getColumnClass(col), col.getLongName()); putColumnBuilder .addStatement("$T row = $T.of($L)", rowType, rowType, getArgumentsFromRowComponents(tableMetadata)) .addStatement("t.put(tableRef, $T.toCellValues($T.of(row, $T.of($L))))", ColumnValues.class, ImmutableMultimap.class, columnValueType, col.getLongName()); return putColumnBuilder.build(); }
.addJavadoc("@此方法由apt自动生成") .addModifiers(PUBLIC, STATIC) .addParameter(String.class, "name").addParameter(HashMap.class, "extra") .addJavadoc("@此方法由apt自动生成") .addModifiers(PUBLIC, STATIC) .addParameter(ClassName.get("android.app", "Activity"), "mContext"); .addJavadoc("@此方法由apt自动生成") .addModifiers(PUBLIC, STATIC) .addParameter(String.class, "name") .addJavadoc("@此方法由apt自动生成") .addModifiers(PUBLIC, STATIC) .addParameter(String.class, "name")
.addJavadoc("Return the constant for {@code $N} or null.\n", value) .addModifiers(PUBLIC, STATIC) .returns(javaType)
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(e.getSimpleName().toString()) .addJavadoc("@此方法由apt自动生成") .addModifiers(PUBLIC, STATIC);
.addJavadoc("@此方法由apt自动生成") .returns(Object.class).addModifiers(PUBLIC, STATIC).addException(IllegalAccessException.class).addException(InstantiationException.class) .addParameter(Class.class, "mClass");
.addJavadoc(AdapterJavadocs.GET_DEPENDENCIES_METHOD) .addAnnotation(Override.class) .addModifiers(PUBLIC)
TypeSpec.Builder tb = classBuilder(CLASS_NAME).addModifiers(PUBLIC, FINAL).addJavadoc("@ 实例化工厂 此类由apt自动生成"); MethodSpec.Builder methodBuilder1 = MethodSpec.methodBuilder("create").addAnnotation(MemoryCache.class) .addJavadoc("@此方法由apt自动生成") .returns(Object.class).addModifiers(PUBLIC, STATIC).addException(IllegalAccessException.class).addException(InstantiationException.class) .addParameter(Class.class, "mClass");
.addJavadoc(AdapterJavadocs.ATTACH_METHOD) .addAnnotation(Override.class) .addAnnotation(Util.UNCHECKED) .addJavadoc(AdapterJavadocs.GET_DEPENDENCIES_METHOD) .addAnnotation(Override.class) .addModifiers(PUBLIC) .addJavadoc(AdapterJavadocs.GET_METHOD, returnType) .addAnnotation(Override.class) .addModifiers(PUBLIC)
private MethodSpec setter( NameAllocator nameAllocator, TypeName builderType, OneOf oneOf, Field field) { TypeName javaType = fieldType(field); String fieldName = nameAllocator.get(field); MethodSpec.Builder result = MethodSpec.methodBuilder(fieldName) .addModifiers(PUBLIC) .addParameter(javaType, fieldName) .returns(builderType); if (!field.documentation().isEmpty()) { result.addJavadoc("$L\n", sanitizeJavadoc(field.documentation())); } if (field.isDeprecated()) { result.addAnnotation(Deprecated.class); } if (field.isRepeated() || field.type().isMap()) { result.addStatement("$T.checkElementsNotNull($L)", Internal.class, fieldName); } result.addStatement("this.$L = $L", fieldName, fieldName); if (oneOf != null) { for (Field other : oneOf.fields()) { if (field != other) { result.addStatement("this.$L = null", nameAllocator.get(other)); } } } result.addStatement("return this"); return result.build(); }
rpcBuilder.addJavadoc("$L\n", rpc.documentation());
final MethodSpec.Builder constructor = MethodSpec.constructorBuilder() .addParameter(ParameterSpec.builder(Types.CONTEXT, PARAM_0).addAnnotation(Types.NON_NULL).build()) .addJavadoc("@param $L object annotated with {@link $T}\n", PARAM_0, baseAnnotation) .addStatement("final $1T $2L = $3L.getClass().getAnnotation($1T.class)", baseAnnotation, VAR_ANNOTATION, PARAM_0); if (!configuration.isPlugin()) {
boolean extendsBinding) throws IOException { MethodSpec.Builder result = MethodSpec.methodBuilder("attach") .addJavadoc(AdapterJavadocs.ATTACH_METHOD) .addModifiers(PUBLIC) .addParameter(Linker.class, "linker");
private MethodSpec getDependenciesMethod(ExecutableElement constructor, List<Element> fields, boolean disambiguateFields, TypeMirror supertype, boolean extendsBinding) throws IOException { MethodSpec.Builder result = MethodSpec.methodBuilder("getDependencies") .addJavadoc(AdapterJavadocs.GET_DEPENDENCIES_METHOD) .addModifiers(PUBLIC) .addParameter(SET_OF_BINDINGS, "getBindings") .addParameter(SET_OF_BINDINGS, "injectMembersBindings"); if (extendsBinding) { result.addAnnotation(Override.class); } if (constructor != null) { for (Element parameter : constructor.getParameters()) { result.addStatement("getBindings.add($N)", parameterName(disambiguateFields, parameter)); } } for (Element field : fields) { result.addStatement("injectMembersBindings.add($N)", fieldName(disambiguateFields, field)); } if (supertype != null) { result.addStatement("injectMembersBindings.add($N)", "supertype"); } return result.build(); }
private MethodSpec.Builder baseMethod(@NonNull ClassName builderName) { final MethodSpec.Builder method = MethodSpec.methodBuilder(getName()) .addModifiers(modifiers) .addParameters(parameters) .addTypeVariables(typeVariables) .addAnnotations(getAnnotations()); if (javadoc != null) { method.addJavadoc(javadoc.replaceAll("(\n|^) ", "$1")); } if (getType().equals(TypeName.VOID)) { method.returns(builderName) .addAnnotation(Types.NON_NULL) .addJavadoc("@return this instance\n"); } else { method.returns(getType()); } return method; }
private MethodSpec getMethod(ExecutableElement constructor, boolean disambiguateFields, boolean injectMembers, ClassName injectedClassName) { MethodSpec.Builder result = MethodSpec.methodBuilder("get") .addJavadoc(AdapterJavadocs.GET_METHOD, injectedClassName) .addAnnotation(Override.class) .returns(injectedClassName) .addModifiers(PUBLIC); result.addCode("$T result = new $T(", injectedClassName, injectedClassName); boolean first = true; for (VariableElement parameter : constructor.getParameters()) { if (!first) result.addCode(", "); else first = false; result.addCode("$N.get()", parameterName(disambiguateFields, parameter)); } result.addCode(");\n"); if (injectMembers) { result.addStatement("injectMembers(result)"); } result.addStatement("return result"); return result.build(); }
private MethodSpec membersInjectMethod(List<Element> fields, boolean disambiguateFields, ClassName injectedClassName, TypeMirror supertype) { MethodSpec.Builder result = MethodSpec.methodBuilder("injectMembers") .addJavadoc(AdapterJavadocs.MEMBERS_INJECT_METHOD, injectedClassName) .addAnnotation(Override.class) .addModifiers(PUBLIC) .addParameter(injectedClassName, "object"); for (Element field : fields) { result.addStatement("object.$N = $N.get()", field.getSimpleName(), fieldName(disambiguateFields, field)); } if (supertype != null) { result.addStatement("supertype.injectMembers(object)"); } return result.build(); }