Search in sources :

Example 76 with TypeNode

use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.

the class ImportWriterVisitorTest method writeThrowExprImports_basic.

@Test
public void writeThrowExprImports_basic() {
    TypeNode exceptionTypes = TypeNode.withReference(ConcreteReference.withClazz(IOException.class));
    String message = "Some message asdf";
    ThrowExpr throwExpr = ThrowExpr.builder().setType(exceptionTypes).setMessageExpr(message).build();
    throwExpr.accept(writerVisitor);
    assertEquals("import java.io.IOException;\n\n", writerVisitor.write());
}
Also used : ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) IOException(java.io.IOException) Test(org.junit.Test)

Example 77 with TypeNode

use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.

the class JavaWriterVisitorTest method writeRelationOperationExpr_notEqualTo.

@Test
public void writeRelationOperationExpr_notEqualTo() {
    TypeNode someType = TypeNode.withReference(VaporReference.builder().setName("SomeClass").setPakkage("com.google.api.generator.engine").build());
    MethodInvocationExpr lhsExpr = MethodInvocationExpr.builder().setMethodName("getName").setStaticReferenceType(someType).setReturnType(TypeNode.STRING).build();
    ValueExpr rhsExpr = ValueExpr.createNullExpr();
    RelationalOperationExpr notEqualToOperationExpr = RelationalOperationExpr.notEqualToWithExprs(lhsExpr, rhsExpr);
    notEqualToOperationExpr.accept(writerVisitor);
    assertThat(writerVisitor.write()).isEqualTo("SomeClass.getName() != null");
}
Also used : ValueExpr(com.google.api.generator.engine.ast.ValueExpr) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) Test(org.junit.Test)

Example 78 with TypeNode

use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.

the class ImportWriterVisitorTest method writeThrowExprImports_messageAndCauseExpr.

@Test
public void writeThrowExprImports_messageAndCauseExpr() {
    TypeNode npeType = TypeNode.withExceptionClazz(NullPointerException.class);
    Expr messageExpr = MethodInvocationExpr.builder().setStaticReferenceType(TypeNode.withReference(ConcreteReference.withClazz(IfStatement.class))).setMethodName("conditionExpr").setReturnType(TypeNode.withReference(ConcreteReference.withClazz(Expr.class))).build();
    messageExpr = MethodInvocationExpr.builder().setExprReferenceExpr(messageExpr).setMethodName("foobar").setReturnType(TypeNode.STRING).build();
    ThrowExpr throwExpr = ThrowExpr.builder().setType(npeType).setMessageExpr(messageExpr).setCauseExpr(NewObjectExpr.builder().setType(TypeNode.withExceptionClazz(FileNotFoundException.class)).build()).build();
    throwExpr.accept(writerVisitor);
    assertEquals(LineFormatter.lines("import com.google.api.generator.engine.ast.Expr;\n", "import com.google.api.generator.engine.ast.IfStatement;\n", "import java.io.FileNotFoundException;\n\n"), writerVisitor.write());
}
Also used : IfStatement(com.google.api.generator.engine.ast.IfStatement) ReferenceConstructorExpr(com.google.api.generator.engine.ast.ReferenceConstructorExpr) LogicalOperationExpr(com.google.api.generator.engine.ast.LogicalOperationExpr) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) EnumRefExpr(com.google.api.generator.engine.ast.EnumRefExpr) ReturnExpr(com.google.api.generator.engine.ast.ReturnExpr) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) Expr(com.google.api.generator.engine.ast.Expr) TernaryExpr(com.google.api.generator.engine.ast.TernaryExpr) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) UnaryOperationExpr(com.google.api.generator.engine.ast.UnaryOperationExpr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) InstanceofExpr(com.google.api.generator.engine.ast.InstanceofExpr) ArithmeticOperationExpr(com.google.api.generator.engine.ast.ArithmeticOperationExpr) AnonymousClassExpr(com.google.api.generator.engine.ast.AnonymousClassExpr) LambdaExpr(com.google.api.generator.engine.ast.LambdaExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) Test(org.junit.Test)

Example 79 with TypeNode

use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.

the class ImportWriterVisitorTest method writeEnumRefExprImports_basic.

@Test
public void writeEnumRefExprImports_basic() {
    TypeNode enumType = TypeNode.withReference(ConcreteReference.builder().setClazz(TypeNode.TypeKind.class).setIsStaticImport(true).build());
    EnumRefExpr enumRefExpr = EnumRefExpr.builder().setName("VOID").setType(enumType).build();
    enumRefExpr.accept(writerVisitor);
    assertEquals("import static com.google.api.generator.engine.ast.TypeNode.TypeKind;\n\n", writerVisitor.write());
}
Also used : EnumRefExpr(com.google.api.generator.engine.ast.EnumRefExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) Test(org.junit.Test)

Example 80 with TypeNode

use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.

the class ImportWriterVisitorTest method writeSuperObjectValueImports.

@Test
public void writeSuperObjectValueImports() {
    VaporReference ref = VaporReference.builder().setName("Student").setPakkage("com.google.example.examples.v1").build();
    TypeNode typeNode = TypeNode.withReference(ref);
    SuperObjectValue superObjectValue = SuperObjectValue.withType(typeNode);
    MethodInvocationExpr methodExpr = MethodInvocationExpr.builder().setMethodName("getName").setExprReferenceExpr(ValueExpr.withValue(superObjectValue)).setReturnType(TypeNode.STRING).build();
    methodExpr.accept(writerVisitor);
    assertEquals("import com.google.example.examples.v1.Student;\n\n", writerVisitor.write());
}
Also used : MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) VaporReference(com.google.api.generator.engine.ast.VaporReference) TypeNode(com.google.api.generator.engine.ast.TypeNode) SuperObjectValue(com.google.api.generator.engine.ast.SuperObjectValue) Test(org.junit.Test)

Aggregations

TypeNode (com.google.api.generator.engine.ast.TypeNode)232 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)119 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)111 Test (org.junit.Test)103 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)84 Message (com.google.api.generator.gapic.model.Message)81 ArrayList (java.util.ArrayList)81 Expr (com.google.api.generator.engine.ast.Expr)77 ValueExpr (com.google.api.generator.engine.ast.ValueExpr)77 Method (com.google.api.generator.gapic.model.Method)72 NewObjectExpr (com.google.api.generator.engine.ast.NewObjectExpr)68 ResourceName (com.google.api.generator.gapic.model.ResourceName)65 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)64 List (java.util.List)63 ConcreteReference (com.google.api.generator.engine.ast.ConcreteReference)61 MethodDefinition (com.google.api.generator.engine.ast.MethodDefinition)59 Variable (com.google.api.generator.engine.ast.Variable)55 Statement (com.google.api.generator.engine.ast.Statement)53 Collectors (java.util.stream.Collectors)46 RelationalOperationExpr (com.google.api.generator.engine.ast.RelationalOperationExpr)45