use of org.wso2.siddhi.core.stream.input.source.Source in project ballerina by ballerina-lang.
the class WorkspaceUtils method prepareCompilerContext.
private static CompilerContext prepareCompilerContext(String fileName, String source) {
CompilerContext context = new CompilerContext();
List<Name> names = new ArrayList<>();
names.add(new Name("."));
// Registering custom PackageRepository to provide ballerina content without a file in file-system
context.put(PackageRepository.class, new InMemoryPackageRepository(new PackageID(Names.ANON_ORG, names, new Name("0.0.0")), "", fileName, source.getBytes(StandardCharsets.UTF_8)));
return context;
}
use of org.wso2.siddhi.core.stream.input.source.Source in project ballerina by ballerina-lang.
the class CommandUtil method getStructDocumentationByPosition.
/**
* Get the Documentation attachment for the struct definition.
* @param bLangPackage BLangPackage built
* @param line Start line of the struct in the source
* @return {@link String} Documentation attachment for the struct
*/
static DocAttachmentInfo getStructDocumentationByPosition(BLangPackage bLangPackage, int line) {
for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
if (topLevelNode instanceof BLangStruct) {
BLangStruct structNode = (BLangStruct) topLevelNode;
DiagnosticPos structPos = CommonUtil.toZeroBasedPosition(structNode.getPosition());
int structStart = structPos.getStartLine();
if (structStart == line) {
return getStructNodeDocumentation(structNode, line);
}
}
}
return null;
}
use of org.wso2.siddhi.core.stream.input.source.Source 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;
}
use of org.wso2.siddhi.core.stream.input.source.Source in project ballerina by ballerina-lang.
the class ParserUtils method getBallerinaFileForContent.
/**
* This method is designed to generate the Ballerina model and Diagnostic information for a given Ballerina content.
* Ideal use case is generating Ballerina model and Diagnostic information for unsaved Ballerina files.
*
* @param fileName - File name. This can be any arbitrary name as as we haven't save the file yet.
* @param source - Ballerina source content that needs to be parsed.
* @param compilerPhase - This will tell up to which point(compiler phase) we should process the model
* @return BallerinaFile - Object which contains Ballerina model and Diagnostic information
*/
public static BallerinaFile getBallerinaFileForContent(Path filePath, String fileName, String source, CompilerPhase compilerPhase) {
CompilerContext context = prepareCompilerContext(fileName, source);
CompilerOptions options = CompilerOptions.getInstance(context);
options.put(COMPILER_PHASE, compilerPhase.toString());
options.put(PRESERVE_WHITESPACE, Boolean.TRUE.toString());
return getBallerinaFile(filePath, fileName, context);
}
use of org.wso2.siddhi.core.stream.input.source.Source in project ballerina by ballerina-lang.
the class ParserUtils method prepareCompilerContext.
/**
* Returns a CompilerContext for the provided fileName and Ballerina source content.
*
* @param fileName - File name. This can be any arbitrary name as as we haven't save the file yet.
* @param source - Ballerina source content that needs to be parsed.
* @return CompilerContext
*/
private static CompilerContext prepareCompilerContext(String fileName, String source) {
CompilerContext context = new CompilerContext();
List<Name> names = new ArrayList<>();
names.add(new org.wso2.ballerinalang.compiler.util.Name("."));
// Registering custom PackageRepository to provide ballerina content without a file in file-system
context.put(PackageRepository.class, new InMemoryPackageRepository(PackageID.DEFAULT, "", fileName, source.getBytes(StandardCharsets.UTF_8)));
return context;
}
Aggregations