use of com.google.api.generator.engine.ast.MethodInvocationExpr in project gapic-generator-java by googleapis.
the class SampleCodeWriterTest method setUp.
@BeforeClass
public static void setUp() {
TypeNode settingType = TypeNode.withReference(ConcreteReference.withClazz(ClientSettings.class));
Variable aVar = Variable.builder().setName("clientSettings").setType(settingType).build();
VariableExpr aVarExpr = VariableExpr.withVariable(aVar);
MethodInvocationExpr aValueExpr = MethodInvocationExpr.builder().setExprReferenceExpr(MethodInvocationExpr.builder().setMethodName("newBuilder").setStaticReferenceType(settingType).build()).setReturnType(settingType).setMethodName("build").build();
AssignmentExpr assignmentExpr = AssignmentExpr.builder().setVariableExpr(aVarExpr.toBuilder().setIsDecl(true).build()).setValueExpr(aValueExpr).build();
TryCatchStatement sampleStatement = TryCatchStatement.builder().setTryResourceExpr(createAssignmentExpr("aBool", "false", TypeNode.BOOLEAN)).setTryBody(Arrays.asList(ExprStatement.withExpr(createAssignmentExpr("x", "3", TypeNode.INT)))).setIsSampleCode(true).build();
testingSampleStatements = Arrays.asList(ExprStatement.withExpr(assignmentExpr), sampleStatement);
regionTag = RegionTag.builder().setApiShortName("testing").setApiVersion("v1").setServiceName("samples").setRpcName("write").build();
testingSample = Sample.builder().setFileHeader(Arrays.asList(CommentStatement.withComment(BlockComment.withComment("Apache License")))).setBody(testingSampleStatements).setRegionTag(regionTag).build();
}
use of com.google.api.generator.engine.ast.MethodInvocationExpr in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeLogicalOperationExpr_logicalAnd.
@Test
public void writeLogicalOperationExpr_logicalAnd() {
VariableExpr lhsExpr = VariableExpr.withVariable(createVariable("isEmpty", TypeNode.BOOLEAN));
VaporReference ref = VaporReference.builder().setName("Student").setPakkage("com.google.example.v1").build();
TypeNode classType = TypeNode.withReference(ref);
MethodInvocationExpr rhsExpr = MethodInvocationExpr.builder().setMethodName("isValid").setExprReferenceExpr(ValueExpr.withValue(ThisObjectValue.withType(classType))).setReturnType(TypeNode.BOOLEAN).build();
LogicalOperationExpr logicalOperationExpr = LogicalOperationExpr.logicalAndWithExprs(lhsExpr, rhsExpr);
logicalOperationExpr.accept(writerVisitor);
assertThat(writerVisitor.write()).isEqualTo("isEmpty && this.isValid()");
}
use of com.google.api.generator.engine.ast.MethodInvocationExpr in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeArithmeticOperationExpr_concatStringWithMethod.
@Test
public void writeArithmeticOperationExpr_concatStringWithMethod() {
ValueExpr lhsExpr = ValueExpr.withValue(StringObjectValue.withValue("someWord"));
MethodInvocationExpr methodInvocationExpr = MethodInvocationExpr.builder().setMethodName("getMethod").build();
MethodInvocationExpr rhsExpr = MethodInvocationExpr.builder().setExprReferenceExpr(methodInvocationExpr).setMethodName("getString").setReturnType(TypeNode.STRING).build();
ArithmeticOperationExpr arithmeticOperationExpr = ArithmeticOperationExpr.concatWithExprs(lhsExpr, rhsExpr);
arithmeticOperationExpr.accept(writerVisitor);
assertThat(writerVisitor.write()).isEqualTo("\"someWord\" + getMethod().getString()");
}
use of com.google.api.generator.engine.ast.MethodInvocationExpr in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeCastExpr_methodInvocation.
@Test
public void writeCastExpr_methodInvocation() {
TypeNode someType = TypeNode.withReference(VaporReference.builder().setName("SomeClass").setPakkage("com.google.api.some.pakkage").build());
MethodInvocationExpr methodExpr = MethodInvocationExpr.builder().setMethodName("foobar").setStaticReferenceType(someType).setReturnType(TypeNode.STRING).build();
CastExpr castExpr = CastExpr.builder().setType(TypeNode.withReference(ConcreteReference.withClazz(Object.class))).setExpr(methodExpr).build();
castExpr.accept(writerVisitor);
assertEquals("((Object) SomeClass.foobar())", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.MethodInvocationExpr in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeAssignmentOperationExpr_xorAssignment.
@Test
public void writeAssignmentOperationExpr_xorAssignment() {
VariableExpr lhsExpr = createVariableExpr("h", TypeNode.INT);
TypeNode objectType = TypeNode.withReference(VaporReference.builder().setName("Objects").setPakkage("java.lang.Object").build());
MethodInvocationExpr rhsExpr = MethodInvocationExpr.builder().setReturnType(TypeNode.INT).setMethodName("hashCode").setStaticReferenceType(objectType).setArguments(Arrays.asList(VariableExpr.withVariable(createVariable("fixedValue", TypeNode.OBJECT)))).build();
AssignmentOperationExpr assignmentOperationExpr = AssignmentOperationExpr.xorAssignmentWithExprs(lhsExpr, rhsExpr);
assignmentOperationExpr.accept(writerVisitor);
assertThat(writerVisitor.write()).isEqualTo("h ^= Objects.hashCode(fixedValue)");
}
Aggregations