Search in sources :

Example 6 with JavaWriterVisitor

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());
}
Also used : Path(java.nio.file.Path) ResourceName(com.google.api.generator.gapic.model.ResourceName) GapicClass(com.google.api.generator.gapic.model.GapicClass) JavaWriterVisitor(com.google.api.generator.engine.writer.JavaWriterVisitor) GapicContext(com.google.api.generator.gapic.model.GapicContext) Test(org.junit.Test)

Example 7 with JavaWriterVisitor

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());
}
Also used : Path(java.nio.file.Path) GapicClass(com.google.api.generator.gapic.model.GapicClass) Service(com.google.api.generator.gapic.model.Service) JavaWriterVisitor(com.google.api.generator.engine.writer.JavaWriterVisitor) GapicContext(com.google.api.generator.gapic.model.GapicContext) Test(org.junit.Test)

Example 8 with JavaWriterVisitor

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());
}
Also used : Path(java.nio.file.Path) GapicClass(com.google.api.generator.gapic.model.GapicClass) Service(com.google.api.generator.gapic.model.Service) JavaWriterVisitor(com.google.api.generator.engine.writer.JavaWriterVisitor) GapicContext(com.google.api.generator.gapic.model.GapicContext) Test(org.junit.Test)

Example 9 with JavaWriterVisitor

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();
}
Also used : JavaWriterVisitor(com.google.api.generator.engine.writer.JavaWriterVisitor) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 10 with JavaWriterVisitor

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 @}");
}
Also used : Statement(com.google.api.generator.engine.ast.Statement) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) JavaWriterVisitor(com.google.api.generator.engine.writer.JavaWriterVisitor) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

JavaWriterVisitor (com.google.api.generator.engine.writer.JavaWriterVisitor)25 Path (java.nio.file.Path)22 GapicClass (com.google.api.generator.gapic.model.GapicClass)21 Test (org.junit.Test)21 GapicContext (com.google.api.generator.gapic.model.GapicContext)15 Service (com.google.api.generator.gapic.model.Service)14 ResourceName (com.google.api.generator.gapic.model.ResourceName)5 Message (com.google.api.generator.gapic.model.Message)4 HashSet (java.util.HashSet)4 FileDescriptor (com.google.protobuf.Descriptors.FileDescriptor)3 ServiceDescriptor (com.google.protobuf.Descriptors.ServiceDescriptor)3 ClassDefinition (com.google.api.generator.engine.ast.ClassDefinition)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)1 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)1 MethodDefinition (com.google.api.generator.engine.ast.MethodDefinition)1 Statement (com.google.api.generator.engine.ast.Statement)1 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)1 ByteString (com.google.protobuf.ByteString)1 CodeGeneratorResponse (com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse)1