<commit_before>// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:collection';
import 'dart:mirrors';
import 'dart:sky' as sky;

import '../app/view.dart';
import '../rendering/box.dart';
import '../rendering/object.dart';

export '../rendering/box.dart' show BoxConstraints, BoxDecoration, Border, BorderSide, EdgeDims;
export '../rendering/flex.dart' show FlexDirection;
export '../rendering/object.dart' show Point, Size, Rect, Color, Paint, Path;

final bool _shouldLogRenderDuration = false;

// All Effen nodes derive from Widget. All nodes have a _parent, a _key and
// can be sync'd.
abstract class Widget {

  Widget({ String key }) {
    _key = key != null ? key : runtimeType.toString();
    assert(this is AbstractWidgetRoot || _inRenderDirtyComponents); // you should not build the UI tree ahead of time, build it only during build()
  }

  String _key;
  String get key => _key;

  Widget _parent;
  Widget get parent => _parent;

  bool _mounted = false;
  bool _wasMounted = false;
  bool get mounted => _mounted;
  static bool _notifyingMountStatus = false;
  static Set<Widget> _mountedChanged = new HashSet<Widget>();

  void setParent(Widget newParent) {
    assert(!_notifyingMountStatus);
    _parent = newParent;
    if (newParent == null) {
      if (_mounted) {
        _mounted = false;
        _mountedChanged.add(this);
      }
    } else {
      assert(newParent._mounted);
      if (_parent._mounted != _mounted) {
        _mounted = _parent._mounted;
        _mountedChanged.add(this);
      }
    }
  }

  static void _notifyMountStatusChanged() {
    try {
      _notifyingMountStatus = true;
      for (Widget node in _mountedChanged) {
        if (node._wasMounted != node._mounted) {
          if (node._mounted)
            node.didMount();
          else
            node.didUnmount();
          node._wasMounted = node._mounted;
        }
      }
      _mountedChanged.clear();
    } finally {
      _notifyingMountStatus = false;
    }
  }
  void didMount() { }
  void didUnmount() { }

  RenderObject _root;
  RenderObject get root => _root;

  // Subclasses which implements Nodes that become stateful may return true
  // if the |old| node has become stateful and should be retained.
  // This is called immediately before _sync().
  // Component._retainStatefulNodeIfPossible() calls syncFields().
  bool _retainStatefulNodeIfPossible(Widget old) => false;

  bool get interchangeable => false; // if true, then keys can be duplicated

  void _sync(Widget old, dynamic slot);
  // 'slot' is the identifier that the parent RenderObjectWrapper uses to know
  // where to put this descendant

  void remove() {
    _root = null;
    setParent(null);
  }

  Widget findAncestor(Type targetType) {
    var ancestor = _parent;
    while (ancestor != null && !reflectClass(ancestor.runtimeType).isSubtypeOf(reflectClass(targetType)))
      ancestor = ancestor._parent;
    return ancestor;
  }

  void removeChild(Widget node) {
    node.remove();
  }

  // Returns the child which should be retained as the child of this node.
  Widget syncChild(Widget node, Widget oldNode, dynamic slot) {

    assert(oldNode is! Component || !oldNode._disqualifiedFromEverAppearingAgain);

    if (node == oldNode) {
      assert(node == null || node.mounted);
      return node; // Nothing to do. Subtrees must be identical.
    }

    if (node == null) {
      // the child in this slot has gone away
      assert(oldNode.mounted);
      removeChild(oldNode);
      assert(!oldNode.mounted);
      return null;
    }

    if (oldNode != null && oldNode.runtimeType == node.runtimeType && node.key == oldNode.key && node._retainStatefulNodeIfPossible(oldNode)) {
      assert(oldNode.mounted);
      assert(!node.mounted);
      oldNode._sync(node, slot);
      assert(oldNode.root is RenderObject);
      return oldNode;
    }

    if (oldNode != null && (oldNode.runtimeType != node.runtimeType || node.key != oldNode.key)) {
      assert(oldNode.mounted);
      removeChild(oldNode);
      oldNode = null;
    }

    assert(!node.mounted);
    node.setParent(this);
    node._sync(oldNode, slot);
    assert(node.root is RenderObject);
    return node;
  }
}


// Descendants of TagNode provide a way to tag RenderObjectWrapper and
// Component nodes with annotations, such as event listeners,
// stylistic information, etc.
abstract class TagNode extends Widget {

  TagNode(Widget content, { String key })
    : this.content = content, super(key: key);

  Widget content;

  void _sync(Widget old, dynamic slot) {<commit_msg>Break some lines to make debugging easier. TBR=abarth,jackson<commit_after>// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:collection';
import 'dart:mirrors';
import 'dart:sky' as sky;

import '../app/view.dart';
import '../rendering/box.dart';
import '../rendering/object.dart';

export '../rendering/box.dart' show BoxConstraints, BoxDecoration, Border, BorderSide, EdgeDims;
export '../rendering/flex.dart' show FlexDirection;
export '../rendering/object.dart' show Point, Size, Rect, Color, Paint, Path;

final bool _shouldLogRenderDuration = false;

// All Effen nodes derive from Widget. All nodes have a _parent, a _key and
// can be sync'd.
abstract class Widget {

  Widget({ String key }) {
    _key = key != null ? key : runtimeType.toString();
    assert(this is AbstractWidgetRoot || _inRenderDirtyComponents); // you should not build the UI tree ahead of time, build it only during build()
  }

  String _key;
  String get key => _key;

  Widget _parent;
  Widget get parent => _parent;

  bool _mounted = false;
  bool _wasMounted = false;
  bool get mounted => _mounted;
  static bool _notifyingMountStatus = false;
  static Set<Widget> _mountedChanged = new HashSet<Widget>();

  void setParent(Widget newParent) {
    assert(!_notifyingMountStatus);
    _parent = newParent;
    if (newParent == null) {
      if (_mounted) {
        _mounted = false;
        _mountedChanged.add(this);
      }
    } else {
      assert(newParent._mounted);
      if (_parent._mounted != _mounted) {
        _mounted = _parent._mounted;
        _mountedChanged.add(this);
      }
    }
  }

  static void _notifyMountStatusChanged() {
    try {
      _notifyingMountStatus = true;
      for (Widget node in _mountedChanged) {
        if (node._wasMounted != node._mounted) {
          if (node._mounted)
            node.didMount();
          else
            node.didUnmount();
          node._wasMounted = node._mounted;
        }
      }
      _mountedChanged.clear();
    } finally {
      _notifyingMountStatus = false;
    }
  }
  void didMount() { }
  void didUnmount() { }

  RenderObject _root;
  RenderObject get root => _root;

  // Subclasses which implements Nodes that become stateful may return true
  // if the |old| node has become stateful and should be retained.
  // This is called immediately before _sync().
  // Component._retainStatefulNodeIfPossible() calls syncFields().
  bool _retainStatefulNodeIfPossible(Widget old) => false;

  bool get interchangeable => false; // if true, then keys can be duplicated

  void _sync(Widget old, dynamic slot);
  // 'slot' is the identifier that the parent RenderObjectWrapper uses to know
  // where to put this descendant

  void remove() {
    _root = null;
    setParent(null);
  }

  Widget findAncestor(Type targetType) {
    var ancestor = _parent;
    while (ancestor != null && !reflectClass(ancestor.runtimeType).isSubtypeOf(reflectClass(targetType)))
      ancestor = ancestor._parent;
    return ancestor;
  }

  void removeChild(Widget node) {
    node.remove();
  }

  // Returns the child which should be retained as the child of this node.
  Widget syncChild(Widget node, Widget oldNode, dynamic slot) {

    assert(oldNode is! Component || !oldNode._disqualifiedFromEverAppearingAgain);

    if (node == oldNode) {
      assert(node == null || node.mounted);
      return node; // Nothing to do. Subtrees must be identical.
    }

    if (node == null) {
      // the child in this slot has gone away
      assert(oldNode.mounted);
      removeChild(oldNode);
      assert(!oldNode.mounted);
      return null;
    }

    if (oldNode != null &&
        oldNode.runtimeType == node.runtimeType &&
        oldNode.key == node.key &&
        node._retainStatefulNodeIfPossible(oldNode)) {
      assert(oldNode.mounted);
      assert(!node.mounted);
      oldNode._sync(node, slot);
      assert(oldNode.root is RenderObject);
      return oldNode;
    }

    if (oldNode != null &&
        (oldNode.runtimeType != node.runtimeType || oldNode.key != node.key)) {
      assert(oldNode.mounted);
      removeChild(oldNode);
      oldNode = null;
    }

    assert(!node.mounted);
    node.setParent(this);
    node._sync(oldNode, slot);
    assert(node.root is RenderObject);
    return node;
  }
}


// Descendants of TagNode provide a way to tag RenderObjectWrapper and
// Component nodes with annotations, such as event listeners,
// stylistic information, etc.
abstract class TagNode extends Widget {

  TagNode(Widget content, { String key })
    : this.content = content, super(key: key);

  Widget content;

  void _sync(Widget old, dynamic slot) {
{'fraction_non_alphanumeric': 0.10739881956155144, 'fraction_numerical': 0.0008431703204047217, 'mean_word_length': 3.0327241818954525, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1532961', 'n_tokens_mistral': 2873, 'n_tokens_neox': 2744, 'n_words': 859}