Search in sources :

Example 1 with BLangEndpointTypeNode

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);
    }
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangEndpointTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangEndpointTypeNode) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 2 with BLangEndpointTypeNode

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));
        }
    });
}
Also used : BLangEndpointTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangEndpointTypeNode) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 3 with BLangEndpointTypeNode

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);
    }
}
Also used : BUnionType(org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangEndpointTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangEndpointTypeNode)

Aggregations

BLangEndpointTypeNode (org.wso2.ballerinalang.compiler.tree.types.BLangEndpointTypeNode)3 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)1 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)1 BUnionType (org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType)1 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)1 Name (org.wso2.ballerinalang.compiler.util.Name)1