use of org.wso2.ballerinalang.compiler.tree.BLangResource in project ballerina by ballerina-lang.
the class HTTPServiceCompilerPlugin method process.
@Override
public void process(ServiceNode serviceNode, List<AnnotationAttachmentNode> annotations) {
for (AnnotationAttachmentNode annotation : annotations) {
if (!PROTOCOL_PACKAGE_HTTP.equals(((BLangAnnotationAttachment) annotation).annotationSymbol.pkgID.name.value)) {
continue;
}
if (annotation.getAnnotationName().getValue().equals(ANN_NAME_HTTP_SERVICE_CONFIG) || annotation.getAnnotationName().getValue().equals(WebSocketConstants.WEBSOCKET_ANNOTATION_CONFIGURATION)) {
handleServiceConfigAnnotation(serviceNode, (BLangAnnotationAttachment) annotation);
}
}
if (HttpConstants.HTTP_SERVICE_TYPE.equals(serviceNode.getServiceTypeStruct().getTypeName().getValue())) {
List<BLangResource> resources = (List<BLangResource>) serviceNode.getResources();
resources.forEach(resource -> ResourceSignatureValidator.validate(resource.getParameters()));
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangResource in project ballerina by ballerina-lang.
the class TaintAnalyzer method visit.
public void visit(BLangResource resourceNode) {
BSymbol resourceSymbol = resourceNode.symbol;
SymbolEnv resourceEnv = SymbolEnv.createResourceActionSymbolEnv(resourceNode, resourceSymbol.scope, env);
visitEntryPoint(resourceNode, resourceEnv);
}
use of org.wso2.ballerinalang.compiler.tree.BLangResource in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
public void visit(BLangResource resourceNode) {
BSymbol resourceSymbol = resourceNode.symbol;
SymbolEnv resourceEnv = SymbolEnv.createResourceActionSymbolEnv(resourceNode, resourceSymbol.scope, env);
resourceNode.annAttachments.forEach(a -> {
a.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.RESOURCE);
this.analyzeDef(a, resourceEnv);
});
defineResourceEndpoint(resourceNode, resourceEnv);
resourceNode.docAttachments.forEach(doc -> analyzeDef(doc, resourceEnv));
resourceNode.requiredParams.forEach(p -> analyzeDef(p, resourceEnv));
resourceNode.endpoints.forEach(e -> {
symbolEnter.defineNode(e, resourceEnv);
analyzeDef(e, resourceEnv);
});
analyzeStmt(resourceNode.body, resourceEnv);
this.processWorkers(resourceNode, resourceEnv);
}
use of org.wso2.ballerinalang.compiler.tree.BLangResource in project ballerina by ballerina-lang.
the class CodeGenerator method createResourceInfoEntry.
private void createResourceInfoEntry(BLangResource resourceNode, ServiceInfo serviceInfo) {
BInvokableType resourceType = (BInvokableType) resourceNode.symbol.type;
// Add resource name as an UTFCPEntry to the constant pool
int serviceNameCPIndex = addUTF8CPEntry(currentPkgInfo, resourceNode.name.value);
ResourceInfo resourceInfo = new ResourceInfo(currentPackageRefCPIndex, serviceNameCPIndex);
resourceInfo.paramTypes = resourceType.paramTypes.toArray(new BType[0]);
setParameterNames(resourceNode, resourceInfo);
resourceInfo.retParamTypes = new BType[0];
resourceInfo.signatureCPIndex = addUTF8CPEntry(currentPkgInfo, generateFunctionSig(resourceInfo.paramTypes, resourceInfo.retParamTypes));
// Add worker info
int workerNameCPIndex = addUTF8CPEntry(currentPkgInfo, "default");
resourceInfo.defaultWorkerInfo = new WorkerInfo(workerNameCPIndex, "default");
resourceNode.workers.forEach(worker -> addWorkerInfoEntry(worker, resourceInfo));
// Add resource info to the service info
serviceInfo.resourceInfoMap.put(resourceNode.name.getValue(), resourceInfo);
}
use of org.wso2.ballerinalang.compiler.tree.BLangResource in project ballerina by ballerina-lang.
the class CodeGenerator method setParameterNames.
private void setParameterNames(BLangResource resourceNode, ResourceInfo resourceInfo) {
int paramCount = resourceNode.requiredParams.size();
resourceInfo.paramNameCPIndexes = new int[paramCount];
for (int i = 0; i < paramCount; i++) {
BLangVariable paramVar = resourceNode.requiredParams.get(i);
String paramName = null;
boolean isAnnotated = false;
for (BLangAnnotationAttachment annotationAttachment : paramVar.annAttachments) {
String attachmentName = annotationAttachment.getAnnotationName().getValue();
if ("PathParam".equalsIgnoreCase(attachmentName) || "QueryParam".equalsIgnoreCase(attachmentName)) {
// TODO:
// paramName = annotationAttachment.getAttributeNameValuePairs().get("value")
// .getLiteralValue().stringValue();
isAnnotated = true;
break;
}
}
if (!isAnnotated) {
paramName = paramVar.name.getValue();
}
int paramNameCPIndex = addUTF8CPEntry(currentPkgInfo, paramName);
resourceInfo.paramNameCPIndexes[i] = paramNameCPIndex;
}
}
Aggregations