inch 0.8.0 → 0.9.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29bc9c4b46f07aaf233599632985990b384221ba
4
- data.tar.gz: df72afb72418770a8899c7043c0c461e21df9109
3
+ metadata.gz: 41b166a382d6ff1de903e59116bec0d8c6b37f5e
4
+ data.tar.gz: 9cafc658d7c863fe4f50a73679608c5cb9b5d15d
5
5
  SHA512:
6
- metadata.gz: 17a83dc980f62350222348ac204d6a74c1bdfae464da29c01df42148d36a4f9fa64b4da3afeeae5eebc7bec18a1df649b961f5f44cabdc830e82cf4c17fc1dcc
7
- data.tar.gz: a8673887c631d5113a65db7e2e3fa4f57438e3557cbfdc6642e71a419fa35483d9a98e68b3c6999f95a1a284ea350590d73a12b67c756987528c68979f7cd9a9
6
+ metadata.gz: d51519e786205c2a8f5e199b38625834dc8be8767850f9a964e799f27e4db53450ec5655d588a8fcb21aa609b080c7f7c3be6590be047e535862804d1975b4db
7
+ data.tar.gz: 5fa8fb528ccb9a94cb884f7eabbe0cd5c7163a5f9cbd196ca573cc93dda8b75351a3252d3a6e2fc5ff03510c9cb73f0a5aeddbf087e7a4d3d9ca1f1afb7373b7
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.0
4
+
5
+ - Elixir: Add support for API format of InchEx v2
6
+
3
7
  ## 0.8.0
4
8
 
5
9
  - CLI: Do not include `Term::ANSIColor` into `String`
@@ -0,0 +1,92 @@
1
+ require 'json'
2
+ require 'inch/language/elixir/provider/reader/object'
3
+ require 'inch/language/elixir/provider/reader_v2/object'
4
+
5
+ module Inch
6
+ module Language
7
+ module Elixir
8
+ module Provider
9
+ # Parses the source tree (using Reader)
10
+ class Parser
11
+ attr_reader :objects
12
+
13
+ # Helper method to parse an instance with the given +args+
14
+ #
15
+ # @see #parse
16
+ # @return [CodeObject::Provider::Reader::Parser] the instance that
17
+ # ran
18
+ def self.parse(*args)
19
+ parser = new
20
+ parser.parse(*args)
21
+ parser
22
+ end
23
+
24
+ # @param dir [String] directory
25
+ # @param config [Inch::Config::Codebase] configuration for codebase
26
+ # @return [void]
27
+ def parse(dir, config)
28
+ raise "Directory does not exist: #{dir}" if !File.exist?(dir)
29
+ Dir.chdir(dir) do
30
+ parse_objects(config.included_files, config.excluded_files,
31
+ config.read_dump_file)
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def parse_objects(_paths, _excluded, read_dump_file = nil)
38
+ if read_dump_file.nil?
39
+ fail 'Elixir analysis only works with --read-from-dump.'
40
+ else
41
+ output = File.read(read_dump_file, :encoding => 'utf-8')
42
+ end
43
+
44
+ json = JSON[output]
45
+ is_version1 = !!json['objects']
46
+
47
+ if is_version1
48
+ @objects = parse_objects_v1 json['objects']
49
+ else
50
+ @objects = parse_objects_v2 json['results']
51
+ end
52
+ end
53
+
54
+ def parse_objects_v1(parsed_objects)
55
+ list = parsed_objects.map do |o|
56
+ Reader::Object.for(o) # unless IGNORE_TYPES.include?(o.type)
57
+ end.compact
58
+ children_map = {}
59
+ list.each do |object|
60
+ if object.parent_fullname
61
+ children_map[object.parent_fullname] ||= []
62
+ children_map[object.parent_fullname] << object.fullname
63
+ end
64
+ end
65
+ list.each do |object|
66
+ object.children_fullnames = children_map[object.fullname]
67
+ end
68
+ list
69
+ end
70
+
71
+ def parse_objects_v2(parsed_objects)
72
+ list = parsed_objects.map do |o|
73
+ ReaderV2::Object.for(o) # unless IGNORE_TYPES.include?(o.type)
74
+ end.compact
75
+ children_map = {}
76
+ list.each do |object|
77
+ if object.parent_fullname
78
+ children_map[object.parent_fullname] ||= []
79
+ children_map[object.parent_fullname] << object.fullname
80
+ end
81
+ end
82
+ list.each do |object|
83
+ object.children_fullnames = children_map[object.fullname]
84
+ end
85
+ list
86
+ end
87
+
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'inch/language/elixir/provider/parser'
2
3
 
3
4
  module Inch
4
5
  module Language
@@ -15,5 +16,3 @@ module Inch
15
16
  end
16
17
  end
17
18
  end
18
-
19
- require 'inch/language/elixir/provider/reader/parser'
@@ -0,0 +1,13 @@
1
+
2
+ module Inch
3
+ module Language
4
+ module Elixir
5
+ module Provider
6
+ module ReaderV2
7
+ class Docstring < Ruby::Provider::YARD::Docstring
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,61 @@
1
+ require 'inch/language/elixir/provider/reader_v2/object/base'
2
+ require 'inch/language/elixir/provider/reader_v2/object/function_object'
3
+ require 'inch/language/elixir/provider/reader_v2/object/module_object'
4
+ require 'inch/language/elixir/provider/reader_v2/object/type_object'
5
+
6
+ module Inch
7
+ module Language
8
+ module Elixir
9
+ module Provider
10
+ module ReaderV2
11
+ # CodeObject::Provider::JSDoc::Object object represent code objects.
12
+ #
13
+ module Object
14
+ class << self
15
+ def clear_cache
16
+ @cache = {}
17
+ end
18
+
19
+ # Returns a Proxy object for the given +json_object+
20
+ #
21
+ # @param json_object [Hash]
22
+ # @return [Provider::JSDoc::Object]
23
+ def for(json_object)
24
+ @cache ||= {}
25
+
26
+ if (proxy_object = @cache[cache_key(json_object)])
27
+ proxy_object
28
+ else
29
+ @cache[cache_key(json_object)] =
30
+ class_for(json_object).new(json_object)
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ # Returns a Proxy class for the given +json_object+
37
+ #
38
+ # @param json_object [Hash]
39
+ # @return [Class]
40
+ def class_for(json_object)
41
+ class_name = json_object['type'].capitalize + "Object"
42
+
43
+ ReaderV2::Object.const_get(class_name)
44
+ rescue NameError
45
+ ReaderV2::Object::Base
46
+ end
47
+
48
+ # Returns a cache key for the given +json_object+
49
+ #
50
+ # @param json_object [Hash]
51
+ # @return [String]
52
+ def cache_key(json_object)
53
+ json_object['name']
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,211 @@
1
+ require 'inch/language/elixir/provider/reader_v2/docstring'
2
+ require 'inch/utils/code_location'
3
+
4
+ module Inch
5
+ module Language
6
+ module Elixir
7
+ module Provider
8
+ module ReaderV2
9
+ module Object
10
+ # @abstract
11
+ class Base
12
+ # @param hash [Hash] hash returned via JSON interface
13
+ def initialize(hash)
14
+ @hash = hash
15
+ end
16
+
17
+ def name
18
+ @hash['name']
19
+ end
20
+
21
+ def fullname
22
+ @hash['name']
23
+ end
24
+
25
+ def files
26
+ return [] if location.empty?
27
+ file, line_no = location[0], location[1]
28
+ [Inch::Utils::CodeLocation.new('', file, line_no)]
29
+ end
30
+
31
+ def filename
32
+ location[0]
33
+ end
34
+
35
+ attr_writer :children_fullnames
36
+ def children_fullnames
37
+ @children_fullnames ||= []
38
+ end
39
+
40
+ def parent_fullname
41
+ if depth == 1
42
+ nil
43
+ else
44
+ fullname.split('.')[0...-1].join('.')
45
+ end
46
+ end
47
+
48
+ def api_tag?
49
+ nil
50
+ end
51
+
52
+ def aliased_object_fullname
53
+ nil
54
+ end
55
+
56
+ def aliases_fullnames
57
+ nil
58
+ end
59
+
60
+ def attributes
61
+ []
62
+ end
63
+
64
+ def bang_name?
65
+ false
66
+ end
67
+
68
+ def constant?
69
+ false # raise NotImplementedError
70
+ end
71
+
72
+ def constructor?
73
+ false
74
+ end
75
+
76
+ def depth
77
+ fullname.split('.').size
78
+ end
79
+
80
+ # @return [Docstring]
81
+ def docstring
82
+ @docstring ||= Docstring.new(original_docstring)
83
+ end
84
+
85
+ def getter?
86
+ name =~ /^get_/ # raise NotImplementedError
87
+ end
88
+
89
+ def has_children?
90
+ !children_fullnames.empty?
91
+ end
92
+
93
+ def has_code_example?
94
+ docstring.code_examples.size > 0
95
+ end
96
+
97
+ def has_doc?
98
+ !undocumented?
99
+ end
100
+
101
+ def has_multiple_code_examples?
102
+ docstring.code_examples.size > 1
103
+ end
104
+
105
+ def has_unconsidered_tags?
106
+ false # raise NotImplementedError
107
+ end
108
+
109
+ def method?
110
+ false
111
+ end
112
+
113
+ HIDDEN_TYPES = %w(exception impl)
114
+ def nodoc?
115
+ @hash['doc'] == false ||
116
+ HIDDEN_TYPES.include?(@hash['type'])
117
+ end
118
+
119
+ def namespace?
120
+ false
121
+ end
122
+
123
+ def original_docstring
124
+ @hash['doc']
125
+ end
126
+
127
+ def overridden?
128
+ false # raise NotImplementedError
129
+ end
130
+
131
+ def overridden_method_fullname
132
+ nil # raise NotImplementedError
133
+ end
134
+
135
+ def parameters
136
+ []
137
+ end
138
+
139
+ def private?
140
+ false
141
+ end
142
+
143
+ def tagged_as_internal_api?
144
+ false
145
+ end
146
+
147
+ def tagged_as_private?
148
+ nodoc?
149
+ end
150
+
151
+ def protected?
152
+ false
153
+ end
154
+
155
+ def public?
156
+ true
157
+ end
158
+
159
+ def questioning_name?
160
+ fullname =~ /\?$/
161
+ end
162
+
163
+ def return_described?
164
+ false # raise NotImplementedError
165
+ end
166
+
167
+ def return_mentioned?
168
+ false # raise NotImplementedError
169
+ end
170
+
171
+ def return_typed?
172
+ false # raise NotImplementedError
173
+ end
174
+
175
+ def in_root?
176
+ depth == 1
177
+ end
178
+
179
+ def setter?
180
+ name =~ /^set_/ # raise NotImplementedError
181
+ end
182
+
183
+ def source
184
+ nil
185
+ end
186
+
187
+ def unconsidered_tag_count
188
+ 0
189
+ end
190
+
191
+ def undocumented?
192
+ original_docstring.nil? || original_docstring.to_s.strip.empty?
193
+ end
194
+
195
+ def visibility
196
+ :public
197
+ end
198
+
199
+ private
200
+
201
+ def location
202
+ @hash['location'].to_s.split(':')
203
+ end
204
+
205
+ end
206
+ end
207
+ end
208
+ end
209
+ end
210
+ end
211
+ end
@@ -0,0 +1,56 @@
1
+ require 'inch/language/elixir/provider/reader_v2/object/function_parameter_object'
2
+
3
+ module Inch
4
+ module Language
5
+ module Elixir
6
+ module Provider
7
+ module ReaderV2
8
+ module Object
9
+ # Proxy class for functions
10
+ class FunctionObject < Base
11
+ def method?
12
+ true
13
+ end
14
+
15
+ def parameters
16
+ names = FunctionSignature.new(@hash['signature']).parameter_names
17
+ names.map do |name|
18
+ FunctionParameterObject.new(self, name)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ class FunctionSignature < Struct.new(:signature)
25
+ def parameter_names
26
+ return [] if signature.nil?
27
+ signature.map do |tuple|
28
+ name_from_tuple(*tuple)
29
+ end
30
+ end
31
+
32
+ def name_from_tuple(a, _, b)
33
+ if b.nil? || b == 'Elixir'
34
+ a
35
+ else
36
+ if a == '\\\\'
37
+ candidate = b.first
38
+ if candidate.is_a?(Array)
39
+ name_from_tuple(*candidate)
40
+ else
41
+ candidate
42
+ end
43
+ else
44
+ warn "[WARN] could not parse FunctionSignature: #{[a, _, b].inspect}"
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,66 @@
1
+ module Inch
2
+ module Language
3
+ module Elixir
4
+ module Provider
5
+ module ReaderV2
6
+ module Object
7
+ # Proxy class for function parameters
8
+ class FunctionParameterObject
9
+ attr_reader :name # @return [String]
10
+
11
+ # @param method [YARD::Object::MethodObject] the method the
12
+ # parameter belongs to
13
+ # @param name [String] the name of the parameter
14
+ def initialize(method, name)
15
+ @method = method
16
+ @name = name
17
+ end
18
+
19
+ # @return [Boolean] +true+ if the parameter is a block
20
+ def block?
21
+ false
22
+ end
23
+
24
+ # @return [Boolean] +true+ if an additional description is given?
25
+ def described?
26
+ described_by_docstring?
27
+ end
28
+
29
+ # @return [Boolean] +true+ if the parameter is mentioned in the
30
+ # docs
31
+ def mentioned?
32
+ mentioned_by_docstring?
33
+ end
34
+
35
+ # @return [Boolean] +true+ if the parameter is a splat argument
36
+ def splat?
37
+ false
38
+ end
39
+
40
+ # @return [Boolean] +true+ if the type of the parameter is defined
41
+ def typed?
42
+ false # TODO: parse types of params
43
+ end
44
+
45
+ # @return [Boolean] +true+ if the parameter is mentioned in the
46
+ # docs, but not present in the method's signature
47
+ def wrongly_mentioned?
48
+ false
49
+ end
50
+
51
+ private
52
+
53
+ def described_by_docstring?
54
+ @method.docstring.describes_parameter?(name)
55
+ end
56
+
57
+ def mentioned_by_docstring?
58
+ @method.docstring.mentions_parameter?(name)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,18 @@
1
+ module Inch
2
+ module Language
3
+ module Elixir
4
+ module Provider
5
+ module ReaderV2
6
+ module Object
7
+ # Proxy class for modules
8
+ class ModuleObject < Base
9
+ def namespace?
10
+ true
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module Inch
2
+ module Language
3
+ module Elixir
4
+ module Provider
5
+ module ReaderV2
6
+ module Object
7
+ # Proxy class for types
8
+ class TypeObject < Base
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Inch
2
- VERSION = '0.8.0'
2
+ VERSION = '0.9.0.rc1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - René Föhring
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-10 00:00:00.000000000 Z
11
+ date: 2018-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -219,6 +219,7 @@ files:
219
219
  - lib/inch/language/elixir/evaluation/module_object.rb
220
220
  - lib/inch/language/elixir/evaluation/type_object.rb
221
221
  - lib/inch/language/elixir/import.rb
222
+ - lib/inch/language/elixir/provider/parser.rb
222
223
  - lib/inch/language/elixir/provider/reader.rb
223
224
  - lib/inch/language/elixir/provider/reader/docstring.rb
224
225
  - lib/inch/language/elixir/provider/reader/object.rb
@@ -227,7 +228,13 @@ files:
227
228
  - lib/inch/language/elixir/provider/reader/object/function_parameter_object.rb
228
229
  - lib/inch/language/elixir/provider/reader/object/module_object.rb
229
230
  - lib/inch/language/elixir/provider/reader/object/type_object.rb
230
- - lib/inch/language/elixir/provider/reader/parser.rb
231
+ - lib/inch/language/elixir/provider/reader_v2/docstring.rb
232
+ - lib/inch/language/elixir/provider/reader_v2/object.rb
233
+ - lib/inch/language/elixir/provider/reader_v2/object/base.rb
234
+ - lib/inch/language/elixir/provider/reader_v2/object/function_object.rb
235
+ - lib/inch/language/elixir/provider/reader_v2/object/function_parameter_object.rb
236
+ - lib/inch/language/elixir/provider/reader_v2/object/module_object.rb
237
+ - lib/inch/language/elixir/provider/reader_v2/object/type_object.rb
231
238
  - lib/inch/language/elixir/roles/base.rb
232
239
  - lib/inch/language/elixir/roles/function.rb
233
240
  - lib/inch/language/elixir/roles/function_parameter.rb
@@ -400,9 +407,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
400
407
  version: '0'
401
408
  required_rubygems_version: !ruby/object:Gem::Requirement
402
409
  requirements:
403
- - - ">="
410
+ - - ">"
404
411
  - !ruby/object:Gem::Version
405
- version: '0'
412
+ version: 1.3.1
406
413
  requirements: []
407
414
  rubyforge_project:
408
415
  rubygems_version: 2.6.8
@@ -1,70 +0,0 @@
1
- require 'json'
2
- require 'inch/language/elixir/provider/reader/object'
3
-
4
- module Inch
5
- module Language
6
- module Elixir
7
- module Provider
8
- module Reader
9
- # Parses the source tree (using Reader)
10
- class Parser
11
- attr_reader :parsed_objects
12
-
13
- # Helper method to parse an instance with the given +args+
14
- #
15
- # @see #parse
16
- # @return [CodeObject::Provider::Reader::Parser] the instance that
17
- # ran
18
- def self.parse(*args)
19
- parser = new
20
- parser.parse(*args)
21
- parser
22
- end
23
-
24
- # @param dir [String] directory
25
- # @param config [Inch::Config::Codebase] configuration for codebase
26
- # @return [void]
27
- def parse(dir, config)
28
- raise "Directory does not exist: #{dir}" if !File.exist?(dir)
29
- Dir.chdir(dir) do
30
- parse_objects(config.included_files, config.excluded_files,
31
- config.read_dump_file)
32
- end
33
- end
34
-
35
- # @return [Array<YARD::Object::Base>]
36
- def objects
37
- @objects ||= begin
38
- list = parsed_objects.map do |o|
39
- Reader::Object.for(o) # unless IGNORE_TYPES.include?(o.type)
40
- end.compact
41
- children_map = {}
42
- list.each do |object|
43
- if object.parent_fullname
44
- children_map[object.parent_fullname] ||= []
45
- children_map[object.parent_fullname] << object.fullname
46
- end
47
- end
48
- list.each do |object|
49
- object.children_fullnames = children_map[object.fullname]
50
- end
51
- list
52
- end
53
- end
54
-
55
- private
56
-
57
- def parse_objects(_paths, _excluded, read_dump_file = nil)
58
- if read_dump_file.nil?
59
- fail 'Elixir analysis only works with --read-from-dump.'
60
- else
61
- output = File.read(read_dump_file, :encoding => 'utf-8')
62
- end
63
- @parsed_objects = JSON[output]['objects']
64
- end
65
- end
66
- end
67
- end
68
- end
69
- end
70
- end