Search in sources :

Example 81 with VariableExpr

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

the class RetrySettingsComposerTest method batchingSettings_fullFlowControlSettings.

@Test
public void batchingSettings_fullFlowControlSettings() {
    String filename = "logging_gapic.yaml";
    Path path = Paths.get(TestProtoLoader.instance().getTestFilesDirectory(), filename);
    Optional<List<GapicBatchingSettings>> batchingSettingsOpt = BatchingSettingsConfigParser.parse(Optional.of(path.toString()));
    assertTrue(batchingSettingsOpt.isPresent());
    String jsonFilename = "logging_grpc_service_config.json";
    Path jsonPath = Paths.get(TestProtoLoader.instance().getTestFilesDirectory(), jsonFilename);
    Optional<GapicServiceConfig> configOpt = ServiceConfigParser.parse(jsonPath.toString());
    assertTrue(configOpt.isPresent());
    GapicServiceConfig config = configOpt.get();
    config.setBatchingSettings(batchingSettingsOpt);
    GapicContext context = TestProtoLoader.instance().parseLogging();
    Service service = context.services().get(0);
    assertEquals("LoggingServiceV2", service.name());
    VariableExpr builderVarExpr = createBuilderVarExpr(service);
    String methodSettingsName = "writeLogEntriesSettings";
    GapicBatchingSettings batchingSettings = GapicBatchingSettings.builder().setProtoPakkage("com.google.logging.v2").setServiceName("LoggingServiceV2").setMethodName("WriteLogEntries").setElementCountThreshold(1000).setRequestByteThreshold(1048576).setDelayThresholdMillis(50).setFlowControlElementLimit(100000).setFlowControlByteLimit(10485760).setFlowControlLimitExceededBehavior(GapicBatchingSettings.FlowControlLimitExceededBehavior.THROW_EXCEPTION).setBatchedFieldName("entries").setDiscriminatorFieldNames(Arrays.asList("log_name", "resource", "labels")).build();
    Expr builderExpr = RetrySettingsComposer.createBatchingBuilderSettingsExpr(methodSettingsName, batchingSettings, builderVarExpr);
    builderExpr.accept(writerVisitor);
    String expected = "builder" + ".writeLogEntriesSettings()" + ".setBatchingSettings(" + "BatchingSettings.newBuilder()" + ".setElementCountThreshold(1000L)" + ".setRequestByteThreshold(1048576L)" + ".setDelayThreshold(Duration.ofMillis(50L))" + ".setFlowControlSettings(" + "FlowControlSettings.newBuilder()" + ".setMaxOutstandingElementCount(100000L)" + ".setMaxOutstandingRequestBytes(10485760L)" + ".setLimitExceededBehavior(FlowController.LimitExceededBehavior.ThrowException)" + ".build())" + ".build())";
    assertEquals(expected, writerVisitor.write());
}
Also used : Path(java.nio.file.Path) Expr(com.google.api.generator.engine.ast.Expr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Service(com.google.api.generator.gapic.model.Service) List(java.util.List) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) GapicContext(com.google.api.generator.gapic.model.GapicContext) GapicServiceConfig(com.google.api.generator.gapic.model.GapicServiceConfig) GapicBatchingSettings(com.google.api.generator.gapic.model.GapicBatchingSettings) Test(org.junit.Test)

Example 82 with VariableExpr

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

the class SampleCodeWriterTest method createAssignmentExpr.

private static AssignmentExpr createAssignmentExpr(String varName, String varValue, TypeNode type) {
    Variable variable = Variable.builder().setName(varName).setType(type).build();
    VariableExpr variableExpr = VariableExpr.builder().setVariable(variable).setIsDecl(true).build();
    return AssignmentExpr.builder().setVariableExpr(variableExpr).setValueExpr(ValueExpr.withValue(PrimitiveValue.builder().setType(type).setValue(varValue).build())).build();
}
Also used : Variable(com.google.api.generator.engine.ast.Variable) VariableExpr(com.google.api.generator.engine.ast.VariableExpr)

Example 83 with VariableExpr

use of com.google.api.generator.engine.ast.VariableExpr 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();
}
Also used : Variable(com.google.api.generator.engine.ast.Variable) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) TryCatchStatement(com.google.api.generator.engine.ast.TryCatchStatement) ClientSettings(com.google.api.gax.rpc.ClientSettings) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) BeforeClass(org.junit.BeforeClass)

Example 84 with VariableExpr

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

the class SampleComposerUtilTest method handleDuplicateSamples_distinctDuplicates.

@Test
public void handleDuplicateSamples_distinctDuplicates() {
    VariableExpr echoClientVariableExprDiffVarName = VariableExpr.withVariable(Variable.builder().setName("echoClient2").setType(clientType).build());
    Sample echoClientSampleDiffVarName = echoClientSample.toBuilder().setBody(Arrays.asList(ExprStatement.withExpr(SampleComposerUtil.assignClientVariableWithCreateMethodExpr(echoClientVariableExprDiffVarName)))).build();
    List<Sample> samples = Arrays.asList(echoClientSample, echoClientSample, echoClientSampleDiffVarName);
    assertEquals(samples.size(), 3);
    assertEquals(samples.get(0).name(), "SyncCreate");
    assertEquals(samples.get(1).name(), "SyncCreate");
    assertEquals(samples.get(2).name(), "SyncCreate");
    List<Sample> result = SampleComposerUtil.handleDuplicateSamples(samples);
    assertEquals(result.size(), 2);
    assertTrue(result.contains(echoClientSample));
    assertTrue(result.stream().filter(s -> s.name().equals("SyncCreate1")).findFirst().isPresent());
}
Also used : VariableExpr(com.google.api.generator.engine.ast.VariableExpr) VaporReference(com.google.api.generator.engine.ast.VaporReference) Arrays(java.util.Arrays) TypeNode(com.google.api.generator.engine.ast.TypeNode) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) Variable(com.google.api.generator.engine.ast.Variable) RegionTag(com.google.api.generator.gapic.model.RegionTag) Sample(com.google.api.generator.gapic.model.Sample) ArrayList(java.util.ArrayList) List(java.util.List) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Sample(com.google.api.generator.gapic.model.Sample) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Test(org.junit.Test)

Example 85 with VariableExpr

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

the class JavaWriterVisitorTest method writeWhileStatement_simple.

@Test
public void writeWhileStatement_simple() {
    AssignmentExpr assignExpr = createAssignmentExpr("x", "3", TypeNode.INT);
    Statement assignExprStatement = ExprStatement.withExpr(assignExpr);
    List<Statement> whileBody = Arrays.asList(assignExprStatement, assignExprStatement);
    VariableExpr condExpr = createVariableExpr("condition", TypeNode.BOOLEAN);
    WhileStatement whileStatement = WhileStatement.builder().setConditionExpr(condExpr).setBody(whileBody).build();
    whileStatement.accept(writerVisitor);
    assertEquals(LineFormatter.lines("while (condition) {\n", "int x = 3;\n", "int x = 3;\n", "}\n"), writerVisitor.write());
}
Also used : BlockStatement(com.google.api.generator.engine.ast.BlockStatement) BreakStatement(com.google.api.generator.engine.ast.BreakStatement) WhileStatement(com.google.api.generator.engine.ast.WhileStatement) ForStatement(com.google.api.generator.engine.ast.ForStatement) EmptyLineStatement(com.google.api.generator.engine.ast.EmptyLineStatement) IfStatement(com.google.api.generator.engine.ast.IfStatement) GeneralForStatement(com.google.api.generator.engine.ast.GeneralForStatement) TryCatchStatement(com.google.api.generator.engine.ast.TryCatchStatement) SynchronizedStatement(com.google.api.generator.engine.ast.SynchronizedStatement) CommentStatement(com.google.api.generator.engine.ast.CommentStatement) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) Statement(com.google.api.generator.engine.ast.Statement) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) WhileStatement(com.google.api.generator.engine.ast.WhileStatement) Test(org.junit.Test)

Aggregations

VariableExpr (com.google.api.generator.engine.ast.VariableExpr)217 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)137 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)132 TypeNode (com.google.api.generator.engine.ast.TypeNode)118 Expr (com.google.api.generator.engine.ast.Expr)114 ValueExpr (com.google.api.generator.engine.ast.ValueExpr)107 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)91 Variable (com.google.api.generator.engine.ast.Variable)88 NewObjectExpr (com.google.api.generator.engine.ast.NewObjectExpr)87 ArrayList (java.util.ArrayList)87 Test (org.junit.Test)82 Statement (com.google.api.generator.engine.ast.Statement)80 List (java.util.List)64 ConcreteReference (com.google.api.generator.engine.ast.ConcreteReference)62 MethodDefinition (com.google.api.generator.engine.ast.MethodDefinition)58 RelationalOperationExpr (com.google.api.generator.engine.ast.RelationalOperationExpr)56 CastExpr (com.google.api.generator.engine.ast.CastExpr)53 CommentStatement (com.google.api.generator.engine.ast.CommentStatement)53 Arrays (java.util.Arrays)48 IfStatement (com.google.api.generator.engine.ast.IfStatement)47