Utility class for handling package-related URIs in the context of LF (Lingua Franca) libraries.
More...
|
| 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.
|
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>.
| 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
-
| uriStr | A package import path. The last segment must be a .lf or .ulf file (e.g., package/file.lf or package/subdir/file.lf). |
| resource | The resource from which the URI resolution should start. |
- Returns
- The path to the imported library file.
- Exceptions
-
| IllegalArgumentException | if the URI does not end in a library file, if no "src" directory is found, or if the package cannot be located. |
| 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
-
| uriStr | The package import string (e.g., packageName,
packageName/subdir, or packageName/file.lf). |
| resource | The resource from which the URI resolution should start. |
| defaultFileName | The file name to use if uriStr does not end in a library file. |
- Returns
- The path to the imported library file.
- Exceptions
-
| IllegalArgumentException | if the URI string does not contain a package name, if no "src" directory is found, or if the package cannot be located. |
| 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
-
| uriStr | A package import path. The last segment must be a .lf or .ulf file (e.g., package/file.lf or package/subdir/file.lf). |
| srcPath | The path from which the URI resolution should start. |
- Returns
- The path to the imported library file.
- Exceptions
-
| IllegalArgumentException | if 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. |
| 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.