lingua-franca 0.10.1
Lingua Franca code generator
Loading...
Searching...
No Matches
org.lflang.util.ImportUtil Class Reference

Utility class for handling package-related URIs in the context of LF (Lingua Franca) libraries. More...

Static Public Member Functions

static String buildPackageURI (String uriStr, Resource resource)
 Build a package URI based on the provided URI string and resource.
static String buildPackageURI (String uriStr, Resource resource, String defaultFileName)
 Like buildPackageURI(String, Resource), but allows the imported file name to be omitted.
static Path buildPackageURIfromSrc (String uriStr, String srcPath)
 Builds a package URI based on the provided URI string and source path.
static Path buildPackageURIfromSrc (String uriStr, String srcPath, String defaultFileName)
 Like buildPackageURIfromSrc(String, String), but allows the imported file name to be omitted.
static List< String > buildPackageURIs (String uriStr, Resource resource, String defaultFileName)
 Resolve the library file path(s) for a package import.
static String getImportedReactorClassName (ImportedReactor importedReactor)
 Return the reactor class name referenced by an ImportedReactor.
static boolean specifiesLibraryFile (String uriStr)
 Return whether uriStr already names a library file (.lf or .ulf) as its last path segment.

Detailed Description

Utility class for handling package-related URIs in the context of LF (Lingua Franca) libraries.

This class provides methods to build URIs for accessing library files based on their location in a project structure, searching build/lfc_include, lf-packages, and the
LF_PACKAGES
environment variable for library inclusion.

Package imports use the form <package/...> and are resolved under the package's
src/lib
directory. The last path segment may be a library file (.lf or .ulf). If a named library file does not exist, the alternate extension is tried (.lf
.ulf
). If the file name is omitted, ReactorClassName.lf is preferred, with the same alternate-extension fallback (and finally listing all library files). This supports both
import R from <package>
and imports that name a subdirectory such as <package/subdir>.

Member Function Documentation

◆ buildPackageURI() [1/2]

String org.lflang.util.ImportUtil.buildPackageURI ( String uriStr,
Resource resource )
static

Build a package URI based on the provided URI string and resource.

This traverses upwards from the current resource URI until it finds the nearest parent directory named "src", then searches for the imported package under <root>/build/lfc_include, <root>/lf-packages, and the LF_PACKAGES environment variable.

Parameters
uriStrA package import path. The last segment must be a .lf or .ulf file (e.g., package/file.lf or package/subdir/file.lf).
resourceThe resource from which the URI resolution should start.
Returns
The path to the imported library file.
Exceptions
IllegalArgumentExceptionif the URI does not end in a library file, if no "src" directory is found, or if the package cannot be located.

◆ buildPackageURI() [2/2]

String org.lflang.util.ImportUtil.buildPackageURI ( String uriStr,
Resource resource,
String defaultFileName )
static

Like buildPackageURI(String, Resource), but allows the imported file name to be omitted.

If the last path segment is not a .lf/.ulf file, then
defaultFileName
is appended under src/lib/ (and any intervening subdirectory segments).

This is used to support import statements of the form:


import ReactorClassName from <packageName>
import ReactorClassName from <packageName/subdir>
Parameters
uriStrThe package import string (e.g., packageName,
packageName/subdir
, or packageName/file.lf).
resourceThe resource from which the URI resolution should start.
defaultFileNameThe file name to use if uriStr does not end in a library file.
Returns
The path to the imported library file.
Exceptions
IllegalArgumentExceptionif the URI string does not contain a package name, if no "src" directory is found, or if the package cannot be located.

◆ buildPackageURIfromSrc() [1/2]

Path org.lflang.util.ImportUtil.buildPackageURIfromSrc ( String uriStr,
String srcPath )
static

Builds a package URI based on the provided URI string and source path.

This method works similarly to the buildPackageURI, but it accepts a direct source path instead of a resource. It traverses upwards to locate the nearest parent directory named "src", then searches for the imported package under <root>/build/lfc_include,
<root>/lf-packages
, and the LF_PACKAGES environment variable.

Parameters
uriStrA package import path. The last segment must be a .lf or .ulf file (e.g., package/file.lf or package/subdir/file.lf).
srcPathThe path from which the URI resolution should start.
Returns
The path to the imported library file.
Exceptions
IllegalArgumentExceptionif the URI string or source path is null, empty, or does not end in a library file, if no "src" directory is found, or if the package cannot be located.

◆ buildPackageURIfromSrc() [2/2]

Path org.lflang.util.ImportUtil.buildPackageURIfromSrc ( String uriStr,
String srcPath,
String defaultFileName )
static

Like buildPackageURIfromSrc(String, String), but allows the imported file name to be omitted.

If the last path segment is not a .lf/.ulf file, then
defaultFileName
is appended under src/lib/ (and any intervening subdirectory segments).

Parameters
uriStrThe package import string (e.g., packageName,
packageName/subdir
, or packageName/file.lf).
srcPathThe path from which the URI resolution should start.
defaultFileNameThe file name to use if uriStr does not end in a library file.
Returns
The path to the imported library file.

◆ buildPackageURIs()

List< String > org.lflang.util.ImportUtil.buildPackageURIs ( String uriStr,
Resource resource,
String defaultFileName )
static

Resolve the library file path(s) for a package import.

If uriStr ends with a .lf/.ulf file, a single path is returned (preserving any subdirectory segments). Otherwise:

  • if the path names a library file (or defaultFileName supplies one), that file is resolved under src/lib/. If it does not exist, the alternate library extension (.lf/.ulf) is tried. For an omitted file name, all library files in the directory are listed when neither extension exists;
  • otherwise all .lf/.ulf files under the corresponding src/lib directory (or subdirectory) are returned.

Returned values are file: URI strings so they round-trip through URI.createURI(...) on all platforms.

The latter case supports import ReactorClassName from <packageName> during linking, when the reactor class name may not yet be readable from the AST.

◆ getImportedReactorClassName()

String org.lflang.util.ImportUtil.getImportedReactorClassName ( ImportedReactor importedReactor)
static

Return the reactor class name referenced by an ImportedReactor.

During linking, getReactorClass() may be an unresolved proxy or null. Accessing the linked object (or its name) can re-enter linking, so this method never resolves the cross-reference. It prefers the textual identifier from the parse tree.

Parameters
importedReactorThe imported reactor AST node.
Returns
The reactor class name from the import statement, or null if unavailable.

◆ specifiesLibraryFile()

boolean org.lflang.util.ImportUtil.specifiesLibraryFile ( String uriStr)
static

Return whether uriStr already names a library file (.lf or .ulf) as its last path segment.


The documentation for this class was generated from the following file:
  • /Users/runner/work/lingua-franca/lingua-franca/core/src/main/java/org/lflang/util/ImportUtil.java