Skip to content

Commit

Permalink
Remove comment
Browse files Browse the repository at this point in the history
  • Loading branch information
deusaquilus committed Aug 22, 2023
1 parent 8deb5d3 commit 3347d09
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
1 change: 1 addition & 0 deletions morphir/extensibility/src/org/finos/morphir/Names.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ trait Names
with PackageNameModule
with QualifiedModuleNameModule
with QNameModule
with NamingOptionsModule
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.finos.morphir

trait NamingOptionsModule { self: PackageNameModule with ModuleNameModule =>

sealed case class FQNamingOptions(defaultPackage: PackageName, defaultModule: ModuleName, defaultSeparator: String)

object FQNamingOptions {
implicit val default: FQNamingOptions =
FQNamingOptions(PackageName.empty, ModuleName.empty, ":")
}
}
10 changes: 2 additions & 8 deletions morphir/extensibility/src/org/finos/morphir/fqname.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package org.finos.morphir
trait FQNameModule {
self: NameModule with ModuleNameModule with NamespaceModule with PackageNameModule with PathModule
with QualifiedModuleNameModule
with QNameModule =>
with QNameModule
with NamingOptionsModule =>

sealed case class FQName(packagePath: PackageName, modulePath: ModuleName, localName: Name) { self =>
def getPackagePath: Path = packagePath.toPath
Expand Down Expand Up @@ -100,13 +101,6 @@ trait FQNameModule {
}
}

sealed case class FQNamingOptions(defaultPackage: PackageName, defaultModule: ModuleName, defaultSeparator: String)

object FQNamingOptions {
implicit val default: FQNamingOptions =
FQNamingOptions(PackageName.empty, ModuleName.empty, ":")
}

sealed case class FQNameParsingError(invalidName: String)
extends Exception(s"Unable to parse: [$invalidName] into a valid FQName")
}
3 changes: 2 additions & 1 deletion morphir/extensibility/src/org/finos/morphir/nodeID.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.finos.morphir

trait NodeIDModule {
self: FQNameModule with NameModule with PathModule with PackageNameModule with ModuleNameModule
self: FQNameModule with NamingOptionsModule with NameModule with PathModule with PackageNameModule
with ModuleNameModule
with QualifiedModuleNameModule =>
import NodePath.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.finos.morphir

// TODO printing options
trait QualifiedModuleNameModule {
self: PackageNameModule with PathModule with ModuleNameModule with NamespaceModule =>
self: NameModule with PackageNameModule with PathModule with ModuleNameModule with NamespaceModule
with NamingOptionsModule =>

/// A qualified module name is a globally unique identifier for a module. It is represented by the combination of a package name and the module name.
sealed case class QualifiedModuleName(packageName: PackageName, modulePath: ModuleName) { self =>
Expand All @@ -12,6 +12,11 @@ trait QualifiedModuleNameModule {
QualifiedModuleName(self.packageName, modulePath.addPart(namespaceAddition))

def toTuple: (Path, Path) = (packageName.toPath, modulePath.toPath)

override def toString: String = Array(
Path.toString(Name.toTitleCase, ".", packageName.toPath),
Path.toString(Name.toTitleCase, ".", modulePath.toPath)
).mkString(":")
}

object QualifiedModuleName {
Expand All @@ -23,9 +28,33 @@ trait QualifiedModuleNameModule {
def apply(modulePath: String)(implicit packageName: PackageName): QualifiedModuleName =
QualifiedModuleName(packageName, ModuleName.fromString(modulePath))

/** Parse a string into a QualifedModuleName using splitter as the separator between package, and module */
def fromString(nameString: String, splitter: String)(implicit options: FQNamingOptions): QualifiedModuleName =
nameString.split(splitter) match {
case Array(moduleNameString, localNameString) =>
qmn(moduleNameString, localNameString)
case Array(localNameString) =>
qmn(localNameString)
case _ => throw QualifiedModuleNameParsingError(nameString)
}

def fromString(fqNameString: String)(implicit options: FQNamingOptions): QualifiedModuleName =
fromString(fqNameString, options.defaultSeparator)

/** Convenience function to create a fully-qualified name from 2 strings with default package name */
def qmn(packageName: String, moduleName: String)(implicit options: FQNamingOptions): QualifiedModuleName =
QualifiedModuleName(PackageName.fromString(packageName), ModuleName(Path.fromString(moduleName)))

/** Convenience function to create a fully-qualified name from 1 string with defaults for package and module */
def qmn(moduleName: String)(implicit options: FQNamingOptions): QualifiedModuleName =
QualifiedModuleName(options.defaultPackage, ModuleName(Path.fromString(moduleName)))

object AsTuple {
def unapply(name: QualifiedModuleName): Option[(Path, Path)] =
Some(name.toTuple)
}
}

sealed case class QualifiedModuleNameParsingError(invalidName: String)
extends Exception(s"Unable to parse: [$invalidName] into a valid QualifiedModuleName")
}

0 comments on commit 3347d09

Please sign in to comment.