Module: XDry
- Defined in:
- lib/xdry.rb,
lib/xdry/run.rb,
lib/xdry/boxing.rb,
lib/xdry/parsing/pos.rb,
lib/xdry/parsing/model.rb,
lib/xdry/parsing/nodes.rb,
lib/xdry/parsing/driver.rb,
lib/xdry/parsing/scopes.rb,
lib/xdry/parsing/parsers.rb,
lib/xdry/patching/emitter.rb,
lib/xdry/patching/patcher.rb,
lib/xdry/generators/dealloc.rb,
lib/xdry/parsing/scope_stack.rb,
lib/xdry/generators/synthesize.rb,
lib/xdry/parsing/scopes_support.rb,
lib/xdry/patching/item_patchers.rb,
lib/xdry/parsing/parts/selectors.rb,
lib/xdry/parsing/parts/var_types.rb,
lib/xdry/support/string_additions.rb,
lib/xdry/support/symbol_additions.rb,
lib/xdry/patching/insertion_points.rb,
lib/xdry/generators/ctor_from_field.rb,
lib/xdry/generators/dictionary_coding.rb,
lib/xdry/support/enumerable_additions.rb,
lib/xdry/generators/field_from_property.rb,
lib/xdry/generators/property-from-field.rb,
lib/xdry/generators/storing_constructor.rb
Defined Under Namespace
Modules: Boxing, EnumerableAdditions, Generators, RetainPolicy, StringAdditions, SymbolAdditions
Classes: AfterDefineIP, BaseFileRef, BeforeImplementationStartIP, BeforeInterfaceEndIP, BeforeReturnIP, BeforeSuperCallIP, ChildScope, CompoundSelectorDef, Config, Emitter, FileRef, IdVarType, ImplementationStartIP, InsertionPoint, InsideConstructorIfSuperIP, ItemPatcher, MethodPatcher, MultiIP, NClosingBrace, NDefine, NEnd, NFieldDef, NFullLineMarker, NImplementationStart, NInterfaceFieldsEnd, NInterfaceStart, NLine, NMarker, NMethodEnd, NMethodHeader, NMethodStart, NOpeningBrace, NPartLineMarker, NPropertyDef, NReleaseCall, NReturn, NSuperCall, NSynthesize, Node, OAttribute, OClass, OGlobal, OMethod, PGlobal, PInterfaceFields, PInterfaceHeader, PMethodImpl, Parser, ParsingDriver, Patcher, PointerPointerVarType, PointerVarType, Pos, SFile, SImplementation, SInterface, SInterfaceFields, SMethodImpl, Scope, ScopeStack, SelectorComponent, SelectorDef, SimpleSelectorDef, SimpleVarType, SynthesizeItem, TestFileRef, UnknownVarType, VarType
Constant Summary
collapse
- INDENT_STEP =
FIXME: all usages of this should be changed to something smart
"\t"
- FIELD_PREFIX =
FIXME: all usages of this should be changed to something smart
"_"
Class Method Summary
collapse
Class Method Details
.parse_command_line_config(args) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/xdry/run.rb', line 56
def self.parse_command_line_config(args)
config = Config.new
opts = OptionParser.new do |opts|
opts.banner = "Usage: xdry [options]"
opts.separator ""
opts.separator "General options:"
opts.on("-w", "--watch", "Watch for file system changes and rerun each time .h/.m is modified") do
config.watch = true
end
opts.separator ""
opts.separator "Filtering options:"
opts.on("-o", "--only=MASK", "Only process files matching this mask") do |v|
config.only = v
end
opts.separator ""
opts.separator "Choosing which generators to run:"
opts.on("-e", "--enable-only=LIST", "Only run the given generators (e.g.: -e dealloc,synth)") do |v|
config.enable_only = v.split(",").collect { |n| n.strip }
all = XDry::Generators::ALL.collect { |kl| kl.id }
unless (unsup = config.enable_only - all).empty?
puts "Unknown generator names in -e: #{unsup.join(', ')}."
puts "Supported names are: #{all.join(', ')}."
exit 1
end
end
opts.on("-d", "--disable=LIST", "Disable the given generators (e.g.: -d dealloc,synth)") do |v|
config.disable = v.split(",").collect { |n| n.strip }
all = XDry::Generators::ALL.collect { |kl| kl.id }
unless (unsup = config.disable - all).empty?
puts "Unknown generator names in -d: #{unsup.join(', ')}."
puts "Supported names are: #{all.join(', ')}."
exit 1
end
end
opts.on("--list", "List all supported generators and exit") do |v|
XDry::Generators::ALL.each { |kl| puts "#{kl.id}" }
exit
end
opts.separator ""
opts.separator "Patching options:"
opts.on("-n", "--dry-run", "Save changed files as .xdry.{h/m}") do |v|
config.dry_run = true
end
opts.separator ""
opts.separator "Common options:"
opts.on("-v", "--verbose", "Print TONS of progress information") do
config.verbose = true
end
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
end
opts.parse!(args)
return config
end
|
.produce_everything(oglobal, patcher, config) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/xdry/run.rb', line 5
def self.produce_everything oglobal, patcher, config
puts "Generating code... " if config.verbose
generators = Generators::ALL.select { |klass| config.enabled?(klass.id) }.
collect { |klass| klass.new(config, patcher) }
if config.verbose
puts "Running generators: " + generators.collect { |gen| gen.class.id }.join(", ")
end
oglobal.classes.each do |oclass|
puts " - #{oclass.name}" if config.verbose
if config.verbose
oclass.attributes.each do |oattr|
puts " #{oattr}"
end
oclass.methods.each do |omethod|
puts " #{omethod}"
end
oclass.implementations.each do |nimpl|
puts " #{nimpl}"
nimpl.synthesizes.each do |nsynth|
puts " #{nsynth}"
end
end
end
generators.each { |gen| gen.process_class(oclass) }
end
end
|
.run(args) ⇒ Object
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
# File 'lib/xdry/run.rb', line 178
def self.run args
config = parse_command_line_config(args)
while Dir.pwd != '/' && Dir['*.xcodeproj'] == []
Dir.chdir('..')
end
if Dir['*.xcodeproj'] == []
puts "Cannot find *.xcodeproj in any of the parent directories. Stop."
exit 1
end
changed_file_refs = run_once config
if config.watch
require 'rubygems'
require 'fssm'
rebuild = lambda do |base, relative|
unless File.basename(relative) == 'xdry.m'
changed_file_refs = run_once(config)
unless changed_file_refs.empty?
system "growlnotify", "-a", "Xcode", "-t", "XD.R.Y.", "-m", "Updating..."
system "osascript", "-e", '
tell application "Finder" to activate
delay 0.3
tell application "Xcode" to activate
delay 0.5
tell application "System Events" to keystroke "u" using {command down}
'
system "growlnotify", "-a", "Xcode", "-t", "XD.R.Y.", "-m", "Updated!"
end
end
end
puts
puts "Monitoring for file system changes..."
FSSM.monitor '.', ['**/*.{h,m}'] do |monitor|
monitor.create &rebuild
monitor.update &rebuild
monitor.delete &rebuild
end
else
if changed_file_refs.empty?
puts "No changes."
else
puts "Modified:"
changed_file_refs.each { |ref| puts "-> #{ref.path}" }
end
end
end
|
.run_once(config) ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/xdry/run.rb', line 130
def self.run_once config
oglobal = OGlobal.new
parser = ParsingDriver.new(oglobal)
parser.verbose = config.verbose
Dir["**/*.m"].each do |m_file|
next if config.only and not File.fnmatch(config.only, m_file)
next if m_file =~ /\.xdry\./
h_file = m_file.sub /\.m$/, '.h'
if File.file? h_file
puts h_file if config.verbose
parser.parse_file(h_file)
parser.parse_file(m_file)
end
end
patcher = Patcher.new
patcher.dry_run = config.dry_run
patcher.verbose = config.verbose
parser.markers.each { |marker| patcher.remove_marker! marker }
self.produce_everything(oglobal, patcher, config)
return patcher.save!
end
|
.test_run(sources, config) ⇒ Object
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/xdry/run.rb', line 159
def self.test_run sources, config
oglobal = OGlobal.new
parser = ParsingDriver.new(oglobal)
parser.verbose = config.verbose
sources.each do |file_path, content|
parser.parse_string file_path, content
end
patcher = Patcher.new
patcher.verbose = config.verbose
parser.markers.each { |marker| patcher.remove_marker! marker }
self.produce_everything(oglobal, patcher, config)
return patcher.retrieve!
end
|