use of org.wso2.ballerinalang.compiler.tree.types.BLangEndpointTypeNode in project ballerina by ballerina-lang.
the class TreeVisitor method visit.
@Override
public void visit(BLangVariable varNode) {
boolean isCursorBeforeNode = ScopeResolverConstants.getResolverByClass(cursorPositionResolver).isCursorBeforeNode(varNode.getPosition(), varNode, this, this.documentServiceContext);
// This is an endpoint definition
if (!isCursorBeforeNode && varNode.typeNode instanceof BLangEndpointTypeNode && this.isCursorWithinEndpointDef(varNode.getPosition())) {
SymbolEnv endpointVarInitEnv = SymbolEnv.createVarInitEnv(varNode, symbolEnv, varNode.symbol);
Map<Name, Scope.ScopeEntry> visibleSymbols = this.resolveAllVisibleSymbols(symbolEnv);
this.populateSymbols(visibleSymbols, endpointVarInitEnv);
this.setTerminateVisitor(true);
}
}
use of org.wso2.ballerinalang.compiler.tree.types.BLangEndpointTypeNode in project ballerina by ballerina-lang.
the class EndpointDefContextItemSorter method sortItems.
/**
* Sort Completion Items based on a particular criteria.
*
* @param ctx Completion context
* @param completionItems List of initial completion items
*/
@Override
public void sortItems(TextDocumentServiceContext ctx, List<CompletionItem> completionItems) {
this.setPriorities(completionItems);
BLangVariable bLangVariable = (BLangVariable) ctx.get(CompletionKeys.SYMBOL_ENV_NODE_KEY);
if (!(bLangVariable.typeNode instanceof BLangEndpointTypeNode)) {
return;
}
String constraintType = ((BLangEndpointTypeNode) bLangVariable.typeNode).endpointType.type.toString();
completionItems.forEach(completionItem -> {
if (completionItem.getDetail().equals(ItemResolverConstants.FUNCTION_TYPE)) {
String label = completionItem.getLabel();
String[] returnTypes = label.substring(label.lastIndexOf("(") + 1, label.lastIndexOf(")")).split(",");
if (returnTypes.length == 1 && returnTypes[0].equals(constraintType)) {
String newPriority = Priority.shiftPriority(completionItem.getSortText(), -1);
completionItem.setSortText(String.valueOf(newPriority));
}
} else if (completionItem.getDetail().equals(ItemResolverConstants.KEYWORD_TYPE)) {
completionItem.setSortText(Priority.shiftPriority(Priority.PRIORITY110.toString(), -1));
} else if (completionItem.getDetail().equals(constraintType)) {
completionItem.setSortText(Priority.shiftPriority(completionItem.getSortText(), -1));
}
});
}
use of org.wso2.ballerinalang.compiler.tree.types.BLangEndpointTypeNode in project ballerina by ballerina-lang.
the class PositionTreeVisitor method visit.
@Override
public void visit(BLangUserDefinedType userDefinedType) {
userDefinedType.getPosition().sCol += (previousNode instanceof BLangEndpointTypeNode ? "endpoint<".length() : 0);
CommonUtil.calculateEndColumnOfGivenName(userDefinedType.getPosition(), userDefinedType.typeName.value, userDefinedType.pkgAlias.value);
if (userDefinedType.type instanceof BUnionType && HoverUtil.isMatchingPosition(userDefinedType.getPosition(), this.position)) {
try {
BUnionType bUnionType = (BUnionType) userDefinedType.type;
for (BType type : bUnionType.memberTypes) {
if (type.tsymbol != null && type.tsymbol.getName().getValue().equals(userDefinedType.typeName.getValue())) {
this.context.put(NodeContextKeys.NODE_KEY, userDefinedType);
this.context.put(NodeContextKeys.PREVIOUSLY_VISITED_NODE_KEY, this.previousNode);
this.context.put(NodeContextKeys.NAME_OF_NODE_KEY, userDefinedType.typeName.getValue());
this.context.put(NodeContextKeys.PACKAGE_OF_NODE_KEY, type.tsymbol.pkgID);
this.context.put(NodeContextKeys.SYMBOL_KIND_OF_NODE_PARENT_KEY, type.tsymbol.kind.name());
this.context.put(NodeContextKeys.SYMBOL_KIND_OF_NODE_KEY, type.tsymbol.kind.name());
this.context.put(NodeContextKeys.NODE_OWNER_KEY, type.tsymbol.owner.name.getValue());
this.context.put(NodeContextKeys.NODE_OWNER_PACKAGE_KEY, type.tsymbol.owner.pkgID);
this.context.put(NodeContextKeys.VAR_NAME_OF_NODE_KEY, userDefinedType.typeName.getValue());
setTerminateVisitor(true);
break;
}
}
} catch (ClassCastException e) {
// Ignores
}
} else if (userDefinedType.type.tsymbol != null && HoverUtil.isMatchingPosition(userDefinedType.getPosition(), this.position)) {
this.context.put(NodeContextKeys.NODE_KEY, userDefinedType);
this.context.put(NodeContextKeys.PREVIOUSLY_VISITED_NODE_KEY, this.previousNode);
this.context.put(NodeContextKeys.NAME_OF_NODE_KEY, userDefinedType.typeName.getValue());
this.context.put(NodeContextKeys.PACKAGE_OF_NODE_KEY, userDefinedType.type.tsymbol.pkgID);
this.context.put(NodeContextKeys.SYMBOL_KIND_OF_NODE_PARENT_KEY, userDefinedType.type.tsymbol.kind.name());
this.context.put(NodeContextKeys.SYMBOL_KIND_OF_NODE_KEY, userDefinedType.type.tsymbol.kind.name());
this.context.put(NodeContextKeys.NODE_OWNER_KEY, userDefinedType.type.tsymbol.owner.name.getValue());
this.context.put(NodeContextKeys.NODE_OWNER_PACKAGE_KEY, userDefinedType.type.tsymbol.owner.pkgID);
this.context.put(NodeContextKeys.VAR_NAME_OF_NODE_KEY, userDefinedType.typeName.getValue());
setTerminateVisitor(true);
}
}
Aggregations