Class: GSONClassGenerator::JavaField

Inherits:
Object
  • Object
show all
Defined in:
lib/gson-class-generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value) ⇒ JavaField

Returns a new instance of JavaField.



244
245
246
247
248
249
250
# File 'lib/gson-class-generator.rb', line 244

def initialize(key, value)
	@array_dimens = self.class.array_dimens(value)
	@json_key = key
	@name = self.class.javaify_key(key, self.is_array?)
	@java_class = self.class.class_for_value(key, value)
	@custom_class = !JAVA_TYPES.value?(@java_class)
end

Instance Attribute Details

#java_classObject (readonly)

Returns the value of attribute java_class.



242
243
244
# File 'lib/gson-class-generator.rb', line 242

def java_class
  @java_class
end

#nameObject (readonly)

Returns the value of attribute name.



242
243
244
# File 'lib/gson-class-generator.rb', line 242

def name
  @name
end

Instance Method Details

#custom_class?Boolean

Returns:

  • (Boolean)


256
257
258
# File 'lib/gson-class-generator.rb', line 256

def custom_class?
	@custom_class
end

#default_initalized_object(opts) ⇒ Object



295
296
297
298
299
300
301
# File 'lib/gson-class-generator.rb', line 295

def default_initalized_object(opts)
	if (opts.boxed_primatives?)
		"null"
	else
		JAVA_DEFAULT_INITIALIZED_PRIMATIVES.fetch(@java_class, "null")
	end
end

#is_array?Boolean

Returns:

  • (Boolean)


252
253
254
# File 'lib/gson-class-generator.rb', line 252

def is_array?
	@array_dimens > 0
end

#type_definition(opts) ⇒ Object



286
287
288
289
290
291
292
293
# File 'lib/gson-class-generator.rb', line 286

def type_definition(opts)
	class_name = @java_class
	if (opts.boxed_primatives?)
		class_name = JAVA_TYPES_BOXED.fetch(class_name, @java_class)
	end
	array_def = Array.new(@array_dimens, "[]").join
	"#{class_name}#{array_def}"
end

#write_accessors(stream, tabs, opts) ⇒ Object



277
278
279
280
281
282
283
284
# File 'lib/gson-class-generator.rb', line 277

def write_accessors(stream, tabs, opts)
	if (opts.getters?)
		write_getter_definition(stream, tabs)
	end
	if (opts.setters?)
		write_setter_definition(stream, tabs)
	end
end

#write_constructor_assignment(stream, tabs, opts) ⇒ Object



272
273
274
275
# File 'lib/gson-class-generator.rb', line 272

def write_constructor_assignment(stream, tabs, opts)
	stream << tabs
	stream << "this.#{@name} = #{@name};\n"
end

#write_declaration(stream, tabs, opts) ⇒ Object



260
261
262
263
264
265
# File 'lib/gson-class-generator.rb', line 260

def write_declaration(stream, tabs, opts)
	stream << tabs
	stream << serialized_name_definition
	stream << tabs
	stream << field_definition(opts)
end

#write_default_constructor_assignment(stream, tabs, opts) ⇒ Object



267
268
269
270
# File 'lib/gson-class-generator.rb', line 267

def write_default_constructor_assignment(stream, tabs, opts)
	stream << tabs
	stream << "#{@name} = #{default_initalized_object(opts)};\n"
end