Search in sources :

Example 26 with BLangRecordLiteral

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral in project ballerina by ballerina-lang.

the class ClientGeneratorPlugin method isClientGenerationEnabled.

private boolean isClientGenerationEnabled(AnnotationAttachmentNode ann) {
    boolean isClientRequested;
    if (ann == null) {
        return false;
    }
    BLangRecordLiteral bLiteral = ((BLangRecordLiteral) ((BLangAnnotationAttachment) ann).getExpression());
    List<BLangRecordLiteral.BLangRecordKeyValue> list = bLiteral.getKeyValuePairs();
    Map<String, String[]> attrs = GeneratorUtils.getKeyValuePairAsMap(list);
    String val = attrs.get("generate")[0];
    isClientRequested = Boolean.parseBoolean(val);
    return isClientRequested;
}
Also used : BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)

Example 27 with BLangRecordLiteral

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral in project ballerina by ballerina-lang.

the class EndpointContextHolder method extractDetails.

private void extractDetails(EndpointNode ep, AnnotationAttachmentNode ann) {
    this.name = ep.getName().getValue();
    BLangRecordLiteral bLiteral = (BLangRecordLiteral) ep.getConfigurationExpression();
    List<BLangRecordLiteral.BLangRecordKeyValue> list = bLiteral.getKeyValuePairs();
    Map<String, String[]> configs = GeneratorUtils.getKeyValuePairAsMap(list);
    String httpsPort = configs.get(GeneratorConstants.ATTR_HTTPS_PORT) != null ? configs.get(GeneratorConstants.ATTR_HTTPS_PORT)[0] : null;
    this.host = configs.get(GeneratorConstants.ATTR_HOST) != null ? configs.get(GeneratorConstants.ATTR_HOST)[0] : null;
    this.port = configs.get(GeneratorConstants.ATTR_HTTP_PORT) != null ? configs.get(GeneratorConstants.ATTR_HTTP_PORT)[0] : null;
    bLiteral = ((BLangRecordLiteral) ((BLangAnnotationAttachment) ann).getExpression());
    List<BLangRecordLiteral.BLangRecordKeyValue> attrList = bLiteral.getKeyValuePairs();
    Map<String, String[]> attrs = GeneratorUtils.getKeyValuePairAsMap(attrList);
    this.basePath = attrs.get(GeneratorConstants.ATTR_BASE_PATH) != null ? attrs.get(GeneratorConstants.ATTR_BASE_PATH)[0] : null;
    StringBuffer sb = new StringBuffer();
    // Select protocol according to given ports. HTTPS is given the priority
    if (httpsPort != null) {
        sb.append(GeneratorConstants.ATTR_HTTPS);
        port = httpsPort;
    } else {
        sb.append(GeneratorConstants.ATTR_HTTP);
    }
    // Set default values to host and port if values are not defined
    if (host == null) {
        host = GeneratorConstants.ATTR_DEF_HOST;
    }
    if (port == null) {
        port = GeneratorConstants.ATTR_DEF_PORT;
    }
    this.url = sb.append(host).append(':').append(port).append(basePath).toString();
}
Also used : BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)

Aggregations

BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)25 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)10 AnnotationAttachmentNode (org.ballerinalang.model.tree.AnnotationAttachmentNode)8 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)5 BLangArrayLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral)5 HashSet (java.util.HashSet)4 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)4 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 SecretModel (org.ballerinax.kubernetes.models.SecretModel)2 ServiceModel (org.ballerinax.kubernetes.models.ServiceModel)2 BLangAnnotationAttachment (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)2 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)2 BLangIndexBasedAccess (org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess)2 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)2 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)2 Collections (java.util.Collections)1