Skip to content

Commit 3fdee84

Browse files
JimClarke5rnett
authored andcommitted
Add checks for summary and description when empty, them provide default text.
Add missing description and @return for Getters/Setters Add fixes for missing @param's and Generic Types Reformat code. Signed-off-by: Ryan Nett <JNett96@gmail.com>
1 parent 003c888 commit 3fdee84

File tree

1 file changed

+69
-27
lines changed
  • tensorflow-core/tensorflow-core-generator/src/main/java/org/tensorflow/op/generator

1 file changed

+69
-27
lines changed

tensorflow-core/tensorflow-core-generator/src/main/java/org/tensorflow/op/generator/ClassGenerator.java

Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,22 @@ private void buildOptionsClass() {
341341

342342
ApiDef.Attr apiAttr = attrApis.get(attr);
343343

344-
// add the setter method, adding one with varargs and one with List if the attribute is iterable
344+
String description =
345+
apiAttr.getDescription().isEmpty()
346+
? String.format("the %s option", name)
347+
: apiAttr.getDescription();
348+
349+
// add the setter method, adding one with varargs and one with List if the attribute is
350+
// iterable
345351
if (type.iterable) {
346352
optionsBuilder.addMethod(
347353
MethodSpec.methodBuilder(name)
348354
.returns(optionsClassName)
349355
.addModifiers(Modifier.PUBLIC)
350356
.addParameter(type.classIfGeneric().listIfIterable().javaType, name)
351-
.addJavadoc("@param $L $L\n", name, parseDocumentation(apiAttr.getDescription()))
357+
.addJavadoc("Sets the $L option.\n", name)
358+
.addJavadoc("@param $L $L\n", name, parseDocumentation(description))
359+
.addJavadoc("@return this Options instance.\n")
352360
.addCode("this.$L = $L;\nreturn this;\n", name, name)
353361
.build());
354362

@@ -357,7 +365,9 @@ private void buildOptionsClass() {
357365
.returns(optionsClassName)
358366
.addModifiers(Modifier.PUBLIC)
359367
.addParameter(type.classIfGeneric().arrayIfIterable().javaType, name)
360-
.addJavadoc("@param $L $L\n", name, parseDocumentation(apiAttr.getDescription()))
368+
.addJavadoc("Sets the $L option.\n", name)
369+
.addJavadoc("@param $L $L\n", name, parseDocumentation(description))
370+
.addJavadoc("@return this Options instance.\n")
361371
.addCode("this.$L = $T.asList($L);\nreturn this;\n", name, Arrays.class, name)
362372
.varargs()
363373
.build());
@@ -368,7 +378,9 @@ private void buildOptionsClass() {
368378
.returns(optionsClassName)
369379
.addModifiers(Modifier.PUBLIC)
370380
.addParameter(type.classIfGeneric().javaType, name)
371-
.addJavadoc("@param $L $L\n", name, parseDocumentation(apiAttr.getDescription()))
381+
.addJavadoc("Sets the $L option.\n", name)
382+
.addJavadoc("@param $L $L\n", name, parseDocumentation(description))
383+
.addJavadoc("@return this Options instance.\n")
372384
.addCode("this.$L = $L;\nreturn this;\n", name, name)
373385
.build());
374386
}
@@ -534,12 +546,27 @@ private void buildFactoryMethods() {
534546
body.addStatement("return new $L(opBuilder.build())", typeParams.isEmpty() ? className : (className + "<>"));
535547

536548
factoryBuilder.addCode(body.build());
537-
paramTags.forEach((param, doc) -> {
538-
factoryBuilder.addJavadoc("@param $L $L", param, doc);
539-
});
540-
factoryBuilder.addJavadoc("\n@return a new instance of $L", className);
541-
factoryBuilder.addTypeVariables(typeVars);
549+
paramTags.forEach(
550+
(param, doc) -> {
551+
String description = doc.toString();
552+
if (description.isEmpty() || description.equals("\n")) {
553+
factoryBuilder.addJavadoc(
554+
"@param $L $L", param, String.format("the %s property", param));
555+
} else {
556+
factoryBuilder.addJavadoc("@param $L $L", param, doc);
557+
}
558+
});
559+
for (TypeVariableName typeVar : typeVars) {
560+
factoryBuilder.addJavadoc(
561+
"\n@param <"
562+
+ typeVar.name
563+
+ "> data type for {@code "
564+
+ op.getName()
565+
+ "} output and operands\n");
566+
}
542567

568+
factoryBuilder.addTypeVariables(typeVars);
569+
factoryBuilder.addJavadoc("\n@return a new instance of $L\n", className);
543570
MethodSpec method = factoryBuilder.build();
544571
builder.addMethod(method);
545572

@@ -594,39 +621,54 @@ private void buildSecondaryFactory(Map<AttrDef, TypeName> defaultTypes, Map<Stri
594621
factoryBuilder.addJavadoc("\n@return a new instance of $L, with default output types", className);
595622
factoryBuilder.addCode(body.build());
596623
factoryBuilder.addTypeVariables(typeVars);
624+
for (TypeVariableName typeVar : typeVars) {
625+
factoryBuilder.addJavadoc(
626+
"\n@param <"
627+
+ typeVar.name
628+
+ "> data type for {@code "
629+
+ op.getName()
630+
+ "} output and operands\n");
631+
}
597632

598633
builder.addMethod(factoryBuilder.build());
599634
}
600635

601636
/**
602637
* Add getters for the outputs and setters/Options creators for the optional attributes.
603638
*
604-
* Needs to be called after {@link #buildOptionsClass()}
639+
* <p>Needs to be called after {@link #buildOptionsClass()}
605640
*/
606641
private void buildGettersAndSetters() {
607642
if (optionsClass != null) {
608-
optionsClass.methodSpecs.stream().filter(x -> !x.isConstructor()).forEach(method -> {
609-
String argName = method.parameters.get(0).name;
610-
611-
builder.addMethod(MethodSpec.methodBuilder(method.name)
612-
.addParameter(method.parameters.get(0))
613-
.addJavadoc(method.javadoc)
614-
.returns(ClassName.get(fullPackage, className, "Options"))
615-
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
616-
.addCode("return new Options().$L($L);", method.name, argName)
617-
.build());
618-
});
643+
optionsClass.methodSpecs.stream()
644+
.filter(x -> !x.isConstructor())
645+
.forEach(
646+
method -> {
647+
String argName = method.parameters.get(0).name;
648+
builder.addMethod(
649+
MethodSpec.methodBuilder(method.name)
650+
.addParameter(method.parameters.get(0))
651+
.addJavadoc("Sets the $L property.", method.name)
652+
.addJavadoc(method.javadoc)
653+
.returns(ClassName.get(fullPackage, className, "Options"))
654+
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
655+
.addCode("return new Options().$L($L);", method.name, argName)
656+
.build());
657+
});
619658
}
620659

621660
for (ArgDef output : op.getOutputArgList()) {
622661
String name = getJavaName(output);
623662
ApiDef.Arg argDef = argApis.get(output);
624-
builder.addMethod(MethodSpec.methodBuilder(name)
625-
.addModifiers(Modifier.PUBLIC)
626-
.returns(resolver.typeOf(output).listIfIterable().javaType)
627-
.addJavadoc("$L", parseDocumentation(argDef.getDescription()))
628-
.addCode("return $L;", name)
629-
.build());
663+
builder.addMethod(
664+
MethodSpec.methodBuilder(name)
665+
.addModifiers(Modifier.PUBLIC)
666+
.returns(resolver.typeOf(output).listIfIterable().javaType)
667+
.addJavadoc("Gets $L.\n", name)
668+
.addJavadoc("$L", parseDocumentation(argDef.getDescription()))
669+
.addJavadoc("@return $L.\n", name)
670+
.addCode("return $L;", name)
671+
.build());
630672
}
631673

632674
}

0 commit comments

Comments
 (0)