Search in sources :

Example 1 with SynchronizedStatement

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

the class JavaWriterVisitorTest method writeSynchronizedStatement_basicVariableExpr.

@Test
public void writeSynchronizedStatement_basicVariableExpr() {
    VariableExpr strVarExpr = VariableExpr.withVariable(Variable.builder().setName("str").setType(TypeNode.STRING).build());
    SynchronizedStatement synchronizedStatement = SynchronizedStatement.builder().setLock(strVarExpr).setBody(ExprStatement.withExpr(MethodInvocationExpr.builder().setMethodName("doStuff").build())).build();
    synchronizedStatement.accept(writerVisitor);
    assertEquals(LineFormatter.lines("synchronized (str) {\n", "doStuff();\n", "}\n"), writerVisitor.write());
}
Also used : VariableExpr(com.google.api.generator.engine.ast.VariableExpr) SynchronizedStatement(com.google.api.generator.engine.ast.SynchronizedStatement) Test(org.junit.Test)

Example 2 with SynchronizedStatement

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

the class JavaWriterVisitorTest method writeSynchronizedStatement_basicThis.

@Test
public void writeSynchronizedStatement_basicThis() {
    SynchronizedStatement synchronizedStatement = SynchronizedStatement.builder().setLock(ThisObjectValue.withType(TypeNode.withReference(ConcreteReference.withClazz(Expr.class)))).setBody(ExprStatement.withExpr(MethodInvocationExpr.builder().setMethodName("doStuff").build())).build();
    synchronizedStatement.accept(writerVisitor);
    assertEquals(LineFormatter.lines("synchronized (this) {\n", "doStuff();\n", "}\n"), writerVisitor.write());
}
Also used : 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) CastExpr(com.google.api.generator.engine.ast.CastExpr) ArithmeticOperationExpr(com.google.api.generator.engine.ast.ArithmeticOperationExpr) AnonymousClassExpr(com.google.api.generator.engine.ast.AnonymousClassExpr) LambdaExpr(com.google.api.generator.engine.ast.LambdaExpr) AssignmentOperationExpr(com.google.api.generator.engine.ast.AssignmentOperationExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) SynchronizedStatement(com.google.api.generator.engine.ast.SynchronizedStatement) Test(org.junit.Test)

Example 3 with SynchronizedStatement

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

the class ImportWriterVisitorTest method writeSynchronizedStatementImports_basicThis.

@Test
public void writeSynchronizedStatementImports_basicThis() {
    SynchronizedStatement synchronizedStatement = SynchronizedStatement.builder().setLock(ThisObjectValue.withType(TypeNode.withReference(ConcreteReference.withClazz(Expr.class)))).setBody(ExprStatement.withExpr(MethodInvocationExpr.builder().setMethodName("doStuff").setReturnType(TypeNode.withReference(ConcreteReference.withClazz(Arrays.class))).build())).build();
    synchronizedStatement.accept(writerVisitor);
    assertEquals(LineFormatter.lines("import com.google.api.generator.engine.ast.Expr;\n", "import java.util.Arrays;\n\n"), writerVisitor.write());
}
Also used : 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) SynchronizedStatement(com.google.api.generator.engine.ast.SynchronizedStatement) Test(org.junit.Test)

Example 4 with SynchronizedStatement

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

the class ImportWriterVisitorTest method writeSynchronizedStatementImports_basicVariableExpr.

@Test
public void writeSynchronizedStatementImports_basicVariableExpr() {
    VariableExpr strVarExpr = VariableExpr.withVariable(Variable.builder().setName("str").setType(TypeNode.withReference(ConcreteReference.withClazz(AssignmentExpr.class))).build());
    SynchronizedStatement synchronizedStatement = SynchronizedStatement.builder().setLock(strVarExpr).setBody(ExprStatement.withExpr(MethodInvocationExpr.builder().setMethodName("doStuff").setReturnType(TypeNode.withReference(ConcreteReference.withClazz(Map.class))).build())).build();
    synchronizedStatement.accept(writerVisitor);
    assertEquals(LineFormatter.lines("import com.google.api.generator.engine.ast.AssignmentExpr;\n", "import java.util.Map;\n\n"), writerVisitor.write());
}
Also used : VariableExpr(com.google.api.generator.engine.ast.VariableExpr) SynchronizedStatement(com.google.api.generator.engine.ast.SynchronizedStatement) Test(org.junit.Test)

Aggregations

SynchronizedStatement (com.google.api.generator.engine.ast.SynchronizedStatement)4 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)4 Test (org.junit.Test)4 AnonymousClassExpr (com.google.api.generator.engine.ast.AnonymousClassExpr)2 ArithmeticOperationExpr (com.google.api.generator.engine.ast.ArithmeticOperationExpr)2 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)2 EnumRefExpr (com.google.api.generator.engine.ast.EnumRefExpr)2 Expr (com.google.api.generator.engine.ast.Expr)2 InstanceofExpr (com.google.api.generator.engine.ast.InstanceofExpr)2 LambdaExpr (com.google.api.generator.engine.ast.LambdaExpr)2 LogicalOperationExpr (com.google.api.generator.engine.ast.LogicalOperationExpr)2 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)2 NewObjectExpr (com.google.api.generator.engine.ast.NewObjectExpr)2 ReferenceConstructorExpr (com.google.api.generator.engine.ast.ReferenceConstructorExpr)2 RelationalOperationExpr (com.google.api.generator.engine.ast.RelationalOperationExpr)2 ReturnExpr (com.google.api.generator.engine.ast.ReturnExpr)2 TernaryExpr (com.google.api.generator.engine.ast.TernaryExpr)2 ThrowExpr (com.google.api.generator.engine.ast.ThrowExpr)2 UnaryOperationExpr (com.google.api.generator.engine.ast.UnaryOperationExpr)2 ValueExpr (com.google.api.generator.engine.ast.ValueExpr)2