Search in sources :

Example 81 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project ballerina by ballerina-lang.

the class CommandUtil method getServiceDocumentationByPosition.

/**
 * Get the Documentation attachment for the service.
 * @param bLangPackage      BLangPackage built
 * @param line              Start line of the service in the source
 * @return {@link String}   Documentation attachment for the service
 */
static DocAttachmentInfo getServiceDocumentationByPosition(BLangPackage bLangPackage, int line) {
    // TODO: Currently resource position is invalid and we use the annotation attachment positions.
    for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
        if (topLevelNode instanceof BLangService) {
            BLangService serviceNode = (BLangService) topLevelNode;
            DiagnosticPos servicePos = CommonUtil.toZeroBasedPosition(serviceNode.getPosition());
            List<BLangAnnotationAttachment> annotationAttachments = serviceNode.getAnnotationAttachments();
            if (!annotationAttachments.isEmpty()) {
                DiagnosticPos lastAttachmentPos = CommonUtil.toZeroBasedPosition(annotationAttachments.get(annotationAttachments.size() - 1).getPosition());
                if (lastAttachmentPos.getEndLine() < line && line < servicePos.getEndLine()) {
                    return getServiceNodeDocumentation(serviceNode, lastAttachmentPos.getEndLine() + 1);
                }
            } else if (servicePos.getStartLine() == line) {
                return getServiceNodeDocumentation(serviceNode, line);
            }
        }
    }
    return null;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) TopLevelNode(org.ballerinalang.model.tree.TopLevelNode)

Example 82 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project ballerina by ballerina-lang.

the class ParserUtils method getAllPackages.

/**
 * Get All Native Packages.
 *
 * @return {@link Map} Package name, package functions and connectors
 */
public static Map<String, ModelPackage> getAllPackages() {
    final Map<String, ModelPackage> modelPackage = new HashMap<>();
    // TODO: remove once the packerina api for package listing is available
    final String[] packageNames = { "net.http", "net.http.authadaptor", "net.http.endpoints", "net.http.mock", "net.http.swagger", "net.uri", "mime", "net.websub", "net.websub.hub", "net.grpc", "auth", "auth.authz", "auth.authz.permissionstore", "auth.basic", "auth.jwtAuth", "auth.userstore", "auth.utils", "caching", "collections", "config", "data.sql", "file", "internal", "io", "jwt", "jwt.signature", "log", "math", "os", "reflect", "runtime", "security.crypto", "task", "time", "transactions.coordinator", "user", "util" };
    try {
        List<BLangPackage> builtInPackages = LSPackageLoader.getBuiltinPackages();
        for (BLangPackage bLangPackage : builtInPackages) {
            loadPackageMap(bLangPackage.packageID.getName().getValue(), bLangPackage, modelPackage);
        }
        CompilerContext context = CommonUtil.prepareTempCompilerContext();
        for (String packageName : packageNames) {
            PackageID packageID = new PackageID(new Name("ballerina"), new Name(packageName), new Name("0.0.0"));
            BLangPackage bLangPackage = LSPackageLoader.getPackageById(context, packageID);
            loadPackageMap(bLangPackage.packageID.getName().getValue(), bLangPackage, modelPackage);
        }
    } catch (Exception e) {
        // Above catch is to fail safe composer front end due to core errors.
        logger.warn("Error while loading packages");
    }
    return modelPackage;
}
Also used : BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) HashMap(java.util.HashMap) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) ModelPackage(org.ballerinalang.composer.service.ballerina.parser.service.model.lang.ModelPackage) PackageID(org.ballerinalang.model.elements.PackageID) IOException(java.io.IOException) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 83 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project ballerina by ballerina-lang.

the class ParserUtils method getBuiltinTypes.

/**
 * Get the builtin types.
 *
 * @return {@link List} list of builtin types
 */
public static List<SymbolInformation> getBuiltinTypes() {
    CompilerContext context = prepareCompilerContext("", "");
    SymbolTable symbolTable = SymbolTable.getInstance(context);
    List<SymbolInformation> symbolInformationList = new ArrayList<>();
    // TODO: Need to fill the default values
    symbolTable.rootScope.entries.forEach((key, value) -> {
        if (value.symbol instanceof BTypeSymbol) {
            SymbolInformation symbolInfo = new SymbolInformation();
            String symbolName = value.symbol.getName().getValue();
            if (!symbolName.equals(BuiltInType.INVALID_TYPE)) {
                symbolInfo.setName(symbolName);
                setDefaultValuesForType(symbolName, symbolInfo);
                symbolInformationList.add(symbolInfo);
            }
        }
    });
    return symbolInformationList;
}
Also used : CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) ArrayList(java.util.ArrayList) SymbolTable(org.wso2.ballerinalang.compiler.semantics.model.SymbolTable) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) SymbolInformation(org.ballerinalang.composer.service.ballerina.parser.service.model.SymbolInformation)

Example 84 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project ballerina by ballerina-lang.

the class LSPackageCache method findPackage.

/**
 * Find the package by Package ID.
 * @param compilerContext       compiler context
 * @param pkgId                 Package Id to lookup
 * @return {@link BLangPackage} BLang Package resolved
 */
public BLangPackage findPackage(CompilerContext compilerContext, PackageID pkgId) {
    if (containsPackage(pkgId.getName().getValue())) {
        return packageMap.get(pkgId.getName().getValue());
    } else {
        BLangPackage bLangPackage = LSPackageLoader.getPackageById(compilerContext, pkgId);
        addPackage(bLangPackage);
        return bLangPackage;
    }
}
Also used : BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage)

Example 85 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project ballerina by ballerina-lang.

the class BCompileUtil method getDiagnostics.

/**
 * Used by IntelliJ IDEA plugin to provide semantic analyzing capability.
 *
 * @param classLoader a {@link ClassLoader} to be set as thread context class loader. This is used by {@link
 *                    java.util.ServiceLoader}. Otherwise semantic analyzing capability providing wont work since it
 *                    cant find core package.
 * @param sourceRoot  source root of a project
 * @param fileName    either the file name (if in project root) or the package name
 * @return list of diagnostics
 */
public static List<Diagnostic> getDiagnostics(ClassLoader classLoader, String sourceRoot, String fileName) {
    Thread.currentThread().setContextClassLoader(classLoader);
    CompilerContext context = new CompilerContext();
    CompilerOptions options = CompilerOptions.getInstance(context);
    options.put(PROJECT_DIR, sourceRoot);
    options.put(COMPILER_PHASE, CompilerPhase.CODE_GEN.toString());
    options.put(PRESERVE_WHITESPACE, "false");
    CompileResult comResult = new CompileResult();
    // catch errors
    DiagnosticListener listener = comResult::addDiagnostic;
    context.put(DiagnosticListener.class, listener);
    // compile
    Compiler compiler = Compiler.getInstance(context);
    BLangPackage entryPackageNode = compiler.compile(fileName);
    CompiledBinaryFile.ProgramFile programFile = compiler.getExecutableProgram(entryPackageNode);
    if (programFile != null) {
        comResult.setProgFile(LauncherUtils.getExecutableProgram(programFile));
    }
    Diagnostic[] diagnostics = comResult.getDiagnostics();
    return Arrays.stream(diagnostics).collect(Collectors.toList());
}
Also used : Compiler(org.wso2.ballerinalang.compiler.Compiler) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) CompiledBinaryFile(org.wso2.ballerinalang.programfile.CompiledBinaryFile) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) CompilerOptions(org.wso2.ballerinalang.compiler.util.CompilerOptions) Diagnostic(org.ballerinalang.util.diagnostic.Diagnostic) DiagnosticListener(org.ballerinalang.util.diagnostic.DiagnosticListener)

Aggregations

PreparedStatement (java.sql.PreparedStatement)47 ArrayList (java.util.ArrayList)47 Connection (java.sql.Connection)43 SQLException (java.sql.SQLException)41 ResultSet (java.sql.ResultSet)37 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)26 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)18 HashSet (java.util.HashSet)16 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)15 IOException (java.io.IOException)14 HashMap (java.util.HashMap)14 List (java.util.List)13 Map (java.util.Map)13 Expression (org.wso2.siddhi.query.api.expression.Expression)13 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)12 TimeConstant (org.wso2.siddhi.query.api.expression.constant.TimeConstant)12 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)11 API (org.wso2.carbon.apimgt.core.models.API)11 UserStoreException (org.wso2.carbon.user.api.UserStoreException)10 SiddhiQLParser (org.wso2.siddhi.query.compiler.SiddhiQLParser)10