Skip to content

Commit 4409572

Browse files
authored
Merge pull request #2123 from ksss/k-namespace
Deprecate `Kernel#Namespace`
2 parents 1877ae5 + c95e936 commit 4409572

39 files changed

+247
-239
lines changed

bin/query-rdoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ source.load()
2828

2929
case
3030
when match = name.match(/(?<constant_name>[^#]+)#(?<method_name>.+)/)
31-
type_name = TypeName(match[:constant_name] || raise)
31+
type_name = RBS::TypeName.parse(match[:constant_name] || raise)
3232
instance_method = (match[:method_name] or raise).to_sym
3333

3434
doc = annotator.doc_for_method(type_name, instance_method: instance_method, tester: tester)
3535
when match = name.match(/(?<constant_name>[^#]+)\.(?<method_name>.+)/)
36-
type_name = TypeName(match[:constant_name] || raise)
36+
type_name = RBS::TypeName.parse(match[:constant_name] || raise)
3737
singleton_method = (match[:method_name] or raise).to_sym
3838

3939
doc = annotator.doc_for_method(type_name, singleton_method: singleton_method, tester: tester)
4040
else
41-
type_name = TypeName(name)
41+
type_name = RBS::TypeName.parse(name)
4242

4343
doc = annotator.doc_for_class(type_name, tester: tester) || annotator.doc_for_constant(type_name, tester: tester)
4444
end

docs/architecture.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ The `#build_singleton` calculates the type of `.new` methods based on the defini
9292
`DefinitionBuilder#expand_alias` and its variants provide one step *unfold* operation of type aliases.
9393

9494
```ruby
95-
builder.expand_alias2(TypeName("::int"), []) # => returns `::Integer | ::_ToInt`
95+
builder.expand_alias2(RBS::TypeName.parse("::int"), []) # => returns `::Integer | ::_ToInt`
9696
```
9797

9898
We don't have *normalize* operation for type aliases, because RBS allows recursive type alias definition, which cannot be *fully* unfolded.

lib/rbs/annotate/annotations.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,23 @@ def partition
9393
case
9494
when match = source.match(/(?<constant_name>[^#]+)#(?<method_name>.+)/)
9595
[
96-
TypeName(match[:constant_name] || raise),
96+
TypeName.parse(match[:constant_name] || raise),
9797
[
9898
false,
9999
(match[:method_name] or raise).to_sym
100100
]
101101
]
102102
when match = source.match(/(?<constant_name>[^#]+)\.(?<method_name>.+)/)
103103
[
104-
TypeName(match[:constant_name] || raise),
104+
TypeName.parse(match[:constant_name] || raise),
105105
[
106106
true,
107107
(match[:method_name] or raise).to_sym
108108
]
109109
]
110110
else
111111
[
112-
TypeName(source),
112+
TypeName.parse(source),
113113
nil
114114
]
115115
end

lib/rbs/annotate/rdoc_source.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def class_docs(typename)
7070
def find_const(const_name)
7171
namespace =
7272
if const_name.namespace.empty?
73-
TypeName("::Object")
73+
TypeName.parse("::Object")
7474
else
7575
const_name.namespace.to_type_name
7676
end

lib/rbs/cli.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def run_ancestors(args, options)
288288
env = Environment.from_loader(loader).resolve_type_names
289289

290290
builder = DefinitionBuilder::AncestorBuilder.new(env: env)
291-
type_name = TypeName(args[0]).absolute!
291+
type_name = TypeName.parse(args[0]).absolute!
292292

293293
case env.constant_entry(type_name)
294294
when Environment::ClassEntry, Environment::ModuleEntry, Environment::ClassAliasEntry, Environment::ModuleAliasEntry
@@ -353,7 +353,7 @@ def run_methods(args, options)
353353
env = Environment.from_loader(loader).resolve_type_names
354354

355355
builder = DefinitionBuilder.new(env: env)
356-
type_name = TypeName(args[0]).absolute!
356+
type_name = TypeName.parse(args[0]).absolute!
357357

358358
if env.module_name?(type_name)
359359
definition = case kind
@@ -406,7 +406,7 @@ def run_method(args, options)
406406
env = Environment.from_loader(loader).resolve_type_names
407407

408408
builder = DefinitionBuilder.new(env: env)
409-
type_name = TypeName(args[0]).absolute!
409+
type_name = TypeName.parse(args[0]).absolute!
410410
method_name = args[1].to_sym
411411

412412
unless env.module_name?(type_name)
@@ -479,9 +479,9 @@ def run_constant(args, options)
479479
builder = DefinitionBuilder.new(env: env)
480480
resolver = Resolver::ConstantResolver.new(builder: builder)
481481

482-
resolver_context = context ? [nil, TypeName(context).absolute!] : nil #: Resolver::context
482+
resolver_context = context ? [nil, TypeName.parse(context).absolute!] : nil #: Resolver::context
483483
stdout.puts "Context: #{context}"
484-
const_name = TypeName(args[0])
484+
const_name = TypeName.parse(args[0])
485485
stdout.puts "Constant name: #{const_name}"
486486

487487
if const_name.absolute?

lib/rbs/cli/diff.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def initialize(argv:, library_options:, stdout: $stdout, stderr: $stderr)
4646
end
4747

4848
@diff = RBS::Diff.new(
49-
type_name: TypeName(type_name).absolute!,
49+
type_name: TypeName.parse(type_name).absolute!,
5050
library_options: library_options,
5151
after_path: after_path,
5252
before_path: before_path,

lib/rbs/namespace.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def ascend
119119

120120
module Kernel
121121
def Namespace(name)
122+
warn "Kernel#Namespace() is deprecated. Use RBS::Namespace.parse instead.", category: :deprecated
122123
RBS::Namespace.parse(name)
123124
end
124125
end

lib/rbs/prototype/rb.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,9 @@ def param_type(node, default: Types::Bases::Any.new(location: nil))
722722
when :FLOAT
723723
BuiltinNames::Float.instance_type
724724
when :RATIONAL
725-
Types::ClassInstance.new(name: TypeName("::Rational"), args: [], location: nil)
725+
Types::ClassInstance.new(name: TypeName.parse("::Rational"), args: [], location: nil)
726726
when :IMAGINARY
727-
Types::ClassInstance.new(name: TypeName("::Complex"), args: [], location: nil)
727+
Types::ClassInstance.new(name: TypeName.parse("::Complex"), args: [], location: nil)
728728
when :LIT
729729
case node.children[0]
730730
when Symbol

lib/rbs/prototype/runtime.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,9 @@ def generate_constants(mod, decls)
449449
location: nil
450450
)
451451
when ARGF
452-
Types::ClassInstance.new(name: TypeName("::RBS::Unnamed::ARGFClass"), args: [], location: nil)
452+
Types::ClassInstance.new(name: TypeName.parse("::RBS::Unnamed::ARGFClass"), args: [], location: nil)
453453
when ENV
454-
Types::ClassInstance.new(name: TypeName("::RBS::Unnamed::ENVClass"), args: [], location: nil)
454+
Types::ClassInstance.new(name: TypeName.parse("::RBS::Unnamed::ENVClass"), args: [], location: nil)
455455
else
456456
value_type_name = to_type_name(const_name!(Reflection.object_class(value)), full_name: true).absolute!
457457
args = type_args(value_type_name)

lib/rbs/prototype/runtime/value_object_generator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def self.generatable?(target)
102102
CAN_CALL_KEYWORD_INIT_P = Struct.new(:tmp).respond_to?(:keyword_init?)
103103

104104
def build_super_class
105-
AST::Declarations::Class::Super.new(name: TypeName("::Struct"), args: [untyped], location: nil)
105+
AST::Declarations::Class::Super.new(name: TypeName.parse("::Struct"), args: [untyped], location: nil)
106106
end
107107

108108
def add_decl_members(decl)
@@ -223,7 +223,7 @@ def self.generatable?(target)
223223
private
224224

225225
def build_super_class
226-
AST::Declarations::Class::Super.new(name: TypeName("::Data"), args: [], location: nil)
226+
AST::Declarations::Class::Super.new(name: TypeName.parse("::Data"), args: [], location: nil)
227227
end
228228

229229
def add_decl_members(decl)

0 commit comments

Comments
 (0)