Define attr_writer method for the new attribute
   with the added feature of validations and coercions.

 @param [Symbol] name the attribute name
 @param [Class] type the class type

 @raise [TypeError] if unable to coerce the value

 @private
198803
def define_attr_writer(name, type)
      define_method("#{name}=") do |value|
        unless value.kind_of?(type)
          value = coerce(value, to: type)
          unless value.kind_of?(type)
            raise TypeError, "Attribute `#{name}` only accepts `#{type}` but got `#{value}`:`#{value.class}` instead"
          end
        end
        instance_variable_set("@#{name}", value)
      end
    end
1076839
public static NamedAttributeType<Object> newNamedUnknownType(final String name, final Type type) {
	return new NamedAttributeType<>(name, new AttributeType<Object>(type) {});
    }
1236018
def write_attribute(name, value)
      name = name.to_s
      modify(name, @attributes[name], value)
    end
1124044
public static function input($type, $name, $attributes)
    {
        // Set id attribute to be same as the name
        // if one has not been set
        if (!isset($attributes['id'])) {
            $attributes['id'] =  $name;
        }

        // Check if the value is set in the
        // attributes array
        if (isset($attributes['value'])) {
            $value = $attributes['value'];
        }
        // Check if its in the _POST array
        elseif (isset($_POST[$name])) {
            $value = $_POST[$name];
        }
        // It's nowhere...
        else {
            $value = '';
        }

        // Add selected or checked attribute?
        foreach (array('selected', 'checked') as $attr) {
            if (isset($attributes[$attr]) and !$attributes[$attr]) {
                unset($attributes[$attr]);
            } elseif (isset($attributes[$attr])) {
                $attributes[$attr] = $attr;
            }
        }

        // Merge default attributes with
        // the specified attributes.
        $attributes = array_merge(array('type' => $type, 'name' => $name), $attributes);

        // Textareas
        if ($type == 'textarea') {
            return "<textarea " . HTML::buildAttributes($attributes) . ">{$value}</textarea>";
        }
        // Everything else
        else {
            // Don't pass the checked attribute if its false.
            if (isset($attributes['checked']) and !$attributes['checked']) {
                unset($attributes['checked']);
            }
            return "<input " . HTML::buildAttributes($attributes) . ">";
        }
    }
138148
def attrs
      @attrs.inject({}) do |attrs, (key, value)|
        attrs.merge!(key => respond_to?(key) ? send(key) : value)
      end
    end
1160648
def _AssAttr(self, t):
        
        self._dispatch(t.expr)
        self._write('.'+t.attrname)
1290576
def define_attribute(name, type)
      _name = name.gsub(":", "_")

      define_method(_name) do
        var = instance_variables.include?(:@meta) ? :@meta : :@attributes
        instance_variable_get(var).find do |attribute|
          attribute.key == name
        end.tap{|x| return x.value if x}
      end

      define_method("%s=" % _name) do |value|
        var = instance_variables.include?(:@meta) ? :@meta : :@attributes
        instance_variable_get(var).tap do |attributes|
          if elt = __send__(_name)
            attributes.delete(elt)
          end
          attributes << XES.send(type, name, value)
        end
      end
    end
138964
def instance_readers
      _attrs.map { |k, v| [:attr_writer].any? { |t| v[:type] == t } ? nil : k }.compact
    end
1250058
def add_document_boost(attr_name, &block)
      @document_boost_extractor =
        if attr_name
          if attr_name.respond_to?(:to_f)
            DataExtractor::Constant.new(attr_name)
          else
            DataExtractor::AttributeExtractor.new(attr_name)
          end
        else
          DataExtractor::BlockExtractor.new(&block)
        end
    end
314932
def _attribute_typecaster(attribute_name)
      type = _attribute_type(attribute_name)
      self.class.attributes[attribute_name][:typecaster] || typecaster_for(type) or raise UnknownTypecasterError, "Unable to cast to type #{type}"
    end
1211405
def create!(attributes)
      new_attributes = map_to_keys(attributes)

      new_attributes = new_attributes.merge(
        RecordTypeManager::FIELD_NAME => klass.record_type_id
      ) if klass.record_type_id

      client.create!(klass.object_name, new_attributes)
    end
1225450
def attr_type_for(attribute)
    fields = self.class._module.fields
    field  = fields[attribute]
    raise UninitializedModule, "#{self.class.session.namespace_const}Module #{self.class._module.name} was not initialized properly (fields.length == 0)" if fields.length == 0
    raise InvalidAttribute, "#{self.class}._module.fields does not contain an entry for #{attribute} (of type: #{attribute.class})\nValid fields: #{self.class._module.fields.keys.sort.join(", ")}" if field.nil?
    raise InvalidAttributeType, "#{self.class}._module.fields[#{attribute}] does not have a key for \'type\'" if field["type"].nil?
    field["type"].to_sym
  end
1222107
def write_attribute(name, value)
      name = name.to_s

      if respond_to?("#{name}=")
        __send__("attribute=", name, value)
      else
        raise ::ActiveRemote::UnknownAttributeError, "unknown attribute: #{name}"
      end
    end
210025
def attribute_syntax(attribute)
      type   = attribute_type(attribute)
      syntax = nil
      until type.nil? || syntax = type.syntax
        type = attribute_type(type.sup)
      end
      syntax
    end
73980
def assign_attributes(new_attributes)
      if !new_attributes.respond_to?(:stringify_keys)
        raise ArgumentError, "When assigning attributes, you must pass a hash as an argument."
      end
      return if new_attributes.empty?

      # stringify keys just like https://github.com/rails/rails/blob/4f99a2186479d5f77460622f2c0f37708b3ec1bc/activemodel/lib/active_model/attribute_assignment.rb#L34
      new_attributes.stringify_keys.each do |k, v|
        setter = :"#{k}="
        if respond_to?(setter)
          public_send(setter, v)
        else
          _attr_json_write_unknown_attribute(k, v)
        end
      end
    end
102878
def add_attribute(attribute, type, *flags)
      prop = create_nonjava_property(attribute, type, *flags)
      add_property(prop)
      prop
    end
714209
def write_attr(attr_name, value, to_call = nil)
      self[attr_name] = value && to_call ? value.__send__(to_call) : value
    end