use of org.ballerinalang.compiler.plugins.CompilerPlugin in project ballerina by ballerina-lang.
the class ProgramFileWriter method writeProgram.
public static void writeProgram(ProgramFile programFile, Path execFilePath) throws IOException {
BufferedOutputStream bos = new BufferedOutputStream(Files.newOutputStream(execFilePath));
writeProgram(programFile, bos);
// TODO Fix this properly. Load and invoke compiler plugins
// TODO This will get properly fixed with the new packerina
ServiceLoader<CompilerPlugin> processorServiceLoader = ServiceLoader.load(CompilerPlugin.class);
processorServiceLoader.forEach(plugin -> {
plugin.codeGenerated(execFilePath);
});
}
use of org.ballerinalang.compiler.plugins.CompilerPlugin in project ballerina by ballerina-lang.
the class CompilerPluginRunner method notifyProcessors.
private void notifyProcessors(List<BLangAnnotationAttachment> attachments, BiConsumer<CompilerPlugin, List<AnnotationAttachmentNode>> notifier) {
Map<CompilerPlugin, List<AnnotationAttachmentNode>> attachmentMap = new HashMap<>();
for (BLangAnnotationAttachment attachment : attachments) {
DefinitionID aID = new DefinitionID(attachment.annotationSymbol.pkgID.getName().value, attachment.annotationName.value);
if (!processorMap.containsKey(aID)) {
continue;
}
List<CompilerPlugin> procList = processorMap.get(aID);
procList.forEach(proc -> {
List<AnnotationAttachmentNode> attachmentNodes = attachmentMap.computeIfAbsent(proc, k -> new ArrayList<>());
attachmentNodes.add(attachment);
});
}
for (CompilerPlugin processor : attachmentMap.keySet()) {
notifier.accept(processor, Collections.unmodifiableList(attachmentMap.get(processor)));
}
}
use of org.ballerinalang.compiler.plugins.CompilerPlugin in project ballerina by ballerina-lang.
the class CompilerPluginRunner method handleEndpointProcesses.
private void handleEndpointProcesses(CompilerPlugin plugin) {
// Get the list of endpoint of that this particular compiler plugin is interested in.
SupportEndpointTypes supportEndpointTypes = plugin.getClass().getAnnotation(SupportEndpointTypes.class);
if (supportEndpointTypes == null) {
return;
}
final SupportEndpointTypes.EndpointType[] endpointTypes = supportEndpointTypes.value();
if (endpointTypes.length == 0) {
return;
}
DefinitionID[] definitions = Arrays.stream(endpointTypes).map(endpointType -> new DefinitionID(endpointType.packageName(), endpointType.name())).toArray(DefinitionID[]::new);
for (DefinitionID definitionID : definitions) {
if (isValidEndpoints(definitionID, plugin)) {
List<CompilerPlugin> processorList = endpointProcessorMap.computeIfAbsent(definitionID, k -> new ArrayList<>());
processorList.add(plugin);
}
}
}
use of org.ballerinalang.compiler.plugins.CompilerPlugin in project ballerina by ballerina-lang.
the class CompilerPluginRunner method handleAnnotationProcesses.
private void handleAnnotationProcesses(CompilerPlugin plugin) {
// Get the list of packages of annotations that this particular compiler plugin is interested in.
SupportedAnnotationPackages supportedAnnotationPackages = plugin.getClass().getAnnotation(SupportedAnnotationPackages.class);
if (supportedAnnotationPackages == null) {
return;
}
String[] annotationPkgs = supportedAnnotationPackages.value();
if (annotationPkgs.length == 0) {
return;
}
for (String annPackage : annotationPkgs) {
// Check whether each annotation type definition is available in the AST.
List<BAnnotationSymbol> annotationSymbols = getAnnotationSymbols(annPackage);
annotationSymbols.forEach(annSymbol -> {
DefinitionID definitionID = new DefinitionID(annSymbol.pkgID.name.value, annSymbol.name.value);
List<CompilerPlugin> processorList = processorMap.computeIfAbsent(definitionID, k -> new ArrayList<>());
processorList.add(plugin);
});
}
}
use of org.ballerinalang.compiler.plugins.CompilerPlugin in project ballerina by ballerina-lang.
the class BinaryFileWriter method writeExecutableBinary.
public void writeExecutableBinary(BLangPackage packageNode, String fileName) {
if (fileName == null || fileName.isEmpty()) {
throw new IllegalArgumentException("invalid target file name");
}
if (!fileName.endsWith(BLANG_EXEC_FILE_SUFFIX)) {
fileName += BLANG_EXEC_FILE_SUFFIX;
}
// Generate code for the given executable
ProgramFile programFile = this.codeGenerator.generateBALX(packageNode);
ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
try {
ProgramFileWriter.writeProgram(programFile, byteArrayOS);
} catch (IOException e) {
throw new BLangCompilerException("error writing program file '" + fileName + "'", e);
}
final Path execFilePath = this.sourceDirectory.saveCompiledProgram(new ByteArrayInputStream(byteArrayOS.toByteArray()), fileName);
ServiceLoader<CompilerPlugin> processorServiceLoader = ServiceLoader.load(CompilerPlugin.class);
processorServiceLoader.forEach(plugin -> {
plugin.codeGenerated(execFilePath);
});
}
Aggregations