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);
}
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);
}
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);
}
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);
}
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();
}
Aggregations