Class: CoderCompanion::Java::MemberVariable

Inherits:
Treetop::Runtime::SyntaxNode
  • Object
show all
Defined in:
lib/codercompanion/java/java.rb

Instance Method Summary collapse

Instance Method Details

#buildObject



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
# File 'lib/codercompanion/java/java.rb', line 184

def build
    variable_type = ''
    privacy = ''
    variable_name = ''
    type = ''
    qualifiers = []
    variables = []
    elements.each do |e|
        if e.respond_to? :qualifiers
            qualifiers = e.elements[0].text_value
            privacy = CoderCompanion::Java.extract_privacy(qualifiers)
            if CoderCompanion::Java.has_final_qualifier(qualifiers) && CoderCompanion::Java.has_static_qualifier(qualifiers)
                variable_type = 'constant'
            elsif !CoderCompanion::Java.has_final_qualifier(qualifiers) && CoderCompanion::Java.has_static_qualifier(qualifiers)
                variable_type = 'class_variable'
            else
                variable_type = 'instance_variable'
            end
        end
        variables = e.build if e.respond_to? :build
        type = e.text_value if e.respond_to? :type
        variable_name = e.text_value if e.respond_to? :variable_defined
    end

    to_return = []
    variables.each do |v|
        to_return.push( {:type => 'variable_definition', :value => v.gsub(/[\s]+/, ' '), :return_type => type, :privacy => privacy, :variable_type => variable_type})
    end
    return to_return
end