Module: Steep::AnnotationsHelper

Defined in:
lib/steep/annotations_helper.rb

Class Method Summary collapse

Class Method Details

.deprecated_annotation?(annotations) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/steep/annotations_helper.rb', line 5

def deprecated_annotation?(annotations)
  annotations.reverse_each do |annotation|
    if match = annotation.string.match(/deprecated(:\s*(?<message>.+))?/)
      return [annotation, match[:message]]
    end
    if match = annotation.string.match(/steep:deprecated(:\s*(?<message>.+))?/)
      return [annotation, match[:message]]
    end
  end

  nil
end

.deprecated_type_name?(type_name, env) ⇒ Boolean

Returns:

  • (Boolean)


18
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
# File 'lib/steep/annotations_helper.rb', line 18

def deprecated_type_name?(type_name, env)
  annotations =
    case
    when type_name.class?
      case
      when decl = env.class_decls.fetch(type_name, nil)
        decl.each_decl.flat_map do |decl|
          if decl.is_a?(RBS::AST::Declarations::Base)
            decl.annotations
          else
            []
          end
        end
      when decl = env.class_alias_decls.fetch(type_name, nil)
        if decl.decl.is_a?(RBS::AST::Declarations::Base)
          decl.decl.annotations
        else
          [] #: Array[RBS::AST::Annotation]
        end
      end
    when type_name.interface?
      if decl = env.interface_decls.fetch(type_name, nil)
        decl.decl.annotations
      end
    when type_name.alias?
      if decl = env.type_alias_decls.fetch(type_name, nil)
        decl.decl.annotations
      end
    end

  if annotations
    deprecated_annotation?(annotations)
  end
end