Lines 1-111
Link Here
|
1 |
############################################################################### |
1 |
############################################################################### |
2 |
# Copyright (c) 2005, 2007 IBM Corporation and others. |
2 |
# Copyright (c) 2005, 2007 IBM Corporation and others. |
3 |
# All rights reserved. This program and the accompanying materials |
3 |
# All rights reserved. This program and the accompanying materials |
4 |
# are made available under the terms of the Eclipse Public License v1.0 |
4 |
# are made available under the terms of the Eclipse Public License v1.0 |
5 |
# which accompanies this distribution, and is available at |
5 |
# which accompanies this distribution, and is available at |
6 |
# http://www.eclipse.org/legal/epl-v10.html |
6 |
# http://www.eclipse.org/legal/epl-v10.html |
7 |
# |
7 |
# |
8 |
|
8 |
|
9 |
############################################################################### |
9 |
############################################################################### |
10 |
|
10 |
|
11 |
|
11 |
|
12 |
def has_children(obj) |
12 |
def has_children(obj) |
13 |
atomic_types = [NilClass, TrueClass, FalseClass, Fixnum, String, Symbol] |
13 |
atomic_types = [NilClass, TrueClass, FalseClass, |
14 |
not atomic_types.include?(obj.class) |
14 |
Numeric, Float, Integer, Fixnum, Bignum, |
15 |
end |
15 |
String] |
16 |
|
16 |
not atomic_types.include?(obj.class) |
17 |
def get_string(obj) |
17 |
end |
18 |
obj.nil? ? 'nil' : (has_children(obj) ? '' : obj.to_s) |
18 |
|
19 |
end |
19 |
def get_string(obj) |
20 |
|
20 |
obj.nil? ? 'nil' : (has_children(obj) ? '' : obj.to_s) |
21 |
def prepare_object(name, obj) |
21 |
end |
22 |
x = { :name => name, |
22 |
|
23 |
:eval_name => name, |
23 |
def prepare_object(name, obj) |
24 |
:_type => obj.class, |
24 |
x = { :name => name, |
25 |
:is_cosntant => false, |
25 |
:eval_name => name, |
26 |
:has_children => has_children(obj), |
26 |
:_type => obj.class, |
27 |
:_value => get_string(obj), |
27 |
:is_cosntant => false, |
28 |
:key => obj.object_id } |
28 |
:has_children => has_children(obj), |
29 |
|
29 |
:_value => get_string(obj), |
30 |
if x[:has_children] |
30 |
:key => obj.object_id } |
31 |
children = obj.instance_variables.collect { |var| |
31 |
|
32 |
real_var = obj.instance_variable_get(var) |
32 |
if x[:has_children] |
33 |
|
33 |
children = obj.instance_variables.collect { |var| |
34 |
{ :name => var, |
34 |
real_var = obj.instance_variable_get(var) |
35 |
:eval_name => sprintf("%s.instance_eval('%s')", name, var), |
35 |
|
36 |
:_type => real_var.class, |
36 |
{ :name => var, |
37 |
:is_constant => false, |
37 |
:eval_name => sprintf("%s.instance_eval('%s')", name, var), |
38 |
:has_children => has_children(real_var), |
38 |
:_type => real_var.class, |
39 |
:_value => get_string(real_var), |
39 |
:is_constant => false, |
40 |
:key => real_var.object_id } |
40 |
:has_children => has_children(real_var), |
41 |
} |
41 |
:_value => get_string(real_var), |
42 |
|
42 |
:key => real_var.object_id } |
43 |
x[:num_children] = children.length |
43 |
} |
44 |
x[:children_props] = children |
44 |
|
45 |
end |
45 |
x[:num_children] = children.length |
46 |
|
46 |
x[:children_props] = children |
47 |
x |
47 |
end |
48 |
end |
48 |
|
49 |
|
49 |
x |
50 |
def prepare_array(name, array) |
50 |
end |
51 |
x = { :name => name, |
51 |
|
52 |
:eval_name => name, |
52 |
def prepare_array(name, array) |
53 |
:_type => array.class, |
53 |
x = { :name => name, |
54 |
:is_cosntant => false, |
54 |
:eval_name => name, |
55 |
:has_children => true, |
55 |
:_type => array.class, |
56 |
:_value => '[...]', |
56 |
:is_cosntant => false, |
57 |
:key => array.object_id } |
57 |
:has_children => true, |
58 |
|
58 |
:_value => '[...]', |
59 |
index = -1 |
59 |
:key => array.object_id } |
60 |
children = array.collect { |value| |
60 |
|
61 |
index += 1 |
61 |
index = -1 |
62 |
|
62 |
children = array.collect { |value| |
63 |
{ :name => sprintf('[%d]', index), |
63 |
index += 1 |
64 |
:eval_name => sprintf('%s[%d]', name, index), |
64 |
|
65 |
:_type => value.class, |
65 |
{ :name => sprintf('[%d]', index), |
66 |
:is_constant => false, |
66 |
:eval_name => sprintf('%s[%d]', name, index), |
67 |
:has_children => has_children(value), |
67 |
:_type => value.class, |
68 |
:_value => get_string(value), |
68 |
:is_constant => false, |
69 |
:key => value.object_id } |
69 |
:has_children => has_children(value), |
70 |
} |
70 |
:_value => get_string(value), |
71 |
|
71 |
:key => value.object_id } |
72 |
x[:num_children] = children.length |
72 |
} |
73 |
x[:children_props] = children |
73 |
|
74 |
x |
74 |
x[:num_children] = children.length |
75 |
end |
75 |
x[:children_props] = children |
76 |
|
76 |
x |
77 |
def prepare_hash(name, hash) |
77 |
end |
78 |
x = { :name => name, |
78 |
|
79 |
:eval_name => name, |
79 |
def prepare_hash(name, hash) |
80 |
:_type => hash.class, |
80 |
x = { :name => name, |
81 |
:is_cosntant => false, |
81 |
:eval_name => name, |
82 |
:has_children => true, |
82 |
:_type => hash.class, |
83 |
:_value => '{...}', |
83 |
:is_cosntant => false, |
84 |
:key => hash.object_id } |
84 |
:has_children => true, |
85 |
|
85 |
:_value => '{...}', |
86 |
children = hash.collect { |key, value| |
86 |
:key => hash.object_id } |
87 |
{ :name => sprintf("[%s]", key.inspect), |
87 |
|
88 |
:eval_name => sprintf("%s[%s]", name, key.inspect), |
88 |
children = hash.collect { |key, value| |
89 |
:_type => value.class, |
89 |
{ :name => sprintf("[%s]", key.inspect), |
90 |
:is_constant => false, |
90 |
:eval_name => sprintf("%s[%s]", name, key.inspect), |
91 |
:has_children => has_children(value), |
91 |
:_type => value.class, |
92 |
:_value => get_string(value), |
92 |
:is_constant => false, |
93 |
:key => value.object_id } |
93 |
:has_children => has_children(value), |
94 |
} |
94 |
:_value => get_string(value), |
95 |
|
95 |
:key => value.object_id } |
96 |
x[:num_children] = children.length |
96 |
} |
97 |
x[:children_props] = children |
97 |
|
98 |
x |
98 |
x[:num_children] = children.length |
99 |
end |
99 |
x[:children_props] = children |
100 |
|
100 |
x |
101 |
def make_property(name, obj) |
101 |
end |
102 |
type = obj.class |
102 |
|
103 |
|
103 |
def prepare_match_data(name, obj) |
104 |
if type == Hash |
104 |
x = { :name => name, |
105 |
prepare_hash(name, obj) |
105 |
:eval_name => name, |
106 |
elsif type == Array |
106 |
:_type => obj.class, |
107 |
prepare_array(name, obj) |
107 |
:is_cosntant => false, |
108 |
else |
108 |
:has_children => true, |
109 |
prepare_object(name, obj) |
109 |
:_value => '[...]', |
110 |
end |
110 |
:key => obj.object_id } |
111 |
end |
111 |
|
|
|
112 |
index = -1 |
113 |
children = obj.to_a.collect { |value| |
114 |
index += 1 |
115 |
|
116 |
{ :name => sprintf('[%d]', index), |
117 |
:eval_name => sprintf('%s[%d]', name, index), |
118 |
:_type => value.class, |
119 |
:is_constant => false, |
120 |
:has_children => has_children(value), |
121 |
:_value => get_string(value), |
122 |
:key => value.object_id } |
123 |
} |
124 |
|
125 |
x[:num_children] = children.length |
126 |
x[:children_props] = children |
127 |
x |
128 |
end |
129 |
|
130 |
def make_property(name, obj) |
131 |
type = obj.class |
132 |
|
133 |
if type == Hash |
134 |
prepare_hash(name, obj) |
135 |
elsif type == Array |
136 |
prepare_array(name, obj) |
137 |
elsif type == MatchData |
138 |
prepare_match_data(name, obj) |
139 |
else |
140 |
prepare_object(name, obj) |
141 |
end |
142 |
end |