1. Kink Programming Language
  2. Untitled project
  3. kink

Commits

Taku Miyakawa  committed 9c3eab2

Refines function names of paths

  • Participants
  • Parent commits 0f210b5
  • Branches default

Comments (0)

Files changed (3)

File src/build/deleteassertion.kn

View file
 :handle = { (:Src :Dest)
     print_line(expand('Dir #Src -> #Dest'))
     Src.child_paths.loop { (:Src_child)
-        :Dest_child = Dest + (Src_child - Src)
+        :Dest_child = Dest + (Src_child.relative_path_from(Src))
         switch(
-            { Src_child.dir? } {
+            { Src_child.directory? } {
                 handle(Src_child Dest_child)
             }
             { Src_child.name.ends_with?('.class') } {
                     }
                 ).call(Opcodes.ASM4 Writer)
                 Reader.accept(Adapter ClassReader.SKIP_FRAMES)
-                Dest_child.parent_path.make_dir_recursively
+                Dest_child.parent_path.make_directory_recursively
                 Dest_child.write_bytes(Writer.toByteArray)
             }
         )

File src/main/kink/_enhance/java/nio/file/Path.kn

View file
     }
 
     # Relative path of the receiver from the argument
-    # ex. path('/usr/local/bin') - '/usr' -> path('local/bin')
-    # ex. path('/usr/local/bin') - path('/usr') -> path('local/bin')
-    'op_sub' { > :One_path (:Other)
-        Other.switch(
-            (instance_of(Path)) { Other.relativize(One_path) }
-            (instance_of(String)) { Paths.get(Other).relativize(One_path) }
-        )
+    # ex. path('/usr/local/bin').relative_path_from(path('/usr')) -> path('local/bin')
+    'relative_path_from' { > :One_path (:Other)
+        Other.relativize(One_path)
     }
 
     # Sibling path
-    # ex. path('/usr/local/bin').sibling('lib') -> path('/usr/local/lib')
-    # ex. path('/usr/local/bin').sibling(path('lib')) -> path('/usr/local/lib')
-    'sibling' { > :File_path (:Other)
+    # ex. path('/usr/local/bin').sibling_path('lib') -> path('/usr/local/lib')
+    # ex. path('/usr/local/bin').sibling_path(path('lib')) -> path('/usr/local/lib')
+    'sibling_path' { > :File_path (:Other)
         File_path.resolveSibling(Other)
     }
 
-    # Leaf of the path
+    # Path of the last part of the self path.
     # ex. path('/usr/local/bin').leaf -> path('bin')
-    'leaf' { > :File_path ()
+    'base_path' { > :File_path ()
         File_path.getFileName
     }
 
     # Decides if the path has a root or not
-    # ex. path('/usr/local/bin').has_root? -> true
-    # ex. path('bin/kink').has_root? -> false
-    'has_root?' { > :File_path ()
+    # ex. path('/usr/local/bin').has_root_path? -> true
+    # ex. path('bin/kink').has_root_path? -> false
+    'has_root_path?' { > :File_path ()
         File_path.getRoot.object??
     }
 
     # Root path
-    # ex. path('/usr/local/bin').root -> path('/')
-    'root' { > :File_path ()
+    # ex. path('/usr/local/bin').root_path -> path('/')
+    'root_path' { > :File_path ()
         File_path.getRoot
     }
 
     }
 
     # Determines the path is absolute or not
-    # ex. path('/usr/local/bin').absolute? -> true
-    # ex. path('bin').absolute? -> false
-    'absolute?' { > :File_path ()
+    # ex. path('/usr/local/bin').absolute_path? -> true
+    # ex. path('bin').absolute_path? -> false
+    'absolute_path?' { > :File_path ()
         File_path.isAbsolute
     }
 
     # Returns the absolute path
-    # ex. path('some.txt').absolute -> path('/home/me/work/some.txt')
-    'absolute' { > :File_path ()
+    # ex. path('some.txt').absolute_path -> path('/home/me/work/some.txt')
+    'absolute_path' { > :File_path ()
         File_path.toAbsolutePath
     }
 
     # Returns the real path
     # ex. path('.' LinkOption.NOFOLLOW_LINKS) -> path('/home/me')
     # ex. path('/bin/sh') -> path('/usr/bin/bash') # Follows the link
-    'real' { > :File_path (* :Args)
+    'real_path' { > :File_path (* :Args)
         File_path.toRealPath(*** Args)
     }
 
     # Determines if the path is a directory or not
-    # ex. path('/usr/bin').dir? -> true
-    # ex. path('/usr/bin/ls').dir? -> false
-    'dir?' { > :File_path (* :Link_options)
+    # ex. path('/usr/bin').directory? -> true
+    # ex. path('/usr/bin/ls').directory? -> false
+    'directory?' { > :File_path (* :Link_options)
         Files.isDirectory(File_path *** Link_options)
     }
 
     }
 
     # Makes directories
-    # ex. path('/home/me/parent/child').make_dir_recursively
-    'make_dir_recursively' { > :Dirpath (* :Attributes)
+    # ex. path('/home/me/parent/child').make_directory_recursively
+    'make_directory_recursively' { > :Dirpath (* :Attributes)
         Files.createDirectories(Dirpath *** Attributes)
         ()
     }

File src/test/kink/enhancertest/Path_test.kn

View file
     Child.check(Paths.get('/usr/local/bin'))
 }
 
-# Get a sibling via sibling with a string
+# Get a sibling via sibling_path with a string
 test {
     :Bin = Paths.get('/usr/local/bin')
-    :Lib = Bin.sibling('lib')
+    :Lib = Bin.sibling_path('lib')
     Lib.check(Paths.get('/usr/local/lib'))
 }
 
-# Get a sibling via sibling with a path
+# Get a sibling via sibling_path with a path
 test {
     :Bin = Paths.get('/usr/local/bin')
-    :Lib = Bin.sibling(Paths.get('lib'))
+    :Lib = Bin.sibling_path(Paths.get('lib'))
     Lib.check(Paths.get('/usr/local/lib'))
 }
 
-# Get a resolve via sibling with a path
-test {
-    :Bin = Paths.get('/usr/local/bin')
-    :Lib = Bin.sibling(Paths.get('lib'))
-    Lib.check(Paths.get('/usr/local/lib'))
-}
-
-# Get a relative path via op_sub with a string
+# Get a relative path via relative_path_from
 test {
     :Usr_local_bin = Paths.get('/usr/local/bin')
-    :Local_bin = Usr_local_bin - '/usr'
+    :Usr = Paths.get('/usr')
+    :Local_bin = Usr_local_bin.relative_path_from(Usr)
     Local_bin.check(Paths.get('local/bin'))
 }
 
-# Get a relative path via op_sub with a path
+# Get the basename from a path via base_path
 test {
     :Usr_local_bin = Paths.get('/usr/local/bin')
-    :Usr = Paths.get('/usr')
-    :Local_bin = Usr_local_bin - Usr
-    Local_bin.check(Paths.get('local/bin'))
-}
-
-# Get the leaf from a path via leaf
-test {
-    :Usr_local_bin = Paths.get('/usr/local/bin')
-    Usr_local_bin.leaf.check(Paths.get('bin'))
+    Usr_local_bin.base_path.check(Paths.get('bin'))
 }
 
 # Get the root of a path
 test {
-    Paths.get('/usr/local/bin').has_root?.check(true)
-    Paths.get('/usr/local/bin').root.check(Paths.get('/'))
-    Paths.get('bin/kink').has_root?.check(false)
+    Paths.get('/usr/local/bin').has_root_path?.check(true)
+    Paths.get('/usr/local/bin').root_path.check(Paths.get('/'))
+    Paths.get('bin/kink').has_root_path?.check(false)
 }
 
 # Normalize the path
 
 # Determine if the path is absolute or not
 test {
-    Paths.get(System.getProperty('user.dir')).absolute?.check(true)
-    Paths.get('bin').absolute?.check(false)
+    Paths.get(System.getProperty('user.dir')).absolute_path?.check(true)
+    Paths.get('bin').absolute_path?.check(false)
 }
 
 # Get the absolute path
 test {
     :Relative = Paths.get('bin')
-    Relative.absolute.check(Paths.get(System.getProperty('user.dir') 'bin'))
+    Relative.absolute_path.check(Paths.get(System.getProperty('user.dir') 'bin'))
 }
 
 # Get the real path
 test {
     :Relative = Paths.get('.')
-    Relative.real.check(Paths.get(System.getProperty('user.dir')))
+    Relative.real_path.check(Paths.get(System.getProperty('user.dir')))
 }
 
 #
     # with a prefix
     using_workdir { (:Work_dir)
         :Temp = Work_dir.make_temp_dir('tempdir')
-        Temp.dir?.check(true)
-        Temp.leaf.name.starts_with?('tempdir').check(true)
+        Temp.directory?.check(true)
+        Temp.base_path.name.starts_with?('tempdir').check(true)
     }
 }
 
     # without a prefix
     using_workdir { (:Work_dir)
         :Temp = Work_dir.make_temp_dir
-        Temp.dir?.check(true)
+        Temp.directory?.check(true)
     }
 }
 
     using_workdir { (:Work_dir)
         :Temp = Work_dir.make_temp_file('tempfile' '.log')
         Temp.file?.check(true)
-        Temp.leaf.name.starts_with?('tempfile').check(true)
-        Temp.leaf.name.ends_with?('.log').check(true)
+        Temp.base_path.name.starts_with?('tempfile').check(true)
+        Temp.base_path.name.ends_with?('.log').check(true)
     }
 }
 
     using_workdir { (:Work_dir)
         :Temp = Work_dir.make_temp_file('tempfile')
         Temp.file?.check(true)
-        Temp.leaf.name.starts_with?('tempfile').check(true)
-        Temp.leaf.name.ends_with?('.tmp').check(true)
+        Temp.base_path.name.starts_with?('tempfile').check(true)
+        Temp.base_path.name.ends_with?('.tmp').check(true)
     }
 }
 
     using_workdir { (:Work_dir)
         :Temp = Work_dir.make_temp_file
         Temp.file?.check(true)
-        Temp.leaf.name.ends_with?('.tmp').check(true)
+        Temp.base_path.name.ends_with?('.tmp').check(true)
     }
 }
 
     using_workdir { (:Work_dir)
         :Dir = Work_dir + 'dir_by_make_dir'
         Dir.make_dir
-        Dir.dir?.check(true)
+        Dir.directory?.check(true)
         # Cannot create an existing directory
         check_thrown { Dir.make_dir }
     }
 # Create directories
 test {
     using_workdir { (:Work_dir)
-        :Dir = Work_dir + 'parentdir/dir_by_make_dir_recursively'
-        Dir.make_dir_recursively
-        Dir.dir?.check(true)
+        :Dir = Work_dir + 'parentdir/dir_by_make_directory_recursively'
+        Dir.make_directory_recursively
+        Dir.directory?.check(true)
         # Do nothing for an existing directory
-        Dir.make_dir_recursively
+        Dir.make_directory_recursively
     }
 }
 
         :Dir = Work_dir + 'removed_by_delete'
         Dir.make_dir
         Dir.delete
-        Dir.dir?.check(false)
+        Dir.directory?.check(false)
     }
 }
 
         :Child_dir = Dir + 'childdir'
         Child_dir.make_dir
         Dir.delete_recursively
-        Dir.dir?.check(false)
+        Dir.directory?.check(false)
     }
 }
 
             :Symlink = Work_dir + 'symlink'
             Symlink.make_symlink(Paths.get('../target'))
             Dir.delete_recursively
-            Dir.dir?.check(false)
+            Dir.directory?.check(false)
             Target.file?.check(true)
         }
     }