nitpackage: move package path services up to `model/mpackage.nit`
[nit.git] / src / model / mpackage.nit
index 8309b5a..d2f15dd 100644 (file)
@@ -25,14 +25,14 @@ class MPackage
        super MConcern
 
        # The name of the package
-       redef var name: String
+       redef var name
 
        redef fun full_name do return name
 
        redef var c_name = name.to_cmangle is lazy
 
        # The model of the package
-       redef var model: Model
+       redef var model
 
        redef var location
 
@@ -55,8 +55,27 @@ class MPackage
 
        redef fun mdoc_or_fallback
        do
+               var mdoc = self.mdoc
                if mdoc != null then return mdoc
-               return root.mdoc_or_fallback
+               var root = self.root
+               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
 
@@ -66,7 +85,7 @@ class MGroup
 
        # The name of the group
        # empty name for a default group in a single-module package
-       redef var name: String
+       redef var name
 
        redef var location