use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.
the class BLangMatchContextResolver method resolveItems.
@Override
public ArrayList<CompletionItem> resolveItems(TextDocumentServiceContext completionContext) {
ArrayList<CompletionItem> completionItems = new ArrayList<>();
BLangNode symbolEnvNode = completionContext.get(CompletionKeys.SYMBOL_ENV_NODE_KEY);
List<SymbolInfo> visibleSymbols = completionContext.get(CompletionKeys.VISIBLE_SYMBOLS_KEY);
if (!(symbolEnvNode instanceof BLangMatch)) {
return completionItems;
}
BLangMatch bLangMatch = (BLangMatch) symbolEnvNode;
if (bLangMatch.expr.type instanceof BUnionType) {
Set<BType> memberTypes = ((BUnionType) ((BLangSimpleVarRef) bLangMatch.expr).type).getMemberTypes();
memberTypes.forEach(bType -> {
completionItems.add(this.populateCompletionItem(bType.toString(), ItemResolverConstants.B_TYPE, bType.toString()));
});
} else if (bLangMatch.expr.type instanceof BJSONType) {
ArrayList<Integer> typeTagsList = new ArrayList<>(Arrays.asList(TypeTags.INT, TypeTags.FLOAT, TypeTags.BOOLEAN, TypeTags.STRING, TypeTags.NULL, TypeTags.JSON));
List<SymbolInfo> filteredBasicTypes = visibleSymbols.stream().filter(symbolInfo -> {
BSymbol bSymbol = symbolInfo.getScopeEntry().symbol;
return bSymbol instanceof BTypeSymbol && typeTagsList.contains(bSymbol.getType().tag);
}).collect(Collectors.toList());
this.populateCompletionItemList(filteredBasicTypes, completionItems);
} else {
if (bLangMatch.expr.type instanceof BStructType) {
List<SymbolInfo> structSymbols = visibleSymbols.stream().filter(symbolInfo -> {
BSymbol bSymbol = symbolInfo.getScopeEntry().symbol;
return bSymbol instanceof BStructSymbol && !bSymbol.getName().getValue().startsWith(UtilSymbolKeys.ANON_STRUCT_CHECKER);
}).collect(Collectors.toList());
this.populateCompletionItemList(structSymbols, completionItems);
}
}
return completionItems;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.
the class SymbolEnter method createAssignmentStmt.
private StatementNode createAssignmentStmt(BLangVariable variable, BVarSymbol varSym, BVarSymbol fieldVar) {
// Create LHS reference variable
BLangSimpleVarRef varRef = (BLangSimpleVarRef) TreeBuilder.createSimpleVariableReferenceNode();
varRef.pos = variable.pos;
varRef.variableName = (BLangIdentifier) createIdentifier(fieldVar.name.getValue());
varRef.pkgAlias = (BLangIdentifier) TreeBuilder.createIdentifierNode();
// Create RHS variable reference
BLangSimpleVarRef exprVar = (BLangSimpleVarRef) TreeBuilder.createSimpleVariableReferenceNode();
exprVar.pos = variable.pos;
exprVar.variableName = (BLangIdentifier) createIdentifier(varSym.name.getValue());
exprVar.pkgAlias = (BLangIdentifier) TreeBuilder.createIdentifierNode();
// Create assignment statement
BLangAssignment assignmentStmt = (BLangAssignment) TreeBuilder.createAssignmentNode();
assignmentStmt.expr = exprVar;
assignmentStmt.pos = variable.pos;
assignmentStmt.addVariable(varRef);
return assignmentStmt;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.
the class SymbolEnter method createAssignmentStmt.
private StatementNode createAssignmentStmt(BLangVariable variable) {
BLangSimpleVarRef varRef = (BLangSimpleVarRef) TreeBuilder.createSimpleVariableReferenceNode();
varRef.pos = variable.pos;
varRef.variableName = variable.name;
varRef.pkgAlias = (BLangIdentifier) TreeBuilder.createIdentifierNode();
BLangAssignment assignmentStmt = (BLangAssignment) TreeBuilder.createAssignmentNode();
assignmentStmt.expr = variable.expr;
assignmentStmt.pos = variable.pos;
assignmentStmt.addVariable(varRef);
return assignmentStmt;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.
the class TaintAnalyzer method visit.
public void visit(BLangSimpleVarRef varRefExpr) {
if (varRefExpr.symbol == null) {
Name varName = names.fromIdNode(varRefExpr.variableName);
if (varName != Names.IGNORE) {
if (varRefExpr.pkgSymbol.tag == SymTag.XMLNS) {
setTaintedStatusList(varRefExpr.pkgSymbol.tainted);
return;
}
}
setTaintedStatusList(false);
} else {
setTaintedStatusList(varRefExpr.symbol.tainted);
}
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.
the class TaintAnalyzer method updatedVarRefTaintedState.
private void updatedVarRefTaintedState(BLangVariableReference varRef, boolean taintedState) {
if (varRef instanceof BLangSimpleVarRef) {
setTaintedStatus(varRef, taintedState);
} else if (varRef instanceof BLangIndexBasedAccess) {
BLangIndexBasedAccess indexBasedAccessExpr = (BLangIndexBasedAccess) varRef;
updatedVarRefTaintedState(indexBasedAccessExpr.expr, taintedState);
} else if (varRef instanceof BLangFieldBasedAccess) {
BLangFieldBasedAccess fieldBasedAccessExpr = (BLangFieldBasedAccess) varRef;
updatedVarRefTaintedState(fieldBasedAccessExpr.expr, taintedState);
}
}
Aggregations