Class: Steep::Drivers::Annotations

Inherits:
Object
  • Object
show all
Includes:
Utils::DriverHelper
Defined in:
lib/steep/drivers/annotations.rb

Instance Attribute Summary collapse

Attributes included from Utils::DriverHelper

#steepfile

Instance Method Summary collapse

Methods included from Utils::DriverHelper

#load_config, #type_check

Constructor Details

#initialize(stdout:, stderr:) ⇒ Annotations

Returns a new instance of Annotations.



11
12
13
14
15
16
17
# File 'lib/steep/drivers/annotations.rb', line 11

def initialize(stdout:, stderr:)
  @stdout = stdout
  @stderr = stderr

  @command_line_patterns = []
  @labeling = ASTUtils::Labeling.new
end

Instance Attribute Details

#command_line_patternsObject (readonly)

Returns the value of attribute command_line_patterns.



4
5
6
# File 'lib/steep/drivers/annotations.rb', line 4

def command_line_patterns
  @command_line_patterns
end

#labelingObject (readonly)

Returns the value of attribute labeling.



7
8
9
# File 'lib/steep/drivers/annotations.rb', line 7

def labeling
  @labeling
end

#stderrObject (readonly)

Returns the value of attribute stderr.



6
7
8
# File 'lib/steep/drivers/annotations.rb', line 6

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



5
6
7
# File 'lib/steep/drivers/annotations.rb', line 5

def stdout
  @stdout
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/steep/drivers/annotations.rb', line 19

def run
  project = load_config()

  loader = Project::FileLoader.new(project: project)
  loader.load_sources(command_line_patterns)
  loader.load_signatures()

  project.targets.each do |target|
    Steep.logger.tagged "target=#{target.name}" do
      target.load_signatures do |_, subtyping, _|
        case (status = target.status)
        when nil     # status set on error cases
          target.source_files.each_value do |file|
            file.parse(subtyping.factory) do |source|
              source.each_annotation.sort_by {|node, _| [node.loc.expression.begin_pos, node.loc.expression.end_pos] }.each do |node, annotations|
                loc = node.loc
                stdout.puts "#{file.path}:#{loc.line}:#{loc.column}:#{node.type}:\t#{node.loc.expression.source.lines.first}"
                annotations.each do |annotation|
                  stdout.puts "  #{annotation.location.source}"
                end
              end
            end
          end
        when Project::Target::SignatureSyntaxErrorStatus
          printer = SignatureErrorPrinter.new(stdout: stdout, stderr: stderr)
          printer.print_syntax_errors(status.errors)
        when Project::Target::SignatureValidationErrorStatus
          printer = SignatureErrorPrinter.new(stdout: stdout, stderr: stderr)
          printer.print_semantic_errors(status.errors)
        end
      end
    end
  end

  project.targets.each do |target|
    Steep.logger.tagged "target=#{target.name}" do
    end
  end

  project.targets.all? {|target| !target.status } ? 0 : 1
end