replace top level element with new element of given type
973808
public void replace(ClassNode type) {
        int size = stack.size();
        try {
            if (size==0) throw new ArrayIndexOutOfBoundsException("size==0");
        } catch (ArrayIndexOutOfBoundsException ai) {
            System.err.println("index problem in "+controller.getSourceUnit().getName());
            throw ai;
        }
        stack.set(size-1, type);
    }
1194747
def replace(self, old, new):
        """"""
        if old.type != new.type:
            raise TypeError("new instruction has a different type")
        pos = self.instructions.index(old)
        self.instructions.remove(old)
        self.instructions.insert(pos, new)

        for bb in self.parent.basic_blocks:
            for instr in bb.instructions:
                instr.replace_usage(old, new)
253925
function replaceElementPseudoMentions (element, selector) {
  const processor = selectorParser((selectors) => {
    let nodesToReplace = []

    /**
     * looping breaks if we replace dynamically
     * so instead collect an array of nodes to swap and do it at the end
     */
    selectors.each((selector) => {
      let onElementTag = false

      selector.each((node) => {
        if (node.type === 'tag' && node.value === element.tag) {
          onElementTag = true
        } else if (node.type === 'combinator') {
          onElementTag = false
        } else if (node.type === 'pseudo' && onElementTag) {
          const matchedPseudos = Object.entries(element.pseudos).filter(([ pseudo ]) => {
            return node.value.replace(/::?/, '') === pseudo
          })

          if (matchedPseudos.length > 0) {
            const [, value] = matchedPseudos[0]
            nodesToReplace.push({ node, value })
          }
        }
      })
    })

    nodesToReplace.forEach(({ node, value }) => node.replaceWith(` ${value}`))
  })

  return processor.process(selector).result
}
955562
function replaceSelectors(source, bareTokenList, getSubstitution){
  var target = new FastArray(new Array(source.length));
  var tokenList = new FastArray(bareTokenList);
  target.endCursor = 0;

  for (var i = source.length - 1; i >= 0; i--) {
    var token = tokenList.first();
    if (token && i === token.end) {
      var length = token.end - token.start;

      var substitution = getSubstitution(token);
      i -= length;

      for (var j = substitution.length - 1; j >= 0; j--) {
        target.push(substitution[j]);
      }
      tokenList.shift();
    } else {
      target.push(source[i]);
    }
  }

  return target;
}
1269297
function (prevNode, newNode) {
      if (prevNode === newNode) {
          return;
      }
      TNode.replaceNodeBy.call(this,prevNode, newNode);
      var aen=this.attEltNodes;
      if (aen) {
          for (var i=0,sz=aen.length; sz>i;i++) {
              aen[i].replaceNodeBy(prevNode, newNode);
          }
      }
  }
1227024
def transform_dot(self, node, results):
        """"""
        module_dot = results.get("bare_with_attr")
        member = results.get("member")
        new_name = None
        if isinstance(member, list):
            member = member[0]
        for change in MAPPING[module_dot.value]:
            if member.value in change[1]:
                new_name = change[0]
                break
        if new_name:
            module_dot.replace(Name(new_name,
                                    prefix=module_dot.prefix))
        else:
            self.cannot_convert(node, "This is an invalid module element")
963956
function updateOptions( $elem, prev, curr ) {
        var bselect = _callMethod( $elem, "element" );

        $.each( prev, function(key, val) {
            if ( curr[ key ] !== val ) {
                if ( key === "size" ) {
                    var sizes = $.map( bootstrapButtonSizes.slice( 0 ), function( size ) {
                        return "bselect-" + size;
                    }).join( " " );

                    bselect.removeClass( sizes );
                    if ( bootstrapButtonSizes.indexOf( curr.size ) > -1 ) {
                        bselect.addClass( "bselect-" + curr.size );
                    }
                }
            }
        });
    }
1262951
def add(self, type, orig, replace):
        
        ret = libxml2mod.xmlACatalogAdd(self._o, type, orig, replace)
        return ret
537560
function mergeAtLevel(summary, level, newValue) {
    var levelParts = level.split('.');
    var partIndex = Number(levelParts[0]) -1;

    var parts = summary.getParts();
    var part = parts.get(partIndex);
    if (!part) {
        return summary;
    }

    var isEditingPart = levelParts.length < 2;
    if (isEditingPart) {
        part = part.merge(newValue);
    } else {
        part = editArticleInPart(part, level, newValue);
    }

    parts = parts.set(partIndex, part);
    return summary.set('parts', parts);
}
998628
public function replaceTemplateTypesWithStandins(
        array &$template_types,
        array &$generic_params,
        Codebase $codebase = null,
        Atomic $input_type = null,
        bool $replace = true,
        bool $add_upper_bound = false,
        int $depth = 0
    ) {
        if ($this->params) {
            foreach ($this->params as $offset => $param) {
                $input_param_type = null;

                if (($input_type instanceof Atomic\Fn || $input_type instanceof Atomic\TCallable)
                    && isset($input_type->params[$offset])
                ) {
                    $input_param_type = $input_type->params[$offset]->type;
                }

                if (!$param->type) {
                    continue;
                }

                $param->type->replaceTemplateTypesWithStandins(
                    $template_types,
                    $generic_params,
                    $codebase,
                    $input_param_type,
                    $replace,
                    !$add_upper_bound,
                    $depth
                );
            }
        }

        if (($input_type instanceof Atomic\TCallable || $input_type instanceof Atomic\Fn)
            && $this->return_type
            && $input_type->return_type
        ) {
            $this->return_type->replaceTemplateTypesWithStandins(
                $template_types,
                $generic_params,
                $codebase,
                $input_type->return_type,
                $replace,
                $add_upper_bound
            );
        }
    }
867943
function Element (tagName, props, children) {
  if (!(this instanceof Element)) {
    if (!_.isArray(children) && children != null) {
      children = _.slice(arguments, 2).filter(_.truthy)
    }
    return new Element(tagName, props, children)
  }

  if (_.isArray(props)) {
    children = props
    props = {}
  }

  this.tagName = tagName
  this.props = props || {}
  this.children = children || []
  this.key = props
    ? props.key
    : void 666

  var count = 0

  _.each(this.children, function (child, i) {
    if (child instanceof Element) {
      count += child.count
    } else {
      children[i] = '' + child
    }
    count++
  })

  this.count = count
}
1051068
function transformElement({ name: type, attribs: props, children: childElements }) {
  transformStyle(props);
  rename(props, 'for', 'htmlFor');
  rename(props, 'class', 'className');
  if ('input' === type) {
    rename(props, 'checked', 'defaultChecked');
    rename(props, 'value', 'defaultValue');
  }
  let children = transformElements(childElements);

  if ('textarea' === type && children.length) {
    props.defaultValue = children[0];
    children = [];
  }

  return { type, props, children };
}
1213059
function upgradeElementsInternal(elements) {
    if (!Array.isArray(elements)) {
      if (elements instanceof Element) {
        elements = [elements];
      } else {
        elements = Array.prototype.slice.call(elements);
      }
    }
    for (var i = 0, n = elements.length, element; i < n; i++) {
      element = elements[i];
      if (element instanceof HTMLElement) {
        upgradeElementInternal(element);
        if (element.children.length > 0) {
          upgradeElementsInternal(element.children);
        }
      }
    }
  }
1205191
private void addNthLastOfType() {
        for (Node node : nodes) {
            int count = 1;
            Node n = DOMHelper.getNextSiblingElement(node);
            while (n != null) {
                if (DOMHelper.getNodeName(n).equals(DOMHelper.getNodeName(node))) {
                    count++;
                }
                
                n = DOMHelper.getNextSiblingElement(n);
            }
            
            if (specifier.isMatch(count)) {
                result.add(node);
            }
        }
    }
560887
def replace(
        self,
        name=_void,
        kind=_void,
        annotation=_void,
        default=_void,
        _partial_kwarg=_void,
    ):
        """"""

        if name is _void:
            name = self._name

        if kind is _void:
            kind = self._kind

        if annotation is _void:
            annotation = self._annotation

        if default is _void:
            default = self._default

        if _partial_kwarg is _void:
            _partial_kwarg = self._partial_kwarg

        return type(self)(
            name,
            kind,
            default=default,
            annotation=annotation,
            _partial_kwarg=_partial_kwarg,
        )
1219666
public function replaceTemplateTypesWithStandins(
        array &$template_types,
        array &$generic_params,
        Codebase $codebase = null,
        Atomic $input_type = null,
        bool $replace = true,
        bool $add_upper_bound = false,
        int $depth = 0
    ) {
        foreach ($this->type_params as $offset => $type_param) {
            $input_type_param = null;

            if (($input_type instanceof Atomic\TGenericObject
                    || $input_type instanceof Atomic\TIterable
                    || $input_type instanceof Atomic\TArray)
                &&
                    isset($input_type->type_params[$offset])
            ) {
                $input_type_param = $input_type->type_params[$offset];
            } elseif ($input_type instanceof Atomic\ObjectLike) {
                if ($offset === 0) {
                    $input_type_param = $input_type->getGenericKeyType();
                } elseif ($offset === 1) {
                    $input_type_param = $input_type->getGenericValueType();
                } else {
                    throw new \UnexpectedValueException('Not expecting offset of ' . $offset);
                }
            }

            $type_param->replaceTemplateTypesWithStandins(
                $template_types,
                $generic_params,
                $codebase,
                $input_type_param,
                $replace,
                $add_upper_bound,
                $depth + 1
            );
        }
    }
533239
private static Node<Container> replace(Node<Container> list, Container old, AbstractConfigValue replacement) {
        Container child = list.head();
        if (child != old)
            throw new ConfigException.BugOrBroken("Can only replace() the top node we're resolving; had " + child
                    + " on top and tried to replace " + old + " overall list was " + list);
        Container parent = list.tail() == null ? null : list.tail().head();
        if (replacement == null || !(replacement instanceof Container)) {
            if (parent == null) {
                return null;
            } else {
                /*
                 * we are deleting the child from the stack of containers
                 * because it's either going away or not a container
                 */
                AbstractConfigValue newParent = parent.replaceChild((AbstractConfigValue) old, null);

                return replace(list.tail(), parent, newParent);
            }
        } else {
            /* we replaced the container with another container */
            if (parent == null) {
                return new Node<Container>((Container) replacement);
            } else {
                AbstractConfigValue newParent = parent.replaceChild((AbstractConfigValue) old, replacement);
                Node<Container> newTail = replace(list.tail(), parent, newParent);
                if (newTail != null)
                    return newTail.prepend((Container) replacement);
                else
                    return new Node<Container>((Container) replacement);
            }
        }
    }