Search in sources :

Example 16 with BLangAnnotationAttachment

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

the class BLangPackageBuilder method setAnnotationAttachmentName.

public void setAnnotationAttachmentName(Set<Whitespace> ws, boolean hasExpr, DiagnosticPos currentPos, boolean popAnnAttachment) {
    BLangNameReference nameReference = nameReferenceStack.pop();
    BLangAnnotationAttachment bLangAnnotationAttachment = (BLangAnnotationAttachment) annotAttachmentStack.peek();
    bLangAnnotationAttachment.pos = currentPos;
    bLangAnnotationAttachment.addWS(nameReference.ws);
    bLangAnnotationAttachment.addWS(ws);
    bLangAnnotationAttachment.setAnnotationName(nameReference.name);
    bLangAnnotationAttachment.setPackageAlias(nameReference.pkgAlias);
    if (hasExpr) {
        bLangAnnotationAttachment.setExpression(exprNodeStack.pop());
    }
    if (popAnnAttachment) {
        annotAttachmentStack.pop();
    }
}
Also used : BLangNameReference(org.wso2.ballerinalang.compiler.tree.BLangNameReference) BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)

Example 17 with BLangAnnotationAttachment

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

the class BLangPackageBuilder method startAnnotationAttachment.

public void startAnnotationAttachment(DiagnosticPos currentPos) {
    BLangAnnotationAttachment annotAttachmentNode = (BLangAnnotationAttachment) TreeBuilder.createAnnotAttachmentNode();
    annotAttachmentNode.pos = currentPos;
    annotAttachmentStack.push(annotAttachmentNode);
}
Also used : BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)

Example 18 with BLangAnnotationAttachment

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

the class ResourceContextHolder method buildContext.

public static ResourceContextHolder buildContext(ResourceNode resource) throws CodeGeneratorException {
    ResourceContextHolder context = new ResourceContextHolder();
    context.name = resource.getName().getValue();
    context.parameters = new ArrayList<>();
    for (VariableNode node : resource.getParameters()) {
        ParameterContextHolder parameter = ParameterContextHolder.buildContext(node);
        if (parameter != null) {
            context.parameters.add(parameter);
        }
    }
    // Iterate through all resource level annotations and find out resource configuration information
    AnnotationAttachmentNode ann = GeneratorUtils.getAnnotationFromList(GeneratorConstants.RES_CONFIG_ANNOTATION, GeneratorConstants.HTTP_PKG_ALIAS, resource.getAnnotationAttachments());
    if (ann == null) {
        throw new CodeGeneratorException("Incomplete resource configuration found");
    }
    BLangRecordLiteral bLiteral = ((BLangRecordLiteral) ((BLangAnnotationAttachment) ann).getExpression());
    List<BLangRecordLiteral.BLangRecordKeyValue> list = bLiteral.getKeyValuePairs();
    Map<String, String[]> attrs = GeneratorUtils.getKeyValuePairAsMap(list);
    // We don't expect multiple http methods to be supported by single action
    // We only consider first content type for a single resource
    context.method = attrs.get(GeneratorConstants.ATTR_METHODS) != null ? attrs.get(GeneratorConstants.ATTR_METHODS)[0] : null;
    context.contentType = attrs.get(GeneratorConstants.ATTR_CONSUMES) != null ? attrs.get(GeneratorConstants.ATTR_CONSUMES)[0] : null;
    String path = attrs.get(GeneratorConstants.ATTR_PATH) != null ? attrs.get(GeneratorConstants.ATTR_PATH)[0] : null;
    context.path = context.getTemplatePath(path);
    return context;
}
Also used : VariableNode(org.ballerinalang.model.tree.VariableNode) BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment) CodeGeneratorException(org.ballerinalang.code.generator.exception.CodeGeneratorException) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 19 with BLangAnnotationAttachment

use of org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment 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 20 with BLangAnnotationAttachment

use of org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment 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)10 BLangAnnotationAttachment (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)9 AnnotationAttachmentNode (org.ballerinalang.model.tree.AnnotationAttachmentNode)5 HashSet (java.util.HashSet)4 List (java.util.List)4 BLangResource (org.wso2.ballerinalang.compiler.tree.BLangResource)4 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)4 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)3 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)3 BLangArrayLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral)3 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)3 ArrayList (java.util.ArrayList)2 TopLevelNode (org.ballerinalang.model.tree.TopLevelNode)2 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 Set (java.util.Set)1