Search in sources :

Example 1 with BDiagnostic

use of org.wso2.ballerinalang.compiler.util.diagnotic.BDiagnostic in project ballerina by ballerina-lang.

the class WorkspaceUtils method getBallerinaPackage.

private static BLangPackage getBallerinaPackage(String fileName, CompilerContext context) {
    Compiler compiler = Compiler.getInstance(context);
    BLangPackage balPkg = null;
    try {
        balPkg = compiler.compile(fileName);
    } catch (Exception ex) {
        BDiagnostic catastrophic = new BDiagnostic();
        catastrophic.msg = "Failed in the runtime parse/analyze. " + ex.getMessage();
    }
    return balPkg;
}
Also used : Compiler(org.wso2.ballerinalang.compiler.Compiler) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BDiagnostic(org.wso2.ballerinalang.compiler.util.diagnotic.BDiagnostic)

Example 2 with BDiagnostic

use of org.wso2.ballerinalang.compiler.util.diagnotic.BDiagnostic in project ballerina by ballerina-lang.

the class ParserUtils method getBallerinaFile.

/**
 * Returns an object which contains Ballerina model and Diagnostic information.
 *
 * @param fileName - File name
 * @param context  - CompilerContext
 * @return BallerinaFile - Object which contains Ballerina model and Diagnostic information
 */
private static BallerinaFile getBallerinaFile(Path packagePath, String fileName, CompilerContext context) {
    List<Diagnostic> diagnostics = new ArrayList<>();
    ComposerDiagnosticListener composerDiagnosticListener = new ComposerDiagnosticListener(diagnostics);
    context.put(DiagnosticListener.class, composerDiagnosticListener);
    BallerinaFile ballerinaFile = new BallerinaFile();
    CompilerOptions options = CompilerOptions.getInstance(context);
    options.put(PROJECT_DIR, packagePath.toString());
    options.put(COMPILER_PHASE, CompilerPhase.DEFINE.toString());
    options.put(PRESERVE_WHITESPACE, "true");
    context.put(SourceDirectory.class, new FileSystemProjectDirectory(packagePath));
    Compiler compiler = Compiler.getInstance(context);
    // compile
    try {
        ballerinaFile.setBLangPackage(compiler.compile(fileName));
    } catch (Exception ex) {
        BDiagnostic catastrophic = new BDiagnostic();
        catastrophic.msg = "Failed in the runtime parse/analyze. " + ex.getMessage();
        diagnostics.add(catastrophic);
    }
    ballerinaFile.setDiagnostics(diagnostics);
    return ballerinaFile;
}
Also used : Compiler(org.wso2.ballerinalang.compiler.Compiler) FileSystemProjectDirectory(org.wso2.ballerinalang.compiler.FileSystemProjectDirectory) BallerinaFile(org.ballerinalang.composer.service.ballerina.parser.service.model.BallerinaFile) ArrayList(java.util.ArrayList) CompilerOptions(org.wso2.ballerinalang.compiler.util.CompilerOptions) Diagnostic(org.ballerinalang.util.diagnostic.Diagnostic) BDiagnostic(org.wso2.ballerinalang.compiler.util.diagnotic.BDiagnostic) BDiagnostic(org.wso2.ballerinalang.compiler.util.diagnotic.BDiagnostic) IOException(java.io.IOException)

Aggregations

Compiler (org.wso2.ballerinalang.compiler.Compiler)2 BDiagnostic (org.wso2.ballerinalang.compiler.util.diagnotic.BDiagnostic)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 BallerinaFile (org.ballerinalang.composer.service.ballerina.parser.service.model.BallerinaFile)1 Diagnostic (org.ballerinalang.util.diagnostic.Diagnostic)1 FileSystemProjectDirectory (org.wso2.ballerinalang.compiler.FileSystemProjectDirectory)1 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)1 CompilerOptions (org.wso2.ballerinalang.compiler.util.CompilerOptions)1