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;
}
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;
}
Aggregations