Search in sources :

Example 6 with ClassDefinition

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);
    }
}
Also used : MethodDefinition(com.google.api.generator.engine.ast.MethodDefinition) ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition)

Example 7 with ClassDefinition

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();
    }
}
Also used : ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition)

Example 8 with ClassDefinition

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);
}
Also used : 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) Queue(java.util.Queue)

Example 9 with ClassDefinition

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);
}
Also used : 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 10 with ClassDefinition

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());
}
Also used : ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition) Test(org.junit.Test)

Aggregations

ClassDefinition (com.google.api.generator.engine.ast.ClassDefinition)23 TypeStore (com.google.api.generator.gapic.composer.store.TypeStore)13 GapicClass (com.google.api.generator.gapic.model.GapicClass)12 Kind (com.google.api.generator.gapic.model.GapicClass.Kind)10 ArrayList (java.util.ArrayList)9 CommentStatement (com.google.api.generator.engine.ast.CommentStatement)8 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)8 Message (com.google.api.generator.gapic.model.Message)7 MethodDefinition (com.google.api.generator.engine.ast.MethodDefinition)6 TypeNode (com.google.api.generator.engine.ast.TypeNode)6 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)5 Statement (com.google.api.generator.engine.ast.Statement)5 ResourceName (com.google.api.generator.gapic.model.ResourceName)5 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)4 ConcreteReference (com.google.api.generator.engine.ast.ConcreteReference)4 Reference (com.google.api.generator.engine.ast.Reference)4 List (java.util.List)4 BetaApi (com.google.api.core.BetaApi)3