Search in sources :

Example 21 with GapicClass

use of com.google.api.generator.gapic.model.GapicClass in project gapic-generator-java by googleapis.

the class AbstractServiceClientTestClassComposer method generate.

protected GapicClass generate(String className, GapicContext context, Service service) {
    Map<String, ResourceName> resourceNames = context.helperResourceNames();
    String pakkage = service.pakkage();
    TypeStore typeStore = new TypeStore();
    addDynamicTypes(context, service, typeStore);
    GapicClass.Kind kind = Kind.MAIN;
    Map<String, VariableExpr> classMemberVarExprs = createClassMemberVarExprs(service, context, typeStore);
    ClassDefinition classDef = ClassDefinition.builder().setPackageString(pakkage).setAnnotations(createClassAnnotations()).setScope(ScopeNode.PUBLIC).setName(className).setStatements(createClassMemberFieldDecls(classMemberVarExprs)).setMethods(createClassMethods(service, context, classMemberVarExprs, typeStore, resourceNames)).build();
    return GapicClass.create(kind, classDef);
}
Also used : ResourceName(com.google.api.generator.gapic.model.ResourceName) GapicClass(com.google.api.generator.gapic.model.GapicClass) TypeStore(com.google.api.generator.gapic.composer.store.TypeStore) Kind(com.google.api.generator.gapic.model.GapicClass.Kind) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition)

Example 22 with GapicClass

use of com.google.api.generator.gapic.model.GapicClass in project gapic-generator-java by googleapis.

the class AbstractServiceCallableFactoryClassComposer method generate.

@Override
public GapicClass generate(GapicContext context, Service service) {
    TypeStore typeStore = createTypes(service);
    String className = getTransportContext().classNames().getTransportServiceCallableFactoryClassName(service);
    GapicClass.Kind kind = Kind.STUB;
    String pakkage = String.format("%s.stub", service.pakkage());
    StubCommentComposer commentComposer = new StubCommentComposer(getTransportContext().transportName());
    ClassDefinition classDef = ClassDefinition.builder().setPackageString(pakkage).setHeaderCommentStatements(commentComposer.createTransportServiceCallableFactoryClassHeaderComments(service.name(), service.isDeprecated())).setAnnotations(createClassAnnotations(service, typeStore)).setImplementsTypes(createClassImplements(service, typeStore)).setName(className).setMethods(createClassMethods(service, typeStore)).setScope(ScopeNode.PUBLIC).build();
    return GapicClass.create(kind, classDef);
}
Also used : StubCommentComposer(com.google.api.generator.gapic.composer.comment.StubCommentComposer) GapicClass(com.google.api.generator.gapic.model.GapicClass) TypeStore(com.google.api.generator.gapic.composer.store.TypeStore) Kind(com.google.api.generator.gapic.model.GapicClass.Kind) ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition)

Example 23 with GapicClass

use of com.google.api.generator.gapic.model.GapicClass in project gapic-generator-java by googleapis.

the class AbstractServiceStubClassComposer method generate.

@Override
public GapicClass generate(GapicContext context, Service service) {
    Map<String, Message> messageTypes = context.messages();
    TypeStore typeStore = createTypes(service, messageTypes);
    String className = ClassNames.getServiceStubClassName(service);
    GapicClass.Kind kind = Kind.STUB;
    String pakkage = String.format("%s.stub", service.pakkage());
    ClassDefinition classDef = ClassDefinition.builder().setPackageString(pakkage).setHeaderCommentStatements(StubCommentComposer.createServiceStubClassHeaderComments(service.name(), service.isDeprecated())).setAnnotations(createClassAnnotations(service, typeStore)).setIsAbstract(true).setImplementsTypes(createClassImplements(typeStore)).setName(className).setMethods(createClassMethods(service, messageTypes, typeStore)).setScope(ScopeNode.PUBLIC).build();
    return GapicClass.create(kind, classDef);
}
Also used : Message(com.google.api.generator.gapic.model.Message) GapicClass(com.google.api.generator.gapic.model.GapicClass) TypeStore(com.google.api.generator.gapic.composer.store.TypeStore) Kind(com.google.api.generator.gapic.model.GapicClass.Kind) ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition)

Example 24 with GapicClass

use of com.google.api.generator.gapic.model.GapicClass in project gapic-generator-java by googleapis.

the class Generator method generateGapic.

public static CodeGeneratorResponse generateGapic(CodeGeneratorRequest request) {
    GapicContext context = Parser.parse(request);
    List<GapicClass> clazzes = Composer.composeServiceClasses(context);
    GapicPackageInfo packageInfo = Composer.composePackageInfo(context);
    String outputFilename = "temp-codegen.srcjar";
    return Writer.write(context, clazzes, packageInfo, outputFilename);
}
Also used : GapicPackageInfo(com.google.api.generator.gapic.model.GapicPackageInfo) GapicClass(com.google.api.generator.gapic.model.GapicClass) GapicContext(com.google.api.generator.gapic.model.GapicContext)

Example 25 with GapicClass

use of com.google.api.generator.gapic.model.GapicClass in project gapic-generator-java by googleapis.

the class Writer method write.

public static CodeGeneratorResponse write(GapicContext context, List<GapicClass> clazzes, GapicPackageInfo gapicPackageInfo, String outputFilePath) {
    ByteString.Output output = ByteString.newOutput();
    JavaWriterVisitor codeWriter = new JavaWriterVisitor();
    JarOutputStream jos;
    try {
        jos = new JarOutputStream(output);
    } catch (IOException e) {
        throw new GapicWriterException(e.getMessage(), e);
    }
    for (GapicClass gapicClazz : clazzes) {
        String classPath = writeClazz(gapicClazz, codeWriter, jos);
        writeSamples(gapicClazz, getSamplePackage(gapicClazz), classPath, jos);
    }
    writeMetadataFile(context, writePackageInfo(gapicPackageInfo, codeWriter, jos), jos);
    try {
        jos.finish();
        jos.flush();
    } catch (IOException e) {
        throw new GapicWriterException(e.getMessage(), e);
    }
    CodeGeneratorResponse.Builder response = CodeGeneratorResponse.newBuilder();
    response.setSupportedFeatures(CodeGeneratorResponse.Feature.FEATURE_PROTO3_OPTIONAL_VALUE).addFileBuilder().setName(outputFilePath).setContentBytes(output.toByteString());
    return response.build();
}
Also used : ByteString(com.google.protobuf.ByteString) GapicClass(com.google.api.generator.gapic.model.GapicClass) JarOutputStream(java.util.jar.JarOutputStream) CodeGeneratorResponse(com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse) JavaWriterVisitor(com.google.api.generator.engine.writer.JavaWriterVisitor) IOException(java.io.IOException) ByteString(com.google.protobuf.ByteString)

Aggregations

GapicClass (com.google.api.generator.gapic.model.GapicClass)45 Test (org.junit.Test)35 Service (com.google.api.generator.gapic.model.Service)29 GapicContext (com.google.api.generator.gapic.model.GapicContext)24 JavaWriterVisitor (com.google.api.generator.engine.writer.JavaWriterVisitor)21 Path (java.nio.file.Path)20 ClassDefinition (com.google.api.generator.engine.ast.ClassDefinition)9 TypeStore (com.google.api.generator.gapic.composer.store.TypeStore)8 Kind (com.google.api.generator.gapic.model.GapicClass.Kind)8 Message (com.google.api.generator.gapic.model.Message)7 ResourceName (com.google.api.generator.gapic.model.ResourceName)7 HashSet (java.util.HashSet)4 FileDescriptor (com.google.protobuf.Descriptors.FileDescriptor)3 ServiceDescriptor (com.google.protobuf.Descriptors.ServiceDescriptor)3 CommentStatement (com.google.api.generator.engine.ast.CommentStatement)2 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)2 StubCommentComposer (com.google.api.generator.gapic.composer.comment.StubCommentComposer)2 Sample (com.google.api.generator.gapic.model.Sample)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2