Skip to content

Commit cb7c20a

Browse files
committed
Udated to highest level of void-safety.
Fixed obsolete calls.
1 parent b7750b9 commit cb7c20a

File tree

3 files changed

+46
-53
lines changed

3 files changed

+46
-53
lines changed

library/json-safe.ecf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="ISO-8859-1"?>
2-
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="json" uuid="4E21C3BD-7951-4C6E-A673-431E762D7414" library_target="json">
2+
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="json" uuid="4E21C3BD-7951-4C6E-A673-431E762D7414" library_target="json">
33
<target name="json">
44
<root all_classes="true"/>
55
<file_rule>

library/kernel/converters/json_hash_table_converter.e

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
note
22
description: "A JSON converter for HASH_TABLE [ANY, HASHABLE]"
33
author: "Paul Cohen"
4-
date: "$Date$"
5-
revision: "$Revision$"
4+
date: "$Date: 2014-01-30 15:27:41 +0100 (jeu., 30 janv. 2014) $"
5+
revision: "$Revision: 94128 $"
66
file: "$HeadURL: $"
77

88
class JSON_HASH_TABLE_CONVERTER
@@ -27,42 +27,27 @@ feature -- Access
2727
feature -- Conversion
2828

2929
from_json (j: attached like to_json): like object
30-
local
31-
keys: ARRAY [JSON_STRING]
32-
i: INTEGER
33-
h: detachable HASHABLE
34-
jv: detachable JSON_VALUE
35-
a: detachable ANY
3630
do
37-
keys := j.current_keys
38-
create Result.make (keys.count)
39-
from
40-
i := 1
41-
until
42-
i > keys.count
31+
create Result.make (j.count)
32+
across
33+
j as ic
4334
loop
44-
h ?= json.object (keys [i], Void)
45-
check h /= Void end
46-
jv := j.item (keys [i])
47-
if jv /= Void then
48-
a := json.object (jv, Void)
49-
if a /= Void then
50-
Result.put (a, h)
51-
else
52-
check a_attached: a /= Void end
53-
end
54-
else
55-
check j_has_item: False end
35+
if attached json.object (ic.item, Void) as l_object then
36+
if attached {HASHABLE} json.object (ic.key, Void) as h then
37+
Result.put (l_object, h)
38+
else
39+
check key_is_hashable: False end
40+
end
41+
else
42+
check object_attached: False end
5643
end
57-
i := i + 1
5844
end
5945
end
6046

6147
to_json (o: like object): detachable JSON_OBJECT
6248
local
6349
c: HASH_TABLE_ITERATION_CURSOR [ANY, HASHABLE]
6450
js: JSON_STRING
65-
jv: detachable JSON_VALUE
6651
failed: BOOLEAN
6752
do
6853
create Result.make
@@ -76,8 +61,7 @@ feature -- Conversion
7661
else
7762
create js.make_json (c.key.out)
7863
end
79-
jv := json.value (c.item)
80-
if jv /= Void then
64+
if attached json.value (c.item) as jv then
8165
Result.put (jv, js)
8266
else
8367
failed := True

test/autotest/test_suite/test_json_suite.e

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,38 @@ feature -- JSON_FROM_FILE
475475
json_value: detachable JSON_VALUE
476476

477477
json_file_from (fn: STRING): detachable STRING
478+
local
479+
f: RAW_FILE
480+
l_path: STRING
481+
test_dir: STRING
482+
i: INTEGER
478483
do
479-
Result := file_reader.read_json_from (test_dir + fn)
484+
test_dir := (create {EXECUTION_ENVIRONMENT}).current_working_directory
485+
test_dir.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator)
486+
487+
l_path := test_dir + fn
488+
create f.make_with_name (l_path)
489+
if f.exists then
490+
-- Found json file
491+
else
492+
-- before EiffelStudio 7.3 , the current dir of autotest execution was not the parent dir of ecf but something like
493+
-- ..json\test\autotest\test_suite\EIFGENs\test_suite\Testing\execution\TEST_JSON_SUITE.test_json_fail1\..\..\..\..\..\fail1.json
494+
from
495+
i := 5
496+
until
497+
i = 0
498+
loop
499+
test_dir.append_character ('.')
500+
test_dir.append_character ('.')
501+
test_dir.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator)
502+
i := i - 1
503+
end
504+
l_path := test_dir + fn
505+
end
506+
create f.make_with_name (l_path)
507+
if f.exists then
508+
Result := file_reader.read_json_from (l_path)
509+
end
480510
assert ("File contains json data", Result /= Void)
481511
end
482512

@@ -485,30 +515,9 @@ feature -- JSON_FROM_FILE
485515
create Result.make_parser (a_string)
486516
end
487517

488-
test_dir: STRING
489-
local
490-
i: INTEGER
491-
do
492-
Result := (create {EXECUTION_ENVIRONMENT}).current_working_directory
493-
Result.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator)
494-
-- The should looks like
495-
-- ..json\test\autotest\test_suite\EIFGENs\test_suite\Testing\execution\TEST_JSON_SUITE.test_json_fail1\..\..\..\..\..\fail1.json
496-
from
497-
i := 5
498-
until
499-
i = 0
500-
loop
501-
Result.append_character ('.')
502-
Result.append_character ('.')
503-
Result.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator)
504-
i := i - 1
505-
end
506-
-- Result := "/home/jvelilla/work/project/Eiffel/ejson_dev/trunk/test/autotest/test_suite/"
507-
end
508518

509519
invariant
510520
file_reader /= Void
511521

512522
end
513523

514-

0 commit comments

Comments
 (0)