Class: TypeProf::Core::TypeAliasEntity

Inherits:
Object
  • Object
show all
Defined in:
lib/typeprof/core/env/type_alias_entity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTypeAliasEntity

Returns a new instance of TypeAliasEntity.



3
4
5
6
# File 'lib/typeprof/core/env/type_alias_entity.rb', line 3

def initialize
  @decls = Set[]
  @type = nil
end

Instance Attribute Details

#declsObject (readonly)

Returns the value of attribute decls.



8
9
10
# File 'lib/typeprof/core/env/type_alias_entity.rb', line 8

def decls
  @decls
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/typeprof/core/env/type_alias_entity.rb', line 8

def type
  @type
end

Instance Method Details

#add_decl(decl) ⇒ Object



14
15
16
17
18
# File 'lib/typeprof/core/env/type_alias_entity.rb', line 14

def add_decl(decl)
  @decls << decl
  @type = decl.type unless @type
  # TODO: report an error if there are duplicated declarations
end

#exist?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/typeprof/core/env/type_alias_entity.rb', line 10

def exist?
  !@decls.empty?
end

#remove_decl(decl) ⇒ Object



20
21
22
23
24
25
# File 'lib/typeprof/core/env/type_alias_entity.rb', line 20

def remove_decl(decl)
  @decls.delete(decl) || raise
  if @type == decl.type
    @type = @decls.empty? ? nil : @decls.to_a.first.type
  end
end