Search in sources :

Example 11 with Node

use of org.wso2.carbon.identity.core.model.Node in project ballerina by ballerina-lang.

the class SymbolEnter method visit.

// Visitor methods
@Override
public void visit(BLangPackage pkgNode) {
    if (pkgNode.completedPhases.contains(CompilerPhase.DEFINE)) {
        return;
    }
    // Create PackageSymbol.
    BPackageSymbol pSymbol = createPackageSymbol(pkgNode);
    SymbolEnv builtinEnv = this.symTable.pkgEnvMap.get(symTable.builtInPackageSymbol);
    SymbolEnv pkgEnv = SymbolEnv.createPkgEnv(pkgNode, pSymbol.scope, builtinEnv);
    this.symTable.pkgEnvMap.put(pSymbol, pkgEnv);
    createPackageInitFunctions(pkgNode);
    // visit the package node recursively and define all package level symbols.
    // And maintain a list of created package symbols.
    pkgNode.imports.forEach(importNode -> defineNode(importNode, pkgEnv));
    // Define struct nodes.
    pkgNode.enums.forEach(enumNode -> defineNode(enumNode, pkgEnv));
    // Define struct nodes.
    pkgNode.structs.forEach(struct -> defineNode(struct, pkgEnv));
    // Define object nodes
    pkgNode.objects.forEach(object -> defineNode(object, pkgEnv));
    // Define connector nodes.
    pkgNode.connectors.forEach(con -> defineNode(con, pkgEnv));
    // Define connector params and type.
    defineConnectorParams(pkgNode.connectors, pkgEnv);
    // Define transformer nodes.
    pkgNode.transformers.forEach(tansformer -> defineNode(tansformer, pkgEnv));
    // Define service and resource nodes.
    pkgNode.services.forEach(service -> defineNode(service, pkgEnv));
    // Define struct field nodes.
    defineStructFields(pkgNode.structs, pkgEnv);
    // Define object field nodes.
    defineObjectFields(pkgNode.objects, pkgEnv);
    // Define connector action nodes.
    defineConnectorMembers(pkgNode.connectors, pkgEnv);
    // Define object functions
    defineObjectMembers(pkgNode.objects, pkgEnv);
    // Define function nodes.
    pkgNode.functions.forEach(func -> defineNode(func, pkgEnv));
    // Define transformer params
    defineTransformerMembers(pkgNode.transformers, pkgEnv);
    // Define service resource nodes.
    defineServiceMembers(pkgNode.services, pkgEnv);
    // Define annotation nodes.
    pkgNode.annotations.forEach(annot -> defineNode(annot, pkgEnv));
    resolveAnnotationAttributeTypes(pkgNode.annotations, pkgEnv);
    pkgNode.globalVars.forEach(var -> defineNode(var, pkgEnv));
    pkgNode.globalEndpoints.forEach(ep -> defineNode(ep, pkgEnv));
    definePackageInitFunctions(pkgNode, pkgEnv);
    pkgNode.completedPhases.add(CompilerPhase.DEFINE);
}
Also used : BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 12 with Node

use of org.wso2.carbon.identity.core.model.Node in project ballerina by ballerina-lang.

the class TaintAnalyzer method isEntryPoint.

// Private methods related to invokable node analysis and taint-table generation.
private boolean isEntryPoint(BLangFunction funcNode) {
    // Service resources are handled through BLangResource visitor.
    boolean isMainFunction = false;
    if (funcNode.name.value.equals(MAIN_FUNCTION_NAME) && funcNode.symbol.params.size() == 1 && funcNode.symbol.retParams.size() == 0) {
        BType paramType = funcNode.symbol.params.get(0).type;
        BArrayType arrayType = (BArrayType) paramType;
        if (paramType.tag == TypeTags.ARRAY && arrayType.eType.tag == TypeTags.STRING) {
            isMainFunction = true;
        }
    }
    return isMainFunction;
}
Also used : BArrayType(org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType)

Example 13 with Node

use of org.wso2.carbon.identity.core.model.Node in project ballerina by ballerina-lang.

the class CodeAnalyzer method analyzeNode.

private void analyzeNode(BLangNode node, SymbolEnv env) {
    SymbolEnv prevEnv = this.env;
    this.env = env;
    node.accept(this);
    this.env = prevEnv;
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 14 with Node

use of org.wso2.carbon.identity.core.model.Node in project ballerina by ballerina-lang.

the class SemanticAnalyzer method analyzeNode.

BType analyzeNode(BLangNode node, SymbolEnv env, BType expType, DiagnosticCode diagCode) {
    SymbolEnv prevEnv = this.env;
    BType preExpType = this.expType;
    DiagnosticCode preDiagCode = this.diagCode;
    // TODO Check the possibility of using a try/finally here
    this.env = env;
    this.expType = expType;
    this.diagCode = diagCode;
    node.accept(this);
    this.env = prevEnv;
    this.expType = preExpType;
    this.diagCode = preDiagCode;
    return resType;
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) DiagnosticCode(org.ballerinalang.util.diagnostic.DiagnosticCode)

Example 15 with Node

use of org.wso2.carbon.identity.core.model.Node in project ballerina by ballerina-lang.

the class CodeGenerator method createFunctionInfoEntry.

/**
 * Creates a {@code FunctionInfo} from the given function node in AST.
 *
 * @param funcNode function node in AST
 */
private void createFunctionInfoEntry(BLangFunction funcNode) {
    BInvokableSymbol funcSymbol = funcNode.symbol;
    BInvokableType funcType = (BInvokableType) funcSymbol.type;
    // Add function name as an UTFCPEntry to the constant pool
    int funcNameCPIndex = this.addUTF8CPEntry(currentPkgInfo, funcNode.name.value);
    FunctionInfo funcInfo = new FunctionInfo(currentPackageRefCPIndex, funcNameCPIndex);
    funcInfo.paramTypes = funcType.paramTypes.toArray(new BType[0]);
    funcInfo.retParamTypes = funcType.retTypes.toArray(new BType[0]);
    funcInfo.signatureCPIndex = addUTF8CPEntry(this.currentPkgInfo, generateFunctionSig(funcInfo.paramTypes, funcInfo.retParamTypes));
    funcInfo.flags = funcSymbol.flags;
    if (funcNode.receiver != null) {
        funcInfo.attachedToTypeCPIndex = getTypeCPIndex(funcNode.receiver.type).value;
    }
    this.addWorkerInfoEntries(funcInfo, funcNode.getWorkers());
    // Add parameter default value info
    addParameterDefaultValues(funcNode, funcInfo);
    this.currentPkgInfo.functionInfoMap.put(funcSymbol.name.value, funcInfo);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) AttachedFunctionInfo(org.wso2.ballerinalang.programfile.AttachedFunctionInfo) FunctionInfo(org.wso2.ballerinalang.programfile.FunctionInfo) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Aggregations

ArrayList (java.util.ArrayList)33 Operation (io.swagger.v3.oas.annotations.Operation)26 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)26 Response (javax.ws.rs.core.Response)26 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)25 Test (org.testng.annotations.Test)24 Node (org.wso2.charon3.core.utils.codeutils.Node)22 ExpressionNode (org.wso2.charon3.core.utils.codeutils.ExpressionNode)20 IOException (java.io.IOException)19 Node (org.w3c.dom.Node)19 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 List (java.util.List)16 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)16 OperationNode (org.wso2.charon3.core.utils.codeutils.OperationNode)16 Artifacts (org.wso2.ei.dashboard.core.rest.model.Artifacts)15 CAppArtifacts (org.wso2.ei.dashboard.core.rest.model.CAppArtifacts)15 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)13 Ack (org.wso2.ei.dashboard.core.rest.model.Ack)13 Map (java.util.Map)12 NodeList (org.w3c.dom.NodeList)12