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