use of com.google.api.generator.engine.ast.CommentStatement in project gapic-generator-java by googleapis.
the class AbstractServiceStubSettingsClassComposer method generate.
@Override
public GapicClass generate(GapicContext context, Service service) {
// TODO(miraleung): Robustify this against a null serviceConfig.
GapicServiceConfig serviceConfig = context.serviceConfig();
Map<String, Message> messageTypes = context.messages();
String pakkage = String.format("%s.stub", service.pakkage());
TypeStore typeStore = createDynamicTypes(service, pakkage);
List<Sample> samples = new ArrayList<>();
Set<String> deprecatedSettingVarNames = new HashSet<>();
Map<String, VariableExpr> methodSettingsMemberVarExprs = createMethodSettingsClassMemberVarExprs(service, serviceConfig, typeStore, /* isNestedClass= */
false, deprecatedSettingVarNames);
String className = ClassNames.getServiceStubSettingsClassName(service);
List<CommentStatement> classHeaderComments = createClassHeaderComments(service, typeStore.get(className), samples);
ClassDefinition classDef = ClassDefinition.builder().setPackageString(pakkage).setHeaderCommentStatements(classHeaderComments).setAnnotations(createClassAnnotations(service)).setScope(ScopeNode.PUBLIC).setName(className).setExtendsType(createExtendsType(service, typeStore)).setStatements(createClassStatements(service, serviceConfig, methodSettingsMemberVarExprs, messageTypes, typeStore)).setMethods(createClassMethods(service, methodSettingsMemberVarExprs, deprecatedSettingVarNames, typeStore)).setNestedClasses(Arrays.asList(createNestedBuilderClass(service, serviceConfig, typeStore))).build();
return GapicClass.create(GapicClass.Kind.STUB, classDef, SampleComposerUtil.handleDuplicateSamples(samples));
}
use of com.google.api.generator.engine.ast.CommentStatement in project gapic-generator-java by googleapis.
the class AbstractServiceSettingsClassComposer method generate.
@Override
public GapicClass generate(GapicContext context, Service service) {
String pakkage = service.pakkage();
TypeStore typeStore = createDynamicTypes(service);
String className = ClassNames.getServiceSettingsClassName(service);
GapicClass.Kind kind = Kind.MAIN;
List<Sample> samples = new ArrayList<>();
List<CommentStatement> classHeaderComments = createClassHeaderComments(service, typeStore.get(className), samples);
ClassDefinition classDef = ClassDefinition.builder().setPackageString(pakkage).setHeaderCommentStatements(classHeaderComments).setAnnotations(createClassAnnotations(service)).setScope(ScopeNode.PUBLIC).setName(className).setExtendsType(TypeNode.withReference(FIXED_TYPESTORE.get("ClientSettings").reference().copyAndSetGenerics(Arrays.asList(typeStore.get(ClassNames.getServiceSettingsClassName(service)).reference())))).setMethods(createClassMethods(service, typeStore)).setNestedClasses(Arrays.asList(createNestedBuilderClass(service, typeStore))).build();
return GapicClass.create(kind, classDef, SampleComposerUtil.handleDuplicateSamples(samples));
}
use of com.google.api.generator.engine.ast.CommentStatement in project gapic-generator-java by googleapis.
the class ServiceClientCommentComposer method createRpcMethodHeaderComment.
public static List<CommentStatement> createRpcMethodHeaderComment(Method method, List<MethodArgument> methodArguments, Optional<String> sampleCodeOpt) {
JavaDocComment.Builder methodJavadocBuilder = JavaDocComment.builder();
if (method.hasDescription()) {
methodJavadocBuilder = processProtobufComment(method.description(), methodJavadocBuilder, null);
}
if (sampleCodeOpt.isPresent()) {
methodJavadocBuilder.addParagraph(METHOD_DESCRIPTION_SAMPLE_CODE_SUMMARY_STRING);
methodJavadocBuilder.addSampleCode(sampleCodeOpt.get());
}
if (methodArguments.isEmpty()) {
methodJavadocBuilder.addParam("request", "The request object containing all of the parameters for the API call.");
} else {
for (MethodArgument argument : methodArguments) {
// TODO(miraleung): Remove the newline replacement when we support CommonMark.
String description = argument.field().hasDescription() ? argument.field().description() : EMPTY_STRING;
methodJavadocBuilder.addParam(JavaStyle.toLowerCamelCase(argument.name()), description);
}
}
methodJavadocBuilder.setThrows(API_EXCEPTION_TYPE_NAME, EXCEPTION_CONDITION);
if (method.isDeprecated()) {
methodJavadocBuilder.setDeprecated(CommentComposer.DEPRECATED_METHOD_STRING);
}
List<CommentStatement> comments = new ArrayList<>();
comments.add(CommentComposer.AUTO_GENERATED_METHOD_COMMENT);
if (!methodJavadocBuilder.emptyComments()) {
comments.add(CommentStatement.withComment(methodJavadocBuilder.build()));
}
return comments;
}
use of com.google.api.generator.engine.ast.CommentStatement in project gapic-generator-java by googleapis.
the class ClientLibraryPackageInfoComposer method createPackageInfoJavadoc.
private static CommentStatement createPackageInfoJavadoc(GapicContext context) {
JavaDocComment.Builder javaDocCommentBuilder = JavaDocComment.builder();
if (context.hasServiceYamlProto() && !Strings.isNullOrEmpty(context.serviceYamlProto().getTitle())) {
javaDocCommentBuilder = javaDocCommentBuilder.addComment(String.format(PACKAGE_INFO_TITLE_PATTERN, context.serviceYamlProto().getTitle()));
}
javaDocCommentBuilder = javaDocCommentBuilder.addParagraph(PACKAGE_INFO_DESCRIPTION);
for (Service service : context.services()) {
String javaClientName = ClassNames.getServiceClientClassName(service);
javaDocCommentBuilder = javaDocCommentBuilder.addParagraph(String.format("%s %s %s", DIVIDER, javaClientName, DIVIDER));
// TODO(miraleung): Replace this with a comment converter when we support CommonMark.
if (service.hasDescription()) {
String[] descriptionParagraphs = service.description().split("\\n\\n");
for (int i = 0; i < descriptionParagraphs.length; i++) {
boolean startsWithItemizedList = descriptionParagraphs[i].startsWith(" * ");
// Split by listed items, then join newlines.
List<String> listItems = Stream.of(descriptionParagraphs[i].split("\\n \\*")).map(s -> s.replace("\n", "")).collect(Collectors.toList());
if (startsWithItemizedList) {
// Remove the first asterisk.
listItems.set(0, listItems.get(0).substring(2));
}
if (!startsWithItemizedList) {
if (i == 0) {
javaDocCommentBuilder = javaDocCommentBuilder.addParagraph(String.format(SERVICE_DESCRIPTION_HEADER_PATTERN, listItems.get(0)));
} else {
javaDocCommentBuilder = javaDocCommentBuilder.addParagraph(listItems.get(0));
}
}
if (listItems.size() > 1 || startsWithItemizedList) {
javaDocCommentBuilder = javaDocCommentBuilder.addUnorderedList(listItems.subList(startsWithItemizedList ? 0 : 1, listItems.size()));
}
}
}
javaDocCommentBuilder = javaDocCommentBuilder.addParagraph(String.format(SAMPLE_CODE_HEADER_PATTERN, javaClientName));
TypeNode clientType = TypeNode.withReference(VaporReference.builder().setPakkage(service.pakkage()).setName(ClassNames.getServiceClientClassName(service)).build());
Sample packageInfoSampleCode = ServiceClientHeaderSampleComposer.composeClassHeaderSample(service, clientType, context.resourceNames(), context.messages());
javaDocCommentBuilder.addSampleCode(SampleCodeWriter.writeInlineSample(packageInfoSampleCode.body()));
}
return CommentStatement.withComment(javaDocCommentBuilder.build());
}
use of com.google.api.generator.engine.ast.CommentStatement in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeLineCommentStatement_basic.
@Test
public void writeLineCommentStatement_basic() {
String content = "this is a test comment";
LineComment lineComment = LineComment.builder().setComment(content).build();
CommentStatement commentStatement = CommentStatement.withComment(lineComment);
String expected = "// this is a test comment\n";
commentStatement.accept(writerVisitor);
assertEquals(expected, writerVisitor.write());
}
Aggregations