Class: IcAgent::Ast::Nodes::TypeDeclaration

Inherits:
NamedNode
  • Object
show all
Defined in:
lib/ic_agent/ast/nodes/named_nodes.rb

Instance Method Summary collapse

Methods inherited from NamedNode

#elements_to_s, #source_content, #to_array

Instance Method Details

#titleObject



59
60
61
# File 'lib/ic_agent/ast/nodes/named_nodes.rb', line 59

def title
  :type_declaration
end

#to_objObject



103
104
105
106
107
108
109
110
# File 'lib/ic_agent/ast/nodes/named_nodes.rb', line 103

def to_obj
  {
    'type_param_name' => type_param_name,
    'type_root_opt_code' => type_root_opt_code,
    'type_child_item_keys' => type_child_item_keys,
    'type_child_item_values' => type_refer_items
  }
end

#to_sObject



99
100
101
# File 'lib/ic_agent/ast/nodes/named_nodes.rb', line 99

def to_s
  text_value
end

#type_child_item_keysObject



83
84
85
86
87
88
89
# File 'lib/ic_agent/ast/nodes/named_nodes.rb', line 83

def type_child_item_keys
  names = []
  type_child_items.each do |ele|
    names << ele.elements[0].text_value.strip
  end
  names
end

#type_child_itemsObject



75
76
77
78
79
80
81
# File 'lib/ic_agent/ast/nodes/named_nodes.rb', line 75

def type_child_items
  if elements && elements[1] && elements[1].elements && elements[1].elements[0]
    elements[1].elements[0].elements
  else
    []
  end
end

#type_param_contentObject



67
68
69
# File 'lib/ic_agent/ast/nodes/named_nodes.rb', line 67

def type_param_content
  elements[1].source_content.gsub("\n", '').gsub(';}', '}')
end

#type_param_nameObject



63
64
65
# File 'lib/ic_agent/ast/nodes/named_nodes.rb', line 63

def type_param_name
  elements[0].source_content
end

#type_refer_itemsObject



91
92
93
94
95
96
97
# File 'lib/ic_agent/ast/nodes/named_nodes.rb', line 91

def type_refer_items
  source_string = self.type_param_content
  parser = IcAgent::Ast::StatementParser.new
  parser.parse(source_string)
  refer_type = parser.source_tree.content[:refer_type]
  refer_type
end

#type_root_opt_codeObject



71
72
73
# File 'lib/ic_agent/ast/nodes/named_nodes.rb', line 71

def type_root_opt_code
  elements[1].opt_code
end