use of org.wso2.ballerinalang.compiler.tree.BLangResource in project ballerina by ballerina-lang.
the class AnnotationDesugar method rewritePackageAnnotations.
protected void rewritePackageAnnotations(BLangPackage pkgNode) {
BLangFunction initFunction = pkgNode.initFunction;
// Remove last return statement. we will add it later. TODO : Fix this properly.
initFunction.body.stmts.remove(initFunction.body.stmts.size() - 1);
// This is the variable which store all package level annotations.
BLangVariable annotationMap = createGlobalAnnotationMapVar(pkgNode);
// handle Service Annotations.
for (BLangService service : pkgNode.services) {
generateAnnotations(service, service.name.value, initFunction, annotationMap);
for (BLangResource resource : service.resources) {
String key = service.name.value + DOT + resource.name.value;
generateAnnotations(resource, key, initFunction, annotationMap);
}
}
// Handle Function Annotations.
for (BLangFunction function : pkgNode.functions) {
generateAnnotations(function, function.symbol.name.value, initFunction, annotationMap);
}
// Handle Connector Annotations.
for (BLangConnector connector : pkgNode.connectors) {
generateAnnotations(connector, connector.name.value, initFunction, annotationMap);
for (BLangAction action : connector.actions) {
String key = connector.name.value + DOT + action.name.value;
generateAnnotations(connector, key, initFunction, annotationMap);
}
}
// Handle Struct Annotations.
for (BLangStruct struct : pkgNode.structs) {
generateAnnotations(struct, struct.name.value, initFunction, annotationMap);
for (BLangVariable field : struct.fields) {
String key = struct.name.value + DOT + field.name.value;
generateAnnotations(field, key, initFunction, annotationMap);
}
}
for (BLangEndpoint globalEndpoint : pkgNode.globalEndpoints) {
generateAnnotations(globalEndpoint, globalEndpoint.name.value, initFunction, annotationMap);
}
ASTBuilderUtil.createReturnStmt(pkgNode.pos, initFunction.body);
}
use of org.wso2.ballerinalang.compiler.tree.BLangResource in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addResourceAnnotation.
public void addResourceAnnotation(int annotCount) {
BLangResource resourceNode = (BLangResource) invokableNodeStack.peek();
attachAnnotations(resourceNode, annotCount);
}
use of org.wso2.ballerinalang.compiler.tree.BLangResource in project ballerina by ballerina-lang.
the class BLangPackageBuilder method endResourceDef.
public void endResourceDef(DiagnosticPos pos, Set<Whitespace> ws, String resourceName, boolean docExists, boolean isDeprecated, boolean hasParameters) {
BLangResource resourceNode = (BLangResource) invokableNodeStack.pop();
endEndpointDeclarationScope();
resourceNode.pos = pos;
resourceNode.addWS(ws);
resourceNode.setName(createIdentifier(resourceName));
if (docExists) {
attachDocumentations(resourceNode);
}
if (isDeprecated) {
attachDeprecatedNode(resourceNode);
}
if (hasParameters) {
BLangVariable firstParam = (BLangVariable) varListStack.peek().get(0);
if (firstParam.name.value.startsWith("$")) {
// This is an endpoint variable
Set<Whitespace> wsBeforeComma = removeNthFromLast(firstParam.getWS(), 0);
resourceNode.addWS(wsBeforeComma);
}
varListStack.pop().forEach(variableNode -> {
((BLangVariable) variableNode).docTag = DocTag.PARAM;
resourceNode.addParameter(variableNode);
});
}
serviceNodeStack.peek().addResource(resourceNode);
}
use of org.wso2.ballerinalang.compiler.tree.BLangResource in project ballerina by ballerina-lang.
the class TreeVisitor method visit.
public void visit(BLangResource resourceNode) {
String resourceName = resourceNode.getName().getValue();
BSymbol resourceSymbol = resourceNode.symbol;
SymbolEnv resourceEnv = SymbolEnv.createResourceActionSymbolEnv(resourceNode, resourceSymbol.scope, symbolEnv);
if (isWithinParameterContext(resourceName, NODE_TYPE_RESOURCE)) {
this.populateSymbols(this.resolveAllVisibleSymbols(resourceEnv), resourceEnv);
setTerminateVisitor(true);
} else if (!ScopeResolverConstants.getResolverByClass(cursorPositionResolver).isCursorBeforeNode(resourceNode.getPosition(), resourceNode, this, this.documentServiceContext)) {
// TODO:Handle Annotation attachments
// Visit the endpoints
resourceNode.endpoints.forEach(bLangEndpoint -> this.acceptNode(bLangEndpoint, resourceEnv));
// Cursor position is calculated against the resource parameter scope resolver
cursorPositionResolver = ResourceParamScopeResolver.class;
resourceNode.workers.forEach(w -> this.acceptNode(w, resourceEnv));
this.blockOwnerStack.push(resourceNode);
// Cursor position is calculated against the Block statement scope resolver
cursorPositionResolver = BlockStatementScopeResolver.class;
acceptNode(resourceNode.body, resourceEnv);
this.blockOwnerStack.pop();
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangResource in project ballerina by ballerina-lang.
the class ServiceScopeResolver method isWithinScopeAfterLastChildNode.
/**
* Check whether the given node is within the scope and located after the last child node.
* @param node Current Node to evaluate
* @param treeVisitor Operation Tree Visitor
* @param curLine line of the cursor
* @param curCol column of the cursor
* @return {@link Boolean} whether the last child node or not
*/
protected boolean isWithinScopeAfterLastChildNode(Node node, TreeVisitor treeVisitor, int curLine, int curCol) {
BLangService bLangService = (BLangService) treeVisitor.getBlockOwnerStack().peek();
List<BLangResource> resources = bLangService.resources;
List<BLangVariableDef> variableDefs = bLangService.vars;
int serviceEndLine = bLangService.pos.getEndLine();
int serviceEndCol = bLangService.pos.getEndColumn();
int nodeEndLine = node.getPosition().getEndLine();
int nodeEndCol = node.getPosition().getEndColumn();
boolean isLastChildNode;
if (resources.isEmpty()) {
isLastChildNode = variableDefs.indexOf(node) == (variableDefs.size() - 1);
} else {
isLastChildNode = resources.indexOf(node) == (resources.size() - 1);
}
boolean isWithinScope = (isLastChildNode && (curLine < serviceEndLine || (curLine == serviceEndLine && curCol < serviceEndCol)) && (nodeEndLine < curLine || (nodeEndLine == curLine && nodeEndCol < curCol)));
if (isWithinScope) {
treeVisitor.setPreviousNode((BLangNode) node);
}
return isWithinScope;
}
Aggregations