use of com.google.api.generator.engine.writer.JavaWriterVisitor in project gapic-generator-java by googleapis.
the class ResourceNameHelperClassComposerTest method generateResourceNameClass_childSingleton.
@Test
public void generateResourceNameClass_childSingleton() {
ResourceName agentResname = ResourceName.builder().setVariableName("agent").setPakkage("com.google.cloud.dialogflow.v2beta1").setResourceTypeString("dialogflow.googleapis.com/Agent").setPatterns(Arrays.asList("projects/{project}/locations/{location}/agent", "projects/{project}/agent")).setParentMessageName("Agent").setDescription("This is a description").build();
GapicContext irrelevantContext = TestProtoLoader.instance().parseShowcaseEcho();
GapicClass clazz = ResourceNameHelperClassComposer.instance().generate(agentResname, irrelevantContext);
JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "AgentName.golden", visitor.write());
Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "AgentName.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
use of com.google.api.generator.engine.writer.JavaWriterVisitor in project gapic-generator-java by googleapis.
the class GrpcServiceCallableFactoryClassComposerTest method generateServiceClasses.
@Test
public void generateServiceClasses() {
GapicContext context = GrpcRestTestProtoLoader.instance().parseShowcaseEcho();
Service echoProtoService = context.services().get(0);
GapicClass clazz = GrpcServiceCallableFactoryClassComposer.instance().generate(context, echoProtoService);
JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "GrpcEchoCallableFactory.golden", visitor.write());
Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "GrpcEchoCallableFactory.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
use of com.google.api.generator.engine.writer.JavaWriterVisitor in project gapic-generator-java by googleapis.
the class HttpJsonServiceStubClassComposerTest method generateServiceClasses.
@Test
public void generateServiceClasses() {
GapicContext context = GrpcRestTestProtoLoader.instance().parseShowcaseEcho();
Service echoProtoService = context.services().get(0);
GapicClass clazz = HttpJsonServiceStubClassComposer.instance().generate(context, echoProtoService);
JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "HttpJsonEchoStub.golden", visitor.write());
Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "HttpJsonEchoStub.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
use of com.google.api.generator.engine.writer.JavaWriterVisitor in project gapic-generator-java by googleapis.
the class SampleCodeWriter method write.
@VisibleForTesting
public static String write(ClassDefinition classDefinition) {
JavaWriterVisitor visitor = new JavaWriterVisitor();
classDefinition.accept(visitor);
return visitor.write();
}
use of com.google.api.generator.engine.writer.JavaWriterVisitor in project gapic-generator-java by googleapis.
the class SampleCodeWriter method write.
@VisibleForTesting
public static String write(List<Statement> statements) {
JavaWriterVisitor visitor = new JavaWriterVisitor();
for (Statement statement : statements) {
statement.accept(visitor);
}
String formattedSampleCode = SampleBodyJavaFormatter.format(visitor.write());
// Escape character "@" in the markdown code block <pre>{@code...} tags.
return formattedSampleCode.replaceAll("@", "{@literal @}");
}
Aggregations