Skip to content

Commit

Permalink
Address PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
hubertp committed Jun 8, 2022
1 parent 92f39ba commit fcc650f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
17 changes: 11 additions & 6 deletions distribution/lib/Standard/Base/0.0.0-dev/src/System/File.enso
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ polyglot java import java.nio.file.Path
example_new = File.new Examples.csv_path
new : (Text | File) -> File
new path =
file = case path of
case path of
Text -> here.get_file path
File -> path
_ -> Error.throw (Illegal_Argument_Error "new file should be either a File or a Text")
file

## Open and reads all bytes in the file at the provided `path` into a byte vector.

Expand Down Expand Up @@ -683,7 +682,7 @@ type File
list name_filter=Nothing recursive=False =
all_files = case recursive of
True -> here.list_descendants this
False -> Vector.Vector (this.list_immediate_children)
False -> this.list_immediate_children
filtered = case name_filter of
Nothing -> all_files
_ ->
Expand All @@ -710,8 +709,14 @@ type File
## PRIVATE

Utility function that lists immediate children of a directory.
list_immediate_children : File -> Array File
list_immediate_children directory = @Builtin_Method "File.list_immediate_children"
list_immediate_children : Vector.Vector File
list_immediate_children = Vector.Vector (this.list_immediate_children_array)

## PRIVATE

Utility function that lists immediate children of a directory.
list_immediate_children_array : Array File
list_immediate_children_array = @Builtin_Method "File.list_immediate_children_array"

## PRIVATE

Expand Down Expand Up @@ -966,7 +971,7 @@ list_descendants file =
builder.append file
case file.is_directory of
True ->
children = Vector.Vector (file.list_immediate_children)
children = file.list_immediate_children
children.each go
False -> Nothing
go file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void createDirectories() {
}
}

@Builtin.Method(name = "list_immediate_children")
@Builtin.Method(name = "list_immediate_children_array")
@Builtin.WrapException(from = IOException.class, to = PolyglotError.class, propagate = true)
public EnsoFile[] list() throws IOException {
return this.truffleFile.list().stream().map(EnsoFile::new).toArray(EnsoFile[]::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,12 @@
* }
* </pre>
*
* Given the information from {@link WrapException#from()} and {@link WrapException#to()}
* elements, the processor knows that the call to {@code get()} has to be wrapped in try/catch,
* catching and re-throwing values of a particular type, respectively. The processor will
* automatically infer what parameters need to be passed to the new exception using the
* information from the {@link WrapException#to()} class.
* Given the information from {@link WrapException#from()} element the processor knows that the
* call to {@code get()} has to catch {@code IndexOutOfBounds} exception. {@link
* WrapException#to()}, in turn, means that the exception should be re-wrapped into {@code
* InvalidArrayIndexError} error. The processor will look at the constructor parameters of the
* target exception and opportunistically match them against arguments provided as the arguments
* of the called method, if possible.
*
* <p>The generated class will therefore ensure that calls to methods are safe and wrapped in an
* appropriate catch-clause:
Expand All @@ -195,8 +196,8 @@
* }
* </pre>
*
* <p>Simple exception propagation is also possible by setting the {@link
* WrapException#propagate()} element to true:
* <p>Simple exception propagation, without passing method's arguments, is also possible by
* setting the {@link WrapException#propagate()} element to true:
*
* <pre>
* class Foo {
Expand Down

0 comments on commit fcc650f

Please sign in to comment.