use of org.wso2.carbon.registry.api.Resource in project ballerina by ballerina-lang.
the class CommandUtil method getServiceDocumentationByPosition.
/**
* Get the Documentation attachment for the service.
* @param bLangPackage BLangPackage built
* @param line Start line of the service in the source
* @return {@link String} Documentation attachment for the service
*/
static DocAttachmentInfo getServiceDocumentationByPosition(BLangPackage bLangPackage, int line) {
// TODO: Currently resource position is invalid and we use the annotation attachment positions.
for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
if (topLevelNode instanceof BLangService) {
BLangService serviceNode = (BLangService) topLevelNode;
DiagnosticPos servicePos = CommonUtil.toZeroBasedPosition(serviceNode.getPosition());
List<BLangAnnotationAttachment> annotationAttachments = serviceNode.getAnnotationAttachments();
if (!annotationAttachments.isEmpty()) {
DiagnosticPos lastAttachmentPos = CommonUtil.toZeroBasedPosition(annotationAttachments.get(annotationAttachments.size() - 1).getPosition());
if (lastAttachmentPos.getEndLine() < line && line < servicePos.getEndLine()) {
return getServiceNodeDocumentation(serviceNode, lastAttachmentPos.getEndLine() + 1);
}
} else if (servicePos.getStartLine() == line) {
return getServiceNodeDocumentation(serviceNode, line);
}
}
}
return null;
}
use of org.wso2.carbon.registry.api.Resource in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
// Visitor methods
@Override
public void visit(BLangPackage pkgNode) {
if (pkgNode.completedPhases.contains(CompilerPhase.DEFINE)) {
return;
}
// Create PackageSymbol.
BPackageSymbol pSymbol = createPackageSymbol(pkgNode);
SymbolEnv builtinEnv = this.symTable.pkgEnvMap.get(symTable.builtInPackageSymbol);
SymbolEnv pkgEnv = SymbolEnv.createPkgEnv(pkgNode, pSymbol.scope, builtinEnv);
this.symTable.pkgEnvMap.put(pSymbol, pkgEnv);
createPackageInitFunctions(pkgNode);
// visit the package node recursively and define all package level symbols.
// And maintain a list of created package symbols.
pkgNode.imports.forEach(importNode -> defineNode(importNode, pkgEnv));
// Define struct nodes.
pkgNode.enums.forEach(enumNode -> defineNode(enumNode, pkgEnv));
// Define struct nodes.
pkgNode.structs.forEach(struct -> defineNode(struct, pkgEnv));
// Define object nodes
pkgNode.objects.forEach(object -> defineNode(object, pkgEnv));
// Define connector nodes.
pkgNode.connectors.forEach(con -> defineNode(con, pkgEnv));
// Define connector params and type.
defineConnectorParams(pkgNode.connectors, pkgEnv);
// Define transformer nodes.
pkgNode.transformers.forEach(tansformer -> defineNode(tansformer, pkgEnv));
// Define service and resource nodes.
pkgNode.services.forEach(service -> defineNode(service, pkgEnv));
// Define struct field nodes.
defineStructFields(pkgNode.structs, pkgEnv);
// Define object field nodes.
defineObjectFields(pkgNode.objects, pkgEnv);
// Define connector action nodes.
defineConnectorMembers(pkgNode.connectors, pkgEnv);
// Define object functions
defineObjectMembers(pkgNode.objects, pkgEnv);
// Define function nodes.
pkgNode.functions.forEach(func -> defineNode(func, pkgEnv));
// Define transformer params
defineTransformerMembers(pkgNode.transformers, pkgEnv);
// Define service resource nodes.
defineServiceMembers(pkgNode.services, pkgEnv);
// Define annotation nodes.
pkgNode.annotations.forEach(annot -> defineNode(annot, pkgEnv));
resolveAnnotationAttributeTypes(pkgNode.annotations, pkgEnv);
pkgNode.globalVars.forEach(var -> defineNode(var, pkgEnv));
pkgNode.globalEndpoints.forEach(ep -> defineNode(ep, pkgEnv));
definePackageInitFunctions(pkgNode, pkgEnv);
pkgNode.completedPhases.add(CompilerPhase.DEFINE);
}
use of org.wso2.carbon.registry.api.Resource in project ballerina by ballerina-lang.
the class CodeGenerator method createServiceInfoEntry.
private void createServiceInfoEntry(BLangService serviceNode) {
// Add service name as an UTFCPEntry to the constant pool
int serviceNameCPIndex = addUTF8CPEntry(currentPkgInfo, serviceNode.name.value);
// Create service info
if (serviceNode.endpointType != null) {
String endPointQName = serviceNode.endpointType.tsymbol.toString();
// TODO: bvmAlias needed?
int epNameCPIndex = addUTF8CPEntry(currentPkgInfo, endPointQName);
ServiceInfo serviceInfo = new ServiceInfo(currentPackageRefCPIndex, serviceNameCPIndex, serviceNode.symbol.flags, epNameCPIndex);
// Add service level variables
int localVarAttNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE.value());
LocalVariableAttributeInfo localVarAttributeInfo = new LocalVariableAttributeInfo(localVarAttNameIndex);
serviceNode.vars.forEach(var -> visitVarSymbol(var.var.symbol, pvIndexes, localVarAttributeInfo));
serviceInfo.addAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE, localVarAttributeInfo);
// Create the init function info
BLangFunction serviceInitFunction = (BLangFunction) serviceNode.getInitFunction();
createFunctionInfoEntry(serviceInitFunction);
serviceInfo.initFuncInfo = currentPkgInfo.functionInfoMap.get(serviceInitFunction.name.toString());
currentPkgInfo.addServiceInfo(serviceNode.name.value, serviceInfo);
// Create resource info entries for all resources
serviceNode.resources.forEach(res -> createResourceInfoEntry(res, serviceInfo));
}
}
use of org.wso2.carbon.registry.api.Resource in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangResource resourceNode) {
addReturnIfNotPresent(resourceNode);
SymbolEnv resourceEnv = SymbolEnv.createResourceActionSymbolEnv(resourceNode, resourceNode.symbol.scope, env);
// To preserve endpoint code gen order at resource
Collections.reverse(resourceNode.endpoints);
resourceNode.endpoints = rewrite(resourceNode.endpoints, resourceEnv);
resourceNode.body = rewrite(resourceNode.body, resourceEnv);
resourceNode.workers = rewrite(resourceNode.workers, resourceEnv);
result = resourceNode;
}
use of org.wso2.carbon.registry.api.Resource in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangXMLNS xmlnsNode) {
BLangXMLNS generatedXMLNSNode;
xmlnsNode.namespaceURI = rewriteExpr(xmlnsNode.namespaceURI);
BSymbol ownerSymbol = xmlnsNode.symbol.owner;
// Local namespace declaration in a function/resource/action/worker
if ((ownerSymbol.tag & SymTag.INVOKABLE) == SymTag.INVOKABLE) {
generatedXMLNSNode = new BLangLocalXMLNS();
} else {
generatedXMLNSNode = new BLangPackageXMLNS();
}
generatedXMLNSNode.namespaceURI = xmlnsNode.namespaceURI;
generatedXMLNSNode.prefix = xmlnsNode.prefix;
generatedXMLNSNode.symbol = xmlnsNode.symbol;
result = generatedXMLNSNode;
}
Aggregations