use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
@Override
public void visit(BLangStruct structNode) {
BSymbol structSymbol = Symbols.createStructSymbol(Flags.asMask(structNode.flagSet), names.fromIdNode(structNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
structNode.symbol = structSymbol;
// Create struct type
structNode.symbol.type = new BStructType((BTypeSymbol) structNode.symbol);
defineSymbol(structNode.pos, structSymbol);
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
@Override
public void visit(BLangObject objectNode) {
BSymbol objectSymbol = Symbols.createObjectSymbol(Flags.asMask(objectNode.flagSet), names.fromIdNode(objectNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
objectNode.symbol = objectSymbol;
// Create struct type
objectNode.symbol.type = new BStructType((BTypeSymbol) objectNode.symbol);
defineSymbol(objectNode.pos, objectSymbol);
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
@Override
public void visit(BLangEnum enumNode) {
BTypeSymbol enumSymbol = Symbols.createEnumSymbol(Flags.asMask(enumNode.flagSet), names.fromIdNode(enumNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
enumNode.symbol = enumSymbol;
defineSymbol(enumNode.pos, enumSymbol);
BEnumType enumType = new BEnumType(enumSymbol, null);
enumSymbol.type = enumType;
SymbolEnv enumEnv = SymbolEnv.createPkgLevelSymbolEnv(enumNode, enumSymbol.scope, this.env);
for (int i = 0; i < enumNode.enumerators.size(); i++) {
BLangEnumerator enumerator = enumNode.enumerators.get(i);
BVarSymbol enumeratorSymbol = new BVarSymbol(Flags.PUBLIC, names.fromIdNode(enumerator.name), enumSymbol.pkgID, enumType, enumSymbol);
enumeratorSymbol.docTag = DocTag.FIELD;
enumerator.symbol = enumeratorSymbol;
if (symResolver.checkForUniqueSymbol(enumerator.pos, enumEnv, enumeratorSymbol, enumeratorSymbol.tag)) {
enumEnv.scope.define(enumeratorSymbol.name, enumeratorSymbol);
}
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol in project ballerina by ballerina-lang.
the class ParserRuleVariableDefinitionStatementContextResolver method resolveItems.
@Override
@SuppressWarnings("unchecked")
public ArrayList<CompletionItem> resolveItems(TextDocumentServiceContext completionContext) {
ArrayList<CompletionItem> completionItems = new ArrayList<>();
PackageActionFunctionAndTypesFilter actionFunctionTypeFilter = new PackageActionFunctionAndTypesFilter();
ConnectorInitExpressionItemFilter connectorInitItemFilter = new ConnectorInitExpressionItemFilter();
// action invocation or worker invocation
if (isInvocationOrFieldAccess(completionContext)) {
ArrayList<SymbolInfo> actionAndFunctions = new ArrayList<>();
actionAndFunctions.addAll(actionFunctionTypeFilter.filterItems(completionContext));
this.populateCompletionItemList(actionAndFunctions, completionItems);
} else {
// Fill completions if user is writing a connector init
List<SymbolInfo> filteredConnectorInitSuggestions = connectorInitItemFilter.filterItems(completionContext);
if (!filteredConnectorInitSuggestions.isEmpty()) {
populateCompletionItemList(filteredConnectorInitSuggestions, completionItems);
}
// Add the create keyword
CompletionItem createKeyword = new CompletionItem();
createKeyword.setInsertText(Snippet.CREATE_KEYWORD_SNIPPET.toString());
createKeyword.setLabel(ItemResolverConstants.CREATE_KEYWORD);
createKeyword.setDetail(ItemResolverConstants.KEYWORD_TYPE);
List<SymbolInfo> filteredList = completionContext.get(CompletionKeys.VISIBLE_SYMBOLS_KEY).stream().filter(symbolInfo -> {
BSymbol bSymbol = symbolInfo.getScopeEntry().symbol;
SymbolKind symbolKind = bSymbol.kind;
// Here we return false if the BType is not either a package symbol or ENUM
return !((bSymbol instanceof BTypeSymbol) && !(bSymbol instanceof BPackageSymbol || SymbolKind.ENUM.equals(symbolKind)));
}).collect(Collectors.toList());
// Remove the functions without a receiver symbol
filteredList.removeIf(symbolInfo -> {
BSymbol bSymbol = symbolInfo.getScopeEntry().symbol;
return bSymbol instanceof BInvokableSymbol && ((BInvokableSymbol) bSymbol).receiverSymbol != null;
});
populateCompletionItemList(filteredList, completionItems);
completionItems.add(createKeyword);
}
Class sorterKey = completionContext.get(DocumentServiceKeys.PARSER_RULE_CONTEXT_KEY).getClass();
CompletionItemSorter itemSorter = ItemSorters.getSorterByClass(sorterKey);
itemSorter.sortItems(completionContext, completionItems);
return completionItems;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol in project ballerina by ballerina-lang.
the class PackageActionFunctionAndTypesFilter method getActionsFunctionsAndTypes.
/**
* Get the actions, functions and types.
* @param completionContext Text Document Service context (Completion Context)
* @param delimiterIndex delimiter index (index of either . or :)
* @return {@link ArrayList} List of filtered symbol info
*/
private ArrayList<SymbolInfo> getActionsFunctionsAndTypes(TextDocumentServiceContext completionContext, int delimiterIndex) {
ArrayList<SymbolInfo> actionFunctionList = new ArrayList<>();
TokenStream tokenStream = completionContext.get(DocumentServiceKeys.TOKEN_STREAM_KEY);
List<SymbolInfo> symbols = completionContext.get(CompletionKeys.VISIBLE_SYMBOLS_KEY);
String packageName = tokenStream.get(delimiterIndex - 1).getText();
// Extract the package symbol
SymbolInfo packageSymbolInfo = symbols.stream().filter(item -> {
Scope.ScopeEntry scopeEntry = item.getScopeEntry();
return item.getSymbolName().equals(packageName) && scopeEntry.symbol instanceof BPackageSymbol;
}).findFirst().orElse(null);
if (packageSymbolInfo != null) {
Scope.ScopeEntry packageEntry = packageSymbolInfo.getScopeEntry();
SymbolInfo symbolInfo = new SymbolInfo(packageSymbolInfo.getSymbolName(), packageEntry);
symbolInfo.getScopeEntry().symbol.scope.entries.forEach((name, value) -> {
if ((value.symbol instanceof BInvokableSymbol && ((BInvokableSymbol) value.symbol).receiverSymbol == null) || (value.symbol instanceof BTypeSymbol && !(value.symbol instanceof BPackageSymbol))) {
actionFunctionList.add(new SymbolInfo(name.toString(), value));
}
});
}
return actionFunctionList;
}
Aggregations