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();
}
}
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);
}
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;
}
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;
}
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();
}
Aggregations