use of com.google.api.generator.engine.ast.Expr in project gapic-generator-java by googleapis.
the class ImportWriterVisitorTest method writeUnaryOperationExprImports_PostIncrement.
@Test
public void writeUnaryOperationExprImports_PostIncrement() {
MethodInvocationExpr expr = MethodInvocationExpr.builder().setStaticReferenceType(TypeNode.withReference(ConcreteReference.withClazz(Expr.class))).setMethodName("getNumber").setReturnType(TypeNode.INT).build();
UnaryOperationExpr unaryOperationExpr = UnaryOperationExpr.postfixIncrementWithExpr(expr);
unaryOperationExpr.accept(writerVisitor);
assertEquals("import com.google.api.generator.engine.ast.Expr;\n\n", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.Expr in project gapic-generator-java by googleapis.
the class DefaultValueComposerTest method defaultValue_wildcardResourceNameWithOnlyDeletedTopic.
@Test
public void defaultValue_wildcardResourceNameWithOnlyDeletedTopic() {
// Edge case that should never happen in practice.
// Wildcard, but the resource names map has only other names that contain only the deleted-topic
// constant.
FileDescriptor lockerServiceFileDescriptor = LockerProto.getDescriptor();
Map<String, ResourceName> typeStringsToResourceNames = Parser.parseResourceNames(lockerServiceFileDescriptor);
ResourceName resourceName = typeStringsToResourceNames.get("cloudresourcemanager.googleapis.com/Anything");
ResourceName topicResourceName = typeStringsToResourceNames.get("pubsub.googleapis.com/Topic");
typeStringsToResourceNames.clear();
typeStringsToResourceNames.put(topicResourceName.resourceTypeString(), topicResourceName);
Expr expr = DefaultValueComposer.createResourceHelperValue(resourceName, false, typeStringsToResourceNames.values().stream().collect(Collectors.toList()), "ignored");
expr.accept(writerVisitor);
assertEquals("TopicName.ofDeletedTopic()", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.Expr in project gapic-generator-java by googleapis.
the class DefaultValueComposerTest method defaultValue_resourceNameWithOnePattern.
@Test
public void defaultValue_resourceNameWithOnePattern() {
FileDescriptor lockerServiceFileDescriptor = LockerProto.getDescriptor();
Map<String, ResourceName> typeStringsToResourceNames = Parser.parseResourceNames(lockerServiceFileDescriptor);
ResourceName resourceName = typeStringsToResourceNames.get("cloudbilling.googleapis.com/BillingAccount");
Expr expr = DefaultValueComposer.createResourceHelperValue(resourceName, false, typeStringsToResourceNames.values().stream().collect(Collectors.toList()), "ignored");
expr.accept(writerVisitor);
assertEquals("BillingAccountName.of(\"[BILLING_ACCOUNT]\")", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.Expr in project gapic-generator-java by googleapis.
the class DefaultValueComposerTest method defaultValue_resourceNameWithMultiplePatterns.
@Test
public void defaultValue_resourceNameWithMultiplePatterns() {
FileDescriptor lockerServiceFileDescriptor = LockerProto.getDescriptor();
Map<String, ResourceName> typeStringsToResourceNames = Parser.parseResourceNames(lockerServiceFileDescriptor);
ResourceName resourceName = typeStringsToResourceNames.get("cloudresourcemanager.googleapis.com/Folder");
Expr expr = DefaultValueComposer.createResourceHelperValue(resourceName, false, typeStringsToResourceNames.values().stream().collect(Collectors.toList()), "ignored");
expr.accept(writerVisitor);
assertEquals("FolderName.ofProjectFolderName(\"[PROJECT]\", \"[FOLDER]\")", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.Expr in project gapic-generator-java by googleapis.
the class DefaultValueComposerTest method defaultValue_booleanField.
@Test
public void defaultValue_booleanField() {
Field field = Field.builder().setName("foobar").setType(TypeNode.BOOLEAN).build();
Expr expr = DefaultValueComposer.createValue(field);
expr.accept(writerVisitor);
assertEquals("true", writerVisitor.write());
}
Aggregations