use of org.lflang.lf.KeyValuePairs in project lingua-franca by lf-lang.
the class GeneratorUtils method getLFResource.
/**
* Return the {@code LFResource} representation of the
* given resource.
* @param resource The {@code Resource} to be
* represented as an {@code LFResource}
* @param srcGenBasePath The root directory for any
* generated sources associated with the resource.
* @param context The generator invocation context.
* @param errorReporter An error message acceptor.
* @return the {@code LFResource} representation of the
* given resource.
*/
public static LFResource getLFResource(Resource resource, Path srcGenBasePath, LFGeneratorContext context, ErrorReporter errorReporter) {
TargetDecl target = GeneratorUtils.findTarget(resource);
KeyValuePairs config = target.getConfig();
var targetConfig = new TargetConfig();
if (config != null) {
List<KeyValuePair> pairs = config.getPairs();
TargetProperty.set(targetConfig, pairs != null ? pairs : List.of(), errorReporter);
}
try {
FileConfig fc = new FileConfig(resource, srcGenBasePath, context.useHierarchicalBin());
return new LFResource(resource, fc, targetConfig);
} catch (IOException e) {
throw new RuntimeException("Failed to instantiate an imported resource because an I/O error " + "occurred.");
}
}
Aggregations