-------------------------------------------------------------------------- TODO: move the code below to the core (?)
89
function computeGameStateOfTaskEnvironment(taskEnvironment) {
  const { pastActions, currentAction } = taskEnvironment;
  const initialState = getInitialGameState(taskEnvironment);
  let currentState = doActionMoves(initialState, pastActions);
  if (currentAction !== null) {
    currentState = doAction(currentState, currentAction);
  }
  /*
  const someActionsTaken = taskEnvironment.pastActions.length > 0;
  // TODO: DRY identical someActionsTaken computation at two places (or avoid
  // finalGameStage computation altogether, it feels like a hack...)
  const finalGameStage = decideGameStage(
    currentState.fields,
    currentState.spaceship,
    taskEnvironment.interpreting,
    someActionsTaken);
  return { ...currentState, stage: finalGameStage };
  */
  return currentState;
}
877972
public void init()
    {
        this.leading = 0;
        while (this.leading < this.value.length() && this.value.charAt(this.leading) == ' ')
        {
            this.leading++;
        }

        if (this.leading == this.value.length())
        {
            this.setEmpty();
        }
        else
        {
            this.isEmpty = false;
            this.trailing = 0;
            while (this.value.charAt(this.value.length() - this.trailing - 1) == ' ')
            {
                this.trailing++;
            }
        }
    }
1058597
function () {
        while (this.head !== null) {
            var temp = this.head;
            this.head = this.head.next();   // use next() the instead of "_next", otherwise it will loop forever
            temp._list = null;
            temp._next = null;
            temp._prev = null;
        }

        this.head = null;
        this.size = 0;
    }
268994
function() {
                // Force anything that is inlined onto the stack so we don't have duplication
                // when we examine local
                this.flushInline();
                var local = this.popStack();
                this.pushSource('if (' + local + ' != null) { ' + this.appendToBuffer(local) + ' }');
                if (this.environment.isSimple) {
                    this.pushSource("else { " + this.appendToBuffer("''") + " }");
                }
            }
975647
function () {
                this.$InputElement.initWidget.call(this);

                var bindings = this._cfg.bind;
                if (bindings.value) {
                    var newValue = this._transform(bindings.value.transform, bindings.value.inside[bindings.value.to], "toWidget");
                    if (newValue != null) {
                        this._domElt.value = newValue;
                    }
                } else {
                    this.$logWarn(this.BINDING_NEEDED, [this.$class, "value"]);
                }
                this._setPlaceholder();
            }
946553
function mutateDOM(contexts) {
    var length = contexts.length;
    var index, context, parent, childrenLength, oldOrder, newOrder;
    var moves, movesLength, move, beforeElement;
    var moving = {};

    for (index = 0; index < length; index++) {
        context = contexts[index];
        parent = context.parent;
        childrenLength = context.children.length;

        oldOrder = parent.children;
        newOrder = new Array(childrenLength);
        while (childrenLength--) {
            newOrder[childrenLength] = context.children[childrenLength].node;
        }

        moves = diff(oldOrder, newOrder);

        movesLength = moves.length;
        while (movesLength--) {
            moving[getID(moves[movesLength].element)] = moves[movesLength].index;
        }

        movesLength = moves.length;
        while (movesLength--) {
            move = moves[movesLength];
            beforeElement = newOrder[move.index + 1] || null;

            while (true) {
                if (beforeElement && (moving[getID(beforeElement)] !== undefined)) {
                    // The element we're inserting this one before is going to be moved—but has not
                    // been moved yet, take its place.
                    beforeElement = newOrder[moving[getID(beforeElement)] + 1];
                } else {
                    break;
                }
            }

            moving[getID(move.element)] = undefined;
            parent.insertBefore(move.element, beforeElement);
        }
    }
}
242375
function() {
    this.uuid = undefined;
    this.icon = undefined;
    this.customIcon = undefined;
    this.fgColor = undefined;
    this.bgColor = undefined;
    this.overrideUrl = undefined;
    this.tags = [];
    this.times = new KdbxTimes();
    this.fields = {};
    this.binaries = {};
    this.autoType = {
        enabled: true, obfuscation: undefined, defaultSequence: undefined, items: []
    };
    this.history = [];
    this.parentGroup = undefined;
    this.customData = undefined;
    this._editState = undefined;
    Object.preventExtensions(this);
}
1116550
function() {
            $(this.renderTo).addClass(this.typeName);
            $(this.renderTo).attr('data-gauge-value', this.value);
            if(this.elements.valueDisplay) {
                this.addClassToElement(this.elements.valueDisplay.element, 'gauge-value');
            }
            for(key in this.elements) {
                if(/^tickLabel_/.test(key)) {
                    this.addClassToElement(this.elements[key].element, 'gauge-tick-label');
                }
            }
            for(key in this.elements){
                if(/^colorBand/.test(key)){
                    this.addClassToElement(this.elements[key].element, 'gauge-color-band');
                }
            }
            $('.gauge-color-band').each(function(){
                $(this).attr('data-band-color', $(this).attr('fill'));
            });

            if(this.elements.fill){
                $(this.elements.fill.element).attr('data-indicator-color', $(this.elements.fill.element).attr('fill'));
            }
            // this is bad OOP but I think it's better to keep all of this code in one method
            if(this.elements.needle) {
                this.addClassToElement(this.elements.needle.element, 'gauge-indicator');
            }
            if(this.elements.markerLine) {
                this.addClassToElement(this.elements.markerLine.element, 'gauge-indicator');
            }
        }
126459
void initInputsByIdMap() {
    inputsById.clear();
    for (CompilerInput input : externs) {
      InputId id = input.getInputId();
      CompilerInput previous = putCompilerInput(id, input);
      if (previous != null) {
        report(JSError.make(DUPLICATE_EXTERN_INPUT, input.getName()));
      }
    }
    for (CompilerInput input : moduleGraph.getAllInputs()) {
      InputId id = input.getInputId();
      CompilerInput previous = putCompilerInput(id, input);
      if (previous != null) {
        report(JSError.make(DUPLICATE_INPUT, input.getName()));
      }
    }
  }
933840
function () {
            var x3 = this.dpop();
            var x2 = this.dpop();
            var x1 = this.dpop();
            this.dpush(x2);
            this.dpush(x3);
            this.dpush(x1);
        }
1280089
function (mode, code, tokens, flags, scope, parseMode) {
    var index = code.index,
        length = code.length;

    if ( /* <!-- */
        code.codePointAt(index) === 0x003c &&
        code.codePointAt(++index) === 0x0021 &&
        code.codePointAt(++index) === 0x002d &&
        code.codePointAt(++index) === 0x002d
    ) {
        index++;

        for (; index < length; index++) {
            if ( /* --> */
                code.codePointAt(index) === 0x002d &&
                code.codePointAt(index + 1) === 0x002d &&
                code.codePointAt(index + 2) === 0x003e
            ) {
                index += 3;
                code.index = index;

                return true;
            }
        }

        throw code.makeError(
            code.index, code.index + 4,
            'Unclosed Comment: Expected "-->" to fallow "<!--".'
        );
    }

    return null;
}
161253
@Override
    public void visitCode(Code obj) {

        Method m = getMethod();
        if (m.isSynthetic()) {
            return;
        }

        if (isEnum && "values".equals(m.getName())) {
            return;
        }

        String sig = m.getSignature();
        int sigPos = sig.indexOf(")[");
        if (sigPos < 0) {
            return;
        }
        if (INITIAL_VALUE.equals(m.getName())) {
            try {
                if ((THREAD_LOCAL_CLASS == null) || getClassContext().getJavaClass().instanceOf(THREAD_LOCAL_CLASS)) {
                    return;
                }
            } catch (ClassNotFoundException e) {
                bugReporter.reportMissingClass(e);
                return;
            }
        }

        stack.resetForMethodEntry(this);
        returnArraySig = sig.substring(sigPos + 1);
        uninitializedRegs.clear();
        arrayAliases.clear();
        storedUVs.clear();
        super.visitCode(obj);
    }
409054
function declareRootElement( def, code ) {
    const rootElementName = buildElement( def, code );

    code.section.elements.define.push( "//-----------------------" );
    code.section.elements.define.push( "// Declare root element." );
    code.section.elements.define.push(
        "Object.defineProperty( this, '$', {",
        [
            `value: ${rootElementName}.$,`,
            "writable: false, ",
            "enumerable: false, ",
            "configurable: false"
        ],
        "});"
    );
}
1245598
@Override
    public void visitCode(Code obj) {
        try {
            userValues = new HashMap<>();
            loops = new HashMap<>();
            isInstanceMethod = !getMethod().isStatic();
            super.visitCode(obj);
        } finally {
            userValues = null;
            loops = null;
        }
    }
340211
function() {
			// TODO: should I move this part to renderer? If so, how?
			var tree = this;
			var annotations = tree._treeModel.getAnnotations();
			// Remove existing annotations
			var existingAnnotations = this._parent.getElementsByClassName('treeAnnotationOn');
			var annotationsToRemove = [];
			for (var i = 0; i < existingAnnotations.length; i++){
				annotationsToRemove.push(existingAnnotations[i]);
			};
			annotationsToRemove.forEach(function(annotation) {
				while (annotation.firstChild) {
					annotation.removeChild(annotation.firstChild);
				}
				annotation.classList.remove('treeAnnotationOn');
			})
			// Add new annotations
			// A map from tree item ID to a list of its annotation HTML elements
			var annotationElementsByItem = {};
			var promises = [];
			annotations.forEach(function(annotation) {
				var promise = new Deferred();
				promises.push(promise);
				annotation.findDeepestFitId(tree._treeModel, function(id) {
					// Make sure there is a place to show the annotation
					if (!id) {
						promise.resolve();
						return;
					}
					var container = document.getElementById(id + 'Annotation');
					if (!container) {
						promise.resolve();
						return;
					}
					var annotationElement = annotation.generateHTML();
					if (!annotationElement) {
						promise.resolve();
						return;
					}
					if (!annotationElementsByItem[id]) {
						annotationElementsByItem[id] = [];
					}
					annotationElement.annotation = annotation;
					annotationElementsByItem[id].push(annotationElement);
					promise.resolve();
				});
			});
			Deferred.all(promises).then(function() {
				// All async calls ends. Add these annotations now.
				for (var elementid in annotationElementsByItem) {
					if (annotationElementsByItem.hasOwnProperty(elementid)) {
						var annotationsToAdd = annotationElementsByItem[elementid];
						var container = document.getElementById(elementid + 'Annotation');
						container.classList.add('treeAnnotationOn');
						// var html = annotationsToAdd[0];
						// container.appendChild(html);
						// if (annotationsToAdd.length > 1) {
						// 	var overlay = document.createElement('div');
						// 	overlay.classList.add('overlay');
						// 	container.appendChild(overlay);
						// }
						var showEditing = false;
						annotationsToAdd.forEach(function (html) {
						    container.appendChild(html);
							// Tooltip
							// TODO: make it general
							html.addEventListener('click', function(e) {
								if (tree.tooltip) {
									//tree.tooltip.remove();
								}
								var tooltip = document.createElement('div');
								tooltip.innerHTML = html.annotation.getDescription();
								tooltip.classList.add("treetable-tooltip");
								tooltip.style.left = e.clientX + 'px';
								tooltip.style.top = e.clientY + 'px';
								var cross = document.createElement('div');
								cross.innerHTML = '×';
								cross.classList.add("cross");
								tooltip.appendChild(cross);
								document.body.appendChild(tooltip);
								tooltip.remove = function (e2) {
									window.removeEventListener('click', tooltip.remove);
									document.body.removeChild(tooltip);
									tree.tooltip = null;
								};
								setTimeout(function() {
									window.addEventListener('click', tooltip.remove);
								}, 0);
								tree.tooltip = tooltip;
							});
						});
					}
				}
			});
		}
1137481
function () {
    var title = newTodoTitle.trim();
    if (title) {
      model.create(newTodoTitle, function (results) {
        var todo = createTodoComponent(listComponent, results[0].id, results[0].title);
        todos.push(todo);
        itemsLeft++;
        checkedAll = false;
      });
    }
  }
572649
public function generate()
    {
        $code = array();

        if ($this->namespace !== null) {
            $code[] = $this->getIndentation() . 'namespace ' . $this->namespace;
            $code[] = '{';
            $code[] = null;

            // Temporarily add one more level of indentation.
            $this->addIndentationLevel(1);
        }

        $code = array_merge($code, $this->renderUsesLines());

        $indentation = $this->getIndentation();

        $doc = $this->generateDocumentation();
        if ($doc !== null) {
            $code[] = $doc;
        }

        $line = $indentation . 'interface ' . $this->name;
        if (count($this->extends) > 0) {
            $line .= ' extends ' . implode(', ', $this->extends);
        }

        $code[] = $line;
        $code[] = $indentation . '{';

        // Interface constants.
        $interfaceElements = $this->generateConstantsLines();

        // Interface methods.
        foreach ($this->methods as $method) {
            if ($method->getVisibility() !== Modifiers::VISIBILITY_PUBLIC) {
                throw new RuntimeException('The visibility of methods must be public.');
            }

            $method->setIndentationString($this->getIndentationString());
            $method->setIndentationLevel($this->getIndentationLevel() + 1);

            $doc = $method->generateDocumentation();
            if ($doc !== null) {
                $interfaceElements[] = $doc;
            }

            $interfaceElements[] = $method->generateSignature() . ';';
            $interfaceElements[] = null;
        }

        if (count($interfaceElements) > 0) {
            $code[] = null;
            $code = array_merge($code, $interfaceElements);
            // Remove last empty line.
            array_pop($code);
        }

        $code[] = $indentation . '}';

        if ($this->namespace !== null) {
            // Set back the indentation.
            $this->addIndentationLevel(-1);

            $code[] = $this->getIndentation() . '}';
        }

        return implode($this->getLineFeed(), $code);
    }