-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c43f442
commit c1c0fce
Showing
14 changed files
with
627 additions
and
678 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
11 changes: 4 additions & 7 deletions
11
morphir/src/org/finos/morphir/ir/gen1/NamingOptionsModule.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
package org.finos.morphir.ir.gen1 | ||
|
||
trait NamingOptionsModule { self: PackageNameModule with ModuleNameModule => | ||
sealed case class FQNamingOptions(defaultPackage: PackageName, defaultModule: ModuleName, defaultSeparator: String) | ||
|
||
sealed case class FQNamingOptions(defaultPackage: PackageName, defaultModule: ModuleName, defaultSeparator: String) | ||
|
||
object FQNamingOptions { | ||
implicit val default: FQNamingOptions = | ||
FQNamingOptions(PackageName.empty, ModuleName.empty, ":") | ||
} | ||
object FQNamingOptions { | ||
implicit val default: FQNamingOptions = | ||
FQNamingOptions(PackageName.empty, ModuleName.empty, ":") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
morphir/src/org/finos/morphir/ir/gen1/TypeMapReferenceName.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,99 @@ | ||
package org.finos.morphir.ir.gen1 | ||
|
||
trait FQNameModule { | ||
self: NameModule with ModuleNameModule with NamespaceModule with PackageNameModule with PathModule | ||
with QualifiedModuleNameModule | ||
with QNameModule | ||
with NamingOptionsModule => | ||
|
||
sealed case class FQName(packagePath: PackageName, modulePath: ModuleName, localName: Name) { self => | ||
def getPackagePath: Path = packagePath.toPath | ||
|
||
def getModulePath: Path = modulePath.toPath | ||
def getModuleName: ModuleName = modulePath | ||
|
||
/// An alias for `packagePath` | ||
def pack: PackageName = packagePath | ||
|
||
def toReferenceName: String = Seq( | ||
Path.toString(Name.toTitleCase, ".", packagePath.toPath), | ||
Path.toString(Name.toTitleCase, ".", modulePath.toPath), | ||
localName.toTitleCase | ||
).mkString(".") | ||
|
||
override def toString: String = Array( | ||
Path.toString(Name.toTitleCase, ".", packagePath.toPath), | ||
Path.toString(Name.toTitleCase, ".", modulePath.toPath), | ||
Name.toCamelCase(localName) | ||
).mkString(":") | ||
|
||
def toStringTitleCase: String = Array( | ||
Path.toString(Name.toTitleCase, ".", packagePath.toPath), | ||
Path.toString(Name.toTitleCase, ".", modulePath.toPath), | ||
Name.toTitleCase(this.localName) | ||
).mkString(":") | ||
} | ||
sealed case class FQName(packagePath: PackageName, modulePath: ModuleName, localName: Name) { self => | ||
def getPackagePath: Path = packagePath.toPath | ||
|
||
def getModulePath: Path = modulePath.toPath | ||
def getModuleName: ModuleName = modulePath | ||
|
||
/// An alias for `packagePath` | ||
def pack: PackageName = packagePath | ||
|
||
def toReferenceName: String = Seq( | ||
Path.toString(Name.toTitleCase, ".", packagePath.toPath), | ||
Path.toString(Name.toTitleCase, ".", modulePath.toPath), | ||
localName.toTitleCase | ||
).mkString(".") | ||
|
||
override def toString: String = Array( | ||
Path.toString(Name.toTitleCase, ".", packagePath.toPath), | ||
Path.toString(Name.toTitleCase, ".", modulePath.toPath), | ||
Name.toCamelCase(localName) | ||
).mkString(":") | ||
|
||
def toStringTitleCase: String = Array( | ||
Path.toString(Name.toTitleCase, ".", packagePath.toPath), | ||
Path.toString(Name.toTitleCase, ".", modulePath.toPath), | ||
Name.toTitleCase(this.localName) | ||
).mkString(":") | ||
} | ||
|
||
object FQName { | ||
val empty: FQName = FQName(PackageName.empty, ModuleName.empty, Name.empty) | ||
// def apply(packagePath: Path, modulePath: Path, localName: Name): FQName = | ||
// FQName(PackageName(packagePath), ModulePath(modulePath), localName) | ||
object FQName { | ||
val empty: FQName = FQName(PackageName.empty, ModuleName.empty, Name.empty) | ||
// def apply(packagePath: Path, modulePath: Path, localName: Name): FQName = | ||
// FQName(PackageName(packagePath), ModulePath(modulePath), localName) | ||
|
||
val fqName: Path => Path => Name => FQName = packagePath => | ||
modulePath => localName => FQName(PackageName.fromPath(packagePath), ModuleName(modulePath), localName) | ||
val fqName: Path => Path => Name => FQName = packagePath => | ||
modulePath => localName => FQName(PackageName.fromPath(packagePath), ModuleName(modulePath), localName) | ||
|
||
def fromQName(packagePath: Path, qName: QName): FQName = | ||
FQName(PackageName.fromPath(packagePath), ModuleName(qName.modulePath), qName.localName) | ||
def fromQName(packagePath: Path, qName: QName): FQName = | ||
FQName(PackageName.fromPath(packagePath), ModuleName(qName.modulePath), qName.localName) | ||
|
||
def fromQName(qName: QName)(implicit packageName: PackageName): FQName = | ||
FQName(packageName, ModuleName(qName.modulePath), qName.localName) | ||
def fromQName(qName: QName)(implicit packageName: PackageName): FQName = | ||
FQName(packageName, ModuleName(qName.modulePath), qName.localName) | ||
|
||
def fromQName(qName: QName)(implicit options: FQNamingOptions): FQName = | ||
FQName(options.defaultPackage, ModuleName(QName.getModulePath(qName)), QName.getLocalName(qName)) | ||
def fromQName(qName: QName)(implicit options: FQNamingOptions): FQName = | ||
FQName(options.defaultPackage, ModuleName(QName.getModulePath(qName)), QName.getLocalName(qName)) | ||
|
||
/** Get the package path part of a fully-qualified name. */ | ||
def getPackagePath(fqName: FQName): Path = fqName.getPackagePath | ||
/** Get the package path part of a fully-qualified name. */ | ||
def getPackagePath(fqName: FQName): Path = fqName.getPackagePath | ||
|
||
/** Get the module path part of a fully-qualified name */ | ||
def getModulePath(fqName: FQName): Path = fqName.getModulePath | ||
/** Get the module path part of a fully-qualified name */ | ||
def getModulePath(fqName: FQName): Path = fqName.getModulePath | ||
|
||
/** Get the local name part of a fully-qualified name */ | ||
def getLocalName(fqName: FQName): Name = fqName.localName | ||
/** Get the local name part of a fully-qualified name */ | ||
def getLocalName(fqName: FQName): Name = fqName.localName | ||
|
||
/** Convenience function to create a fully-qualified name from 3 strings */ | ||
def fqn(packageName: String, moduleName: String, localName: String): FQName = | ||
FQName(PackageName.fromString(packageName), ModuleName.fromString(moduleName), Name.fromString(localName)) | ||
/** Convenience function to create a fully-qualified name from 3 strings */ | ||
def fqn(packageName: String, moduleName: String, localName: String): FQName = | ||
FQName(PackageName.fromString(packageName), ModuleName.fromString(moduleName), Name.fromString(localName)) | ||
|
||
/** Convenience function to create a fully-qualified name from 2 strings with default package name */ | ||
def fqn(moduleName: String, localName: String)(implicit options: FQNamingOptions): FQName = | ||
FQName(options.defaultPackage, ModuleName(Path.fromString(moduleName)), Name.fromString(localName)) | ||
/** Convenience function to create a fully-qualified name from 2 strings with default package name */ | ||
def fqn(moduleName: String, localName: String)(implicit options: FQNamingOptions): FQName = | ||
FQName(options.defaultPackage, ModuleName(Path.fromString(moduleName)), Name.fromString(localName)) | ||
|
||
/** Convenience function to create a fully-qualified name from 1 string with defaults for package and module */ | ||
def fqn(localName: String)(implicit options: FQNamingOptions): FQName = | ||
FQName(options.defaultPackage, options.defaultModule, Name.fromString(localName)) | ||
/** Convenience function to create a fully-qualified name from 1 string with defaults for package and module */ | ||
def fqn(localName: String)(implicit options: FQNamingOptions): FQName = | ||
FQName(options.defaultPackage, options.defaultModule, Name.fromString(localName)) | ||
|
||
/// Convenience function to create a fully-qualified name from a local name and an implicitly provided `QualifiedModuleName`. | ||
def fromLocalName(localName: String)(implicit qualifiedModuleName: QualifiedModuleName): FQName = | ||
FQName(qualifiedModuleName.packageName, qualifiedModuleName.modulePath, Name.fromString(localName)) | ||
/// Convenience function to create a fully-qualified name from a local name and an implicitly provided `QualifiedModuleName`. | ||
def fromLocalName(localName: String)(implicit qualifiedModuleName: QualifiedModuleName): FQName = | ||
FQName(qualifiedModuleName.packageName, qualifiedModuleName.modulePath, Name.fromString(localName)) | ||
|
||
def fromLocalName(localName: Name)(implicit qualifiedModuleName: QualifiedModuleName): FQName = | ||
FQName(qualifiedModuleName.packageName, qualifiedModuleName.modulePath, localName) | ||
def fromLocalName(localName: Name)(implicit qualifiedModuleName: QualifiedModuleName): FQName = | ||
FQName(qualifiedModuleName.packageName, qualifiedModuleName.modulePath, localName) | ||
|
||
def toString(fqName: FQName): String = fqName.toString | ||
def toString(fqName: FQName): String = fqName.toString | ||
|
||
/** Parse a string into a FQName using splitter as the separator between package, module, and local names */ | ||
def fromString(fqNameString: String, splitter: String)(implicit options: FQNamingOptions): FQName = | ||
fqNameString.split(splitter) match { | ||
case Array(packageNameString, moduleNameString, localNameString) => | ||
fqn(packageNameString, moduleNameString, localNameString) | ||
case Array(moduleNameString, localNameString) => | ||
fqn(moduleNameString, localNameString) | ||
case Array(localNameString) => | ||
fqn(localNameString) | ||
case _ => throw FQNameParsingError(fqNameString) | ||
} | ||
/** Parse a string into a FQName using splitter as the separator between package, module, and local names */ | ||
def fromString(fqNameString: String, splitter: String)(implicit options: FQNamingOptions): FQName = | ||
fqNameString.split(splitter) match { | ||
case Array(packageNameString, moduleNameString, localNameString) => | ||
fqn(packageNameString, moduleNameString, localNameString) | ||
case Array(moduleNameString, localNameString) => | ||
fqn(moduleNameString, localNameString) | ||
case Array(localNameString) => | ||
fqn(localNameString) | ||
case _ => throw FQNameParsingError(fqNameString) | ||
} | ||
|
||
def fromString(fqNameString: String)(implicit options: FQNamingOptions): FQName = | ||
fromString(fqNameString, options.defaultSeparator) | ||
def fromString(fqNameString: String)(implicit options: FQNamingOptions): FQName = | ||
fromString(fqNameString, options.defaultSeparator) | ||
|
||
object ReferenceName { | ||
def unapply(fqName: FQName): Some[String] = Some(fqName.toReferenceName) | ||
} | ||
object ReferenceName { | ||
def unapply(fqName: FQName): Some[String] = Some(fqName.toReferenceName) | ||
} | ||
|
||
sealed case class FQNameParsingError(invalidName: String) | ||
extends Exception(s"Unable to parse: [$invalidName] into a valid FQName") | ||
} | ||
|
||
sealed case class FQNameParsingError(invalidName: String) | ||
extends Exception(s"Unable to parse: [$invalidName] into a valid FQName") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,57 @@ | ||
package org.finos.morphir.ir.gen1 | ||
|
||
trait ModuleNameModule { self: NameModule with PathModule => | ||
|
||
/** A module name is a unique identifier for a module within a package. It is represented by a `Path`, which is a | ||
* "list" of names. | ||
*/ | ||
sealed case class ModuleName(path: Path) { self => | ||
|
||
/// Construct a new module name by concatting the given module name to this one. | ||
def ++(other: ModuleName): ModuleName = ModuleName(path ++ other.path) | ||
|
||
/// Construct a new module name by concatting the given module path to this one. | ||
def ++(other: Path): ModuleName = ModuleName(path ++ other) | ||
|
||
/// Construct a new module name by concatting the given local name to this module name. | ||
def /(name: Name): ModuleName = ModuleName(path / name) | ||
/// Construct a new module name by concatting the given local name to this module name. | ||
def /(name: String): ModuleName = ModuleName(path / Name(name)) | ||
|
||
// Need a non-symbolic version of this for QualifiedModuleName, strange compilation errors | ||
// happen in QualifiedModuleName./(str: String) implementation when using `moduleName / str` otherwise | ||
def addPart(name: String): ModuleName = ModuleName(path / Name(name)) | ||
|
||
/// Check if the module name is empty. | ||
@inline def isEmpty: Boolean = path.isEmpty | ||
|
||
/// Get the name of this module. | ||
/// For example if the module name is `Morphir.SDK.Basics` then the name is `Basics`. | ||
def name: Name = | ||
self match { | ||
case ModuleName(Path(Vector())) => Name.empty | ||
case ModuleName(Path(segments)) => segments.last | ||
} | ||
|
||
// Get the name of this module if a name is present. | ||
def nameOption: Option[Name] = | ||
self match { | ||
case ModuleName(Path(Vector())) => None | ||
case ModuleName(Path(segments)) => Some(segments.last) | ||
} | ||
|
||
/// Convert this module name to a `Path`. | ||
@inline def toPath: Path = path | ||
override def toString: String = path.toString | ||
} | ||
|
||
object ModuleName { | ||
/// Create an empty module name. | ||
val empty: ModuleName = ModuleName(Path.empty) | ||
/** A module name is a unique identifier for a module within a package. It is represented by a `Path`, which is a "list" | ||
* of names. | ||
*/ | ||
sealed case class ModuleName(path: Path) { self => | ||
|
||
/// Construct a new module name by concatting the given module name to this one. | ||
def ++(other: ModuleName): ModuleName = ModuleName(path ++ other.path) | ||
|
||
/// Construct a new module name by concatting the given module path to this one. | ||
def ++(other: Path): ModuleName = ModuleName(path ++ other) | ||
|
||
/// Construct a new module name by concatting the given local name to this module name. | ||
def /(name: Name): ModuleName = ModuleName(path / name) | ||
/// Construct a new module name by concatting the given local name to this module name. | ||
def /(name: String): ModuleName = ModuleName(path / Name(name)) | ||
|
||
// Need a non-symbolic version of this for QualifiedModuleName, strange compilation errors | ||
// happen in QualifiedModuleName./(str: String) implementation when using `moduleName / str` otherwise | ||
def addPart(name: String): ModuleName = ModuleName(path / Name(name)) | ||
|
||
/// Check if the module name is empty. | ||
@inline def isEmpty: Boolean = path.isEmpty | ||
|
||
/// Get the name of this module. | ||
/// For example if the module name is `Morphir.SDK.Basics` then the name is `Basics`. | ||
def name: Name = | ||
self match { | ||
case ModuleName(Path(Vector())) => Name.empty | ||
case ModuleName(Path(segments)) => segments.last | ||
} | ||
|
||
// Get the name of this module if a name is present. | ||
def nameOption: Option[Name] = | ||
self match { | ||
case ModuleName(Path(Vector())) => None | ||
case ModuleName(Path(segments)) => Some(segments.last) | ||
} | ||
|
||
/// Convert this module name to a `Path`. | ||
@inline def toPath: Path = path | ||
override def toString: String = path.toString | ||
} | ||
|
||
def apply(input: String): ModuleName = fromString(input) | ||
object ModuleName { | ||
/// Create an empty module name. | ||
val empty: ModuleName = ModuleName(Path.empty) | ||
|
||
def fromString(input: String): ModuleName = ModuleName(Path.fromString(input)) | ||
def apply(input: String): ModuleName = fromString(input) | ||
|
||
def apply(parts: Name*): ModuleName = ModuleName(Path.fromIterable(parts)) | ||
def fromIterable(segments: Iterable[Name]): ModuleName = ModuleName(Path.fromIterable(segments)) | ||
def fromStrings(parts: String*): ModuleName = ModuleName(Path.fromStrings(parts: _*)) | ||
} | ||
def fromString(input: String): ModuleName = ModuleName(Path.fromString(input)) | ||
|
||
def apply(parts: Name*): ModuleName = ModuleName(Path.fromIterable(parts)) | ||
def fromIterable(segments: Iterable[Name]): ModuleName = ModuleName(Path.fromIterable(segments)) | ||
def fromStrings(parts: String*): ModuleName = ModuleName(Path.fromStrings(parts: _*)) | ||
} |
Oops, something went wrong.