Class: Guff::JavaSource::Class

Inherits:
Object
  • Object
show all
Includes:
AnnotationSupport, JavadocSupport, ModifierSupport, ScopeSupport
Defined in:
lib/guff/java_source.rb

Instance Method Summary collapse

Methods included from ScopeSupport

#package_local, #private, #protected, #public

Methods included from ModifierSupport

#abstract, #final, #modifiers, #static

Methods included from AnnotationSupport

#add_annotation, #annotations, #write_annotations_to

Methods included from JavadocSupport

#add_javadoc, #javadoc_lines, #write_javadoc_to

Constructor Details

#initialize(name, package, source_file) ⇒ Class

Returns a new instance of Class.



446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/guff/java_source.rb', line 446

def initialize(name, package, source_file)
    @name = name;
    @package = package
    @modifiers = ['public']
    @extends = nil
    @instance_methods = []
    @fields = []
    @constructors = []
    @source_file=source_file
    @genericized_using = ''
    @interfaces = nil
    @implements = nil
end

Instance Method Details

#add_constructorObject



505
506
507
508
509
# File 'lib/guff/java_source.rb', line 505

def add_constructor
    result = Constructor.new(self,@name)
    @constructors << result
    result
end

#add_field(name, type) ⇒ Object



460
461
462
463
464
# File 'lib/guff/java_source.rb', line 460

def add_field(name, type)
    f = Field.new(self,name, type)
    @fields << f
    f
end

#add_method(name) ⇒ Object



499
500
501
502
503
# File 'lib/guff/java_source.rb', line 499

def add_method(name)
    result = Method.new(self,name)
    @instance_methods << result
    result
end

#extends(d) ⇒ Object



489
490
491
492
# File 'lib/guff/java_source.rb', line 489

def extends(d)
    @extends = d
    self
end

#fully_qualified_nameObject



485
486
487
# File 'lib/guff/java_source.rb', line 485

def fully_qualified_name
    "#{@package}.#{@name}"
end

#genericized_using(g) ⇒ Object



476
477
478
479
# File 'lib/guff/java_source.rb', line 476

def genericized_using(g)
    @genericized_using = g
    self
end

#get_field_named(name) ⇒ Object



466
467
468
469
# File 'lib/guff/java_source.rb', line 466

def get_field_named(name)
    candidates = @fields.select {|field| field.named?(name)}
    return candidates.size == 1 ? candidates.first : nil;
end

#implements(*interfaces) ⇒ Object



494
495
496
497
# File 'lib/guff/java_source.rb', line 494

def implements(*interfaces)
    @implements = interfaces
    self
end

#import(i) ⇒ Object



471
472
473
474
# File 'lib/guff/java_source.rb', line 471

def import(i)
    @source_file.import(i)
    self
end

#nameObject



481
482
483
# File 'lib/guff/java_source.rb', line 481

def name
    @name
end

#write_to(writer) ⇒ Object



511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
# File 'lib/guff/java_source.rb', line 511

def write_to(writer)
    write_javadoc_to(writer)
    write_annotations_to(writer)
    writer.words(modifiers).word("class").word(@name).append(@genericized_using).word_with_prefix('extends', @extends).list_with_prefix('implements', @implements).open_brace

    @fields.each {|f|
        f.write_to(writer)
    }
    @constructors.each {|c|
        c.write_to(writer)
    }
    @instance_methods.each {|m|
        m.write_to(writer)
    }
    writer.close_brace
end