Class: Puppet::Pops::Model::Positioned

Inherits:
PopsObject show all
Defined in:
lib/puppet/pops/model/ast.rb

Instance Attribute Summary collapse

Attributes inherited from PopsObject

#hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PopsObject

#_pcore_all_contents, #_pcore_contents, #eql?, #to_s

Methods included from Types::PuppetObject

#_pcore_all_contents, #_pcore_contents, #_pcore_type

Constructor Details

#initialize(locator, offset, length) ⇒ Positioned

Returns a new instance of Positioned.



114
115
116
117
118
119
# File 'lib/puppet/pops/model/ast.rb', line 114

def initialize(locator, offset, length)
  super()
  @locator = locator
  @offset = offset
  @length = length
end

Instance Attribute Details

#lengthObject (readonly)



100
101
102
# File 'lib/puppet/pops/model/ast.rb', line 100

def length
  @length
end

#locatorObject (readonly)



98
99
100
# File 'lib/puppet/pops/model/ast.rb', line 98

def locator
  @locator
end

#offsetObject (readonly)



99
100
101
# File 'lib/puppet/pops/model/ast.rb', line 99

def offset
  @offset
end

Class Method Details

._pcore_typeObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/puppet/pops/model/ast.rb', line 51

def self._pcore_type
  @_pcore_type ||= Types::PObjectType.new('Puppet::AST::Positioned', {
    'parent' => PopsObject._pcore_type,
    'attributes' => {
      'locator' => {
        'type' => Parser::Locator::Locator19._pcore_type,
        'kind' => 'reference'
      },
      'offset' => Types::PIntegerType::DEFAULT,
      'length' => Types::PIntegerType::DEFAULT,
      'file' => {
        'type' => Types::PStringType::DEFAULT,
        'kind' => 'derived'
      },
      'line' => {
        'type' => Types::PIntegerType::DEFAULT,
        'kind' => 'derived'
      },
      'pos' => {
        'type' => Types::PIntegerType::DEFAULT,
        'kind' => 'derived'
      }
    },
    'equality' => []
  })
end

.create(locator, offset, length) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/puppet/pops/model/ast.rb', line 89

def self.create(locator, offset, length)
  ta = Types::TypeAsserter
  attrs = _pcore_type.attributes(true)
  ta.assert_instance_of('Puppet::AST::Positioned[locator]', attrs['locator'].type, locator)
  ta.assert_instance_of('Puppet::AST::Positioned[offset]', attrs['offset'].type, offset)
  ta.assert_instance_of('Puppet::AST::Positioned[length]', attrs['length'].type, length)
  new(locator, offset, length)
end

.from_asserted_hash(init_hash) ⇒ Object



82
83
84
85
86
87
# File 'lib/puppet/pops/model/ast.rb', line 82

def self.from_asserted_hash(init_hash)
  new(
    init_hash['locator'],
    init_hash['offset'],
    init_hash['length'])
end

.from_hash(init_hash) ⇒ Object



78
79
80
# File 'lib/puppet/pops/model/ast.rb', line 78

def self.from_hash(init_hash)
  from_asserted_hash(Types::TypeAsserter.assert_instance_of('Puppet::AST::Positioned initializer', _pcore_type.init_hash_type, init_hash))
end

Instance Method Details

#_pcore_init_hashObject



121
122
123
124
125
126
127
# File 'lib/puppet/pops/model/ast.rb', line 121

def _pcore_init_hash
  result = super
  result['locator'] = @locator
  result['offset'] = @offset
  result['length'] = @length
  result
end

#fileObject



102
103
104
# File 'lib/puppet/pops/model/ast.rb', line 102

def file
  @locator.file
end

#lineObject



106
107
108
# File 'lib/puppet/pops/model/ast.rb', line 106

def line
  @locator.line_for_offset(@offset)
end

#posObject



110
111
112
# File 'lib/puppet/pops/model/ast.rb', line 110

def pos
  @locator.pos_on_line(@offset)
end