use of org.wso2.ballerinalang.compiler.semantics.model.types.BStructType.BStructField in project ballerina by ballerina-lang.
the class SymbolEnter method defineObjectFields.
private void defineObjectFields(List<? extends BLangObject> objectNodes, SymbolEnv pkgEnv) {
objectNodes.forEach(object -> {
// Create object type
SymbolEnv objectEnv = SymbolEnv.createObjectEnv(object, object.symbol.scope, pkgEnv);
BStructType objectType = (BStructType) object.symbol.type;
objectType.fields = object.fields.stream().peek(field -> defineNode(field, objectEnv)).map(field -> new BStructField(names.fromIdNode(field.name), field.symbol)).collect(Collectors.toList());
});
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BStructType.BStructField in project ballerina by ballerina-lang.
the class Types method checkEquivalencyOfTwoPrivateStructs.
private boolean checkEquivalencyOfTwoPrivateStructs(BStructType lhsType, BStructType rhsType) {
for (int fieldCounter = 0; fieldCounter < lhsType.fields.size(); fieldCounter++) {
BStructField lhsField = lhsType.fields.get(fieldCounter);
BStructField rhsField = rhsType.fields.get(fieldCounter);
if (lhsField.name.equals(rhsField.name) && isSameType(rhsField.type, lhsField.type)) {
continue;
}
return false;
}
BStructSymbol lhsStructSymbol = (BStructSymbol) lhsType.tsymbol;
List<BAttachedFunction> lhsFuncs = lhsStructSymbol.attachedFuncs;
List<BAttachedFunction> rhsFuncs = ((BStructSymbol) rhsType.tsymbol).attachedFuncs;
int lhsAttachedFuncCount = lhsStructSymbol.initializerFunc != null ? lhsFuncs.size() - 1 : lhsFuncs.size();
if (lhsAttachedFuncCount > rhsFuncs.size()) {
return false;
}
for (BAttachedFunction lhsFunc : lhsFuncs) {
if (lhsFunc == lhsStructSymbol.initializerFunc || lhsFunc == lhsStructSymbol.defaultsValuesInitFunc) {
continue;
}
BAttachedFunction rhsFunc = getMatchingInvokableType(rhsFuncs, lhsFunc);
if (rhsFunc == null) {
return false;
}
}
return true;
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BStructType.BStructField in project ballerina by ballerina-lang.
the class Types method checkEquivalencyOfPublicStructs.
private boolean checkEquivalencyOfPublicStructs(BStructType lhsType, BStructType rhsType) {
int fieldCounter = 0;
for (; fieldCounter < lhsType.fields.size(); fieldCounter++) {
BStructField lhsField = lhsType.fields.get(fieldCounter);
BStructField rhsField = rhsType.fields.get(fieldCounter);
if (Symbols.isPrivate(lhsField.symbol) || Symbols.isPrivate(rhsField.symbol)) {
return false;
}
if (lhsField.name.equals(rhsField.name) && isSameType(rhsField.type, lhsField.type)) {
continue;
}
return false;
}
// Check the rest of the fields in RHS type
for (; fieldCounter < rhsType.fields.size(); fieldCounter++) {
if (Symbols.isPrivate(rhsType.fields.get(fieldCounter).symbol)) {
return false;
}
}
BStructSymbol lhsStructSymbol = (BStructSymbol) lhsType.tsymbol;
List<BAttachedFunction> lhsFuncs = lhsStructSymbol.attachedFuncs;
List<BAttachedFunction> rhsFuncs = ((BStructSymbol) rhsType.tsymbol).attachedFuncs;
int lhsAttachedFuncCount = lhsStructSymbol.initializerFunc != null ? lhsFuncs.size() - 1 : lhsFuncs.size();
if (lhsAttachedFuncCount > rhsFuncs.size()) {
return false;
}
for (BAttachedFunction lhsFunc : lhsFuncs) {
if (lhsFunc == lhsStructSymbol.initializerFunc || lhsFunc == lhsStructSymbol.defaultsValuesInitFunc) {
continue;
}
if (Symbols.isPrivate(lhsFunc.symbol)) {
return false;
}
BAttachedFunction rhsFunc = getMatchingInvokableType(rhsFuncs, lhsFunc);
if (rhsFunc == null || Symbols.isPrivate(rhsFunc.symbol)) {
return false;
}
}
// Check for private attached function of the RHS type
for (BAttachedFunction rhsFunc : rhsFuncs) {
if (Symbols.isPrivate(rhsFunc.symbol)) {
return false;
}
}
return true;
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BStructType.BStructField in project ballerina by ballerina-lang.
the class SymbolEnter method defineStructFields.
private void defineStructFields(List<BLangStruct> structNodes, SymbolEnv pkgEnv) {
structNodes.forEach(struct -> {
// Create struct type
SymbolEnv structEnv = SymbolEnv.createPkgLevelSymbolEnv(struct, struct.symbol.scope, pkgEnv);
BStructType structType = (BStructType) struct.symbol.type;
structType.fields = struct.fields.stream().peek(field -> defineNode(field, structEnv)).map(field -> new BStructField(names.fromIdNode(field.name), field.symbol)).collect(Collectors.toList());
});
// define init function
structNodes.forEach(struct -> {
SymbolEnv structEnv = SymbolEnv.createPkgLevelSymbolEnv(struct, struct.symbol.scope, pkgEnv);
defineStructInitFunction(struct, structEnv);
});
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BStructType.BStructField in project ballerina by ballerina-lang.
the class BLangEndpointContextResolver method resolveItems.
@Override
@SuppressWarnings("unchecked")
public ArrayList<CompletionItem> resolveItems(TextDocumentServiceContext completionContext) {
BLangNode bLangEndpoint = completionContext.get(CompletionKeys.SYMBOL_ENV_NODE_KEY);
ArrayList<CompletionItem> completionItems = new ArrayList<>();
ArrayList<SymbolInfo> configurationFields = new ArrayList<>();
List<BStructSymbol.BAttachedFunction> attachedFunctions = new ArrayList<>();
if (((BLangEndpoint) bLangEndpoint).type.tsymbol instanceof BStructSymbol) {
attachedFunctions.addAll(((BStructSymbol) ((BLangEndpoint) bLangEndpoint).type.tsymbol).attachedFuncs);
}
BStructSymbol.BAttachedFunction initFunction = attachedFunctions.stream().filter(bAttachedFunction -> bAttachedFunction.funcName.getValue().equals(INIT)).findFirst().orElseGet(null);
BVarSymbol configSymbol = initFunction.symbol.getParameters().get(0);
BType configSymbolType = configSymbol.getType();
if (configSymbolType instanceof BStructType) {
((BStructType) configSymbolType).getFields().forEach(bStructField -> configurationFields.add(new SymbolInfo(bStructField.getName().getValue(), new Scope.ScopeEntry(bStructField.symbol, null))));
}
this.populateCompletionItemList(configurationFields, completionItems);
return completionItems;
}
Aggregations