Skip to content
This repository has been archived by the owner on Jun 1, 2021. It is now read-only.

Commit

Permalink
Implement NonDescendant
Browse files Browse the repository at this point in the history
  • Loading branch information
sd-yip committed Jan 27, 2019
1 parent d029698 commit 44dd41f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
1 change: 1 addition & 0 deletions core/src/main/scala/eyrie/ops/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package eyrie

package object ops {
type TrivialDescendant[A] = Descendant[A, A]
type NonDescendant[A] = Descendant[A, Nothing]
}
46 changes: 31 additions & 15 deletions file/src/main/scala/eyrie/file/instances/FilePathSuccessor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,31 @@ package eyrie.file.instances
import java.nio.file.Path

import eyrie.file.FilePath.Internal
import eyrie.file.{AbsoluteFile, FileName, FilePath, RelativeFile, RootDirectory}
import eyrie.ops.{Descendant, Successor, TrivialDescendant}
import eyrie.file.{AbsoluteFile, FileName, FilePath, IdentityFilePath, RelativeFile, RootDirectory}
import eyrie.ops.{Descendant, NonDescendant, Successor, TrivialDescendant}

private[file]
trait FilePathSuccessorInstances {
implicit def eyrieFileRelativeSuccessorInstance[C]: Successor[
RelativeFile[C], FilePath.Relative[C], FileName[C]] =
RelativeFilePathSuccessor.asInstanceOf[Successor[RelativeFile[C], FilePath.Relative[C], FileName[C]]]
implicit def eyrieFileRelativeDescendantInstance[C]:
NonDescendant[RelativeFile[C]] with Successor[RelativeFile[C], FilePath.Relative[C], FileName[C]] =
RelativeFilePathDescendant.asInstanceOf[
NonDescendant[RelativeFile[C]] with Successor[RelativeFile[C], FilePath.Relative[C], FileName[C]]]

implicit def eyrieFileAbsoluteDescendantInstance[C]: Successor[
AbsoluteFile[C], FilePath.Absolute[C], FileName[C]] with Descendant[AbsoluteFile[C], RootDirectory[C]] =
AbsoluteFilePathDescendant.asInstanceOf[Successor[
AbsoluteFile[C], FilePath.Absolute[C], FileName[C]] with Descendant[AbsoluteFile[C], RootDirectory[C]]]
implicit def eyrieFileAbsoluteDescendantInstance[C]:
Descendant[AbsoluteFile[C], RootDirectory[C]] with Successor[AbsoluteFile[C], FilePath.Absolute[C], FileName[C]] =
AbsoluteFilePathDescendant.asInstanceOf[
Descendant[AbsoluteFile[C], RootDirectory[C]] with Successor[AbsoluteFile[C], FilePath.Absolute[C], FileName[C]]]

implicit def eyrieFileTrivialDescendantInstance[C]: TrivialDescendant[RootDirectory[C]] =
TrivialFilePathDescendant.asInstanceOf[TrivialDescendant[RootDirectory[C]]]
implicit def eyrieFileRelativeNonDescendantInstance[C]: NonDescendant[IdentityFilePath[C]] =
FilePathNonDescendant.asInstanceOf[NonDescendant[IdentityFilePath[C]]]

implicit def eyrieFileAbsoluteTrivialDescendantInstance[C]: TrivialDescendant[RootDirectory[C]] =
FilePathTrivialDescendant.asInstanceOf[TrivialDescendant[RootDirectory[C]]]
}

private
object RelativeFilePathSuccessor extends Successor[RelativeFile[Any], FilePath.Relative[Any], FileName[Any]] {
object RelativeFilePathDescendant extends NonDescendant[RelativeFile[Any]]
with Successor[RelativeFile[Any], FilePath.Relative[Any], FileName[Any]] {
import eyrie.file.syntax.asJava._

private
Expand All @@ -40,11 +45,15 @@ object RelativeFilePathSuccessor extends Successor[RelativeFile[Any], FilePath.R
override
def lastSegment: RelativeFile[Any] => FileName[Any] =
a => Internal.FileName(a.asJava.getFileName)

override
def root: RelativeFile[Any] => Nothing =
_ => throw new UnsupportedOperationException("Unexpected invocation")
}

private
object AbsoluteFilePathDescendant extends Successor[
AbsoluteFile[Any], FilePath.Absolute[Any], FileName[Any]] with Descendant[AbsoluteFile[Any], RootDirectory[Any]] {
object AbsoluteFilePathDescendant extends Descendant[AbsoluteFile[Any], RootDirectory[Any]]
with Successor[AbsoluteFile[Any], FilePath.Absolute[Any], FileName[Any]] {
import eyrie.file.syntax.asJava._

private
Expand All @@ -69,7 +78,14 @@ object AbsoluteFilePathDescendant extends Successor[
}

private
object TrivialFilePathDescendant extends TrivialDescendant[RootDirectory[Any]] {
object FilePathNonDescendant extends NonDescendant[IdentityFilePath[Any]] {
override
def root: IdentityFilePath[Any] => Nothing =
_ => throw new UnsupportedOperationException("Unexpected invocation")
}

private
object FilePathTrivialDescendant extends TrivialDescendant[RootDirectory[Any]] {
override
def root: RootDirectory[Any] => RootDirectory[Any] =
identity
Expand Down
14 changes: 13 additions & 1 deletion file/src/test/scala/eyrie/file/test/DescendantSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.nio.file.Paths

import eyrie.file.FilePath.Internal
import eyrie.file.context.Sys
import eyrie.file.{AbsoluteFile, FilePath, RootDirectory}
import eyrie.file.{AbsoluteFile, FilePath, RelativeFile, RootDirectory}
import org.junit.runner.RunWith
import org.scalatest.FreeSpec
import org.scalatest.junit.JUnitRunner
Expand All @@ -19,6 +19,9 @@ object DescendantSpec {

val absolute: FilePath.Absolute[Sys] =
Internal.RootDirectory(Paths.get("a/b/c").toAbsolutePath.getRoot)

val relativeFile: RelativeFile[Sys] =
Internal.RelativeFile(Paths.get("a/b/c"))
}

@RunWith(classOf[JUnitRunner])
Expand All @@ -45,4 +48,13 @@ class DescendantSpec extends FreeSpec {
absolute.root: RootDirectory[Sys]
}
}
"RelativeFile" - {
"root should not be available" in {
illTyped(
"""
relativeFile.root
"""
)
}
}
}

0 comments on commit 44dd41f

Please sign in to comment.