use of org.wso2.ballerinalang.compiler.tree.BLangResource in project ballerina by ballerina-lang.
the class TaintAnalyzer method isEntryPoint.
// Private methods related to invokable node analysis and taint-table generation.
private boolean isEntryPoint(BLangFunction funcNode) {
// Service resources are handled through BLangResource visitor.
boolean isMainFunction = false;
if (funcNode.name.value.equals(MAIN_FUNCTION_NAME) && funcNode.symbol.params.size() == 1 && funcNode.symbol.retParams.size() == 0) {
BType paramType = funcNode.symbol.params.get(0).type;
BArrayType arrayType = (BArrayType) paramType;
if (paramType.tag == TypeTags.ARRAY && arrayType.eType.tag == TypeTags.STRING) {
isMainFunction = true;
}
}
return isMainFunction;
}
use of org.wso2.ballerinalang.compiler.tree.BLangResource in project ballerina by ballerina-lang.
the class SemanticAnalyzer method defineResourceEndpoint.
private void defineResourceEndpoint(BLangResource resourceNode, SymbolEnv resourceEnv) {
if (!resourceNode.getParameters().isEmpty()) {
final BLangVariable variable = resourceNode.getParameters().get(0);
if (variable.type == symTable.endpointType) {
String actualVarName = variable.name.value.substring(1);
variable.name = new BLangIdentifier();
variable.name.value = actualVarName;
if (resourceEnv.enclService.endpointType != null) {
variable.type = resourceEnv.enclService.endpointType;
final BEndpointVarSymbol bEndpointVarSymbol = symbolEnter.defineEndpointVarSymbol(variable.pos, EnumSet.noneOf(Flag.class), variable.type, names.fromString(actualVarName), resourceEnv);
variable.symbol = bEndpointVarSymbol;
endpointSPIAnalyzer.populateEndpointSymbol((BStructSymbol) variable.type.tsymbol, bEndpointVarSymbol);
} else {
variable.type = symTable.errType;
variable.symbol = symbolEnter.defineVarSymbol(variable.pos, EnumSet.noneOf(Flag.class), variable.type, names.fromString(actualVarName), resourceEnv);
}
// Replace old symbol with new one.
resourceNode.symbol.params.remove(0);
resourceNode.symbol.params.add(0, variable.symbol);
((BInvokableType) resourceNode.symbol.type).paramTypes.remove(0);
((BInvokableType) resourceNode.symbol.type).paramTypes.add(0, variable.type);
}
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangResource in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangResource resourceNode) {
ResourceInfo resourceInfo = currentServiceInfo.resourceInfoMap.get(resourceNode.name.getValue());
currentCallableUnitInfo = resourceInfo;
SymbolEnv resourceEnv = SymbolEnv.createResourceActionSymbolEnv(resourceNode, resourceNode.symbol.scope, this.env);
visitInvokableNode(resourceNode, currentCallableUnitInfo, resourceEnv);
}
use of org.wso2.ballerinalang.compiler.tree.BLangResource 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.ballerinalang.compiler.tree.BLangResource in project ballerina by ballerina-lang.
the class ServiceContextItemSorter method sortItems.
@Override
public void sortItems(TextDocumentServiceContext ctx, List<CompletionItem> completionItems) {
BLangNode previousNode = ctx.get(CompletionKeys.PREVIOUS_NODE_KEY);
/*
Remove the statement type completion type. When the going through the parser
rule contexts such as typeNameContext, we add the statements as well.
Sorters are responsible for to the next level of such filtering.
*/
this.removeCompletionsByType(new ArrayList<>(Collections.singletonList(ItemResolverConstants.STATEMENT_TYPE)), completionItems);
if (previousNode == null) {
this.populateWhenCursorBeforeOrAfterEp(completionItems);
} else if (previousNode instanceof BLangVariableDef) {
// BType bLangType = ((BLangVariableDef) previousNode).var.type;
// if (bLangType instanceof BEndpointType) {
// this.populateWhenCursorBeforeOrAfterEp(completionItems);
// } else {
this.setPriorities(completionItems);
CompletionItem resItem = this.getResourceSnippet();
resItem.setSortText(Priority.PRIORITY160.toString());
completionItems.add(resItem);
// }
} else if (previousNode instanceof BLangResource) {
completionItems.clear();
completionItems.add(this.getResourceSnippet());
}
}
Aggregations