Search in sources :

Example 1 with KeyValuePairs

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.");
    }
}
Also used : TargetDecl(org.lflang.lf.TargetDecl) FileConfig(org.lflang.FileConfig) KeyValuePair(org.lflang.lf.KeyValuePair) KeyValuePairs(org.lflang.lf.KeyValuePairs) IOException(java.io.IOException) TargetConfig(org.lflang.TargetConfig)

Aggregations

IOException (java.io.IOException)1 FileConfig (org.lflang.FileConfig)1 TargetConfig (org.lflang.TargetConfig)1 KeyValuePair (org.lflang.lf.KeyValuePair)1 KeyValuePairs (org.lflang.lf.KeyValuePairs)1 TargetDecl (org.lflang.lf.TargetDecl)1