use of com.google.api.generator.engine.ast.ClassDefinition in project gapic-generator-java by googleapis.
the class ImportWriterVisitor method visit.
@Override
public void visit(ClassDefinition classDefinition) {
annotations(classDefinition.annotations());
types(classDefinition.implementsTypes());
if (classDefinition.extendsType() != null) {
classDefinition.extendsType().accept(this);
}
statements(classDefinition.statements());
for (MethodDefinition method : classDefinition.methods()) {
method.accept(this);
}
for (ClassDefinition nestedClass : classDefinition.nestedClasses()) {
nestedClass.accept(this);
}
}
use of com.google.api.generator.engine.ast.ClassDefinition in project gapic-generator-java by googleapis.
the class JavaWriterVisitor method classes.
private void classes(List<ClassDefinition> classes) {
if (!classes.isEmpty()) {
newline();
}
for (ClassDefinition classDef : classes) {
classDef.accept(this);
newline();
newline();
}
}
use of com.google.api.generator.engine.ast.ClassDefinition in project gapic-generator-java by googleapis.
the class MockServiceImplClassComposer method generate.
@Override
public GapicClass generate(GapicContext context, Service service) {
TypeStore typeStore = createDynamicTypes(service);
String className = ClassNames.getMockServiceImplClassName(service);
GapicClass.Kind kind = Kind.TEST;
String pakkage = service.pakkage();
// Affects GCS.
if (context.messages().keySet().stream().anyMatch(s -> s.equals("Object") || s.endsWith(".Object"))) {
javaObjectReference = ConcreteReference.builder().setClazz(Object.class).setUseFullName(true).build();
}
responsesVarExpr = VariableExpr.withVariable(Variable.builder().setName("responses").setType(TypeNode.withReference(ConcreteReference.builder().setClazz(Queue.class).setGenerics(Arrays.asList(javaObjectReference)).build())).build());
ClassDefinition classDef = ClassDefinition.builder().setPackageString(pakkage).setAnnotations(createClassAnnotations()).setScope(ScopeNode.PUBLIC).setName(className).setExtendsType(typeStore.get(String.format(IMPL_BASE_PATTERN, service.name()))).setStatements(createFieldDeclarations()).setMethods(createClassMethods(service, typeStore)).build();
return GapicClass.create(kind, classDef);
}
use of com.google.api.generator.engine.ast.ClassDefinition in project gapic-generator-java by googleapis.
the class MockServiceClassComposer method generate.
@Override
public GapicClass generate(GapicContext ignored, Service service) {
TypeStore typeStore = createTypes(service);
String className = ClassNames.getMockServiceClassName(service);
GapicClass.Kind kind = Kind.TEST;
String pakkage = service.pakkage();
ClassDefinition classDef = ClassDefinition.builder().setPackageString(pakkage).setAnnotations(createClassAnnotations(typeStore)).setScope(ScopeNode.PUBLIC).setName(className).setImplementsTypes(createClassImplements(typeStore)).setStatements(createFieldDeclarations(service, typeStore)).setMethods(createClassMethods(service, typeStore)).build();
return GapicClass.create(kind, classDef);
}
use of com.google.api.generator.engine.ast.ClassDefinition in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeClassDefinition_withAnnotationsExtendsAndImplements.
@Test
public void writeClassDefinition_withAnnotationsExtendsAndImplements() {
ClassDefinition classDef = ClassDefinition.builder().setPackageString("com.google.example.library.v1.stub").setName("LibraryServiceStub").setScope(ScopeNode.PUBLIC).setIsFinal(true).setAnnotations(Arrays.asList(AnnotationNode.DEPRECATED, AnnotationNode.withSuppressWarnings("all"))).setExtendsType(TypeNode.STRING).setImplementsTypes(Arrays.asList(TypeNode.withReference(ConcreteReference.withClazz(Appendable.class)), TypeNode.withReference(ConcreteReference.withClazz(Cloneable.class)), TypeNode.withReference(ConcreteReference.withClazz(Readable.class)))).build();
classDef.accept(writerVisitor);
assertEquals(LineFormatter.lines("package com.google.example.library.v1.stub;\n", "\n", "@Deprecated\n", "@SuppressWarnings(\"all\")\n", "public final class LibraryServiceStub extends String implements Appendable," + " Cloneable, Readable {}\n"), writerVisitor.write());
}
Aggregations