From 64e0e6cf70389ad7bd256a0ca9511d73cefebe19 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Mon, 7 May 2018 13:51:54 -0400 Subject: [PATCH] nitpackage: move package path services up to `model/mpackage.nit` Signed-off-by: Alexandre Terrasa --- src/model/mpackage.nit | 16 ++++++++++++++++ src/nitpackage.nit | 15 +-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/model/mpackage.nit b/src/model/mpackage.nit index bb6856b..d2f15dd 100644 --- a/src/model/mpackage.nit +++ b/src/model/mpackage.nit @@ -61,6 +61,22 @@ class MPackage if root != null then return root.mdoc_or_fallback return null end + + # Does `self` have a source file? + fun has_source: Bool do return location.file != null + + # The path to `self` + fun package_path: nullable String do + if not has_source then return null + return location.file.as(not null).filename + end + + # Is `self` in its own directory? + fun is_expanded: Bool do + var path = package_path + if path == null then return false + return not path.has_suffix(".nit") + end end # A group of modules in a package diff --git a/src/nitpackage.nit b/src/nitpackage.nit index 5373ae0..599aa5a 100644 --- a/src/nitpackage.nit +++ b/src/nitpackage.nit @@ -63,24 +63,11 @@ end redef class MPackage - # Does `self` have a source file? - private var has_source: Bool is lazy do - return location.file != null - end - - # Is `self` in its own directory? - private var is_expanded: Bool is lazy do - if not has_source then return false - var path = location.file.as(not null).filename - if path.has_suffix(".nit") then return false - return true - end - # Expand `self` in its own directory private fun expand: String do assert not is_expanded - var ori_path = location.file.as(not null).filename + var ori_path = package_path.as(not null) var new_path = ori_path.dirname / name new_path.mkdir -- 1.7.9.5