Class: Archruby::Architecture::TypeInferenceChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/archruby/architecture/type_inference_checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dependencies = nil) ⇒ TypeInferenceChecker



8
9
10
11
12
13
14
# File 'lib/archruby/architecture/type_inference_checker.rb', line 8

def initialize(dependencies=nil)
  @dependencies = dependencies
  # @method_and_deps = []
  # @method_calls = []
  # @method_and_deps = method_and_deps unless method_and_deps.nil?
  # @method_calls = method_calls unless method_calls.nil?
end

Instance Attribute Details

#dependenciesObject (readonly)

attr_reader :method_and_deps, :method_calls



6
7
8
# File 'lib/archruby/architecture/type_inference_checker.rb', line 6

def dependencies
  @dependencies
end

Instance Method Details

#add_method_calls(method_calls) ⇒ Object



25
26
27
28
# File 'lib/archruby/architecture/type_inference_checker.rb', line 25

def add_method_calls(method_calls)
  @method_calls << method_calls
  @method_calls.flatten!
end

#add_method_deps(method_deps) ⇒ Object



20
21
22
23
# File 'lib/archruby/architecture/type_inference_checker.rb', line 20

def add_method_deps(method_deps)
  @method_and_deps << method_deps
  @method_and_deps.flatten!
end

#add_new_deps(modules) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/archruby/architecture/type_inference_checker.rb', line 30

def add_new_deps(modules)
  @dependencies.each do |klass, dependencies|
    modules.each do |modl|
      if !klass.nil? && modl.is_mine?(klass)
        dependencies.each do |class_dep_name|
          modl.add_new_dep(klass, class_dep_name)
        end
      end
    end
  end
  # @method_and_deps.each do |dep|
  #   modules.each do |modl|
  #     if !dep[:class_name].nil? && modl.is_mine?(dep[:class_name])
  #       dep[:dep].each do |class_dep|
  #         modl.add_new_dep(dep[:class_name], class_dep)
  #         binding.pry
  #       end
  #     end
  #   end
  # end
end

#populate_dependencies(dependencies) ⇒ Object



16
17
18
# File 'lib/archruby/architecture/type_inference_checker.rb', line 16

def populate_dependencies(dependencies)
  @dependencies = dependencies
end

#verify_typesObject



52
53
54
55
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
# File 'lib/archruby/architecture/type_inference_checker.rb', line 52

def verify_types
  3.times do
    @method_calls.each do |method_call|
      if !method_call[:method_call_params].nil?
        method_call[:method_call_params].each do |param|
          if method_call[:method_arguments] && method_call[:method_arguments].include?(param)
            param_position = method_call[:method_arguments].index param
            if !param_position.nil?
              @method_and_deps.each do |dep|
                if dep[:class_name] == method_call[:class]
                  class_dep = dep[:dep][param_position]
                  if class_dep
                    new_dep = Archruby::Ruby::TypeInferenceDep.new(
                      :class_dep => class_dep.class_dep
                    )
                    add_method_deps([{
                      :class_name => method_call[:class_call],
                      :method_name => method_call[:method_call],
                      :dep => [new_dep] # tem que ser adicionado na posicao param_position
                    }])
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end