Search in sources :

Example 1 with BLangTransformer

use of org.wso2.ballerinalang.compiler.tree.BLangTransformer in project ballerina by ballerina-lang.

the class CommandExecutor method getDocumentEditForNode.

/**
 * Get the document edit attachment info for a given particular node.
 * @param node      Node given
 * @return          Doc Attachment Info
 */
private static CommandUtil.DocAttachmentInfo getDocumentEditForNode(Node node) {
    CommandUtil.DocAttachmentInfo docAttachmentInfo = null;
    int replaceFrom;
    switch(node.getKind()) {
        case FUNCTION:
            if (((BLangFunction) node).docAttachments.isEmpty()) {
                replaceFrom = CommonUtil.toZeroBasedPosition(((BLangFunction) node).getPosition()).getStartLine();
                docAttachmentInfo = CommandUtil.getFunctionNodeDocumentation((BLangFunction) node, replaceFrom);
            }
            break;
        case STRUCT:
            if (((BLangStruct) node).docAttachments.isEmpty()) {
                replaceFrom = CommonUtil.toZeroBasedPosition(((BLangStruct) node).getPosition()).getStartLine();
                docAttachmentInfo = CommandUtil.getStructNodeDocumentation((BLangStruct) node, replaceFrom);
            }
            break;
        case ENUM:
            if (((BLangEnum) node).docAttachments.isEmpty()) {
                replaceFrom = CommonUtil.toZeroBasedPosition(((BLangEnum) node).getPosition()).getStartLine();
                docAttachmentInfo = CommandUtil.getEnumNodeDocumentation((BLangEnum) node, replaceFrom);
            }
            break;
        case TRANSFORMER:
            if (((BLangTransformer) node).docAttachments.isEmpty()) {
                replaceFrom = CommonUtil.toZeroBasedPosition(((BLangTransformer) node).getPosition()).getStartLine();
                docAttachmentInfo = CommandUtil.getTransformerNodeDocumentation((BLangTransformer) node, replaceFrom);
            }
            break;
        case RESOURCE:
            if (((BLangResource) node).docAttachments.isEmpty()) {
                BLangResource bLangResource = (BLangResource) node;
                replaceFrom = getReplaceFromForServiceOrResource(bLangResource, bLangResource.getAnnotationAttachments());
                docAttachmentInfo = CommandUtil.getResourceNodeDocumentation(bLangResource, replaceFrom);
            }
            break;
        case SERVICE:
            if (((BLangService) node).docAttachments.isEmpty()) {
                BLangService bLangService = (BLangService) node;
                replaceFrom = getReplaceFromForServiceOrResource(bLangService, bLangService.getAnnotationAttachments());
                docAttachmentInfo = CommandUtil.getServiceNodeDocumentation(bLangService, replaceFrom);
            }
            break;
        default:
            break;
    }
    return docAttachmentInfo;
}
Also used : BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum)

Example 2 with BLangTransformer

use of org.wso2.ballerinalang.compiler.tree.BLangTransformer in project ballerina by ballerina-lang.

the class SymbolEnter method visit.

@Override
public void visit(BLangTransformer transformerNode) {
    validateTransformerMappingTypes(transformerNode);
    boolean safeConversion = transformerNode.retParams.size() == 1;
    Name name = getTransformerSymbolName(transformerNode);
    BTransformerSymbol transformerSymbol = Symbols.createTransformerSymbol(Flags.asMask(transformerNode.flagSet), name, env.enclPkg.symbol.pkgID, null, safeConversion, env.scope.owner);
    transformerNode.symbol = transformerSymbol;
    // If this is a default transformer, check whether this transformer conflicts with a built-in conversion
    if (transformerNode.name.value.isEmpty()) {
        BType targetType = transformerNode.retParams.get(0).type;
        BSymbol symbol = symResolver.resolveConversionOperator(transformerNode.source.type, targetType);
        if (symbol != symTable.notFoundSymbol) {
            dlog.error(transformerNode.pos, DiagnosticCode.TRANSFORMER_CONFLICTS_WITH_CONVERSION, transformerNode.source.type, targetType);
            return;
        }
    }
    // Define the transformer
    SymbolEnv transformerEnv = SymbolEnv.createTransformerEnv(transformerNode, transformerSymbol.scope, env);
    transformerNode.symbol = transformerSymbol;
    defineSymbol(transformerNode.pos, transformerSymbol);
    transformerEnv.scope = transformerSymbol.scope;
    // Define transformer source.
    defineNode(transformerNode.source, transformerEnv);
}
Also used : BTransformerSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTransformerSymbol) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 3 with BLangTransformer

use of org.wso2.ballerinalang.compiler.tree.BLangTransformer in project ballerina by ballerina-lang.

the class TaintAnalyzer method visit.

public void visit(BLangTransformer transformerNode) {
    SymbolEnv transformerEnv = SymbolEnv.createTransformerEnv(transformerNode, transformerNode.symbol.scope, env);
    visitInvokable(transformerNode, transformerEnv);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 4 with BLangTransformer

use of org.wso2.ballerinalang.compiler.tree.BLangTransformer in project ballerina by ballerina-lang.

the class SemanticAnalyzer method visit.

@Override
public void visit(BLangTransformer transformerNode) {
    SymbolEnv transformerEnv = SymbolEnv.createTransformerEnv(transformerNode, transformerNode.symbol.scope, env);
    transformerNode.annAttachments.forEach(annotationAttachment -> {
        annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.TRANSFORMER);
        this.analyzeDef(annotationAttachment, transformerEnv);
    });
    transformerNode.docAttachments.forEach(doc -> analyzeDef(doc, transformerEnv));
    validateTransformerMappingType(transformerNode.source);
    validateTransformerMappingType(transformerNode.retParams.get(0));
    analyzeStmt(transformerNode.body, transformerEnv);
    // TODO: update this accordingly once the unsafe conversion are supported
    int returnCount = transformerNode.retParams.size();
    if (returnCount == 0) {
        dlog.error(transformerNode.pos, DiagnosticCode.TRANSFORMER_MUST_HAVE_OUTPUT);
    } else if (returnCount > 1) {
        dlog.error(transformerNode.pos, DiagnosticCode.TOO_MANY_OUTPUTS_FOR_TRANSFORMER, 1, returnCount);
    }
    this.processWorkers(transformerNode, transformerEnv);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 5 with BLangTransformer

use of org.wso2.ballerinalang.compiler.tree.BLangTransformer in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

public void visit(BLangTransformer transformerNode) {
    SymbolEnv transformerEnv = SymbolEnv.createTransformerEnv(transformerNode, transformerNode.symbol.scope, this.env);
    currentCallableUnitInfo = currentPkgInfo.transformerInfoMap.get(transformerNode.symbol.name.value);
    visitInvokableNode(transformerNode, currentCallableUnitInfo, transformerEnv);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Aggregations

SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)7 BLangTransformer (org.wso2.ballerinalang.compiler.tree.BLangTransformer)6 ArrayList (java.util.ArrayList)4 BLangDocumentation (org.wso2.ballerinalang.compiler.tree.BLangDocumentation)4 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)4 CompileResult (org.ballerinalang.launcher.util.CompileResult)3 PackageNode (org.ballerinalang.model.tree.PackageNode)3 Test (org.testng.annotations.Test)3 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)3 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)2 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)2 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2 BLangEnum (org.wso2.ballerinalang.compiler.tree.BLangEnum)2 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)2 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)2 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 DocumentServiceKeys (org.ballerinalang.langserver.DocumentServiceKeys)1