class Puppet::Pops::Types::PObjectType::PAnnotatedMember

@abstract Encapsulates behavior common to {PAttribute} and {PFunction} @api public

Attributes

container[R]

@return [PObjectType] the object type containing this member @api public

name[R]

@return [String] the name of this member @api public

type[R]

@return [PAnyType] the type of this member @api public

Public Class Methods

feature_type() click to toggle source

@api private

    # File lib/puppet/pops/types/p_object_type.rb
263 def self.feature_type
264   raise NotImplementedError, "'#{self.class.name}' should implement #feature_type"
265 end
label(container, name) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
267 def self.label(container, name)
268   "#{feature_type} #{container.label}[#{name}]"
269 end
new(name, container, init_hash) click to toggle source

@param name [String] The name of the member @param container [PObjectType] The containing object type @param init_hash [Hash{String=>Object}] Hash containing feature options @option init_hash [PAnyType] 'type' The member type (required) @option init_hash [Boolean] 'override' `true` if this feature must override an inherited feature. Default is `false`. @option init_hash [Boolean] 'final' `true` if this feature cannot be overridden. Default is `false`. @option init_hash [Hash{PTypeType => Hash}] 'annotations' Annotations hash. Default is `nil`. @api public

    # File lib/puppet/pops/types/p_object_type.rb
117 def initialize(name, container, init_hash)
118   @name = name
119   @container = container
120   @type = init_hash[KEY_TYPE]
121   @override = init_hash[KEY_OVERRIDE]
122   @override = false if @override.nil?
123   @final = init_hash[KEY_FINAL]
124   @final = false if @final.nil?
125   init_annotatable(init_hash)
126 end

Public Instance Methods

==(o) click to toggle source

@api public

    # File lib/puppet/pops/types/p_object_type.rb
207 def ==(o)
208   eql?(o)
209 end
_pcore_init_hash() click to toggle source

Returns the member as a hash suitable as an argument for constructor. Name is excluded @return [Hash{String=>Object}] the initialization hash @api private

    # File lib/puppet/pops/types/p_object_type.rb
214 def _pcore_init_hash
215   hash = { KEY_TYPE => @type }
216   hash[KEY_FINAL] = true if @final
217   hash[KEY_OVERRIDE] = true if @override
218   hash[KEY_ANNOTATIONS] = @annotations unless @annotations.nil?
219   hash
220 end
accept(visitor, guard) click to toggle source

Delegates to the contained type @param visitor [TypeAcceptor] the visitor @param guard [RecursionGuard] guard against recursion. Only used by internal calls @api public

    # File lib/puppet/pops/types/p_object_type.rb
132 def accept(visitor, guard)
133   annotatable_accept(visitor, guard)
134   @type.accept(visitor, guard)
135 end
assert_can_be_overridden(member) click to toggle source

Checks if the given member can override this member.

@param member [PAnnotatedMember] the overriding member @return [PAnnotatedMember] its argument @raises [Puppet::ParseError] if the assertion fails @api private

    # File lib/puppet/pops/types/p_object_type.rb
163 def assert_can_be_overridden(member)
164   unless self.class == member.class
165     raise Puppet::ParseError, _("%{member} attempts to override %{label}") % { member: member.label, label: label }
166   end
167   if @final && !(constant? && member.constant?)
168     raise Puppet::ParseError, _("%{member} attempts to override final %{label}") % { member: member.label, label: label }
169   end
170   unless member.override?
171     #TRANSLATOR 'override => true' is a puppet syntax and should not be translated
172     raise Puppet::ParseError, _("%{member} attempts to override %{label} without having override => true") % { member: member.label, label: label }
173   end
174   unless @type.assignable?(member.type)
175     raise Puppet::ParseError, _("%{member} attempts to override %{label} with a type that does not match") % { member: member.label, label: label }
176   end
177   member
178 end
assert_override(parent_members) click to toggle source

Checks if the this member overrides an inherited member, and if so, that this member is declared with override = true and that the inherited member accepts to be overridden by this member.

@param parent_members [Hash{String=>PAnnotatedMember}] the hash of inherited members @return [PAnnotatedMember] this instance @raises [Puppet::ParseError] if the assertion fails @api private

    # File lib/puppet/pops/types/p_object_type.rb
144 def assert_override(parent_members)
145   parent_member = parent_members[@name]
146   if parent_member.nil?
147     if @override
148       raise Puppet::ParseError, _("expected %{label} to override an inherited %{feature_type}, but no such %{feature_type} was found") %
149           { label: label, feature_type: feature_type }
150     end
151     self
152   else
153     parent_member.assert_can_be_overridden(self)
154   end
155 end
constant?() click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
180 def constant?
181   false
182 end
create_dispatch(instance) click to toggle source

@api private

    # File lib/puppet/pops/types/p_object_type.rb
251 def create_dispatch(instance)
252   # TODO: Assumes Ruby implementation for now
253   if(callable_type.is_a?(PVariantType))
254     callable_type.types.map do |ct|
255       Functions::Dispatch.new(ct, RubyGenerator.protect_reserved_name(name), [], false, ct.block_type.nil? ? nil : 'block')
256     end
257   else
258     [Functions::Dispatch.new(callable_type, RubyGenerator.protect_reserved_name(name), [], false, callable_type.block_type.nil? ? nil : 'block')]
259   end
260 end
eql?(o) click to toggle source

@api public

    # File lib/puppet/pops/types/p_object_type.rb
202 def eql?(o)
203   self.class == o.class && @name == o.name && @type == o.type && @override == o.override? && @final == o.final?
204 end
feature_type() click to toggle source

@api private

    # File lib/puppet/pops/types/p_object_type.rb
223 def feature_type
224   self.class.feature_type
225 end
final?() click to toggle source

@return [Boolean] `true` if this feature cannot be overridden @api public

    # File lib/puppet/pops/types/p_object_type.rb
186 def final?
187   @final
188 end
hash() click to toggle source

@api public

    # File lib/puppet/pops/types/p_object_type.rb
197 def hash
198   @name.hash ^ @type.hash
199 end
invoke(receiver, scope, args, &block) click to toggle source

Performs type checking of arguments and invokes the method that corresponds to this method. The result of the invocation is returned

@param receiver [Object] The receiver of the call @param scope [Puppet::Parser::Scope] The caller scope @param args [Array] Array of arguments. @return [Object] The result returned by the member function or attribute

@api private

    # File lib/puppet/pops/types/p_object_type.rb
241 def invoke(receiver, scope, args, &block)
242   @dispatch ||= create_dispatch(receiver)
243 
244   args_type = TypeCalculator.infer_set(block_given? ? args + [block] : args)
245   found = @dispatch.find { |d| d.type.callable?(args_type) }
246   raise ArgumentError, TypeMismatchDescriber.describe_signatures(label, @dispatch, args_type) if found.nil?
247   found.invoke(receiver, scope, args, &block)
248 end
label() click to toggle source

@api private

    # File lib/puppet/pops/types/p_object_type.rb
228 def label
229   self.class.label(@container, @name)
230 end
override?() click to toggle source

@return [Boolean] `true` if this feature must override an inherited feature @api public

    # File lib/puppet/pops/types/p_object_type.rb
192 def override?
193   @override
194 end