use of org.wso2.ballerinalang.compiler.util.CompilerContext in project ballerina by ballerina-lang.
the class BallerinaTextDocumentService method compileAndSendDiagnostics.
private void compileAndSendDiagnostics(String content, LSDocument document, Path path) {
String sourceRoot = TextDocumentServiceUtil.getSourceRoot(path);
String pkgName = TextDocumentServiceUtil.getPackageNameForGivenFile(sourceRoot, path.toString());
LSDocument sourceDocument = new LSDocument();
sourceDocument.setUri(document.getURIString());
sourceDocument.setSourceRoot(sourceRoot);
PackageRepository packageRepository = new WorkspacePackageRepository(sourceRoot, documentManager);
CompilerContext context = TextDocumentServiceUtil.prepareCompilerContext(packageRepository, sourceDocument, false, documentManager);
List<org.ballerinalang.util.diagnostic.Diagnostic> balDiagnostics = new ArrayList<>();
CollectDiagnosticListener diagnosticListener = new CollectDiagnosticListener(balDiagnostics);
context.put(DiagnosticListener.class, diagnosticListener);
Compiler compiler = Compiler.getInstance(context);
if ("".equals(pkgName)) {
Path filePath = path.getFileName();
if (filePath != null) {
compiler.compile(filePath.toString());
}
} else {
compiler.compile(pkgName);
}
publishDiagnostics(balDiagnostics, path);
}
use of org.wso2.ballerinalang.compiler.util.CompilerContext in project ballerina by ballerina-lang.
the class LSPackageCache method loadPackagesMap.
private void loadPackagesMap() {
CompilerContext tempCompilerContext = CommonUtil.prepareTempCompilerContext();
for (String staticPkgName : staticPkgNames) {
PackageID packageID = new PackageID(new org.wso2.ballerinalang.compiler.util.Name("ballerina"), new org.wso2.ballerinalang.compiler.util.Name(staticPkgName), new org.wso2.ballerinalang.compiler.util.Name("0.0.0"));
this.packageMap.put(getPackageName(packageID), LSPackageLoader.getPackageById(tempCompilerContext, packageID));
}
}
use of org.wso2.ballerinalang.compiler.util.CompilerContext in project ballerina by ballerina-lang.
the class LSPackageLoader method getBuiltinPackages.
/**
* Get the Builtin Package.
* @return {@link BLangPackage} Builtin BLang package
*/
public static List<BLangPackage> getBuiltinPackages() {
List<BLangPackage> builtins = new ArrayList<>();
CompilerContext context = CommonUtil.prepareTempCompilerContext();
PackageLoader pkgLoader = PackageLoader.getInstance(context);
SemanticAnalyzer semAnalyzer = SemanticAnalyzer.getInstance(context);
CodeAnalyzer codeAnalyzer = CodeAnalyzer.getInstance(context);
BLangPackage builtInPkg = codeAnalyzer.analyze(semAnalyzer.analyze(pkgLoader.loadAndDefinePackage(Names.BUILTIN_ORG.value, Names.BUILTIN_PACKAGE.getValue())));
builtins.add(builtInPkg);
return builtins;
}
use of org.wso2.ballerinalang.compiler.util.CompilerContext in project ballerina by ballerina-lang.
the class ParserUtils method getBallerinaFile.
/**
* This method is designed to generate the Ballerina model and Diagnostic information for a given Ballerina file.
* saved in the file-system.
*
* @param programDir - Path of the program directory.
* @param compilationUnitName - compilationUnitName name.
* @return BallerinaFile - Object which contains Ballerina model and Diagnostic information
*/
public static BallerinaFile getBallerinaFile(String programDir, String compilationUnitName) {
CompilerContext context = new CompilerContext();
CompilerOptions options = CompilerOptions.getInstance(context);
options.put(PROJECT_DIR, programDir);
options.put(COMPILER_PHASE, CompilerPhase.CODE_ANALYZE.toString());
options.put(PRESERVE_WHITESPACE, Boolean.TRUE.toString());
return getBallerinaFile(Paths.get(programDir), compilationUnitName, context);
}
use of org.wso2.ballerinalang.compiler.util.CompilerContext in project ballerina by ballerina-lang.
the class ParserUtils method loadBuiltInPackage.
/**
* Loading builtin packages.
*
* @param context compiler context
* @return {BLangPackage} builtIn package
*/
private static BLangPackage loadBuiltInPackage(CompilerContext context) {
PackageLoader pkgLoader = PackageLoader.getInstance(context);
SymbolTable symbolTable = SymbolTable.getInstance(context);
SemanticAnalyzer semAnalyzer = SemanticAnalyzer.getInstance(context);
CodeAnalyzer codeAnalyzer = CodeAnalyzer.getInstance(context);
Desugar desugar = Desugar.getInstance(context);
BLangPackage builtInPkg = desugar.perform(codeAnalyzer.analyze(semAnalyzer.analyze(pkgLoader.loadAndDefinePackage(Names.BUILTIN_ORG.getValue(), Names.BUILTIN_PACKAGE.getValue()))));
symbolTable.builtInPackageSymbol = builtInPkg.symbol;
return builtInPkg;
}
Aggregations