\");\n\tiframeDoc.close();\n\tdeepEqual(\n\t\tSizzle( \"p:contains(bar)\", iframeDoc ),\n\t\t[ iframeDoc.getElementById(\"foo\") ],\n\t\t\"Other document as context\"\n\t);\n\n\tvar html = \"\";\n\tfor ( i = 0; i < 100; i++ ) {\n\t\thtml = \"
\" + html + \"
\";\n\t}\n\thtml = jQuery( html ).appendTo( document.body );\n\tok( !!Sizzle(\"body div div div\").length, \"No stack or performance problems with large amounts of descendents\" );\n\tok( !!Sizzle(\"body>div div div\").length, \"No stack or performance problems with large amounts of descendents\" );\n\thtml.remove();\n\n\t// Real use case would be using .watch in browsers with window.watch (see Issue #157)\n\tq(\"qunit-fixture\")[0].appendChild( document.createElement(\"toString\") ).id = \"toString\";\n\tt( \"Element name matches Object.prototype property\", \"toString#toString\", [\"toString\"] );\n});\n\ntest(\"XML Document Selectors\", function() {\n\tvar xml = createWithFriesXML();\n\texpect( 10 );\n\n\tequal( Sizzle(\"foo_bar\", xml).length, 1, \"Element Selector with underscore\" );\n\tequal( Sizzle(\".component\", xml).length, 1, \"Class selector\" );\n\tequal( Sizzle(\"[class*=component]\", xml).length, 1, \"Attribute selector for class\" );\n\tequal( Sizzle(\"property[name=prop2]\", xml).length, 1, \"Attribute selector with name\" );\n\tequal( Sizzle(\"[name=prop2]\", xml).length, 1, \"Attribute selector with name\" );\n\tequal( Sizzle(\"#seite1\", xml).length, 1, \"Attribute selector with ID\" );\n\tequal( Sizzle(\"component#seite1\", xml).length, 1, \"Attribute selector with ID\" );\n\tequal( Sizzle.matches( \"#seite1\", Sizzle(\"component\", xml) ).length, 1, \"Attribute selector filter with ID\" );\n\tequal( Sizzle(\"meta property thing\", xml).length, 2, \"Descendent selector and dir caching\" );\n\tok( Sizzle.matchesSelector( xml.lastChild, \"soap\\\\:Envelope\" ), \"Check for namespaced element\" );\n});\n\ntest(\"broken\", function() {\n\texpect( 26 );\n\n\tfunction broken( name, selector ) {\n\t\traises(function() {\n\t\t\t// Setting context to null here somehow avoids QUnit's window.error handling\n\t\t\t// making the e & e.message correct\n\t\t\t// For whatever reason, without this,\n\t\t\t// Sizzle.error will be called but no error will be seen in oldIE\n\t\t\tSizzle.call( null, selector );\n\t\t}, function( e ) {\n\t\t\treturn e.message.indexOf(\"Syntax error\") >= 0;\n\t\t}, name + \": \" + selector );\n\t}\n\n\tbroken( \"Broken Selector\", \"[\" );\n\tbroken( \"Broken Selector\", \"(\" );\n\tbroken( \"Broken Selector\", \"{\" );\n\tbroken( \"Broken Selector\", \"<\" );\n\tbroken( \"Broken Selector\", \"()\" );\n\tbroken( \"Broken Selector\", \"<>\" );\n\tbroken( \"Broken Selector\", \"{}\" );\n\tbroken( \"Broken Selector\", \",\" );\n\tbroken( \"Broken Selector\", \",a\" );\n\tbroken( \"Broken Selector\", \"a,\" );\n\t// Hangs on IE 9 if regular expression is inefficient\n\tbroken( \"Broken Selector\", \"[id=012345678901234567890123456789\");\n\tbroken( \"Doesn't exist\", \":visble\" );\n\tbroken( \"Nth-child\", \":nth-child\" );\n\t// Sigh again. IE 9 thinks this is also a real selector\n\t// not super critical that we fix this case\n\t//broken( \"Nth-child\", \":nth-child(-)\" );\n\t// Sigh. WebKit thinks this is a real selector in qSA\n\t// They've already fixed this and it'll be coming into\n\t// current browsers soon. Currently, Safari 5.0 still has this problem\n\t// broken( \"Nth-child\", \":nth-child(asdf)\", [] );\n\tbroken( \"Nth-child\", \":nth-child(2n+-0)\" );\n\tbroken( \"Nth-child\", \":nth-child(2+0)\" );\n\tbroken( \"Nth-child\", \":nth-child(- 1n)\" );\n\tbroken( \"Nth-child\", \":nth-child(-1 n)\" );\n\tbroken( \"First-child\", \":first-child(n)\" );\n\tbroken( \"Last-child\", \":last-child(n)\" );\n\tbroken( \"Only-child\", \":only-child(n)\" );\n\tbroken( \"Nth-last-last-child\", \":nth-last-last-child(1)\" );\n\tbroken( \"First-last-child\", \":first-last-child\" );\n\tbroken( \"Last-last-child\", \":last-last-child\" );\n\tbroken( \"Only-last-child\", \":only-last-child\" );\n\n\t// Make sure attribute value quoting works correctly. See: #6093\n\tvar attrbad = jQuery('').appendTo(\"body\");\n\n\tbroken( \"Attribute not escaped\", \"input[name=foo.baz]\", [] );\n\t// Shouldn't be matching those inner brackets\n\tbroken( \"Attribute not escaped\", \"input[name=foo[baz]]\", [] );\n\n\tattrbad.remove();\n});\n\ntest(\"id\", function() {\n\texpect( 31 );\n\n\tt( \"ID Selector\", \"#body\", [\"body\"] );\n\tt( \"ID Selector w/ Element\", \"body#body\", [\"body\"] );\n\tt( \"ID Selector w/ Element\", \"ul#first\", [] );\n\tt( \"ID selector with existing ID descendant\", \"#firstp #simon1\", [\"simon1\"] );\n\tt( \"ID selector with non-existant descendant\", \"#firstp #foobar\", [] );\n\tt( \"ID selector using UTF8\", \"#台北Táiběi\", [\"台北Táiběi\"] );\n\tt( \"Multiple ID selectors using UTF8\", \"#台北Táiběi, #台北\", [\"台北Táiběi\",\"台北\"] );\n\tt( \"Descendant ID selector using UTF8\", \"div #台北\", [\"台北\"] );\n\tt( \"Child ID selector using UTF8\", \"form > #台北\", [\"台北\"] );\n\n\tt( \"Escaped ID\", \"#foo\\\\:bar\", [\"foo:bar\"] );\n\tt( \"Escaped ID with descendent\", \"#foo\\\\:bar span:not(:input)\", [\"foo_descendent\"] );\n\tt( \"Escaped ID\", \"#test\\\\.foo\\\\[5\\\\]bar\", [\"test.foo[5]bar\"] );\n\tt( \"Descendant escaped ID\", \"div #foo\\\\:bar\", [\"foo:bar\"] );\n\tt( \"Descendant escaped ID\", \"div #test\\\\.foo\\\\[5\\\\]bar\", [\"test.foo[5]bar\"] );\n\tt( \"Child escaped ID\", \"form > #foo\\\\:bar\", [\"foo:bar\"] );\n\tt( \"Child escaped ID\", \"form > #test\\\\.foo\\\\[5\\\\]bar\", [\"test.foo[5]bar\"] );\n\n\tvar fiddle = jQuery(\"
\").appendTo(\"#qunit-fixture\");\n\tdeepEqual( Sizzle( \"> span\", Sizzle(\"#fiddle\\\\\\\\Foo\")[0] ), q([ \"fiddleSpan\" ]), \"Escaped ID as context\" );\n\tfiddle.remove();\n\n\tt( \"ID Selector, child ID present\", \"#form > #radio1\", [\"radio1\"] ); // bug #267\n\tt( \"ID Selector, not an ancestor ID\", \"#form #first\", [] );\n\tt( \"ID Selector, not a child ID\", \"#form > #option1a\", [] );\n\n\tt( \"All Children of ID\", \"#foo > *\", [\"sndp\", \"en\", \"sap\"] );\n\tt( \"All Children of ID with no children\", \"#firstUL > *\", [] );\n\n\tvar a = jQuery(\"
\").appendTo(\"#qunit-fixture\");\n\tequal( Sizzle(\"#tName1\")[0].id, 'tName1', \"ID selector with same value for a name attribute\" );\n\tequal( Sizzle(\"#tName2\").length, 0, \"ID selector non-existing but name attribute on an A tag\" );\n\ta.remove();\n\n\ta = jQuery(\"\").appendTo(\"#qunit-fixture\");\n\tt( \"ID Selector contains backslash\", \"#backslash\\\\\\\\foo\", [\"backslash\\\\foo\"] );\n\n\tt( \"ID Selector on Form with an input that has a name of 'id'\", \"#lengthtest\", [\"lengthtest\"] );\n\n\tt( \"ID selector with non-existant ancestor\", \"#asdfasdf #foobar\", [] ); // bug #986\n\n\tdeepEqual( Sizzle(\"div#form\", document.body), [], \"ID selector within the context of another element\" );\n\n\tt( \"Underscore ID\", \"#types_all\", [\"types_all\"] );\n\tt( \"Dash ID\", \"#qunit-fixture\", [\"qunit-fixture\"] );\n\n\tt( \"ID with weird characters in it\", \"#name\\\\+value\", [\"name+value\"] );\n});\n\ntest(\"class\", function() {\n\texpect( 25 );\n\n\tt( \"Class Selector\", \".blog\", [\"mark\",\"simon\"] );\n\tt( \"Class Selector\", \".GROUPS\", [\"groups\"] );\n\tt( \"Class Selector\", \".blog.link\", [\"simon\"] );\n\tt( \"Class Selector w/ Element\", \"a.blog\", [\"mark\",\"simon\"] );\n\tt( \"Parent Class Selector\", \"p .blog\", [\"mark\",\"simon\"] );\n\n\tt( \"Class selector using UTF8\", \".台北Táiběi\", [\"utf8class1\"] );\n\t//t( \"Class selector using UTF8\", \".台北\", [\"utf8class1\",\"utf8class2\"] );\n\tt( \"Class selector using UTF8\", \".台北Táiběi.台北\", [\"utf8class1\"] );\n\tt( \"Class selector using UTF8\", \".台北Táiběi, .台北\", [\"utf8class1\",\"utf8class2\"] );\n\tt( \"Descendant class selector using UTF8\", \"div .台北Táiběi\", [\"utf8class1\"] );\n\tt( \"Child class selector using UTF8\", \"form > .台北Táiběi\", [\"utf8class1\"] );\n\n\tt( \"Escaped Class\", \".foo\\\\:bar\", [\"foo:bar\"] );\n\tt( \"Escaped Class\", \".test\\\\.foo\\\\[5\\\\]bar\", [\"test.foo[5]bar\"] );\n\tt( \"Descendant escaped Class\", \"div .foo\\\\:bar\", [\"foo:bar\"] );\n\tt( \"Descendant escaped Class\", \"div .test\\\\.foo\\\\[5\\\\]bar\", [\"test.foo[5]bar\"] );\n\tt( \"Child escaped Class\", \"form > .foo\\\\:bar\", [\"foo:bar\"] );\n\tt( \"Child escaped Class\", \"form > .test\\\\.foo\\\\[5\\\\]bar\", [\"test.foo[5]bar\"] );\n\n\tvar div = document.createElement(\"div\");\n\tdiv.innerHTML = \"
\";\n\tdeepEqual( Sizzle(\".e\", div), [ div.firstChild ], \"Finding a second class.\" );\n\n\tdiv.lastChild.className = \"e\";\n\n\tdeepEqual( Sizzle(\".e\", div), [ div.firstChild, div.lastChild ], \"Finding a modified class.\" );\n\n\tok( !Sizzle.matchesSelector( div, \".null\"), \".null does not match an element with no class\" );\n\tok( !Sizzle.matchesSelector( div.firstChild, \".null div\"), \".null does not match an element with no class\" );\n\tdiv.className = \"null\";\n\tok( Sizzle.matchesSelector( div, \".null\"), \".null matches element with class 'null'\" );\n\tok( Sizzle.matchesSelector( div.firstChild, \".null div\"), \"caching system respects DOM changes\" );\n\tok( !Sizzle.matchesSelector( document, \".foo\" ), \"testing class on document doesn't error\" );\n\tok( !Sizzle.matchesSelector( window, \".foo\" ), \"testing class on window doesn't error\" );\n\n\tdiv.lastChild.className += \" hasOwnProperty toString\";\n\tdeepEqual( Sizzle(\".e.hasOwnProperty.toString\", div), [ div.lastChild ], \"Classes match Object.prototype properties\" );\n});\n\ntest(\"name\", function() {\n\texpect( 15 );\n\n\tt( \"Name selector\", \"input[name=action]\", [\"text1\"] );\n\tt( \"Name selector with single quotes\", \"input[name='action']\", [\"text1\"] );\n\tt( \"Name selector with double quotes\", 'input[name=\"action\"]', [\"text1\"] );\n\n\tt( \"Name selector non-input\", \"[name=example]\", [\"name-is-example\"] );\n\tt( \"Name selector non-input\", \"[name=div]\", [\"name-is-div\"] );\n\tt( \"Name selector non-input\", \"*[name=iframe]\", [\"iframe\"] );\n\n\tt( \"Name selector for grouped input\", \"input[name='types[]']\", [\"types_all\", \"types_anime\", \"types_movie\"] );\n\n\tvar form = document.getElementById(\"form\");\n\tdeepEqual( Sizzle(\"input[name=action]\", form), q(\"text1\"), \"Name selector within the context of another element\" );\n\tdeepEqual( Sizzle(\"input[name='foo[bar]']\", form), q(\"hidden2\"), \"Name selector for grouped form element within the context of another element\" );\n\n\tform = jQuery(\"
\").appendTo(\"body\");\n\tequal( Sizzle(\"input\", form[0]).length, 1, \"Make sure that rooted queries on forms (with possible expandos) work.\" );\n\n\tform.remove();\n\n\tvar a = jQuery(\"
\")[0];\n\tdeepEqual( Sizzle( \":last\", context ), q(\"jquery12526\"), \"Post-manipulation positional\" );\n\tQUnit.reset();\n\n\t// Sizzle extension\n\tSizzle.selectors.setFilters[\"primary\"] = Sizzle.selectors.setFilters[\"first\"];\n\tt( \"Extend Sizzle's POS selectors to rename first to primary\", \"div:primary\", [\"qunit\"] );\n\t// Reset\n\tdelete Sizzle.selectors.setFilters[\"primary\"];\n});\n\ntest(\"pseudo - form\", function() {\n\texpect( 10 );\n\n\tvar extraTexts = jQuery(\"\").appendTo(\"#form\");\n\n\tt( \"Form element :input\", \"#form :input\", [\"text1\", \"text2\", \"radio1\", \"radio2\", \"check1\", \"check2\", \"hidden1\", \"hidden2\", \"name\", \"search\", \"button\", \"area1\", \"select1\", \"select2\", \"select3\", \"select4\", \"select5\", \"impliedText\", \"capitalText\"] );\n\tt( \"Form element :radio\", \"#form :radio\", [\"radio1\", \"radio2\"] );\n\tt( \"Form element :checkbox\", \"#form :checkbox\", [\"check1\", \"check2\"] );\n\tt( \"Form element :text\", \"#form :text\", [\"text1\", \"text2\", \"hidden2\", \"name\", \"impliedText\", \"capitalText\"] );\n\tt( \"Form element :radio:checked\", \"#form :radio:checked\", [\"radio2\"] );\n\tt( \"Form element :checkbox:checked\", \"#form :checkbox:checked\", [\"check1\"] );\n\tt( \"Form element :radio:checked, :checkbox:checked\", \"#form :radio:checked, #form :checkbox:checked\", [\"radio2\", \"check1\"] );\n\n\tt( \"Selected Option Element\", \"#form option:selected\", [\"option1a\",\"option2d\",\"option3b\",\"option3c\",\"option4b\",\"option4c\",\"option4d\",\"option5a\"] );\n\tt( \"Selected Option Element are also :checked\", \"#form option:checked\", [\"option1a\",\"option2d\",\"option3b\",\"option3c\",\"option4b\",\"option4c\",\"option4d\",\"option5a\"] );\n\tt( \"Hidden inputs should be treated as enabled. See QSA test.\", \"#hidden1:enabled\", [\"hidden1\"] );\n\n\textraTexts.remove();\n});\n\ntest(\"caching\", function() {\n\texpect( 1 );\n\tSizzle( \":not(code)\", document.getElementById(\"ap\") );\n\tdeepEqual( Sizzle( \":not(code)\", document.getElementById(\"foo\") ), q(\"sndp\", \"en\", \"yahoo\", \"sap\", \"anchor2\", \"simon\"), \"Reusing selector with new context\" );\n});\n"},"new_file":{"kind":"string","value":"test/unit/selector.js"},"old_contents":{"kind":"string","value":"/*global\n\tQUnit: true,\n\tq: true,\n\tt: true,\n\turl: true,\n\tcreateWithFriesXML: true,\n\tSizzle: true,\n\tmodule: true,\n\ttest: true,\n\tasyncTest: true,\n\texpect: true,\n\tstop: true,\n\tstart: true,\n\tok: true,\n\tequal: true,\n\tnotEqual: true,\n\tdeepEqual: true,\n\tnotDeepEqual: true,\n\tstrictEqual: true,\n\tnotStrictEqual: true,\n\traises: true,\n\tmoduleTeardown: true\n*/\n\nmodule(\"selector\", { teardown: moduleTeardown });\n\n// #### NOTE: ####\n// jQuery should not be used in this module\n// except for DOM manipulation\n// If jQuery is mandatory for the selection, move the test to jquery/test/unit/selector.js\n// Use t() or Sizzle()\n// ###############\n\n/*\n\t======== QUnit Reference ========\n\thttp://docs.jquery.com/QUnit\n\n\tTest methods:\n\t\texpect(numAssertions)\n\t\tstop()\n\t\tstart()\n\t\t\tnote: QUnit's eventual addition of an argument to stop/start is ignored in this test suite\n\t\t\tso that start and stop can be passed as callbacks without worrying about\n\t\t\t\ttheir parameters\n\tTest assertions:\n\t\tok(value, [message])\n\t\tequal(actual, expected, [message])\n\t\tnotEqual(actual, expected, [message])\n\t\tdeepEqual(actual, expected, [message])\n\t\tnotDeepEqual(actual, expected, [message])\n\t\tstrictEqual(actual, expected, [message])\n\t\tnotStrictEqual(actual, expected, [message])\n\t\traises(block, [expected], [message])\n\n\t======== testinit.js reference ========\n\tSee data/testinit.js\n\n\tq(...);\n\t\tReturns an array of elements with the given IDs\n\t\t@example q(\"main\", \"foo\", \"bar\") => [
, , ]\n\n\tt( testName, selector, [ \"array\", \"of\", \"ids\" ] );\n\t\tAsserts that a select matches the given IDs\n\t\t@example t(\"Check for something\", \"//[a]\", [\"foo\", \"baar\"]);\n\n\turl( \"some/url.php\" );\n\t\tAdd random number to url to stop caching\n\t\t@example url(\"data/test.html\") => \"data/test.html?10538358428943\"\n\t\t@example url(\"data/test.php?foo=bar\") => \"data/test.php?foo=bar&10538358345554\"\n*/\n\ntest(\"element\", function() {\n\texpect( 37 );\n\n\tequal( Sizzle(\"\").length, 0, \"Empty selector returns an empty array\" );\n\tequal( Sizzle(\" \").length, 0, \"Empty selector returns an empty array\" );\n\tequal( Sizzle(\"\\t\").length, 0, \"Empty selector returns an empty array\" );\n\tvar form = document.getElementById(\"form\");\n\tok( !Sizzle.matchesSelector( form, \"\" ), \"Empty string passed to matchesSelector does not match\" );\n\n\tok( Sizzle(\"*\").length >= 30, \"Select all\" );\n\tvar all = Sizzle(\"*\"), good = true;\n\tfor ( var i = 0; i < all.length; i++ ) {\n\t\tif ( all[i].nodeType == 8 ) {\n\t\t\tgood = false;\n\t\t}\n\t}\n\tok( good, \"Select all elements, no comment nodes\" );\n\tt( \"Element Selector\", \"html\", [\"html\"] );\n\tt( \"Element Selector\", \"body\", [\"body\"] );\n\tt( \"Element Selector\", \"#qunit-fixture p\", [\"firstp\",\"ap\",\"sndp\",\"en\",\"sap\",\"first\"] );\n\n\tt( \"Leading space\", \" #qunit-fixture p\", [\"firstp\",\"ap\",\"sndp\",\"en\",\"sap\",\"first\"] );\n\tt( \"Leading tab\", \"\\t#qunit-fixture p\", [\"firstp\",\"ap\",\"sndp\",\"en\",\"sap\",\"first\"] );\n\tt( \"Leading carriage return\", \"\\r#qunit-fixture p\", [\"firstp\",\"ap\",\"sndp\",\"en\",\"sap\",\"first\"] );\n\tt( \"Leading line feed\", \"\\n#qunit-fixture p\", [\"firstp\",\"ap\",\"sndp\",\"en\",\"sap\",\"first\"] );\n\tt( \"Leading form feed\", \"\\f#qunit-fixture p\", [\"firstp\",\"ap\",\"sndp\",\"en\",\"sap\",\"first\"] );\n\tt( \"Trailing space\", \"#qunit-fixture p \", [\"firstp\",\"ap\",\"sndp\",\"en\",\"sap\",\"first\"] );\n\tt( \"Trailing tab\", \"#qunit-fixture p\\t\", [\"firstp\",\"ap\",\"sndp\",\"en\",\"sap\",\"first\"] );\n\tt( \"Trailing carriage return\", \"#qunit-fixture p\\r\", [\"firstp\",\"ap\",\"sndp\",\"en\",\"sap\",\"first\"] );\n\tt( \"Trailing line feed\", \"#qunit-fixture p\\n\", [\"firstp\",\"ap\",\"sndp\",\"en\",\"sap\",\"first\"] );\n\tt( \"Trailing form feed\", \"#qunit-fixture p\\f\", [\"firstp\",\"ap\",\"sndp\",\"en\",\"sap\",\"first\"] );\n\n\tt( \"Parent Element\", \"dl ol\", [\"empty\", \"listWithTabIndex\"] );\n\tt( \"Parent Element (non-space descendant combinator)\", \"dl\\tol\", [\"empty\", \"listWithTabIndex\"] );\n\tvar obj1 = document.getElementById(\"object1\");\n\tequal( Sizzle(\"param\", obj1).length, 2, \"Object/param as context\" );\n\n\tdeepEqual( Sizzle(\"select\", form), q(\"select1\",\"select2\",\"select3\",\"select4\",\"select5\"), \"Finding selects with a context.\" );\n\n\t// Check for unique-ness and sort order\n\tdeepEqual( Sizzle(\"p, div p\"), Sizzle(\"p\"), \"Check for duplicates: p, div p\" );\n\n\tt( \"Checking sort order\", \"h2, h1\", [\"qunit-header\", \"qunit-banner\", \"qunit-userAgent\"] );\n\tt( \"Checking sort order\", \"h2:first, h1:first\", [\"qunit-header\", \"qunit-banner\"] );\n\tt( \"Checking sort order\", \"#qunit-fixture p, #qunit-fixture p a\", [\"firstp\", \"simon1\", \"ap\", \"google\", \"groups\", \"anchor1\", \"mark\", \"sndp\", \"en\", \"yahoo\", \"sap\", \"anchor2\", \"simon\", \"first\"] );\n\n\t// Test Conflict ID\n\tvar lengthtest = document.getElementById(\"lengthtest\");\n\tdeepEqual( Sizzle(\"#idTest\", lengthtest), q(\"idTest\"), \"Finding element with id of ID.\" );\n\tdeepEqual( Sizzle(\"[name='id']\", lengthtest), q(\"idTest\"), \"Finding element with id of ID.\" );\n\tdeepEqual( Sizzle(\"input[id='idTest']\", lengthtest), q(\"idTest\"), \"Finding elements with id of ID.\" );\n\n\tvar siblingTest = document.getElementById(\"siblingTest\");\n\tdeepEqual( Sizzle(\"div em\", siblingTest), [], \"Element-rooted QSA does not select based on document context\" );\n\tdeepEqual( Sizzle(\"div em, div em, div em:not(div em)\", siblingTest), [], \"Element-rooted QSA does not select based on document context\" );\n\tdeepEqual( Sizzle(\"div em, em\\\\,\", siblingTest), [], \"Escaped commas do not get treated with an id in element-rooted QSA\" );\n\n\tvar iframe = document.getElementById(\"iframe\"),\n\t\tiframeDoc = iframe.contentDocument || iframe.contentWindow.document;\n\tiframeDoc.open();\n\tiframeDoc.write(\"
bar
\");\n\tiframeDoc.close();\n\tdeepEqual(\n\t\tSizzle( \"p:contains(bar)\", iframeDoc ),\n\t\t[ iframeDoc.getElementById(\"foo\") ],\n\t\t\"Other document as context\"\n\t);\n\n\tvar html = \"\";\n\tfor ( i = 0; i < 100; i++ ) {\n\t\thtml = \"
\" + html + \"
\";\n\t}\n\thtml = jQuery( html ).appendTo( document.body );\n\tok( !!Sizzle(\"body div div div\").length, \"No stack or performance problems with large amounts of descendents\" );\n\tok( !!Sizzle(\"body>div div div\").length, \"No stack or performance problems with large amounts of descendents\" );\n\thtml.remove();\n\n\t// Real use case would be using .watch in browsers with window.watch (see Issue #157)\n\tq(\"qunit-fixture\")[0].appendChild( document.createElement(\"toString\") ).id = \"toString\";\n\tt( \"Element name matches Object.prototype property\", \"toString#toString\", [\"toString\"] );\n});\n\ntest(\"XML Document Selectors\", function() {\n\tvar xml = createWithFriesXML();\n\texpect( 10 );\n\n\tequal( Sizzle(\"foo_bar\", xml).length, 1, \"Element Selector with underscore\" );\n\tequal( Sizzle(\".component\", xml).length, 1, \"Class selector\" );\n\tequal( Sizzle(\"[class*=component]\", xml).length, 1, \"Attribute selector for class\" );\n\tequal( Sizzle(\"property[name=prop2]\", xml).length, 1, \"Attribute selector with name\" );\n\tequal( Sizzle(\"[name=prop2]\", xml).length, 1, \"Attribute selector with name\" );\n\tequal( Sizzle(\"#seite1\", xml).length, 1, \"Attribute selector with ID\" );\n\tequal( Sizzle(\"component#seite1\", xml).length, 1, \"Attribute selector with ID\" );\n\tequal( Sizzle.matches( \"#seite1\", Sizzle(\"component\", xml) ).length, 1, \"Attribute selector filter with ID\" );\n\tequal( Sizzle(\"meta property thing\", xml).length, 2, \"Descendent selector and dir caching\" );\n\tok( Sizzle.matchesSelector( xml.lastChild, \"soap\\\\:Envelope\" ), \"Check for namespaced element\" );\n});\n\ntest(\"broken\", function() {\n\texpect( 26 );\n\n\tfunction broken( name, selector ) {\n\t\traises(function() {\n\t\t\tSizzle.call( null, selector );\n\t\t}, function( e ) {\n\t\t\treturn e.message.indexOf(\"Syntax error\") >= 0;\n\t\t}, name + \": \" + selector );\n\t}\n\n\tbroken( \"Broken Selector\", \"[\" );\n\tbroken( \"Broken Selector\", \"(\" );\n\tbroken( \"Broken Selector\", \"{\" );\n\tbroken( \"Broken Selector\", \"<\" );\n\tbroken( \"Broken Selector\", \"()\" );\n\tbroken( \"Broken Selector\", \"<>\" );\n\tbroken( \"Broken Selector\", \"{}\" );\n\tbroken( \"Broken Selector\", \",\" );\n\tbroken( \"Broken Selector\", \",a\" );\n\tbroken( \"Broken Selector\", \"a,\" );\n\t// Hangs on IE 9 if regular expression is inefficient\n\tbroken( \"Broken Selector\", \"[id=012345678901234567890123456789\");\n\tbroken( \"Doesn't exist\", \":visble\" );\n\tbroken( \"Nth-child\", \":nth-child\" );\n\t// Sigh again. IE 9 thinks this is also a real selector\n\t// not super critical that we fix this case\n\t//broken( \"Nth-child\", \":nth-child(-)\" );\n\t// Sigh. WebKit thinks this is a real selector in qSA\n\t// They've already fixed this and it'll be coming into\n\t// current browsers soon. Currently, Safari 5.0 still has this problem\n\t// broken( \"Nth-child\", \":nth-child(asdf)\", [] );\n\tbroken( \"Nth-child\", \":nth-child(2n+-0)\" );\n\tbroken( \"Nth-child\", \":nth-child(2+0)\" );\n\tbroken( \"Nth-child\", \":nth-child(- 1n)\" );\n\tbroken( \"Nth-child\", \":nth-child(-1 n)\" );\n\tbroken( \"First-child\", \":first-child(n)\" );\n\tbroken( \"Last-child\", \":last-child(n)\" );\n\tbroken( \"Only-child\", \":only-child(n)\" );\n\tbroken( \"Nth-last-last-child\", \":nth-last-last-child(1)\" );\n\tbroken( \"First-last-child\", \":first-last-child\" );\n\tbroken( \"Last-last-child\", \":last-last-child\" );\n\tbroken( \"Only-last-child\", \":only-last-child\" );\n\n\t// Make sure attribute value quoting works correctly. See: #6093\n\tvar attrbad = jQuery('').appendTo(\"body\");\n\n\tbroken( \"Attribute not escaped\", \"input[name=foo.baz]\", [] );\n\t// Shouldn't be matching those inner brackets\n\tbroken( \"Attribute not escaped\", \"input[name=foo[baz]]\", [] );\n\n\tattrbad.remove();\n});\n\ntest(\"id\", function() {\n\texpect( 31 );\n\n\tt( \"ID Selector\", \"#body\", [\"body\"] );\n\tt( \"ID Selector w/ Element\", \"body#body\", [\"body\"] );\n\tt( \"ID Selector w/ Element\", \"ul#first\", [] );\n\tt( \"ID selector with existing ID descendant\", \"#firstp #simon1\", [\"simon1\"] );\n\tt( \"ID selector with non-existant descendant\", \"#firstp #foobar\", [] );\n\tt( \"ID selector using UTF8\", \"#台北Táiběi\", [\"台北Táiběi\"] );\n\tt( \"Multiple ID selectors using UTF8\", \"#台北Táiběi, #台北\", [\"台北Táiběi\",\"台北\"] );\n\tt( \"Descendant ID selector using UTF8\", \"div #台北\", [\"台北\"] );\n\tt( \"Child ID selector using UTF8\", \"form > #台北\", [\"台北\"] );\n\n\tt( \"Escaped ID\", \"#foo\\\\:bar\", [\"foo:bar\"] );\n\tt( \"Escaped ID with descendent\", \"#foo\\\\:bar span:not(:input)\", [\"foo_descendent\"] );\n\tt( \"Escaped ID\", \"#test\\\\.foo\\\\[5\\\\]bar\", [\"test.foo[5]bar\"] );\n\tt( \"Descendant escaped ID\", \"div #foo\\\\:bar\", [\"foo:bar\"] );\n\tt( \"Descendant escaped ID\", \"div #test\\\\.foo\\\\[5\\\\]bar\", [\"test.foo[5]bar\"] );\n\tt( \"Child escaped ID\", \"form > #foo\\\\:bar\", [\"foo:bar\"] );\n\tt( \"Child escaped ID\", \"form > #test\\\\.foo\\\\[5\\\\]bar\", [\"test.foo[5]bar\"] );\n\n\tvar fiddle = jQuery(\"
\").appendTo(\"#qunit-fixture\");\n\tdeepEqual( Sizzle( \"> span\", Sizzle(\"#fiddle\\\\\\\\Foo\")[0] ), q([ \"fiddleSpan\" ]), \"Escaped ID as context\" );\n\tfiddle.remove();\n\n\tt( \"ID Selector, child ID present\", \"#form > #radio1\", [\"radio1\"] ); // bug #267\n\tt( \"ID Selector, not an ancestor ID\", \"#form #first\", [] );\n\tt( \"ID Selector, not a child ID\", \"#form > #option1a\", [] );\n\n\tt( \"All Children of ID\", \"#foo > *\", [\"sndp\", \"en\", \"sap\"] );\n\tt( \"All Children of ID with no children\", \"#firstUL > *\", [] );\n\n\tvar a = jQuery(\"
\\\n '\n\n var budgetAction = $('.nav-main').find(\".mail-1\").closest(\"a\").data('ember-action');\n var accountAction = $('.nav-main').find(\".government-1\").closest(\"a\").data('ember-action');\n\n var expandBtns = '\\\n
\\\n '\n\n var budgetAction = $('.nav-main').find(\".mail-1\").closest(\"a\").data('ember-action');\n var accountAction = $('.nav-main').find(\".government-1\").closest(\"a\").data('ember-action');\n\n var expandBtns = '\\\n
';\n\n var originalSizes = {\n sidebarWidth: $(\".sidebar\").width(),\n contentLeft: $(\".content\").css(\"left\"),\n headerLeft: $(\".budget-header\").css(\"left\"),\n contentWidth: $(\".budget-content\").css(\"width\"),\n inspectorWidth: $(\".budget-inspector\").css(\"width\")\n }\n\n if (!$(\".collapsed-buttons\").length) {\n $(\".sidebar\").prepend(expandBtns);\n } else {\n $(\".collapsed-buttons\").remove();\n $(\".sidebar\").prepend(expandBtns);\n }\n\n $(\".nav-main\").append(collapseBtn);\n $(\".collapsed-buttons\").hide();\n\n $(\".navlink-collapse\").on(\"click\", collapseMenu);\n $(\".navbar-expand\").on(\"click\", function() {\n expandMenu(originalSizes)\n });\n\n // Monitor our button and set up watcher in case we change screens\n watchButton();\n}\n\n// Handle clicking expand button. Puts things back to original sizes\nfunction expandMenu(originalSizes) {\n $(\".sidebar > .ember-view\").show();\n $(\".sidebar\").width(originalSizes.sidebarWidth);\n $(\".content\").css(\"left\", originalSizes.contentLeft);\n $(\".budget-header\").css(\"left\", originalSizes.headerLeft);\n $(\".budget-content\").css(\"width\", originalSizes.contentWidth);\n $(\".budget-inspector\").css(\"width\", originalSizes.inspectorWidth);\n $(\".collapsed-buttons\").hide();\n}\n\n// Handle clicking the collapse button\nfunction collapseMenu() {\n setActiveButton();\n $(\".sidebar > .ember-view\").hide();\n $(\".collapsed-buttons\").show();\n setCollapsedSizes();\n}\n\n// Set collapsed sizes\nfunction setCollapsedSizes() {\n $(\".sidebar\").width(\"40px\");\n $(\".content\").css(\"left\", \"40px\");\n $(\".budget-header\").css(\"left\", \"40px\");\n $(\".budget-content\").css(\"width\", \"73%\");\n $(\".budget-inspector\").css(\"width\", \"27%\");\n $(\".ynab-grid-header\").removeAttr(\"style\");\n}\n\n// Add the active style to correct button\nfunction setActiveButton() {\n deactivateCollapsedActive();\n if ($(\".accounts-toolbar\").length) {\n $(\".collapsed-account\").addClass('collapsed-active');\n }\n if ($(\".budget-toolbar\").length) {\n $(\".collapsed-budget\").addClass('collapsed-active');\n }\n}\n\n// Deactivate collapsed buttons\nfunction deactivateCollapsedActive() {\n $(\".collapsed-account\").removeClass('collapsed-active');\n $(\".collapsed-budget\").removeClass('collapsed-active');\n}"},"message":{"kind":"string","value":"Change function name to avoid conflict\n"},"old_file":{"kind":"string","value":"src/features/collapse-side-menu/main.js"},"subject":{"kind":"string","value":"Change function name to avoid conflict"},"git_diff":{"kind":"string","value":"rc/features/collapse-side-menu/main.js\nfunction injectInitializer() {\nfunction injectCollapseInitializer() {\n if (typeof Em !== 'undefined' && typeof Ember !== 'undefined') {\n (function($){\n $.event.special.destroyed = {\n }\n });\n } else {\n setTimeout(injectInitializer, 250);\n setTimeout(injectCollapseInitializer, 250);\n }\n }\n \nsetTimeout(injectInitializer, 250);\nsetTimeout(injectCollapseInitializer, 250);\n \n // Watch for the budget grid\n function watchBudgetGrid() {"}}},{"rowIdx":646,"cells":{"lang":{"kind":"string","value":"JavaScript"},"license":{"kind":"string","value":"bsd-2-clause"},"stderr":{"kind":"string","value":""},"commit":{"kind":"string","value":"f28eacffc3c7092c337e0622196ea1df1cda84c5"},"returncode":{"kind":"number","value":0,"string":"0"},"repos":{"kind":"string","value":"macbre/phantomas,macbre/phantomas,macbre/phantomas"},"new_contents":{"kind":"string","value":"/**\n * phantomas CommonJS module\n */\n\"use strict\";\n\nconst Browser = require(\"./browser\"),\n EventEmitter = require(\"./AwaitEventEmitter\"),\n debug = require(\"debug\")(\"phantomas:core\"),\n loader = require(\"./loader\"),\n puppeteer = require(\"puppeteer\"),\n path = require(\"path\"),\n Results = require(\"../core/results\"),\n VERSION = require(\"./../package\").version;\n\n/**\n * Main CommonJS module entry point\n *\n * @param {string} url\n * @param {Object} opts\n * @returns {browser}\n */\nfunction phantomas(url, opts) {\n var events = new EventEmitter(),\n browser,\n options;\n\n debug(\"OS: %s %s\", process.platform, process.arch);\n debug(\"Node.js: %s\", process.version);\n debug(\"phantomas: %s\", VERSION);\n debug(\n \"Puppeteer: preferred revision r%s\",\n puppeteer._launcher._preferredRevision\n );\n debug(\"URL: <%s>\", url);\n\n // options handling\n options = Object.assign({}, opts || {}); // avoid #563\n options.url = options.url || url || false;\n\n debug(\"Options: %s\", JSON.stringify(options));\n\n events.setMaxListeners(100); // MaxListenersExceededWarning: Possible EventEmitter memory leak detected.\n\n var results = new Results();\n results.setUrl(url);\n results.setGenerator(\"phantomas v\" + VERSION);\n\n // set up and run Puppeteer\n browser = new Browser();\n browser.bind(events);\n\n var promise = new Promise(async (resolve, reject) => {\n try {\n if (typeof options.url !== \"string\") {\n return reject(Error(\"URL must be a string\"));\n }\n\n const page = await browser.init(options),\n debugScope = require(\"debug\")(\"phantomas:scope:log\");\n\n // prepare a small instance object that will be passed to modules and extensions on init\n const scope = {\n getParam: (param, _default) => {\n return options[param] || _default;\n },\n getVersion: () => VERSION,\n\n emit: events.emit.bind(events),\n on: events.on.bind(events),\n once: events.once.bind(events),\n\n log: debugScope.bind(debug),\n\n addOffender: results.addOffender.bind(results),\n incrMetric: results.incrMetric.bind(results),\n setMetric: results.setMetric,\n addToAvgMetric: results.addToAvgMetric,\n\n getMetric: results.getMetric,\n\n // @see https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pageevaluatepagefunction-args\n evaluate: page.evaluate.bind(page),\n\n // @see https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pageselector-1\n /* istanbul ignore next */\n querySelectorAll: async (selector) => {\n debug('querySelectorAll(\"%s\")', selector);\n return page.$$(selector);\n },\n\n // @see https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pageevaluateonnewdocumentpagefunction-args\n injectJs: async (script) => {\n const debug = require(\"debug\")(\"phantomas:injectJs\");\n\n // Make sure we're on an HTML document, not an XML document for example\n const prefix = \"if (document.constructor.name === 'HTMLDocument') {\",\n suffix = \"}\";\n\n const preloadFile =\n prefix + require(\"fs\").readFileSync(script, \"utf8\") + suffix;\n\n await page.evaluateOnNewDocument(preloadFile);\n\n debug(script + \" JavaScript file has been injected into page scope\");\n },\n };\n\n // pass phantomas options to page scope\n // https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pageevaluateonnewdocumentpagefunction-args\n /* istanbul ignore next */\n await page.evaluateOnNewDocument((options) => {\n window.__phantomas_options = options;\n }, options);\n\n // expose the function that will pass events from page scope code into Node.js layer\n // @see https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pageexposefunctionname-puppeteerfunction\n await page.exposeFunction(\"__phantomas_emit\", scope.emit);\n\n // Inject helper code into the browser's scope\n events.on(\"init\", () => {\n scope.injectJs(__dirname + \"/../core/scope.js\");\n });\n\n // bind to sendMsg calls from page scope code\n events.on(\"scopeMessage\", (type, args) => {\n const debug = require(\"debug\")(\"phantomas:core:scopeEvents\");\n // debug(type + ' [' + args + ']');\n\n switch (type) {\n case \"addOffender\":\n case \"incrMetric\":\n case \"log\":\n case \"setMetric\":\n scope[type].apply(scope, args);\n break;\n\n /* istanbul ignore next */\n default:\n debug(\"Unrecognized event type: \" + type);\n }\n });\n\n // bind to a first response\n // and reject a promise if the first response is 4xx / 5xx HTTP error\n var firstResponseReceived = false;\n\n events.once(\"recv\", async (entry) => {\n if (!firstResponseReceived && entry.status >= 400) {\n debug(\n \"<%s> response code is HTTP %d %s\",\n entry.url,\n entry.status,\n entry.statusText\n );\n\n // close the browser before leaving here, otherwise subsequent instances will have problems\n await browser.close();\n reject(\n new Error(\n \"HTTP response code from <\" + entry.url + \"> is \" + entry.status\n )\n );\n }\n\n firstResponseReceived = true;\n });\n\n // load modules and extensions\n debug(\"Loading core modules...\");\n loader.loadCoreModules(scope);\n\n debug(\"Loading extensions...\");\n loader.loadExtensions(scope);\n\n debug(\"Loading modules...\");\n loader.loadModules(scope);\n\n await events.emit(\"init\", page, browser.getPuppeteerBrowser()); // @desc Browser's scope and modules are set up, the page is about to be loaded\n\n // https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pagegotourl-options\n const waitUntil = options[\"wait-for-network-idle\"]\n ? \"networkidle0\"\n : undefined,\n timeout = options.timeout;\n\n await browser.visit(url, waitUntil, timeout);\n\n // resolve our run\n // https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#browserclose\n await events.emit(\"beforeClose\", page); // @desc Called before the Chromium (and all of its pages) is closed\n await browser.close();\n\n // your last chance to add metrics\n await events.emit(\"report\"); // @desc Called just before the phantomas results are returned to the caller\n\n resolve(results);\n } catch (ex) {\n debug(\"Exception caught: \" + ex);\n debug(ex);\n\n // close the browser before leaving here, otherwise subsequent instances will have problems\n await browser.close();\n reject(ex);\n }\n });\n\n promise.on = events.on.bind(events);\n promise.once = events.once.bind(events);\n\n return promise;\n}\n\nphantomas.metadata = require(__dirname + \"/metadata/metadata.json\");\nphantomas.path = path.normalize(__dirname + \"/..\");\nphantomas.version = VERSION;\n\nmodule.exports = phantomas;\n"},"new_file":{"kind":"string","value":"lib/index.js"},"old_contents":{"kind":"string","value":"/**\n * phantomas CommonJS module\n */\n\"use strict\";\n\nconst Browser = require(\"./browser\"),\n EventEmitter = require(\"./AwaitEventEmitter\"),\n debug = require(\"debug\")(\"phantomas:core\"),\n loader = require(\"./loader\"),\n puppeteer = require(\"puppeteer\"),\n path = require(\"path\"),\n Results = require(\"../core/results\"),\n VERSION = require(\"./../package\").version;\n\n/**\n * Main CommonJS module entry point\n *\n * @param {string} url\n * @param {Object} opts\n * @returns {browser}\n */\nfunction phantomas(url, opts) {\n var events = new EventEmitter(),\n browser,\n options;\n\n debug(\"OS: %s %s\", process.platform, process.arch);\n debug(\"Node.js: %s\", process.version);\n debug(\"phantomas: %s\", VERSION);\n debug(\n \"Puppeteer: preferred revision r%s\",\n puppeteer._launcher._preferredRevision\n );\n debug(\"URL: <%s>\", url);\n\n // options handling\n options = Object.assign({}, opts || {}); // avoid #563\n options.url = options.url || url || false;\n\n debug(\"Options: %s\", JSON.stringify(options));\n\n events.setMaxListeners(100); // MaxListenersExceededWarning: Possible EventEmitter memory leak detected.\n\n var results = new Results();\n results.setUrl(url);\n results.setGenerator(\"phantomas v\" + VERSION);\n\n // set up and run Puppeteer\n browser = new Browser();\n browser.bind(events);\n\n var promise = new Promise(async (resolve, reject) => {\n try {\n if (typeof options.url !== \"string\") {\n return reject(Error(\"URL must be a string\"));\n }\n\n const page = await browser.init(options),\n debugScope = require(\"debug\")(\"phantomas:scope:log\");\n\n // prepare a small instance object that will be passed to modules and extensions on init\n const scope = {\n getParam: (param, _default) => {\n return options[param] || _default;\n },\n getVersion: () => VERSION,\n\n emit: events.emit.bind(events),\n on: events.on.bind(events),\n once: events.once.bind(events),\n\n log: debugScope.bind(debug),\n\n addOffender: results.addOffender.bind(results),\n incrMetric: results.incrMetric.bind(results),\n setMetric: results.setMetric,\n addToAvgMetric: results.addToAvgMetric,\n\n getMetric: results.getMetric,\n\n // @see https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pageevaluatepagefunction-args\n evaluate: page.evaluate.bind(page),\n\n // @see https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pageselector-1\n querySelectorAll: async (selector) => {\n debug('querySelectorAll(\"%s\")', selector);\n return page.$$(selector);\n },\n\n // @see https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pageevaluateonnewdocumentpagefunction-args\n injectJs: async (script) => {\n const debug = require(\"debug\")(\"phantomas:injectJs\");\n\n // Make sure we're on an HTML document, not an XML document for example\n const prefix = \"if (document.constructor.name === 'HTMLDocument') {\",\n suffix = \"}\";\n\n const preloadFile =\n prefix + require(\"fs\").readFileSync(script, \"utf8\") + suffix;\n\n await page.evaluateOnNewDocument(preloadFile);\n\n debug(script + \" JavaScript file has been injected into page scope\");\n },\n };\n\n // pass phantomas options to page scope\n // https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pageevaluateonnewdocumentpagefunction-args\n /* istanbul ignore next */\n await page.evaluateOnNewDocument((options) => {\n window.__phantomas_options = options;\n }, options);\n\n // expose the function that will pass events from page scope code into Node.js layer\n // @see https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pageexposefunctionname-puppeteerfunction\n await page.exposeFunction(\"__phantomas_emit\", scope.emit);\n\n // Inject helper code into the browser's scope\n events.on(\"init\", () => {\n scope.injectJs(__dirname + \"/../core/scope.js\");\n });\n\n // bind to sendMsg calls from page scope code\n events.on(\"scopeMessage\", (type, args) => {\n const debug = require(\"debug\")(\"phantomas:core:scopeEvents\");\n // debug(type + ' [' + args + ']');\n\n switch (type) {\n case \"addOffender\":\n case \"incrMetric\":\n case \"log\":\n case \"setMetric\":\n scope[type].apply(scope, args);\n break;\n\n default:\n debug(\"Unrecognized event type: \" + type);\n }\n });\n\n // bind to a first response\n // and reject a promise if the first response is 4xx / 5xx HTTP error\n var firstResponseReceived = false;\n\n events.once(\"recv\", async (entry) => {\n if (!firstResponseReceived && entry.status >= 400) {\n debug(\n \"<%s> response code is HTTP %d %s\",\n entry.url,\n entry.status,\n entry.statusText\n );\n\n // close the browser before leaving here, otherwise subsequent instances will have problems\n await browser.close();\n reject(\n new Error(\n \"HTTP response code from <\" + entry.url + \"> is \" + entry.status\n )\n );\n }\n\n firstResponseReceived = true;\n });\n\n // load modules and extensions\n debug(\"Loading core modules...\");\n loader.loadCoreModules(scope);\n\n debug(\"Loading extensions...\");\n loader.loadExtensions(scope);\n\n debug(\"Loading modules...\");\n loader.loadModules(scope);\n\n await events.emit(\"init\", page, browser.getPuppeteerBrowser()); // @desc Browser's scope and modules are set up, the page is about to be loaded\n\n // https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pagegotourl-options\n const waitUntil = options[\"wait-for-network-idle\"]\n ? \"networkidle0\"\n : undefined,\n timeout = options.timeout;\n\n await browser.visit(url, waitUntil, timeout);\n\n // resolve our run\n // https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#browserclose\n await events.emit(\"beforeClose\", page); // @desc Called before the Chromium (and all of its pages) is closed\n await browser.close();\n\n // your last chance to add metrics\n await events.emit(\"report\"); // @desc Called just before the phantomas results are returned to the caller\n\n resolve(results);\n } catch (ex) {\n debug(\"Exception caught: \" + ex);\n debug(ex);\n\n // close the browser before leaving here, otherwise subsequent instances will have problems\n await browser.close();\n reject(ex);\n }\n });\n\n promise.on = events.on.bind(events);\n promise.once = events.once.bind(events);\n\n return promise;\n}\n\nphantomas.metadata = require(__dirname + \"/metadata/metadata.json\");\nphantomas.path = path.normalize(__dirname + \"/..\");\nphantomas.version = VERSION;\n\nmodule.exports = phantomas;\n"},"message":{"kind":"string","value":"lib/index.js: skip coverage for two code branches\n"},"old_file":{"kind":"string","value":"lib/index.js"},"subject":{"kind":"string","value":"lib/index.js: skip coverage for two code branches"},"git_diff":{"kind":"string","value":"ib/index.js\n evaluate: page.evaluate.bind(page),\n \n // @see https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pageselector-1\n /* istanbul ignore next */\n querySelectorAll: async (selector) => {\n debug('querySelectorAll(\"%s\")', selector);\n return page.$$(selector);\n scope[type].apply(scope, args);\n break;\n \n /* istanbul ignore next */\n default:\n debug(\"Unrecognized event type: \" + type);\n }"}}},{"rowIdx":647,"cells":{"lang":{"kind":"string","value":"Java"},"license":{"kind":"string","value":"apache-2.0"},"stderr":{"kind":"string","value":""},"commit":{"kind":"string","value":"29b2d19e511c8a264d6688eaedd6fbb57c99506e"},"returncode":{"kind":"number","value":0,"string":"0"},"repos":{"kind":"string","value":"pinotlytics/pinot,linkedin/pinot,fx19880617/pinot-1,Hanmourang/Pinot,izzizz/pinot,fx19880617/pinot-1,Hanmourang/Pinot,linkedin/pinot,fx19880617/pinot-1,pinotlytics/pinot,izzizz/pinot,Hanmourang/Pinot,sajavadi/pinot,apucher/pinot,slietz/pinot,apucher/pinot,izzizz/pinot,tkao1000/pinot,apucher/pinot,fx19880617/pinot-1,pinotlytics/pinot,slietz/pinot,tkao1000/pinot,slietz/pinot,tkao1000/pinot,Hanmourang/Pinot,Hanmourang/Pinot,apucher/pinot,tkao1000/pinot,izzizz/pinot,tkao1000/pinot,izzizz/pinot,apucher/pinot,pinotlytics/pinot,Hanmourang/Pinot,slietz/pinot,slietz/pinot,linkedin/pinot,slietz/pinot,pinotlytics/pinot,pinotlytics/pinot,linkedin/pinot,izzizz/pinot,fx19880617/pinot-1,sajavadi/pinot,sajavadi/pinot,linkedin/pinot,sajavadi/pinot,sajavadi/pinot"},"new_contents":{"kind":"string","value":"/**\n * Copyright (C) 2014-2015 LinkedIn Corp. (pinot-core@linkedin.com)\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage com.linkedin.pinot.common.utils;\n\nimport java.io.File;\nimport java.lang.reflect.Method;\nimport java.nio.ByteBuffer;\nimport java.util.Collections;\nimport java.util.Map;\nimport java.util.WeakHashMap;\nimport java.util.concurrent.atomic.AtomicLong;\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\n\n\n/**\n * Utilities to deal with memory mapped buffers, which may not be portable.\n *\n */\npublic class MmapUtils {\n private static final Logger LOGGER = LoggerFactory.getLogger(MmapUtils.class);\n private static final AtomicLong DIRECT_BYTE_BUFFER_USAGE = new AtomicLong(0L);\n private static final long BYTES_IN_MEGABYTE = 1024L * 1024L;\n private static final Map BUFFER_TO_CONTEXT_MAP = Collections.synchronizedMap(new WeakHashMap<>());\n\n /**\n * Unloads a byte buffer from memory\n * @param buffer The buffer to unload\n */\n public static void unloadByteBuffer(ByteBuffer buffer) {\n if (null == buffer)\n return;\n\n // Non direct byte buffers do not require any special handling, since they're on heap\n if (!buffer.isDirect())\n return;\n\n // Remove usage from direct byte buffer usage\n final int bufferSize = buffer.capacity();\n DIRECT_BYTE_BUFFER_USAGE.addAndGet(-bufferSize);\n LOGGER.info(\"Releasing byte buffer of size {} with context {}, currently allocated {} MB\",\n bufferSize, BUFFER_TO_CONTEXT_MAP.get(buffer), DIRECT_BYTE_BUFFER_USAGE.get() / BYTES_IN_MEGABYTE);\n\n // A DirectByteBuffer can be cleaned up by doing buffer.cleaner().clean(), but this is not a public API. This is\n // probably not portable between JVMs.\n try {\n Method cleanerMethod = buffer.getClass().getMethod(\"cleaner\");\n Method cleanMethod = Class.forName(\"sun.misc.Cleaner\").getMethod(\"clean\");\n\n cleanerMethod.setAccessible(true);\n cleanMethod.setAccessible(true);\n\n // buffer.cleaner().clean()\n Object cleaner = cleanerMethod.invoke(buffer);\n if (cleaner != null) {\n cleanMethod.invoke(cleaner);\n }\n } catch (Exception e) {\n LOGGER.warn(\"Caught (ignored) exception while unloading byte buffer\", e);\n }\n }\n\n /**\n * Allocates a direct byte buffer, tracking usage information.\n *\n * @param capacity The capacity to allocate.\n * @param allocationContext The file that this byte buffer refers to\n * @param details Further details about the allocation\n * @return A new allocated byte buffer with the requested capacity\n */\n public static ByteBuffer allocateDirectByteBuffer(int capacity, File allocationContext, String details) {\n String context;\n if (allocationContext != null) {\n context = allocationContext.getAbsolutePath() + \" (\" + details + \")\";\n } else {\n context = \"no file (\" + details + \")\";\n }\n\n DIRECT_BYTE_BUFFER_USAGE.addAndGet(capacity);\n\n LOGGER.info(\"Allocating byte buffer of size {} with context {}, currently allocated {} MB\", capacity,\n context, DIRECT_BYTE_BUFFER_USAGE.get() / BYTES_IN_MEGABYTE);\n\n final ByteBuffer byteBuffer = ByteBuffer.allocateDirect(capacity);\n\n BUFFER_TO_CONTEXT_MAP.put(byteBuffer, context);\n\n return byteBuffer;\n }\n}\n"},"new_file":{"kind":"string","value":"pinot-common/src/main/java/com/linkedin/pinot/common/utils/MmapUtils.java"},"old_contents":{"kind":"string","value":"/**\n * Copyright (C) 2014-2015 LinkedIn Corp. (pinot-core@linkedin.com)\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage com.linkedin.pinot.common.utils;\n\nimport java.io.File;\nimport java.lang.reflect.Method;\nimport java.nio.ByteBuffer;\nimport java.util.WeakHashMap;\nimport java.util.concurrent.atomic.AtomicLong;\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\n\n\n/**\n * Utilities to deal with memory mapped buffers, which may not be portable.\n *\n */\npublic class MmapUtils {\n private static final Logger LOGGER = LoggerFactory.getLogger(MmapUtils.class);\n private static final AtomicLong DIRECT_BYTE_BUFFER_USAGE = new AtomicLong(0L);\n private static final long BYTES_IN_MEGABYTE = 1024L * 1024L;\n private static final WeakHashMap BUFFER_TO_CONTEXT_MAP = new WeakHashMap<>();\n\n /**\n * Unloads a byte buffer from memory\n * @param buffer The buffer to unload\n */\n public static void unloadByteBuffer(ByteBuffer buffer) {\n if (null == buffer)\n return;\n\n // Non direct byte buffers do not require any special handling, since they're on heap\n if (!buffer.isDirect())\n return;\n\n // Remove usage from direct byte buffer usage\n final int bufferSize = buffer.capacity();\n DIRECT_BYTE_BUFFER_USAGE.addAndGet(-bufferSize);\n LOGGER.info(\"Releasing byte buffer of size {} with context {}, currently allocated {} MB\",\n bufferSize, BUFFER_TO_CONTEXT_MAP.get(buffer), DIRECT_BYTE_BUFFER_USAGE.get() / BYTES_IN_MEGABYTE);\n\n // A DirectByteBuffer can be cleaned up by doing buffer.cleaner().clean(), but this is not a public API. This is\n // probably not portable between JVMs.\n try {\n Method cleanerMethod = buffer.getClass().getMethod(\"cleaner\");\n Method cleanMethod = Class.forName(\"sun.misc.Cleaner\").getMethod(\"clean\");\n\n cleanerMethod.setAccessible(true);\n cleanMethod.setAccessible(true);\n\n // buffer.cleaner().clean()\n Object cleaner = cleanerMethod.invoke(buffer);\n if (cleaner != null) {\n cleanMethod.invoke(cleaner);\n }\n } catch (Exception e) {\n LOGGER.warn(\"Caught (ignored) exception while unloading byte buffer\", e);\n }\n }\n\n /**\n * Allocates a direct byte buffer, tracking usage information.\n *\n * @param capacity The capacity to allocate.\n * @param allocationContext The file that this byte buffer refers to\n * @param details Further details about the allocation\n * @return A new allocated byte buffer with the requested capacity\n */\n public static ByteBuffer allocateDirectByteBuffer(int capacity, File allocationContext, String details) {\n String context;\n if (allocationContext != null) {\n context = allocationContext.getAbsolutePath() + \" (\" + details + \")\";\n } else {\n context = \"no file (\" + details + \")\";\n }\n\n DIRECT_BYTE_BUFFER_USAGE.addAndGet(capacity);\n\n LOGGER.info(\"Allocating byte buffer of size {} with context {}, currently allocated {} MB\", capacity,\n context, DIRECT_BYTE_BUFFER_USAGE.get() / BYTES_IN_MEGABYTE);\n\n final ByteBuffer byteBuffer = ByteBuffer.allocateDirect(capacity);\n\n BUFFER_TO_CONTEXT_MAP.put(byteBuffer, context);\n\n return byteBuffer;\n }\n}\n"},"message":{"kind":"string","value":"[PINOT 2094] Fix MmapUtils to use thread-safe map\n\nFixed MmapUtils to use Collections.synchronizedMap instead of\nthe thread-unsafe version. All integration tests pass reliably on\nthe local machine now.\n\nRB=575684\nG=pinot-dev-reviewers\nR=kgopalak,jfim,ssubrama,dpatel,mshrivas\nA=kgopalak\n"},"old_file":{"kind":"string","value":"pinot-common/src/main/java/com/linkedin/pinot/common/utils/MmapUtils.java"},"subject":{"kind":"string","value":"[PINOT 2094] Fix MmapUtils to use thread-safe map"},"git_diff":{"kind":"string","value":"inot-common/src/main/java/com/linkedin/pinot/common/utils/MmapUtils.java\n import java.io.File;\n import java.lang.reflect.Method;\n import java.nio.ByteBuffer;\nimport java.util.Collections;\nimport java.util.Map;\n import java.util.WeakHashMap;\n import java.util.concurrent.atomic.AtomicLong;\n import org.slf4j.Logger;\n private static final Logger LOGGER = LoggerFactory.getLogger(MmapUtils.class);\n private static final AtomicLong DIRECT_BYTE_BUFFER_USAGE = new AtomicLong(0L);\n private static final long BYTES_IN_MEGABYTE = 1024L * 1024L;\n private static final WeakHashMap BUFFER_TO_CONTEXT_MAP = new WeakHashMap<>();\n private static final Map BUFFER_TO_CONTEXT_MAP = Collections.synchronizedMap(new WeakHashMap<>());\n \n /**\n * Unloads a byte buffer from memory"}}},{"rowIdx":648,"cells":{"lang":{"kind":"string","value":"Java"},"license":{"kind":"string","value":"apache-2.0"},"stderr":{"kind":"string","value":""},"commit":{"kind":"string","value":"0f191731a2aeccb5baf7f19b743e71e4cb3c7413"},"returncode":{"kind":"number","value":0,"string":"0"},"repos":{"kind":"string","value":"protyposis/Spectaculum,protyposis/Spectaculum"},"new_contents":{"kind":"string","value":"/*\n * Copyright (c) 2014 Mario Guggenberger \n *\n * This file is part of MediaPlayer-Extended.\n *\n * MediaPlayer-Extended is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * MediaPlayer-Extended is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with MediaPlayer-Extended. If not, see .\n */\n\npackage net.protyposis.android.spectaculumdemo;\n\nimport android.app.Activity;\nimport android.view.View;\nimport android.view.ViewGroup;\nimport android.widget.AdapterView;\nimport android.widget.ArrayAdapter;\nimport android.widget.BaseAdapter;\nimport android.widget.Button;\nimport android.widget.SeekBar;\nimport android.widget.Spinner;\nimport android.widget.TextView;\nimport android.widget.Toast;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport net.protyposis.android.spectaculum.SpectaculumView;\nimport net.protyposis.android.spectaculum.effects.EnumParameter;\nimport net.protyposis.android.spectaculum.effects.FloatParameter;\nimport net.protyposis.android.spectaculum.effects.IntegerParameter;\nimport net.protyposis.android.spectaculum.effects.Parameter;\n\n/**\n * Created by Mario on 06.09.2014.\n */\npublic class ParameterListAdapter extends BaseAdapter {\n\n private Activity mActivity;\n private SpectaculumView mTextureView;\n public List mParameters;\n\n public ParameterListAdapter(Activity activity, SpectaculumView textureView, List parameters) {\n mActivity = activity;\n mTextureView = textureView;\n mParameters = new ArrayList(parameters);\n }\n\n @Override\n public int getCount() {\n return mParameters.size();\n }\n\n @Override\n public Parameter getItem(int position) {\n return mParameters.get(position);\n }\n\n @Override\n public long getItemId(int position) {\n return position;\n }\n\n @Override\n public View getView(int position, View convertView, ViewGroup parent) {\n final Parameter parameter = getItem(position);\n View view = convertView;\n\n if(convertView == null || convertView.getTag() != parameter.getType()) {\n if(parameter.getType() == Parameter.Type.ENUM) {\n view = mActivity.getLayoutInflater().inflate(R.layout.list_item_parameter_spinner, parent, false);\n } else {\n view = mActivity.getLayoutInflater().inflate(R.layout.list_item_parameter_seekbar, parent, false);\n }\n view.setTag(parameter.getType());\n }\n\n ((TextView) view.findViewById(R.id.name)).setText(parameter.getName());\n final SeekBar seekBar = (SeekBar) view.findViewById(R.id.seekBar);\n final Spinner spinner = (Spinner) view.findViewById(R.id.spinner);\n final TextView valueView = (TextView) view.findViewById(R.id.value);\n final Button resetButton = (Button) view.findViewById(R.id.reset);\n\n if (parameter.getType() == Parameter.Type.INTEGER) {\n final IntegerParameter p = (IntegerParameter) parameter;\n int interval = p.getMax() - p.getMin();\n seekBar.setMax(interval);\n seekBar.setProgress(p.getValue() - p.getMin());\n SeekBar.OnSeekBarChangeListener changeListener = new SeekBar.OnSeekBarChangeListener() {\n @Override\n public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {\n final int value = progress + p.getMin();\n mTextureView.queueEvent(new Runnable() {\n @Override\n public void run() {\n p.setValue(value);\n }\n });\n valueView.setText(String.format(\"%d\", value));\n }\n\n @Override\n public void onStartTrackingTouch(SeekBar seekBar) {\n if(p.getDescription() != null) {\n Toast.makeText(mActivity, p.getDescription(), Toast.LENGTH_SHORT).show();\n }\n }\n\n @Override\n public void onStopTrackingTouch(SeekBar seekBar) {\n }\n };\n seekBar.setOnSeekBarChangeListener(changeListener);\n changeListener.onProgressChanged(seekBar, seekBar.getProgress(), false); // init value label\n resetButton.setOnClickListener(new View.OnClickListener() {\n @Override\n public void onClick(View v) {\n seekBar.setProgress(p.getDefault() - p.getMin());\n }\n });\n } else if (parameter.getType() == Parameter.Type.FLOAT) {\n final int precision = 100; // 2 digits after comma\n final FloatParameter p = (FloatParameter) parameter;\n float interval = p.getMax() - p.getMin();\n seekBar.setMax((int) (interval * precision));\n seekBar.setProgress((int) ((p.getValue() - p.getMin()) * precision));\n SeekBar.OnSeekBarChangeListener changeListener = new SeekBar.OnSeekBarChangeListener() {\n @Override\n public void onProgressChanged(SeekBar seekBar, final int progress, boolean fromUser) {\n final float value = (progress / (float) precision) + p.getMin();\n mTextureView.queueEvent(new Runnable() {\n @Override\n public void run() {\n p.setValue(value);\n }\n });\n valueView.setText(String.format(\"%.2f\", value));\n }\n\n @Override\n public void onStartTrackingTouch(SeekBar seekBar) {\n if(p.getDescription() != null) {\n Toast.makeText(mActivity, p.getDescription(), Toast.LENGTH_SHORT).show();\n }\n }\n\n @Override\n public void onStopTrackingTouch(SeekBar seekBar) {\n }\n };\n seekBar.setOnSeekBarChangeListener(changeListener);\n changeListener.onProgressChanged(seekBar, seekBar.getProgress(), false); // init value label\n resetButton.setOnClickListener(new View.OnClickListener() {\n @Override\n public void onClick(View v) {\n seekBar.setProgress((int) ((p.getDefault() - p.getMin()) * precision));\n }\n });\n } else if (parameter.getType() == Parameter.Type.ENUM) {\n final EnumParameter p = (EnumParameter) parameter;\n final ArrayAdapter adapter = new ArrayAdapter<>(mActivity, android.R.layout.simple_spinner_item, p.getEnumValues());\n adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);\n spinner.setAdapter(adapter);\n spinner.setSelection(adapter.getPosition(p.getValue()));\n spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {\n @Override\n public void onItemSelected(AdapterView> parent, View view, final int position, long id) {\n Toast.makeText(mActivity, p.getDescription(), Toast.LENGTH_SHORT).show();\n mTextureView.queueEvent(new Runnable() {\n @Override\n public void run() {\n p.setValue(p.getEnumValues()[position]);\n }\n });\n }\n\n @Override\n public void onNothingSelected(AdapterView> parent) {\n }\n });\n resetButton.setOnClickListener(new View.OnClickListener() {\n @Override\n public void onClick(View v) {\n spinner.setSelection(adapter.getPosition(p.getDefault()));\n }\n });\n }\n\n return view;\n }\n\n public void clear() {\n mParameters.clear();\n notifyDataSetChanged();\n }\n}"},"new_file":{"kind":"string","value":"Spectaculum-Demo/src/main/java/net/protyposis/android/spectaculumdemo/ParameterListAdapter.java"},"old_contents":{"kind":"string","value":"/*\n * Copyright (c) 2014 Mario Guggenberger \n *\n * This file is part of MediaPlayer-Extended.\n *\n * MediaPlayer-Extended is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * MediaPlayer-Extended is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with MediaPlayer-Extended. If not, see .\n */\n\npackage net.protyposis.android.spectaculumdemo;\n\nimport android.app.Activity;\nimport android.view.View;\nimport android.view.ViewGroup;\nimport android.widget.AdapterView;\nimport android.widget.ArrayAdapter;\nimport android.widget.BaseAdapter;\nimport android.widget.Button;\nimport android.widget.SeekBar;\nimport android.widget.Spinner;\nimport android.widget.TextView;\nimport android.widget.Toast;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport net.protyposis.android.spectaculum.SpectaculumView;\nimport net.protyposis.android.spectaculum.effects.EnumParameter;\nimport net.protyposis.android.spectaculum.effects.FloatParameter;\nimport net.protyposis.android.spectaculum.effects.IntegerParameter;\nimport net.protyposis.android.spectaculum.effects.Parameter;\n\n/**\n * Created by Mario on 06.09.2014.\n */\npublic class ParameterListAdapter extends BaseAdapter {\n\n private Activity mActivity;\n private SpectaculumView mTextureView;\n public List mParameters;\n\n public ParameterListAdapter(Activity activity, SpectaculumView textureView, List parameters) {\n mActivity = activity;\n mTextureView = textureView;\n mParameters = new ArrayList(parameters);\n }\n\n @Override\n public int getCount() {\n return mParameters.size();\n }\n\n @Override\n public Parameter getItem(int position) {\n return mParameters.get(position);\n }\n\n @Override\n public long getItemId(int position) {\n return position;\n }\n\n @Override\n public View getView(int position, View convertView, ViewGroup parent) {\n final Parameter parameter = getItem(position);\n View view = convertView;\n\n if(convertView == null || convertView.getTag() != parameter.getType()) {\n if(parameter.getType() == Parameter.Type.ENUM) {\n view = mActivity.getLayoutInflater().inflate(R.layout.list_item_parameter_spinner, parent, false);\n } else {\n view = mActivity.getLayoutInflater().inflate(R.layout.list_item_parameter_seekbar, parent, false);\n }\n view.setTag(parameter.getType());\n }\n\n ((TextView) view.findViewById(R.id.name)).setText(parameter.getName());\n final SeekBar seekBar = (SeekBar) view.findViewById(R.id.seekBar);\n final Spinner spinner = (Spinner) view.findViewById(R.id.spinner);\n final TextView valueView = (TextView) view.findViewById(R.id.value);\n final Button resetButton = (Button) view.findViewById(R.id.reset);\n\n if (parameter.getType() == Parameter.Type.INTEGER) {\n final IntegerParameter p = (IntegerParameter) parameter;\n int interval = p.getMax() - p.getMin();\n seekBar.setMax(interval);\n seekBar.setProgress(p.getValue() - p.getMin());\n SeekBar.OnSeekBarChangeListener changeListener = new SeekBar.OnSeekBarChangeListener() {\n @Override\n public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {\n final int value = progress + p.getMin();\n mTextureView.queueEvent(new Runnable() {\n @Override\n public void run() {\n p.setValue(value);\n }\n });\n valueView.setText(String.format(\"%d\", value));\n }\n\n @Override\n public void onStartTrackingTouch(SeekBar seekBar) {\n if(p.getDescription() != null) {\n Toast.makeText(mActivity, p.getDescription(), Toast.LENGTH_SHORT).show();\n }\n }\n\n @Override\n public void onStopTrackingTouch(SeekBar seekBar) {\n }\n };\n seekBar.setOnSeekBarChangeListener(changeListener);\n changeListener.onProgressChanged(seekBar, seekBar.getProgress(), false); // init value label\n resetButton.setOnClickListener(new View.OnClickListener() {\n @Override\n public void onClick(View v) {\n seekBar.setProgress(p.getDefault() - p.getMin());\n }\n });\n } else if (parameter.getType() == Parameter.Type.FLOAT) {\n final int precision = 100; // 2 digits after comma\n final FloatParameter p = (FloatParameter) parameter;\n float interval = p.getMax() - p.getMin();\n seekBar.setMax((int) (interval * precision));\n seekBar.setProgress((int) ((p.getValue() - p.getMin()) * precision));\n SeekBar.OnSeekBarChangeListener changeListener = new SeekBar.OnSeekBarChangeListener() {\n @Override\n public void onProgressChanged(SeekBar seekBar, final int progress, boolean fromUser) {\n final float value = (progress / (float) precision) + p.getMin();\n mTextureView.queueEvent(new Runnable() {\n @Override\n public void run() {\n p.setValue(value);\n }\n });\n valueView.setText(String.format(\"%.2f\", value));\n }\n\n @Override\n public void onStartTrackingTouch(SeekBar seekBar) {\n if(p.getDescription() != null) {\n Toast.makeText(mActivity, p.getDescription(), Toast.LENGTH_SHORT).show();\n }\n }\n\n @Override\n public void onStopTrackingTouch(SeekBar seekBar) {\n }\n };\n seekBar.setOnSeekBarChangeListener(changeListener);\n changeListener.onProgressChanged(seekBar, seekBar.getProgress(), false); // init value label\n resetButton.setOnClickListener(new View.OnClickListener() {\n @Override\n public void onClick(View v) {\n seekBar.setProgress((int) ((p.getDefault() - p.getMin()) * precision));\n }\n });\n } else if (parameter.getType() == Parameter.Type.ENUM) {\n final EnumParameter p = (EnumParameter) parameter;\n final ArrayAdapter adapter = new ArrayAdapter<>(mActivity, android.R.layout.simple_spinner_item, p.getEnumValues());\n adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);\n spinner.setAdapter(adapter);\n\n spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {\n @Override\n public void onItemSelected(AdapterView> parent, View view, final int position, long id) {\n Toast.makeText(mActivity, p.getDescription(), Toast.LENGTH_SHORT).show();\n mTextureView.queueEvent(new Runnable() {\n @Override\n public void run() {\n p.setValue(p.getEnumValues()[position]);\n }\n });\n }\n\n @Override\n public void onNothingSelected(AdapterView> parent) {\n }\n });\n resetButton.setOnClickListener(new View.OnClickListener() {\n @Override\n public void onClick(View v) {\n spinner.setSelection(adapter.getPosition(p.getDefault()));\n }\n });\n }\n\n return view;\n }\n\n public void clear() {\n mParameters.clear();\n notifyDataSetChanged();\n }\n}"},"message":{"kind":"string","value":"Init spinner with current value\n"},"old_file":{"kind":"string","value":"Spectaculum-Demo/src/main/java/net/protyposis/android/spectaculumdemo/ParameterListAdapter.java"},"subject":{"kind":"string","value":"Init spinner with current value"},"git_diff":{"kind":"string","value":"pectaculum-Demo/src/main/java/net/protyposis/android/spectaculumdemo/ParameterListAdapter.java\n final ArrayAdapter adapter = new ArrayAdapter<>(mActivity, android.R.layout.simple_spinner_item, p.getEnumValues());\n adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);\n spinner.setAdapter(adapter);\n\n spinner.setSelection(adapter.getPosition(p.getValue()));\n spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {\n @Override\n public void onItemSelected(AdapterView> parent, View view, final int position, long id) {"}}},{"rowIdx":649,"cells":{"lang":{"kind":"string","value":"Java"},"license":{"kind":"string","value":"lgpl-2.1"},"stderr":{"kind":"string","value":""},"commit":{"kind":"string","value":"55aa99926ee7323bb6a101d7a31e3b5671d283f7"},"returncode":{"kind":"number","value":0,"string":"0"},"repos":{"kind":"string","value":"certusoft/swingx,certusoft/swingx"},"new_contents":{"kind":"string","value":"/*\n * $Id$\n *\n * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,\n * Santa Clara, California 95054, U.S.A. All rights reserved.\n */\n\npackage org.jdesktop.swingx;\n\nimport java.awt.Point;\nimport java.awt.event.MouseEvent;\n\nimport javax.swing.JTable;\nimport javax.swing.SwingUtilities;\nimport javax.swing.table.TableModel;\nimport javax.swing.tree.DefaultMutableTreeNode;\nimport javax.swing.tree.DefaultTreeModel;\nimport javax.swing.tree.TreeNode;\nimport javax.swing.tree.TreePath;\n\nimport org.jdesktop.swingx.table.TableColumnExt;\nimport org.jdesktop.swingx.treetable.AbstractTreeTableModel;\nimport org.jdesktop.swingx.treetable.DefaultTreeTableModel;\nimport org.jdesktop.swingx.treetable.FileSystemModel;\nimport org.jdesktop.swingx.treetable.TreeTableModel;\nimport org.jdesktop.swingx.util.ComponentTreeTableModel;\nimport org.jdesktop.swingx.util.PropertyChangeReport;\nimport org.jdesktop.swingx.util.TreeSelectionReport;\n\n\npublic class JXTreeTableUnitTest extends InteractiveTestCase {\n\n protected TreeTableModel treeTableModel;\n protected TreeTableModel simpleTreeTableModel;\n \n public JXTreeTableUnitTest() {\n super(\"JXTreeTable Unit Test\");\n }\n\n /**\n * Issue #270-swingx: NPE in some contexts when accessing the \n * TreeTableModelAdapter.\n *\n */\n public void testConservativeRowForNodeInAdapter() {\n // for testing we need a model which relies on \n // node != null\n TreeTableModel model = new DefaultTreeTableModel((TreeNode) simpleTreeTableModel.getRoot()) {\n\n @Override\n public Object getValueAt(Object node, int column) {\n // access node\n node.toString();\n return super.getValueAt(node, column);\n }\n\n @Override\n public void setValueAt(Object value, Object node, int column) {\n // access node\n node.toString();\n super.setValueAt(value, node, column);\n }\n\n @Override\n public boolean isCellEditable(Object node, int column) {\n // access node\n node.toString();\n return super.isCellEditable(node, column);\n }\n \n };\n // can't use ComponentTreeTableModel in headless environment\n// JXTreeTable treeTable = new JXTreeTable(new ComponentTreeTableModel(new JXFrame()));\n JXTreeTable treeTable = new JXTreeTable(model);\n treeTable.setRootVisible(true);\n TableModel adapter = treeTable.getModel();\n treeTable.collapseAll();\n assertEquals(1, treeTable.getRowCount());\n // simulate contexts where the accessed row isn't currently visible\n adapter.getValueAt(treeTable.getRowCount(), 0);\n adapter.isCellEditable(treeTable.getRowCount(), 0);\n adapter.setValueAt(\"somename\", treeTable.getRowCount(), 0);\n }\n /**\n * test if table and tree rowHeights are the same.\n *\n */\n public void testAdjustedRowHeights() {\n JXTreeTable treeTable = new JXTreeTable(simpleTreeTableModel);\n JXTree tree = (JXTree) treeTable.getCellRenderer(0, 0);\n // sanity: same initially\n assertEquals(\"table and tree rowHeights must be equal\", \n treeTable.getRowHeight(), tree.getRowHeight());\n // change treeTable height\n treeTable.setRowHeight(treeTable.getRowHeight() * 2);\n assertEquals(\"table and tree rowHeights must be equal\", \n treeTable.getRowHeight(), tree.getRowHeight());\n // change treeTable height\n tree.setRowHeight(tree.getRowHeight() * 2);\n assertEquals(\"table and tree rowHeights must be equal\", \n treeTable.getRowHeight(), tree.getRowHeight());\n\n }\n /**\n * #321-swingx: missing tree property toggleClickCount, largeModel.\n *\n */\n public void testToggleClickCount() {\n JXTreeTable treeTable = new JXTreeTable(simpleTreeTableModel);\n int clickCount = treeTable.getToggleClickCount();\n // asserting documented default clickCount == 2\n assertEquals(\"default clickCount\", 2, clickCount);\n int newClickCount = clickCount + 1;\n treeTable.setToggleClickCount(newClickCount);\n assertEquals(\"toggleClickCount must be changed\", \n newClickCount, treeTable.getToggleClickCount());\n boolean largeModel = treeTable.isLargeModel();\n assertFalse(\"initial largeModel\", largeModel);\n treeTable.setLargeModel(!largeModel);\n assertTrue(\"largeModel property must be toggled\", treeTable.isLargeModel());\n \n }\n /**\n * Issue #168-jdnc: dnd enabled breaks node collapse/expand.\n * testing auto-detection of dragHackEnabled.\n * \n */\n public void testDragHackFlagOn() {\n JXTreeTable treeTable = new JXTreeTable(simpleTreeTableModel);\n assertNull(treeTable.getClientProperty(JXTreeTable.DRAG_HACK_FLAG_KEY));\n treeTable.getTreeTableHacker().expandOrCollapseNode(0, new MouseEvent(treeTable, 0, 0, 0, 0, 0, 1, false));\n Boolean dragHackFlag = (Boolean) treeTable.getClientProperty(JXTreeTable.DRAG_HACK_FLAG_KEY);\n assertNotNull(dragHackFlag);\n assertTrue(dragHackFlag);\n }\n\n /**\n * Issue #168-jdnc: dnd enabled breaks node collapse/expand.\n * testing auto-detection of dragHackEnabled.\n * \n */\n public void testDragHackFlagOff() {\n System.setProperty(\"sun.swing.enableImprovedDragGesture\", \"true\");\n JXTreeTable treeTable = new JXTreeTable(simpleTreeTableModel);\n assertNull(treeTable.getClientProperty(JXTreeTable.DRAG_HACK_FLAG_KEY));\n treeTable.getTreeTableHacker().expandOrCollapseNode(0, new MouseEvent(treeTable, 0, 0, 0, 0, 0, 1, false));\n Boolean dragHackFlag = (Boolean) treeTable.getClientProperty(JXTreeTable.DRAG_HACK_FLAG_KEY);\n assertNotNull(dragHackFlag);\n assertFalse(dragHackFlag);\n System.getProperties().remove(\"sun.swing.enableImprovedDragGesture\");\n }\n\n /**\n * loosely related to Issue #248-swingx: setRootVisible (true) after\n * initial rootInvisible didn't show the root.\n * \n * this here is a sanity test that there is exactly one row, the problem\n * is a missing visual update of the table.\n *\n */\n public void testEmptyModelInitiallyInvisibleRoot() {\n final DefaultMutableTreeNode root = new DefaultMutableTreeNode();\n final InsertTreeTableModel model = new InsertTreeTableModel(root);\n final JXTreeTable treeTable = new JXTreeTable(model);\n // sanity...\n assertFalse(treeTable.isRootVisible());\n assertEquals(\"no rows with invisible root\", 0, treeTable.getRowCount());\n treeTable.setRootVisible(true);\n // sanity...\n assertTrue(treeTable.isRootVisible());\n assertEquals(\"one row with visible root\", 1, treeTable.getRowCount());\n\n }\n \n /**\n * Issue #247-swingx: update probs with insert node.\n * The insert under a collapsed node fires a dataChanged on the table \n * which results in the usual total \"memory\" loss (f.i. selection)\n *\n * The tree model is after setup is (see the bug report as well):\n * root\n * childA\n * childB\n * \n * In the view childA is collapsed:\n * root\n * childA \n * \n */\n public void testInsertUnderCollapsedNode() {\n final DefaultMutableTreeNode root = new DefaultMutableTreeNode();\n final InsertTreeTableModel model = new InsertTreeTableModel(root);\n DefaultMutableTreeNode childA = model.addChild(root);\n final DefaultMutableTreeNode childB = model.addChild(childA);\n final JXTreeTable treeTable = new JXTreeTable(model);\n treeTable.setRootVisible(true);\n // sanity...\n assertEquals(2, treeTable.getRowCount());\n final int selected = 1;\n // select childA\n treeTable.setRowSelectionInterval(selected, selected);\n model.addChild(childB);\n // need to invoke - the tableEvent is fired delayed as well\n // Note: doing so will make the test _appear_ to pass, the\n // assertion failure can be seen as an output only!\n // any idea how to make the test fail?\n SwingUtilities.invokeLater(new Runnable() {\n public void run() {\n int selectedAfterInsert = treeTable.getSelectedRow();\n assertEquals(selected, selectedAfterInsert);\n\n }\n });\n }\n \n /**\n * Model used to show insert update issue.\n */\n public static class InsertTreeTableModel extends DefaultTreeTableModel {\n private boolean rootIsFolder;\n \n public InsertTreeTableModel(TreeNode root) {\n super(root);\n }\n\n public InsertTreeTableModel(TreeNode root, boolean rootIsFolder) {\n super(root);\n this.rootIsFolder = rootIsFolder;\n }\n \n @Override\n public boolean isLeaf(Object node) {\n if (rootIsFolder && (node == getRoot())) {\n return false;\n }\n return super.isLeaf(node);\n }\n\n\n public int getColumnCount() {\n return 2;\n }\n\n public DefaultMutableTreeNode addChild(DefaultMutableTreeNode parent) {\n DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(\"Child\");\n parent.add(newNode);\n nodesWereInserted(parent, new int[] {parent.getIndex(newNode) });\n// fireTreeNodesInserted(this, getPathToRoot(parent),\n// new int[] { parent.getIndex(newNode) },\n// new Object[] { newNode });\n\n return newNode;\n }\n }\n\n\n /**\n * Issue #230-swingx: \n * JXTreeTable should fire property change on setTreeTableModel.\n * \n * \n *\n */\n public void testTreeTableModelIsBoundProperty() {\n JXTreeTable treeTable = new JXTreeTable();\n PropertyChangeReport report = new PropertyChangeReport();\n treeTable.addPropertyChangeListener(report);\n treeTable.setTreeTableModel(simpleTreeTableModel);\n int allPropertyCount = report.getEventCount();\n int treeTMPropertyCount = report.getEventCount(\"treeTableModel\");\n assertEquals(\"treeTable must have fired exactly one event for property treeTableModel\", \n 1, treeTMPropertyCount);\n assertEquals(\"treeTable must have fired event for property treeTableModel only\",\n allPropertyCount, treeTMPropertyCount);\n // sanity: must not fire when setting to same\n report.clear();\n treeTable.setTreeTableModel(simpleTreeTableModel);\n assertEquals(\"treeTable must not have fired\", 0, report.getEventCount()); \n }\n /**\n * Issue #54: hidden columns not removed on setModel.\n * sanity test (make sure nothing evil introduced in treeTable as \n * compared to table)\n */\n public void testRemoveAllColumsAfterModelChanged() {\n JXTreeTable table = new JXTreeTable(new FileSystemModel());\n TableColumnExt columnX = table.getColumnExt(1);\n columnX.setVisible(false);\n int columnCount = table.getColumnCount(true);\n assertEquals(\"total column count must be same as model\", table.getModel().getColumnCount(), columnCount);\n assertEquals(\"visible column count must one less as total\", columnCount - 1, table.getColumnCount());\n table.setTreeTableModel(new FileSystemModel());\n assertEquals(\"visible columns must be same as total\", \n table.getColumnCount(), table.getColumnCount(true));\n }\n\n /**\n * Issue #241: treeModelListeners not removed.\n *\n */\n public void testRemoveListeners() {\n JXTreeTable treeTable = new JXTreeTable(treeTableModel);\n treeTable.setTreeTableModel(new FileSystemModel());\n assertEquals(0, ((AbstractTreeTableModel) treeTableModel).getTreeModelListeners().length);\n }\n \n public void testRowForPath() {\n JXTreeTable treeTable = new JXTreeTable(simpleTreeTableModel);\n // @todo - make sure we find an expandible row instead of hardcoding\n int rowCount = treeTable.getRowCount();\n int row = 2;\n TreePath path = treeTable.getPathForRow(row);\n assertEquals(\"original row must be retrieved\", row, treeTable.getRowForPath(path));\n treeTable.expandRow(row - 1);\n // sanity assert\n assertTrue(\"really expanded\", treeTable.getRowCount() > rowCount);\n TreePath expanded = treeTable.getPathForRow(row);\n assertNotSame(\"path at original row must be different when expanded\", path, expanded);\n assertEquals(\"original row must be retrieved\", row, treeTable.getRowForPath(expanded));\n \n }\n \n public void testPathForRowContract() {\n JXTreeTable treeTable = new JXTreeTable(treeTableModel);\n assertNull(\"row < 0 must return null path\", treeTable.getPathForRow(-1));\n assertNull(\"row >= getRowCount must return null path\", treeTable.getPathForRow(treeTable.getRowCount()));\n }\n \n public void testTableRowAtNegativePoint() {\n JXTable treeTable = new JXTable(1, 4);\n int negativeYRowHeight = - treeTable.getRowHeight();\n int negativeYRowHeightPlusOne = negativeYRowHeight + 1;\n int negativeYMinimal = -1;\n assertEquals(\"negative y location rowheight \" + negativeYRowHeight + \" must return row -1\", \n -1, treeTable.rowAtPoint(new Point(-1, negativeYRowHeight)));\n assertEquals(\"negative y location \" + negativeYRowHeightPlusOne +\" must return row -1\", \n -1, treeTable.rowAtPoint(new Point(-1, negativeYRowHeightPlusOne)));\n assertEquals(\"minimal negative y location must return row -1\", \n -1, treeTable.rowAtPoint(new Point(-1, negativeYMinimal)));\n \n }\n\n public void testTableRowAtOutsidePoint() {\n JTable treeTable = new JTable(2, 4);\n int negativeYRowHeight = (treeTable.getRowHeight()+ treeTable.getRowMargin()) * treeTable.getRowCount() ;\n int negativeYRowHeightPlusOne = negativeYRowHeight - 1;\n int negativeYMinimal = -1;\n assertEquals(\"negative y location rowheight \" + negativeYRowHeight + \" must return row -1\", \n -1, treeTable.rowAtPoint(new Point(-1, negativeYRowHeight)));\n assertEquals(\"negative y location \" + negativeYRowHeightPlusOne +\" must return row -1\", \n -1, treeTable.rowAtPoint(new Point(-1, negativeYRowHeightPlusOne)));\n// assertEquals(\"minimal negative y location must return row -1\", \n// -1, treeTable.rowAtPoint(new Point(-1, negativeYMinimal)));\n \n }\n\n public void testPathForLocationContract() {\n JXTreeTable treeTable = new JXTreeTable(treeTableModel);\n // this is actually a JTable rowAtPoint bug: falsely calculates\n // row == 0 if - 1 >= y > - getRowHeight()\n \n //assertEquals(\"location outside must return null path\", null, treeTable.getPathForLocation(-1, -(treeTable.getRowHeight() - 1)));\n int negativeYRowHeight = - treeTable.getRowHeight();\n int negativeYRowHeightPlusOne = negativeYRowHeight + 1;\n int negativeYMinimal = -1;\n assertEquals(\"negative y location rowheight \" + negativeYRowHeight + \" must return row -1\", \n -1, treeTable.rowAtPoint(new Point(-1, negativeYRowHeight)));\n assertEquals(\"negative y location \" + negativeYRowHeightPlusOne +\" must return row -1\", \n -1, treeTable.rowAtPoint(new Point(-1, negativeYRowHeightPlusOne)));\n assertEquals(\"minimal negative y location must return row -1\", \n -1, treeTable.rowAtPoint(new Point(-1, negativeYMinimal)));\n }\n /**\n * Issue #151: renderer properties ignored after setting treeTableModel.\n * \n */\n public void testRendererProperties() {\n JXTreeTable treeTable = new JXTreeTable(treeTableModel);\n // storing negates of properties\n boolean expandsSelected = !treeTable.getExpandsSelectedPaths();\n boolean scrollsOnExpand = !treeTable.getScrollsOnExpand();\n boolean showRootHandles = !treeTable.getShowsRootHandles();\n boolean rootVisible = !treeTable.isRootVisible();\n // setting negates properties\n treeTable.setExpandsSelectedPaths(expandsSelected);\n treeTable.setScrollsOnExpand(scrollsOnExpand);\n treeTable.setShowsRootHandles(showRootHandles);\n treeTable.setRootVisible(rootVisible);\n // assert negates are set - sanity assert\n assertEquals(\"expand selected\", expandsSelected, treeTable\n .getExpandsSelectedPaths());\n assertEquals(\"scrolls expand\", scrollsOnExpand, treeTable\n .getScrollsOnExpand());\n assertEquals(\"shows handles\", showRootHandles, treeTable\n .getShowsRootHandles());\n assertEquals(\"root visible\", rootVisible, treeTable.isRootVisible());\n // setting a new model\n treeTable.setTreeTableModel(new DefaultTreeTableModel());\n // assert negates are set\n assertEquals(\"expand selected\", expandsSelected, treeTable\n .getExpandsSelectedPaths());\n assertEquals(\"scrolls expand\", scrollsOnExpand, treeTable\n .getScrollsOnExpand());\n assertEquals(\"shows handles\", showRootHandles, treeTable\n .getShowsRootHandles());\n assertEquals(\"root visible\", rootVisible, treeTable.isRootVisible());\n\n }\n\n /**\n * Issue #148: line style client property not respected by renderer.\n * \n */\n public void testLineStyle() {\n JXTreeTable treeTable = new JXTreeTable(treeTableModel);\n String propertyName = \"JTree.lineStyle\";\n treeTable.putClientProperty(propertyName, \"Horizontal\");\n JXTree renderer = (JXTree) treeTable.getCellRenderer(0, 0);\n assertEquals(propertyName + \" set on renderer\", \"Horizontal\", renderer\n .getClientProperty(propertyName));\n }\n\n /**\n * sanity test: arbitrary client properties not passed to renderer.\n * \n */\n public void testArbitraryClientProperty() {\n JXTreeTable treeTable = new JXTreeTable(treeTableModel);\n String propertyName = \"someproperty\";\n treeTable.putClientProperty(propertyName, \"Horizontal\");\n JXTree renderer = (JXTree) treeTable.getCellRenderer(0, 0);\n assertNull(propertyName + \" not set on renderer\", renderer\n .getClientProperty(propertyName));\n\n }\n\n\n // ------------------ init\n protected void setUp() throws Exception {\n super.setUp();\n JXTree tree = new JXTree();\n DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();\n simpleTreeTableModel = new DefaultTreeTableModel((TreeNode) treeModel.getRoot());\n treeTableModel = new FileSystemModel();\n }\n\n}\n"},"new_file":{"kind":"string","value":"src/test/org/jdesktop/swingx/JXTreeTableUnitTest.java"},"old_contents":{"kind":"string","value":"/*\n * $Id$\n *\n * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,\n * Santa Clara, California 95054, U.S.A. All rights reserved.\n */\n\npackage org.jdesktop.swingx;\n\nimport java.awt.Point;\nimport java.awt.event.MouseEvent;\n\nimport javax.swing.JTable;\nimport javax.swing.SwingUtilities;\nimport javax.swing.table.TableModel;\nimport javax.swing.tree.DefaultMutableTreeNode;\nimport javax.swing.tree.DefaultTreeModel;\nimport javax.swing.tree.TreeNode;\nimport javax.swing.tree.TreePath;\n\nimport org.jdesktop.swingx.table.TableColumnExt;\nimport org.jdesktop.swingx.treetable.AbstractTreeTableModel;\nimport org.jdesktop.swingx.treetable.DefaultTreeTableModel;\nimport org.jdesktop.swingx.treetable.FileSystemModel;\nimport org.jdesktop.swingx.treetable.TreeTableModel;\nimport org.jdesktop.swingx.util.ComponentTreeTableModel;\nimport org.jdesktop.swingx.util.PropertyChangeReport;\n\n\npublic class JXTreeTableUnitTest extends InteractiveTestCase {\n\n protected TreeTableModel treeTableModel;\n protected TreeTableModel simpleTreeTableModel;\n \n public JXTreeTableUnitTest() {\n super(\"JXTreeTable Unit Test\");\n }\n\n /**\n * Issue #270-swingx: NPE in some contexts when accessing the \n * TreeTableModelAdapter.\n *\n */\n public void testConservativeRowForNodeInAdapter() {\n JXTreeTable treeTable = new JXTreeTable(new ComponentTreeTableModel(new JXFrame()));\n treeTable.setRootVisible(true);\n TableModel adapter = treeTable.getModel();\n treeTable.collapseAll();\n assertEquals(1, treeTable.getRowCount());\n // simulate contexts where the accessed row isn't currently visible\n adapter.getValueAt(treeTable.getRowCount(), 0);\n adapter.isCellEditable(treeTable.getRowCount(), 0);\n adapter.setValueAt(\"somename\", treeTable.getRowCount(), 0);\n }\n /**\n * test if table and tree rowHeights are the same.\n *\n */\n public void testAdjustedRowHeights() {\n JXTreeTable treeTable = new JXTreeTable(simpleTreeTableModel);\n JXTree tree = (JXTree) treeTable.getCellRenderer(0, 0);\n // sanity: same initially\n assertEquals(\"table and tree rowHeights must be equal\", \n treeTable.getRowHeight(), tree.getRowHeight());\n // change treeTable height\n treeTable.setRowHeight(treeTable.getRowHeight() * 2);\n assertEquals(\"table and tree rowHeights must be equal\", \n treeTable.getRowHeight(), tree.getRowHeight());\n // change treeTable height\n tree.setRowHeight(tree.getRowHeight() * 2);\n assertEquals(\"table and tree rowHeights must be equal\", \n treeTable.getRowHeight(), tree.getRowHeight());\n\n }\n /**\n * #321-swingx: missing tree property toggleClickCount, largeModel.\n *\n */\n public void testToggleClickCount() {\n JXTreeTable treeTable = new JXTreeTable(simpleTreeTableModel);\n int clickCount = treeTable.getToggleClickCount();\n // asserting documented default clickCount == 2\n assertEquals(\"default clickCount\", 2, clickCount);\n int newClickCount = clickCount + 1;\n treeTable.setToggleClickCount(newClickCount);\n assertEquals(\"toggleClickCount must be changed\", \n newClickCount, treeTable.getToggleClickCount());\n boolean largeModel = treeTable.isLargeModel();\n assertFalse(\"initial largeModel\", largeModel);\n treeTable.setLargeModel(!largeModel);\n assertTrue(\"largeModel property must be toggled\", treeTable.isLargeModel());\n \n }\n /**\n * Issue #168-jdnc: dnd enabled breaks node collapse/expand.\n * testing auto-detection of dragHackEnabled.\n * \n */\n public void testDragHackFlagOn() {\n JXTreeTable treeTable = new JXTreeTable(simpleTreeTableModel);\n assertNull(treeTable.getClientProperty(JXTreeTable.DRAG_HACK_FLAG_KEY));\n treeTable.getTreeTableHacker().expandOrCollapseNode(0, new MouseEvent(treeTable, 0, 0, 0, 0, 0, 1, false));\n Boolean dragHackFlag = (Boolean) treeTable.getClientProperty(JXTreeTable.DRAG_HACK_FLAG_KEY);\n assertNotNull(dragHackFlag);\n assertTrue(dragHackFlag);\n }\n\n /**\n * Issue #168-jdnc: dnd enabled breaks node collapse/expand.\n * testing auto-detection of dragHackEnabled.\n * \n */\n public void testDragHackFlagOff() {\n System.setProperty(\"sun.swing.enableImprovedDragGesture\", \"true\");\n JXTreeTable treeTable = new JXTreeTable(simpleTreeTableModel);\n assertNull(treeTable.getClientProperty(JXTreeTable.DRAG_HACK_FLAG_KEY));\n treeTable.getTreeTableHacker().expandOrCollapseNode(0, new MouseEvent(treeTable, 0, 0, 0, 0, 0, 1, false));\n Boolean dragHackFlag = (Boolean) treeTable.getClientProperty(JXTreeTable.DRAG_HACK_FLAG_KEY);\n assertNotNull(dragHackFlag);\n assertFalse(dragHackFlag);\n System.getProperties().remove(\"sun.swing.enableImprovedDragGesture\");\n }\n\n /**\n * loosely related to Issue #248-swingx: setRootVisible (true) after\n * initial rootInvisible didn't show the root.\n * \n * this here is a sanity test that there is exactly one row, the problem\n * is a missing visual update of the table.\n *\n */\n public void testEmptyModelInitiallyInvisibleRoot() {\n final DefaultMutableTreeNode root = new DefaultMutableTreeNode();\n final InsertTreeTableModel model = new InsertTreeTableModel(root);\n final JXTreeTable treeTable = new JXTreeTable(model);\n // sanity...\n assertFalse(treeTable.isRootVisible());\n assertEquals(\"no rows with invisible root\", 0, treeTable.getRowCount());\n treeTable.setRootVisible(true);\n // sanity...\n assertTrue(treeTable.isRootVisible());\n assertEquals(\"one row with visible root\", 1, treeTable.getRowCount());\n\n }\n \n /**\n * Issue #247-swingx: update probs with insert node.\n * The insert under a collapsed node fires a dataChanged on the table \n * which results in the usual total \"memory\" loss (f.i. selection)\n *\n * The tree model is after setup is (see the bug report as well):\n * root\n * childA\n * childB\n * \n * In the view childA is collapsed:\n * root\n * childA \n * \n */\n public void testInsertUnderCollapsedNode() {\n final DefaultMutableTreeNode root = new DefaultMutableTreeNode();\n final InsertTreeTableModel model = new InsertTreeTableModel(root);\n DefaultMutableTreeNode childA = model.addChild(root);\n final DefaultMutableTreeNode childB = model.addChild(childA);\n final JXTreeTable treeTable = new JXTreeTable(model);\n treeTable.setRootVisible(true);\n // sanity...\n assertEquals(2, treeTable.getRowCount());\n final int selected = 1;\n // select childA\n treeTable.setRowSelectionInterval(selected, selected);\n model.addChild(childB);\n // need to invoke - the tableEvent is fired delayed as well\n // Note: doing so will make the test _appear_ to pass, the\n // assertion failure can be seen as an output only!\n // any idea how to make the test fail?\n SwingUtilities.invokeLater(new Runnable() {\n public void run() {\n int selectedAfterInsert = treeTable.getSelectedRow();\n assertEquals(selected, selectedAfterInsert);\n\n }\n });\n }\n \n /**\n * Model used to show insert update issue.\n */\n public static class InsertTreeTableModel extends DefaultTreeTableModel {\n private boolean rootIsFolder;\n \n public InsertTreeTableModel(TreeNode root) {\n super(root);\n }\n\n public InsertTreeTableModel(TreeNode root, boolean rootIsFolder) {\n super(root);\n this.rootIsFolder = rootIsFolder;\n }\n \n @Override\n public boolean isLeaf(Object node) {\n if (rootIsFolder && (node == getRoot())) {\n return false;\n }\n return super.isLeaf(node);\n }\n\n\n public int getColumnCount() {\n return 2;\n }\n\n public DefaultMutableTreeNode addChild(DefaultMutableTreeNode parent) {\n DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(\"Child\");\n parent.add(newNode);\n nodesWereInserted(parent, new int[] {parent.getIndex(newNode) });\n// fireTreeNodesInserted(this, getPathToRoot(parent),\n// new int[] { parent.getIndex(newNode) },\n// new Object[] { newNode });\n\n return newNode;\n }\n }\n\n\n /**\n * Issue #230-swingx: \n * JXTreeTable should fire property change on setTreeTableModel.\n * \n * \n *\n */\n public void testTreeTableModelIsBoundProperty() {\n JXTreeTable treeTable = new JXTreeTable();\n PropertyChangeReport report = new PropertyChangeReport();\n treeTable.addPropertyChangeListener(report);\n treeTable.setTreeTableModel(simpleTreeTableModel);\n int allPropertyCount = report.getEventCount();\n int treeTMPropertyCount = report.getEventCount(\"treeTableModel\");\n assertEquals(\"treeTable must have fired exactly one event for property treeTableModel\", \n 1, treeTMPropertyCount);\n assertEquals(\"treeTable must have fired event for property treeTableModel only\",\n allPropertyCount, treeTMPropertyCount);\n // sanity: must not fire when setting to same\n report.clear();\n treeTable.setTreeTableModel(simpleTreeTableModel);\n assertEquals(\"treeTable must not have fired\", 0, report.getEventCount()); \n }\n /**\n * Issue #54: hidden columns not removed on setModel.\n * sanity test (make sure nothing evil introduced in treeTable as \n * compared to table)\n */\n public void testRemoveAllColumsAfterModelChanged() {\n JXTreeTable table = new JXTreeTable(new FileSystemModel());\n TableColumnExt columnX = table.getColumnExt(1);\n columnX.setVisible(false);\n int columnCount = table.getColumnCount(true);\n assertEquals(\"total column count must be same as model\", table.getModel().getColumnCount(), columnCount);\n assertEquals(\"visible column count must one less as total\", columnCount - 1, table.getColumnCount());\n table.setTreeTableModel(new FileSystemModel());\n assertEquals(\"visible columns must be same as total\", \n table.getColumnCount(), table.getColumnCount(true));\n }\n\n /**\n * Issue #241: treeModelListeners not removed.\n *\n */\n public void testRemoveListeners() {\n JXTreeTable treeTable = new JXTreeTable(treeTableModel);\n treeTable.setTreeTableModel(new FileSystemModel());\n assertEquals(0, ((AbstractTreeTableModel) treeTableModel).getTreeModelListeners().length);\n }\n \n public void testRowForPath() {\n JXTreeTable treeTable = new JXTreeTable(simpleTreeTableModel);\n // @todo - make sure we find an expandible row instead of hardcoding\n int rowCount = treeTable.getRowCount();\n int row = 2;\n TreePath path = treeTable.getPathForRow(row);\n assertEquals(\"original row must be retrieved\", row, treeTable.getRowForPath(path));\n treeTable.expandRow(row - 1);\n // sanity assert\n assertTrue(\"really expanded\", treeTable.getRowCount() > rowCount);\n TreePath expanded = treeTable.getPathForRow(row);\n assertNotSame(\"path at original row must be different when expanded\", path, expanded);\n assertEquals(\"original row must be retrieved\", row, treeTable.getRowForPath(expanded));\n \n }\n \n public void testPathForRowContract() {\n JXTreeTable treeTable = new JXTreeTable(treeTableModel);\n assertNull(\"row < 0 must return null path\", treeTable.getPathForRow(-1));\n assertNull(\"row >= getRowCount must return null path\", treeTable.getPathForRow(treeTable.getRowCount()));\n }\n \n public void testTableRowAtNegativePoint() {\n JXTable treeTable = new JXTable(1, 4);\n int negativeYRowHeight = - treeTable.getRowHeight();\n int negativeYRowHeightPlusOne = negativeYRowHeight + 1;\n int negativeYMinimal = -1;\n assertEquals(\"negative y location rowheight \" + negativeYRowHeight + \" must return row -1\", \n -1, treeTable.rowAtPoint(new Point(-1, negativeYRowHeight)));\n assertEquals(\"negative y location \" + negativeYRowHeightPlusOne +\" must return row -1\", \n -1, treeTable.rowAtPoint(new Point(-1, negativeYRowHeightPlusOne)));\n assertEquals(\"minimal negative y location must return row -1\", \n -1, treeTable.rowAtPoint(new Point(-1, negativeYMinimal)));\n \n }\n\n public void testTableRowAtOutsidePoint() {\n JTable treeTable = new JTable(2, 4);\n int negativeYRowHeight = (treeTable.getRowHeight()+ treeTable.getRowMargin()) * treeTable.getRowCount() ;\n int negativeYRowHeightPlusOne = negativeYRowHeight - 1;\n int negativeYMinimal = -1;\n assertEquals(\"negative y location rowheight \" + negativeYRowHeight + \" must return row -1\", \n -1, treeTable.rowAtPoint(new Point(-1, negativeYRowHeight)));\n assertEquals(\"negative y location \" + negativeYRowHeightPlusOne +\" must return row -1\", \n -1, treeTable.rowAtPoint(new Point(-1, negativeYRowHeightPlusOne)));\n// assertEquals(\"minimal negative y location must return row -1\", \n// -1, treeTable.rowAtPoint(new Point(-1, negativeYMinimal)));\n \n }\n\n public void testPathForLocationContract() {\n JXTreeTable treeTable = new JXTreeTable(treeTableModel);\n // this is actually a JTable rowAtPoint bug: falsely calculates\n // row == 0 if - 1 >= y > - getRowHeight()\n \n //assertEquals(\"location outside must return null path\", null, treeTable.getPathForLocation(-1, -(treeTable.getRowHeight() - 1)));\n int negativeYRowHeight = - treeTable.getRowHeight();\n int negativeYRowHeightPlusOne = negativeYRowHeight + 1;\n int negativeYMinimal = -1;\n assertEquals(\"negative y location rowheight \" + negativeYRowHeight + \" must return row -1\", \n -1, treeTable.rowAtPoint(new Point(-1, negativeYRowHeight)));\n assertEquals(\"negative y location \" + negativeYRowHeightPlusOne +\" must return row -1\", \n -1, treeTable.rowAtPoint(new Point(-1, negativeYRowHeightPlusOne)));\n assertEquals(\"minimal negative y location must return row -1\", \n -1, treeTable.rowAtPoint(new Point(-1, negativeYMinimal)));\n }\n /**\n * Issue #151: renderer properties ignored after setting treeTableModel.\n * \n */\n public void testRendererProperties() {\n JXTreeTable treeTable = new JXTreeTable(treeTableModel);\n // storing negates of properties\n boolean expandsSelected = !treeTable.getExpandsSelectedPaths();\n boolean scrollsOnExpand = !treeTable.getScrollsOnExpand();\n boolean showRootHandles = !treeTable.getShowsRootHandles();\n boolean rootVisible = !treeTable.isRootVisible();\n // setting negates properties\n treeTable.setExpandsSelectedPaths(expandsSelected);\n treeTable.setScrollsOnExpand(scrollsOnExpand);\n treeTable.setShowsRootHandles(showRootHandles);\n treeTable.setRootVisible(rootVisible);\n // assert negates are set - sanity assert\n assertEquals(\"expand selected\", expandsSelected, treeTable\n .getExpandsSelectedPaths());\n assertEquals(\"scrolls expand\", scrollsOnExpand, treeTable\n .getScrollsOnExpand());\n assertEquals(\"shows handles\", showRootHandles, treeTable\n .getShowsRootHandles());\n assertEquals(\"root visible\", rootVisible, treeTable.isRootVisible());\n // setting a new model\n treeTable.setTreeTableModel(new DefaultTreeTableModel());\n // assert negates are set\n assertEquals(\"expand selected\", expandsSelected, treeTable\n .getExpandsSelectedPaths());\n assertEquals(\"scrolls expand\", scrollsOnExpand, treeTable\n .getScrollsOnExpand());\n assertEquals(\"shows handles\", showRootHandles, treeTable\n .getShowsRootHandles());\n assertEquals(\"root visible\", rootVisible, treeTable.isRootVisible());\n\n }\n\n /**\n * Issue #148: line style client property not respected by renderer.\n * \n */\n public void testLineStyle() {\n JXTreeTable treeTable = new JXTreeTable(treeTableModel);\n String propertyName = \"JTree.lineStyle\";\n treeTable.putClientProperty(propertyName, \"Horizontal\");\n JXTree renderer = (JXTree) treeTable.getCellRenderer(0, 0);\n assertEquals(propertyName + \" set on renderer\", \"Horizontal\", renderer\n .getClientProperty(propertyName));\n }\n\n /**\n * sanity test: arbitrary client properties not passed to renderer.\n * \n */\n public void testArbitraryClientProperty() {\n JXTreeTable treeTable = new JXTreeTable(treeTableModel);\n String propertyName = \"someproperty\";\n treeTable.putClientProperty(propertyName, \"Horizontal\");\n JXTree renderer = (JXTree) treeTable.getCellRenderer(0, 0);\n assertNull(propertyName + \" not set on renderer\", renderer\n .getClientProperty(propertyName));\n\n }\n\n\n // ------------------ init\n protected void setUp() throws Exception {\n super.setUp();\n JXTree tree = new JXTree();\n DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();\n simpleTreeTableModel = new DefaultTreeTableModel((TreeNode) treeModel.getRoot());\n treeTableModel = new FileSystemModel();\n }\n\n}\n"},"message":{"kind":"string","value":"fixed headlessException in test\n"},"old_file":{"kind":"string","value":"src/test/org/jdesktop/swingx/JXTreeTableUnitTest.java"},"subject":{"kind":"string","value":"fixed headlessException in test"},"git_diff":{"kind":"string","value":"rc/test/org/jdesktop/swingx/JXTreeTableUnitTest.java\n import org.jdesktop.swingx.treetable.TreeTableModel;\n import org.jdesktop.swingx.util.ComponentTreeTableModel;\n import org.jdesktop.swingx.util.PropertyChangeReport;\nimport org.jdesktop.swingx.util.TreeSelectionReport;\n \n \n public class JXTreeTableUnitTest extends InteractiveTestCase {\n *\n */\n public void testConservativeRowForNodeInAdapter() {\n JXTreeTable treeTable = new JXTreeTable(new ComponentTreeTableModel(new JXFrame()));\n // for testing we need a model which relies on \n // node != null\n TreeTableModel model = new DefaultTreeTableModel((TreeNode) simpleTreeTableModel.getRoot()) {\n\n @Override\n public Object getValueAt(Object node, int column) {\n // access node\n node.toString();\n return super.getValueAt(node, column);\n }\n\n @Override\n public void setValueAt(Object value, Object node, int column) {\n // access node\n node.toString();\n super.setValueAt(value, node, column);\n }\n\n @Override\n public boolean isCellEditable(Object node, int column) {\n // access node\n node.toString();\n return super.isCellEditable(node, column);\n }\n \n };\n // can't use ComponentTreeTableModel in headless environment\n// JXTreeTable treeTable = new JXTreeTable(new ComponentTreeTableModel(new JXFrame()));\n JXTreeTable treeTable = new JXTreeTable(model);\n treeTable.setRootVisible(true);\n TableModel adapter = treeTable.getModel();\n treeTable.collapseAll();"}}},{"rowIdx":650,"cells":{"lang":{"kind":"string","value":"Java"},"license":{"kind":"string","value":"apache-2.0"},"stderr":{"kind":"string","value":""},"commit":{"kind":"string","value":"bfa79a5638c09131693eb3b902bd8d9f8a204858"},"returncode":{"kind":"number","value":0,"string":"0"},"repos":{"kind":"string","value":"metaborg/spoofax,metaborg/spoofax,metaborg/spoofax,metaborg/spoofax-eclipse,metaborg/spoofax"},"new_contents":{"kind":"string","value":"/*******************************************************************************\n * Copyright (c) 2006 IBM Corporation and others.\n * All rights reserved. This program and the accompanying materials\n * are made available under the terms of the Eclipse Public License v1.0\n * which accompanies this distribution, and is available at\n * http://www.eclipse.org/legal/epl-v10.html\n *\n * Contributors:\n * IBM Corporation - initial API and implementation\n *******************************************************************************/\npackage org.strategoxt.imp.runtime.services.outline;\n\nimport org.eclipse.jface.dialogs.Dialog;\nimport org.eclipse.jface.dialogs.PopupDialog;\nimport org.eclipse.jface.viewers.ILabelProvider;\nimport org.eclipse.jface.viewers.IStructuredSelection;\nimport org.eclipse.jface.viewers.ITreeContentProvider;\nimport org.eclipse.jface.viewers.StructuredSelection;\nimport org.eclipse.jface.viewers.TreeViewer;\nimport org.eclipse.jface.viewers.Viewer;\nimport org.eclipse.jface.viewers.ViewerFilter;\nimport org.eclipse.swt.SWT;\nimport org.eclipse.swt.events.DisposeEvent;\nimport org.eclipse.swt.events.DisposeListener;\nimport org.eclipse.swt.events.FocusListener;\nimport org.eclipse.swt.events.KeyEvent;\nimport org.eclipse.swt.events.KeyListener;\nimport org.eclipse.swt.events.ModifyEvent;\nimport org.eclipse.swt.events.ModifyListener;\nimport org.eclipse.swt.events.MouseAdapter;\nimport org.eclipse.swt.events.MouseEvent;\nimport org.eclipse.swt.events.MouseMoveListener;\nimport org.eclipse.swt.events.SelectionEvent;\nimport org.eclipse.swt.events.SelectionListener;\nimport org.eclipse.swt.graphics.Color;\nimport org.eclipse.swt.graphics.FontMetrics;\nimport org.eclipse.swt.graphics.GC;\nimport org.eclipse.swt.graphics.Point;\nimport org.eclipse.swt.layout.GridData;\nimport org.eclipse.swt.widgets.Composite;\nimport org.eclipse.swt.widgets.Control;\nimport org.eclipse.swt.widgets.Label;\nimport org.eclipse.swt.widgets.Shell;\nimport org.eclipse.swt.widgets.Text;\nimport org.eclipse.swt.widgets.Tree;\nimport org.eclipse.swt.widgets.TreeItem;\nimport org.eclipse.ui.internal.misc.StringMatcher;\n\n/**\n * Abstract class for showing a filtered tree in a lightweight popup dialog.\n */\npublic abstract class FilteringInfoPopup extends PopupDialog implements DisposeListener {\n\n\t/**\n\t * The NamePatternFilter selects the elements which\n\t * match the given string patterns.\n\t */\n\tprotected class NamePatternFilter extends ViewerFilter {\n\n\t\tpublic NamePatternFilter() {\n\t\t}\n\n\t\t/* (non-Javadoc)\n\t\t * Method declared on ViewerFilter.\n\t\t */\n\t\tpublic boolean select(Viewer viewer, Object parentElement, Object element) {\n\t\t\tif(matcher==null) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\t\n\t\t\tTreeViewer treeViewer= (TreeViewer) viewer;\n\n\t\t\tString matchName = getMatchName(element);\n\t\t\tif (matchName != null && matcher.match(matchName))\n\t\t\t\treturn true;\n\n\t\t\treturn hasUnfilteredChild(treeViewer, element);\n\t\t}\n\n\t\tprivate boolean hasUnfilteredChild(TreeViewer viewer, Object element) {\n\t\t\tObject[] children = ((ITreeContentProvider) viewer\n\t\t\t\t\t.getContentProvider()).getChildren(element);\n\t\t\tfor (int i = 0; i < children.length; i++)\n\t\t\t\tif (select(viewer, element, children[i]))\n\t\t\t\t\treturn true;\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/** The control's text widget */\n\tprivate Text filterText;\n\t/** The control's tree widget */\n\tprivate TreeViewer treeViewer;\n\n\t/**\n\t * Fields that support the dialog menu\n\t */\n\tprivate Composite viewMenuButtonComposite;\n\n\t/**\n\t * Field for tree style since it must be remembered by the instance.\n\t */\n\tprivate int treeStyle;\n\tprivate StringMatcher matcher;\n\n\t/**\n\t * Creates a tree information control with the given shell as parent. The given\n\t * styles are applied to the shell and the tree widget.\n\t *\n\t * @param parent the parent shell\n\t * @param shellStyle the additional styles for the shell\n\t * @param treeStyle the additional styles for the tree widget\n\t * @param showStatusField true iff the control has a status field at the bottom\n\t */\n\tpublic FilteringInfoPopup(Shell parent, int shellStyle, int treeStyle, boolean showStatusField) {\n\t\tsuper(parent, shellStyle, true, true, true, true, null, null);\n\t\tthis.treeStyle= treeStyle;\n\t\t// Title and status text must be set to get the title label created, so force empty values here. \n\t\tif (hasHeader())\n\t\t\tsetTitleText(\"\"); //$NON-NLS-1$\n\t\tsetInfoText(\"\"); // //$NON-NLS-1$\n\n\t\t// Status field text can only be computed after widgets are created.\n\t\tsetInfoText(getStatusFieldText());\n\t}\n\n\t/**\n\t * Create the main content for this information control.\n\t * \n\t * @param parent The parent composite\n\t * @return The control representing the main content.\n\t */\n\tprotected Control createDialogArea(Composite parent) {\n\t\ttreeViewer= createTreeViewer(parent, treeStyle);\n\n\t\tfinal Tree tree= treeViewer.getTree();\n\t\ttree.addKeyListener(new KeyListener() {\n\t\t\tpublic void keyPressed(KeyEvent e) {\n\t\t\t\tif (e.character == SWT.ESC)\n\t\t\t\t\tdispose();\n\t\t\t}\n\t\t\tpublic void keyReleased(KeyEvent e) {\n\t\t\t\t// do nothing\n\t\t\t}\n\t\t});\n\n\t\ttree.addSelectionListener(new SelectionListener() {\n\t\t\tpublic void widgetSelected(SelectionEvent e) {\n\t\t\t\t// do nothing\n\t\t\t}\n\t\t\tpublic void widgetDefaultSelected(SelectionEvent e) {\n\t\t\t\tObject selectedElement = getSelectedElement();\n\t\t\t\tclose();\n handleElementSelected(selectedElement);\n\t\t\t}\n\t\t});\n\n\t\ttree.addMouseMoveListener(new MouseMoveListener()\t {\n\t\t\tpublic void mouseMove(MouseEvent e) {\n\t\t\t\tTreeItem[] selectedItems = tree.getSelection();\n\t\t\t\tTreeItem selectedItem = selectedItems.length == 0 ? null : selectedItems[0];\n\t\t\t\tTreeItem itemUnderPointer = tree.getItem(new Point(e.x, e.y));\n\t\t\t\tif (itemUnderPointer != null) {\n\t\t\t\t\tif (itemUnderPointer != selectedItem) {\n\t\t\t\t\t\tselect(itemUnderPointer);\n\t\t\t\t\t} else if (e.y < tree.getItemHeight() / 4) {\n\t\t\t\t\t\t// Scroll up\n\t\t\t\t\t\tPoint p= tree.toDisplay(e.x, e.y);\n\t\t\t\t\t\tTreeItem item= (TreeItem) treeViewer.scrollUp(p.x, p.y);\n\t\t\t\t\t\tif (item != null) {\n\t\t\t\t\t\t\tselect(item);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (e.y > tree.getBounds().height - tree.getItemHeight() / 4) {\n\t\t\t\t\t\t// Scroll down\n\t\t\t\t\t\tPoint p= tree.toDisplay(e.x, e.y);\n\t\t\t\t\t\tTreeItem item= (TreeItem) treeViewer.scrollDown(p.x, p.y);\n\t\t\t\t\t\tif (item != null) {\n\t\t\t\t\t\t\tselect(item);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tprivate void select(TreeItem item) {\n\t\t\t\t// set selection on viewer instead of directly on tree so that\n\t\t\t\t// selection listeners are notified\n\t\t\t\tObject element = item.getData();\n\t\t\t\tif (element != null) {\n\t\t\t\t\ttreeViewer.setSelection(new StructuredSelection(element));\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\ttree.addMouseListener(new MouseAdapter() {\n\t\t\tpublic void mouseUp(MouseEvent e) {\n\n\t\t\t\tif (tree.getSelectionCount() < 1)\n\t\t\t\t\treturn;\n\n\t\t\t\tif (e.button != 1)\n\t\t\t\t\treturn;\n\n\t\t\t\tif (tree.equals(e.getSource())) {\n\t\t\t\t\tObject o= tree.getItem(new Point(e.x, e.y));\n\t\t\t\t\tTreeItem selection= tree.getSelection()[0];\n\t\t\t\t\tif (selection.equals(o)) {\n\t\t\t\t\t\tObject selectedElement = getSelectedElement();\n\t\t\t\t\t\tclose();\n handleElementSelected(selectedElement);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tinstallFilter();\n\n\t\taddDisposeListener(this);\n\t\treturn treeViewer.getControl();\n\t}\n\t\n\t/**\n\t * Creates a tree information control with the given shell as parent. The given\n\t * styles are applied to the shell and the tree widget.\n\t *\n\t * @param parent the parent shell\n\t * @param shellStyle the additional styles for the shell\n\t * @param treeStyle the additional styles for the tree widget\n\t */\n\tpublic FilteringInfoPopup(Shell parent, int shellStyle, int treeStyle) {\n\t\tthis(parent, shellStyle, treeStyle, false);\n\t}\n\n\tprotected abstract TreeViewer createTreeViewer(Composite parent, int style);\n\n\t/**\n\t * Returns the name of the dialog settings section.\n\t *\n\t * @return the name of the dialog settings section\n\t */\n\tprotected abstract String getId();\n\t\n\t/* (non-Javadoc)\n\t * @see org.eclipse.jface.dialogs.PopupDialog#getFocusControl()\n\t */\n\tprotected Control getFocusControl() {\n\t\treturn filterText;\n\t}\n\n\tprotected TreeViewer getTreeViewer() {\n\t\treturn treeViewer;\n\t}\n\n\t/**\n\t * Returns true if the control has a header, false otherwise.\n\t *
\n\t * The default is to return false.\n\t *
\n\t * \n\t * @return true if the control has a header\n\t */\n\tprotected boolean hasHeader() {\n\t\t// default is to have no header\n\t\treturn false;\n\t}\n\n\tprotected Text getFilterText() {\n\t\treturn filterText;\n\t}\n\n\tprotected Text createFilterText(Composite parent) {\n\t\tfilterText= new Text(parent, SWT.NONE);\n\n\t\tGridData data= new GridData(GridData.FILL_HORIZONTAL);\n\t\tGC gc= new GC(parent);\n\t\tgc.setFont(parent.getFont());\n\t\tFontMetrics fontMetrics= gc.getFontMetrics();\n\t\tgc.dispose();\n\n\t\tdata.heightHint= Dialog.convertHeightInCharsToPixels(fontMetrics, 1);\n\t\tdata.horizontalAlignment= GridData.FILL;\n\t\tdata.verticalAlignment= GridData.CENTER;\n\t\tfilterText.setLayoutData(data);\n\n\t\tfilterText.addKeyListener(new KeyListener() {\n\t\t\tpublic void keyPressed(KeyEvent e) {\n\t\t\t\tif (e.keyCode == 0x0D) {\n\t\t\t\t\t// return\n\t\t\t\t\tObject selectedElement = getSelectedElement();\n\t\t\t\t\tclose();\n\t\t\t\t\thandleElementSelected(selectedElement);\n\t\t\t\t}\n\t\t\t\tif (e.keyCode == SWT.ARROW_DOWN)\n\t\t\t\t\ttreeViewer.getTree().setFocus();\n\t\t\t\tif (e.keyCode == SWT.ARROW_UP)\n\t\t\t\t\ttreeViewer.getTree().setFocus();\n\t\t\t\tif (e.character == 0x1B) // ESC\n\t\t\t\t\tdispose();\n\t\t\t}\n\t\t\tpublic void keyReleased(KeyEvent e) {\n\t\t\t\t// do nothing\n\t\t\t}\n\t\t});\n\n\t\treturn filterText;\n\t}\n\n\tprotected void createHorizontalSeparator(Composite parent) {\n\t\tLabel separator= new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.LINE_DOT);\n\t\tseparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));\n\t}\n\n\tprotected void updateStatusFieldText() {\n\t\tsetInfoText(getStatusFieldText());\n\t}\n\n\t/**\n\t * Handles click in status field.\n\t *
\n\t * Default does nothing.\n\t *
\n\t */\n\tprotected void handleStatusFieldClicked() {\n\t}\n\n\tprotected String getStatusFieldText() {\n\t\treturn \"\"; //$NON-NLS-1$\n\t}\n\n\tprivate void installFilter() {\n\t\tfilterText.setText(\"\"); //$NON-NLS-1$\n\n\t\tfilterText.addModifyListener(new ModifyListener() {\n\t\t\tpublic void modifyText(ModifyEvent e) {\n\t\t\t\tString text= ((Text) e.widget).getText();\n\t\t\t\tint length= text.length();\n\t\t\t\tif (length > 0 && text.charAt(length -1 ) != '*') {\n\t\t\t\t\ttext= text + '*';\n\t\t\t\t}\n\t\t\t\tsetMatcherString(text, true);\n\t\t\t}\n\t\t});\n\t\t\n\t\tgetTreeViewer().addFilter(new NamePatternFilter());\n\t}\n\n\t/**\n\t * The string matcher has been modified. The default implementation\n\t * refreshes the view and selects the first matched element\n\t */\n\tprotected void stringMatcherUpdated() {\n\t\t// refresh viewer to re-filter\n\t\ttreeViewer.getControl().setRedraw(false);\n\t\ttreeViewer.refresh();\n\t\ttreeViewer.expandAll();\n\t\tselectFirstMatch();\n\t\ttreeViewer.getControl().setRedraw(true);\n\t}\n\n\t/**\n\t * Sets the patterns to filter out for the receiver.\n\t *
\n\t * The following characters have special meaning:\n\t * ? => any character\n\t * * => any string\n\t *
\n\t *\n\t * @param pattern the pattern\n\t * @param update true if the viewer should be updated\n\t */\n\tprotected void setMatcherString(String pattern, boolean update) {\n\t\tif (pattern.length() == 0) {\n\t\t\tmatcher= null;\n\t\t} else {\n\t\t\tboolean ignoreCase= pattern.toLowerCase().equals(pattern);\n\t\t\tmatcher= new StringMatcher(pattern, ignoreCase, false);\n\t\t}\n\t\t\n\t\tif (update)\n\t\t\tstringMatcherUpdated();\n\t}\n\n\tprotected StringMatcher getMatcher() {\n\t\treturn matcher;\n\t}\n\n\t/**\n\t * Implementers can modify\n\t *\n\t * @return the selected element\n\t */\n\tprotected Object getSelectedElement() {\n\t\tif (treeViewer == null)\n\t\t\treturn null;\n\n\t\treturn ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\n\t}\n\n\tabstract protected void handleElementSelected(Object selectedElement);\n\n\t/**\n\t * Selects the first element in the tree which\n\t * matches the current filter pattern.\n\t */\n\tprotected void selectFirstMatch() {\n\t\tTree tree= treeViewer.getTree();\n\t\tObject element= findElement(tree.getItems());\n\t\tif (element != null)\n\t\t\ttreeViewer.setSelection(new StructuredSelection(element), true);\n\t\telse\n\t\t\ttreeViewer.setSelection(StructuredSelection.EMPTY);\n\t}\n\n\tprivate Object findElement(TreeItem[] items) {\n\t\tfor (int i= 0; i < items.length; i++) {\n\t\t\tObject element= items[i].getData();\n\t\t\tif (matcher == null)\n\t\t\t\treturn element;\n\n\t\t\tif (element != null) {\n\t\t\t\tString label= getMatchName(element);\n\t\t\t\tif (matcher.match(label))\n\t\t\t\t\treturn element;\n\t\t\t}\n\n\t\t\telement= findElement(items[i].getItems());\n\t\t\tif (element != null)\n\t\t\t\treturn element;\n\t\t}\n\t\treturn null;\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void setInformation(String information) {\n\t\t// this method is ignored, see IInformationControlExtension2\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic abstract void setInput(Object information);\n\n\tprotected void inputChanged(Object newInput, Object newSelection) {\n\t\tfilterText.setText(\"\"); //$NON-NLS-1$\n\t\ttreeViewer.setInput(newInput);\n\t\tif (newSelection != null) {\n\t\t\ttreeViewer.setSelection(new StructuredSelection(newSelection));\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void setVisible(boolean visible) {\n\t\tif (visible) {\n\t\t\topen();\n\t\t} else {\n\t\t\tsaveDialogBounds(getShell());\n\t\t\tgetShell().setVisible(false);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic final void dispose() {\n\t\tclose();\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t * @param event can be null\n\t *
\n\t * Subclasses may extend.\n\t *
\n\t */\n\tpublic void widgetDisposed(DisposeEvent event) {\n\t\ttreeViewer= null;\n\t\tfilterText= null;\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic boolean hasContents() {\n\t\treturn treeViewer != null && treeViewer.getInput() != null;\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void setSizeConstraints(int maxWidth, int maxHeight) {\n\t\t// ignore\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic Point computeSizeHint() {\n\t\t// return the shell's size - note that it already has the persisted size if persisting\n\t\t// is enabled.\n\t\treturn getShell().getSize();\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void setLocation(Point location) {\n\t\t/*\n\t\t * If the location is persisted, it gets managed by PopupDialog - fine. Otherwise, the location is\n\t\t * computed in Window#getInitialLocation, which will center it in the parent shell / main\n\t\t * monitor, which is wrong for two reasons:\n\t\t * - we want to center over the editor / subject control, not the parent shell\n\t\t * - the center is computed via the initalSize, which may be also wrong since the size may \n\t\t * have been updated since via min/max sizing of AbstractInformationControlManager.\n\t\t * In that case, override the location with the one computed by the manager. Note that\n\t\t * the call to constrainShellSize in PopupDialog.open will still ensure that the shell is\n\t\t * entirely visible.\n\t\t */\n\t\tif (!getPersistBounds() || getDialogSettings() == null)\n\t\t\tgetShell().setLocation(location);\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void setSize(int width, int height) {\n\t\tgetShell().setSize(width, height);\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void addDisposeListener(DisposeListener listener) {\n\t\tgetShell().addDisposeListener(listener);\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void removeDisposeListener(DisposeListener listener) {\n\t\tgetShell().removeDisposeListener(listener);\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void setForegroundColor(Color foreground) {\n\t\tapplyForegroundColor(foreground, getContents());\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void setBackgroundColor(Color background) {\n\t\tapplyBackgroundColor(background, getContents());\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic boolean isFocusControl() {\n\t\treturn treeViewer.getControl().isFocusControl() || filterText.isFocusControl();\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void setFocus() {\n\t\tgetShell().forceFocus();\n\t\tfilterText.setFocus();\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void addFocusListener(FocusListener listener) {\n\t\tgetShell().addFocusListener(listener);\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void removeFocusListener(FocusListener listener) {\n\t\tgetShell().removeFocusListener(listener);\n\t}\n\n\t/*\n\t * Overridden to insert the filter text into the title and menu area.\n\t * \n\t * @since 3.2\n\t */\n\tprotected Control createTitleMenuArea(Composite parent) {\n\t\tviewMenuButtonComposite= (Composite) super.createTitleMenuArea(parent);\n\n\t\t// If there is a header, then the filter text must be created\n\t\t// underneath the title and menu area.\n\n\t\tif (hasHeader()) {\n\t\t\tfilterText= createFilterText(parent);\n\t\t}\n\n\t\treturn viewMenuButtonComposite;\n\t}\n\n\t/*\n\t * Overridden to insert the filter text into the title control\n\t * if there is no header specified.\n\t * @since 3.2\n\t */\n\tprotected Control createTitleControl(Composite parent) {\n\t\tif (hasHeader()) {\n\t\t\treturn super.createTitleControl(parent);\n\t\t}\n\t\tfilterText= createFilterText(parent);\n\t\treturn filterText;\n\t}\n\t\n\t/*\n\t * @see org.eclipse.jface.dialogs.PopupDialog#setTabOrder(org.eclipse.swt.widgets.Composite)\n\t */\n\tprotected void setTabOrder(Composite composite) {\n\t\tif (hasHeader()) {\n\t\t\tcomposite.setTabList(new Control[] { filterText, treeViewer.getTree() });\n\t\t} else {\n\t\t\tviewMenuButtonComposite.setTabList(new Control[] { filterText });\n\t\t\tcomposite.setTabList(new Control[] { viewMenuButtonComposite, treeViewer.getTree() });\n\t\t}\n\t}\n\n\t/**\n\t * Returns the name of the given element used for matching. The default\n\t * implementation gets the name from the tree viewer's label provider.\n\t * Subclasses may override.\n\t * \n\t * @param element the element\n\t * @return the name to be used for matching\n\t */\n\tprotected String getMatchName(Object element) {\n\t\treturn ((ILabelProvider) getTreeViewer().getLabelProvider()).getText(element);\n\t}\n}\n"},"new_file":{"kind":"string","value":"org.strategoxt.imp.runtime/src/org/strategoxt/imp/runtime/services/outline/FilteringInfoPopup.java"},"old_contents":{"kind":"string","value":"/*******************************************************************************\n * Copyright (c) 2006 IBM Corporation and others.\n * All rights reserved. This program and the accompanying materials\n * are made available under the terms of the Eclipse Public License v1.0\n * which accompanies this distribution, and is available at\n * http://www.eclipse.org/legal/epl-v10.html\n *\n * Contributors:\n * IBM Corporation - initial API and implementation\n *******************************************************************************/\npackage org.strategoxt.imp.runtime.services.outline;\n\nimport org.eclipse.jface.dialogs.Dialog;\nimport org.eclipse.jface.dialogs.PopupDialog;\nimport org.eclipse.jface.viewers.ILabelProvider;\nimport org.eclipse.jface.viewers.IStructuredSelection;\nimport org.eclipse.jface.viewers.ITreeContentProvider;\nimport org.eclipse.jface.viewers.StructuredSelection;\nimport org.eclipse.jface.viewers.TreeViewer;\nimport org.eclipse.jface.viewers.Viewer;\nimport org.eclipse.jface.viewers.ViewerFilter;\nimport org.eclipse.swt.SWT;\nimport org.eclipse.swt.events.DisposeEvent;\nimport org.eclipse.swt.events.DisposeListener;\nimport org.eclipse.swt.events.FocusListener;\nimport org.eclipse.swt.events.KeyEvent;\nimport org.eclipse.swt.events.KeyListener;\nimport org.eclipse.swt.events.ModifyEvent;\nimport org.eclipse.swt.events.ModifyListener;\nimport org.eclipse.swt.events.MouseAdapter;\nimport org.eclipse.swt.events.MouseEvent;\nimport org.eclipse.swt.events.MouseMoveListener;\nimport org.eclipse.swt.events.SelectionEvent;\nimport org.eclipse.swt.events.SelectionListener;\nimport org.eclipse.swt.graphics.Color;\nimport org.eclipse.swt.graphics.FontMetrics;\nimport org.eclipse.swt.graphics.GC;\nimport org.eclipse.swt.graphics.Point;\nimport org.eclipse.swt.layout.GridData;\nimport org.eclipse.swt.widgets.Composite;\nimport org.eclipse.swt.widgets.Control;\nimport org.eclipse.swt.widgets.Label;\nimport org.eclipse.swt.widgets.Shell;\nimport org.eclipse.swt.widgets.Text;\nimport org.eclipse.swt.widgets.Tree;\nimport org.eclipse.swt.widgets.TreeItem;\nimport org.eclipse.ui.internal.misc.StringMatcher;\n\n/**\n * Abstract class for showing a filtered tree in a lightweight popup dialog.\n */\npublic abstract class FilteringInfoPopup extends PopupDialog implements DisposeListener {\n\n\t/**\n\t * The NamePatternFilter selects the elements which\n\t * match the given string patterns.\n\t */\n\tprotected class NamePatternFilter extends ViewerFilter {\n\n\t\tpublic NamePatternFilter() {\n\t\t}\n\n\t\t/* (non-Javadoc)\n\t\t * Method declared on ViewerFilter.\n\t\t */\n\t\tpublic boolean select(Viewer viewer, Object parentElement, Object element) {\n\t\t\tif(matcher==null) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\t\n\t\t\tTreeViewer treeViewer= (TreeViewer) viewer;\n\n\t\t\tString matchName = getMatchName(element);\n\t\t\tif (matchName != null && matcher.match(matchName))\n\t\t\t\treturn true;\n\n\t\t\treturn hasUnfilteredChild(treeViewer, element);\n\t\t}\n\n\t\tprivate boolean hasUnfilteredChild(TreeViewer viewer, Object element) {\n\t\t\tObject[] children = ((ITreeContentProvider) viewer\n\t\t\t\t\t.getContentProvider()).getChildren(element);\n\t\t\tfor (int i = 0; i < children.length; i++)\n\t\t\t\tif (select(viewer, element, children[i]))\n\t\t\t\t\treturn true;\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/** The control's text widget */\n\tprivate Text filterText;\n\t/** The control's tree widget */\n\tprivate TreeViewer treeViewer;\n\n\t/**\n\t * Fields that support the dialog menu\n\t */\n\tprivate Composite viewMenuButtonComposite;\n\n\t/**\n\t * Field for tree style since it must be remembered by the instance.\n\t */\n\tprivate int treeStyle;\n\tprivate StringMatcher matcher;\n\n\t/**\n\t * Creates a tree information control with the given shell as parent. The given\n\t * styles are applied to the shell and the tree widget.\n\t *\n\t * @param parent the parent shell\n\t * @param shellStyle the additional styles for the shell\n\t * @param treeStyle the additional styles for the tree widget\n\t * @param showStatusField true iff the control has a status field at the bottom\n\t */\n\tpublic FilteringInfoPopup(Shell parent, int shellStyle, int treeStyle, boolean showStatusField) {\n\t\tsuper(parent, shellStyle, true, true, true, true, null, null);\n\t\tthis.treeStyle= treeStyle;\n\t\t// Title and status text must be set to get the title label created, so force empty values here. \n\t\tif (hasHeader())\n\t\t\tsetTitleText(\"\"); //$NON-NLS-1$\n\t\tsetInfoText(\"\"); // //$NON-NLS-1$\n\n\t\t// Create all controls early to preserve the life cycle of the original implementation.\n\t\tcreate();\n\n\t\t// Status field text can only be computed after widgets are created.\n\t\tsetInfoText(getStatusFieldText());\n\t}\n\n\t/**\n\t * Create the main content for this information control.\n\t * \n\t * @param parent The parent composite\n\t * @return The control representing the main content.\n\t */\n\tprotected Control createDialogArea(Composite parent) {\n\t\ttreeViewer= createTreeViewer(parent, treeStyle);\n\n\t\tfinal Tree tree= treeViewer.getTree();\n\t\ttree.addKeyListener(new KeyListener() {\n\t\t\tpublic void keyPressed(KeyEvent e) {\n\t\t\t\tif (e.character == SWT.ESC)\n\t\t\t\t\tdispose();\n\t\t\t}\n\t\t\tpublic void keyReleased(KeyEvent e) {\n\t\t\t\t// do nothing\n\t\t\t}\n\t\t});\n\n\t\ttree.addSelectionListener(new SelectionListener() {\n\t\t\tpublic void widgetSelected(SelectionEvent e) {\n\t\t\t\t// do nothing\n\t\t\t}\n\t\t\tpublic void widgetDefaultSelected(SelectionEvent e) {\n\t\t\t\tObject selectedElement = getSelectedElement();\n\t\t\t\tclose();\n handleElementSelected(selectedElement);\n\t\t\t}\n\t\t});\n\n\t\ttree.addMouseMoveListener(new MouseMoveListener()\t {\n\t\t\tpublic void mouseMove(MouseEvent e) {\n\t\t\t\tTreeItem[] selectedItems = tree.getSelection();\n\t\t\t\tTreeItem selectedItem = selectedItems.length == 0 ? null : selectedItems[0];\n\t\t\t\tTreeItem itemUnderPointer = tree.getItem(new Point(e.x, e.y));\n\t\t\t\tif (itemUnderPointer != null) {\n\t\t\t\t\tif (itemUnderPointer != selectedItem) {\n\t\t\t\t\t\tselect(itemUnderPointer);\n\t\t\t\t\t} else if (e.y < tree.getItemHeight() / 4) {\n\t\t\t\t\t\t// Scroll up\n\t\t\t\t\t\tPoint p= tree.toDisplay(e.x, e.y);\n\t\t\t\t\t\tTreeItem item= (TreeItem) treeViewer.scrollUp(p.x, p.y);\n\t\t\t\t\t\tif (item != null) {\n\t\t\t\t\t\t\tselect(item);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (e.y > tree.getBounds().height - tree.getItemHeight() / 4) {\n\t\t\t\t\t\t// Scroll down\n\t\t\t\t\t\tPoint p= tree.toDisplay(e.x, e.y);\n\t\t\t\t\t\tTreeItem item= (TreeItem) treeViewer.scrollDown(p.x, p.y);\n\t\t\t\t\t\tif (item != null) {\n\t\t\t\t\t\t\tselect(item);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tprivate void select(TreeItem item) {\n\t\t\t\t// set selection on viewer instead of directly on tree so that\n\t\t\t\t// selection listeners are notified\n\t\t\t\tObject element = item.getData();\n\t\t\t\tif (element != null) {\n\t\t\t\t\ttreeViewer.setSelection(new StructuredSelection(element));\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\ttree.addMouseListener(new MouseAdapter() {\n\t\t\tpublic void mouseUp(MouseEvent e) {\n\n\t\t\t\tif (tree.getSelectionCount() < 1)\n\t\t\t\t\treturn;\n\n\t\t\t\tif (e.button != 1)\n\t\t\t\t\treturn;\n\n\t\t\t\tif (tree.equals(e.getSource())) {\n\t\t\t\t\tObject o= tree.getItem(new Point(e.x, e.y));\n\t\t\t\t\tTreeItem selection= tree.getSelection()[0];\n\t\t\t\t\tif (selection.equals(o)) {\n\t\t\t\t\t\tObject selectedElement = getSelectedElement();\n\t\t\t\t\t\tclose();\n handleElementSelected(selectedElement);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tinstallFilter();\n\n\t\taddDisposeListener(this);\n\t\treturn treeViewer.getControl();\n\t}\n\t\n\t/**\n\t * Creates a tree information control with the given shell as parent. The given\n\t * styles are applied to the shell and the tree widget.\n\t *\n\t * @param parent the parent shell\n\t * @param shellStyle the additional styles for the shell\n\t * @param treeStyle the additional styles for the tree widget\n\t */\n\tpublic FilteringInfoPopup(Shell parent, int shellStyle, int treeStyle) {\n\t\tthis(parent, shellStyle, treeStyle, false);\n\t}\n\n\tprotected abstract TreeViewer createTreeViewer(Composite parent, int style);\n\n\t/**\n\t * Returns the name of the dialog settings section.\n\t *\n\t * @return the name of the dialog settings section\n\t */\n\tprotected abstract String getId();\n\t\n\t/* (non-Javadoc)\n\t * @see org.eclipse.jface.dialogs.PopupDialog#getFocusControl()\n\t */\n\tprotected Control getFocusControl() {\n\t\treturn filterText;\n\t}\n\n\tprotected TreeViewer getTreeViewer() {\n\t\treturn treeViewer;\n\t}\n\n\t/**\n\t * Returns true if the control has a header, false otherwise.\n\t *
\n\t * The default is to return false.\n\t *
\n\t * \n\t * @return true if the control has a header\n\t */\n\tprotected boolean hasHeader() {\n\t\t// default is to have no header\n\t\treturn false;\n\t}\n\n\tprotected Text getFilterText() {\n\t\treturn filterText;\n\t}\n\n\tprotected Text createFilterText(Composite parent) {\n\t\tfilterText= new Text(parent, SWT.NONE);\n\n\t\tGridData data= new GridData(GridData.FILL_HORIZONTAL);\n\t\tGC gc= new GC(parent);\n\t\tgc.setFont(parent.getFont());\n\t\tFontMetrics fontMetrics= gc.getFontMetrics();\n\t\tgc.dispose();\n\n\t\tdata.heightHint= Dialog.convertHeightInCharsToPixels(fontMetrics, 1);\n\t\tdata.horizontalAlignment= GridData.FILL;\n\t\tdata.verticalAlignment= GridData.CENTER;\n\t\tfilterText.setLayoutData(data);\n\n\t\tfilterText.addKeyListener(new KeyListener() {\n\t\t\tpublic void keyPressed(KeyEvent e) {\n\t\t\t\tif (e.keyCode == 0x0D) {\n\t\t\t\t\t// return\n\t\t\t\t\tObject selectedElement = getSelectedElement();\n\t\t\t\t\tclose();\n\t\t\t\t\thandleElementSelected(selectedElement);\n\t\t\t\t}\n\t\t\t\tif (e.keyCode == SWT.ARROW_DOWN)\n\t\t\t\t\ttreeViewer.getTree().setFocus();\n\t\t\t\tif (e.keyCode == SWT.ARROW_UP)\n\t\t\t\t\ttreeViewer.getTree().setFocus();\n\t\t\t\tif (e.character == 0x1B) // ESC\n\t\t\t\t\tdispose();\n\t\t\t}\n\t\t\tpublic void keyReleased(KeyEvent e) {\n\t\t\t\t// do nothing\n\t\t\t}\n\t\t});\n\n\t\treturn filterText;\n\t}\n\n\tprotected void createHorizontalSeparator(Composite parent) {\n\t\tLabel separator= new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.LINE_DOT);\n\t\tseparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));\n\t}\n\n\tprotected void updateStatusFieldText() {\n\t\tsetInfoText(getStatusFieldText());\n\t}\n\n\t/**\n\t * Handles click in status field.\n\t *
\n\t * Default does nothing.\n\t *
\n\t */\n\tprotected void handleStatusFieldClicked() {\n\t}\n\n\tprotected String getStatusFieldText() {\n\t\treturn \"\"; //$NON-NLS-1$\n\t}\n\n\tprivate void installFilter() {\n\t\tfilterText.setText(\"\"); //$NON-NLS-1$\n\n\t\tfilterText.addModifyListener(new ModifyListener() {\n\t\t\tpublic void modifyText(ModifyEvent e) {\n\t\t\t\tString text= ((Text) e.widget).getText();\n\t\t\t\tint length= text.length();\n\t\t\t\tif (length > 0 && text.charAt(length -1 ) != '*') {\n\t\t\t\t\ttext= text + '*';\n\t\t\t\t}\n\t\t\t\tsetMatcherString(text, true);\n\t\t\t}\n\t\t});\n\t\t\n\t\tgetTreeViewer().addFilter(new NamePatternFilter());\n\t}\n\n\t/**\n\t * The string matcher has been modified. The default implementation\n\t * refreshes the view and selects the first matched element\n\t */\n\tprotected void stringMatcherUpdated() {\n\t\t// refresh viewer to re-filter\n\t\ttreeViewer.getControl().setRedraw(false);\n\t\ttreeViewer.refresh();\n\t\ttreeViewer.expandAll();\n\t\tselectFirstMatch();\n\t\ttreeViewer.getControl().setRedraw(true);\n\t}\n\n\t/**\n\t * Sets the patterns to filter out for the receiver.\n\t *
\n\t * The following characters have special meaning:\n\t * ? => any character\n\t * * => any string\n\t *
\n\t *\n\t * @param pattern the pattern\n\t * @param update true if the viewer should be updated\n\t */\n\tprotected void setMatcherString(String pattern, boolean update) {\n\t\tif (pattern.length() == 0) {\n\t\t\tmatcher= null;\n\t\t} else {\n\t\t\tboolean ignoreCase= pattern.toLowerCase().equals(pattern);\n\t\t\tmatcher= new StringMatcher(pattern, ignoreCase, false);\n\t\t}\n\t\t\n\t\tif (update)\n\t\t\tstringMatcherUpdated();\n\t}\n\n\tprotected StringMatcher getMatcher() {\n\t\treturn matcher;\n\t}\n\n\t/**\n\t * Implementers can modify\n\t *\n\t * @return the selected element\n\t */\n\tprotected Object getSelectedElement() {\n\t\tif (treeViewer == null)\n\t\t\treturn null;\n\n\t\treturn ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\n\t}\n\n\tabstract protected void handleElementSelected(Object selectedElement);\n\n\t/**\n\t * Selects the first element in the tree which\n\t * matches the current filter pattern.\n\t */\n\tprotected void selectFirstMatch() {\n\t\tTree tree= treeViewer.getTree();\n\t\tObject element= findElement(tree.getItems());\n\t\tif (element != null)\n\t\t\ttreeViewer.setSelection(new StructuredSelection(element), true);\n\t\telse\n\t\t\ttreeViewer.setSelection(StructuredSelection.EMPTY);\n\t}\n\n\tprivate Object findElement(TreeItem[] items) {\n\t\tfor (int i= 0; i < items.length; i++) {\n\t\t\tObject element= items[i].getData();\n\t\t\tif (matcher == null)\n\t\t\t\treturn element;\n\n\t\t\tif (element != null) {\n\t\t\t\tString label= getMatchName(element);\n\t\t\t\tif (matcher.match(label))\n\t\t\t\t\treturn element;\n\t\t\t}\n\n\t\t\telement= findElement(items[i].getItems());\n\t\t\tif (element != null)\n\t\t\t\treturn element;\n\t\t}\n\t\treturn null;\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void setInformation(String information) {\n\t\t// this method is ignored, see IInformationControlExtension2\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic abstract void setInput(Object information);\n\n\tprotected void inputChanged(Object newInput, Object newSelection) {\n\t\tfilterText.setText(\"\"); //$NON-NLS-1$\n\t\ttreeViewer.setInput(newInput);\n\t\tif (newSelection != null) {\n\t\t\ttreeViewer.setSelection(new StructuredSelection(newSelection));\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void setVisible(boolean visible) {\n\t\tif (visible) {\n\t\t\topen();\n\t\t} else {\n\t\t\tsaveDialogBounds(getShell());\n\t\t\tgetShell().setVisible(false);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic final void dispose() {\n\t\tclose();\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t * @param event can be null\n\t *
\n\t * Subclasses may extend.\n\t *
\n\t */\n\tpublic void widgetDisposed(DisposeEvent event) {\n\t\ttreeViewer= null;\n\t\tfilterText= null;\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic boolean hasContents() {\n\t\treturn treeViewer != null && treeViewer.getInput() != null;\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void setSizeConstraints(int maxWidth, int maxHeight) {\n\t\t// ignore\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic Point computeSizeHint() {\n\t\t// return the shell's size - note that it already has the persisted size if persisting\n\t\t// is enabled.\n\t\treturn getShell().getSize();\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void setLocation(Point location) {\n\t\t/*\n\t\t * If the location is persisted, it gets managed by PopupDialog - fine. Otherwise, the location is\n\t\t * computed in Window#getInitialLocation, which will center it in the parent shell / main\n\t\t * monitor, which is wrong for two reasons:\n\t\t * - we want to center over the editor / subject control, not the parent shell\n\t\t * - the center is computed via the initalSize, which may be also wrong since the size may \n\t\t * have been updated since via min/max sizing of AbstractInformationControlManager.\n\t\t * In that case, override the location with the one computed by the manager. Note that\n\t\t * the call to constrainShellSize in PopupDialog.open will still ensure that the shell is\n\t\t * entirely visible.\n\t\t */\n\t\tif (!getPersistBounds() || getDialogSettings() == null)\n\t\t\tgetShell().setLocation(location);\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void setSize(int width, int height) {\n\t\tgetShell().setSize(width, height);\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void addDisposeListener(DisposeListener listener) {\n\t\tgetShell().addDisposeListener(listener);\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void removeDisposeListener(DisposeListener listener) {\n\t\tgetShell().removeDisposeListener(listener);\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void setForegroundColor(Color foreground) {\n\t\tapplyForegroundColor(foreground, getContents());\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void setBackgroundColor(Color background) {\n\t\tapplyBackgroundColor(background, getContents());\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic boolean isFocusControl() {\n\t\treturn treeViewer.getControl().isFocusControl() || filterText.isFocusControl();\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void setFocus() {\n\t\tgetShell().forceFocus();\n\t\tfilterText.setFocus();\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void addFocusListener(FocusListener listener) {\n\t\tgetShell().addFocusListener(listener);\n\t}\n\n\t/**\n\t * {@inheritDoc}\n\t */\n\tpublic void removeFocusListener(FocusListener listener) {\n\t\tgetShell().removeFocusListener(listener);\n\t}\n\n\t/*\n\t * Overridden to insert the filter text into the title and menu area.\n\t * \n\t * @since 3.2\n\t */\n\tprotected Control createTitleMenuArea(Composite parent) {\n\t\tviewMenuButtonComposite= (Composite) super.createTitleMenuArea(parent);\n\n\t\t// If there is a header, then the filter text must be created\n\t\t// underneath the title and menu area.\n\n\t\tif (hasHeader()) {\n\t\t\tfilterText= createFilterText(parent);\n\t\t}\n\n\t\treturn viewMenuButtonComposite;\n\t}\n\n\t/*\n\t * Overridden to insert the filter text into the title control\n\t * if there is no header specified.\n\t * @since 3.2\n\t */\n\tprotected Control createTitleControl(Composite parent) {\n\t\tif (hasHeader()) {\n\t\t\treturn super.createTitleControl(parent);\n\t\t}\n\t\tfilterText= createFilterText(parent);\n\t\treturn filterText;\n\t}\n\t\n\t/*\n\t * @see org.eclipse.jface.dialogs.PopupDialog#setTabOrder(org.eclipse.swt.widgets.Composite)\n\t */\n\tprotected void setTabOrder(Composite composite) {\n\t\tif (hasHeader()) {\n\t\t\tcomposite.setTabList(new Control[] { filterText, treeViewer.getTree() });\n\t\t} else {\n\t\t\tviewMenuButtonComposite.setTabList(new Control[] { filterText });\n\t\t\tcomposite.setTabList(new Control[] { viewMenuButtonComposite, treeViewer.getTree() });\n\t\t}\n\t}\n\n\t/**\n\t * Returns the name of the given element used for matching. The default\n\t * implementation gets the name from the tree viewer's label provider.\n\t * Subclasses may override.\n\t * \n\t * @param element the element\n\t * @return the name to be used for matching\n\t */\n\tprotected String getMatchName(Object element) {\n\t\treturn ((ILabelProvider) getTreeViewer().getLabelProvider()).getText(element);\n\t}\n}\n"},"message":{"kind":"string","value":"I assume this is a bug. Creating controls before the statements in\nsubclass constructors have been executed is likely to result in\nnullpointers."},"old_file":{"kind":"string","value":"org.strategoxt.imp.runtime/src/org/strategoxt/imp/runtime/services/outline/FilteringInfoPopup.java"},"subject":{"kind":"string","value":"I assume this is a bug. Creating controls before the statements in subclass constructors have been executed is likely to result in nullpointers."},"git_diff":{"kind":"string","value":"rg.strategoxt.imp.runtime/src/org/strategoxt/imp/runtime/services/outline/FilteringInfoPopup.java\n \t\t\tsetTitleText(\"\"); //$NON-NLS-1$\n \t\tsetInfoText(\"\"); // //$NON-NLS-1$\n \n\t\t// Create all controls early to preserve the life cycle of the original implementation.\n\t\tcreate();\n\n \t\t// Status field text can only be computed after widgets are created.\n \t\tsetInfoText(getStatusFieldText());\n \t}"}}},{"rowIdx":651,"cells":{"lang":{"kind":"string","value":"Java"},"license":{"kind":"string","value":"agpl-3.0"},"stderr":{"kind":"string","value":""},"commit":{"kind":"string","value":"a7a89a7bf110cb38542626f1d6561aed9f7d51bd"},"returncode":{"kind":"number","value":0,"string":"0"},"repos":{"kind":"string","value":"duaneking/rockstar_test,duaneking/rockstar_test,duaneking/rockstar_test,duaneking/rockstar_test,duaneking/rockstar_test,duaneking/rockstar_test,duaneking/rockstar_test,duaneking/rockstar_test,duaneking/rockstar_test,duaneking/rockstar_test"},"new_contents":{"kind":"string","value":"0d97ee18-2e62-11e5-9284-b827eb9e62be"},"new_file":{"kind":"string","value":"hello.java"},"old_contents":{"kind":"string","value":"0d9243a0-2e62-11e5-9284-b827eb9e62be"},"message":{"kind":"string","value":"0d97ee18-2e62-11e5-9284-b827eb9e62be"},"old_file":{"kind":"string","value":"hello.java"},"subject":{"kind":"string","value":"0d97ee18-2e62-11e5-9284-b827eb9e62be"},"git_diff":{"kind":"string","value":"ello.java\n0d9243a0-2e62-11e5-9284-b827eb9e62be\n0d97ee18-2e62-11e5-9284-b827eb9e62be"}}},{"rowIdx":652,"cells":{"lang":{"kind":"string","value":"JavaScript"},"license":{"kind":"string","value":"mit"},"stderr":{"kind":"string","value":""},"commit":{"kind":"string","value":"b243052a20279509b4b6566bbe44e58daf2b9d42"},"returncode":{"kind":"number","value":0,"string":"0"},"repos":{"kind":"string","value":"tolmasky/language,tolmasky/language"},"new_contents":{"kind":"string","value":"\nvar hasOwnProperty = Object.prototype.hasOwnProperty;\n\n// start = ((\"a\" \"a\") \"a\") \"b\") /\n// ((\"a\" \"a\") \"a\") !\"d\" \"c\")\n\n// A?\n// R = A / \"\"\n// A*\n// U = A / \"\"\n// R = U / R\n// A+\n//\n\nvar CHARACTER = 0,\n CHOICE = 1,\n SEQUENCE = 2,\n NOT = 3,\n AND = 4,\n NAME = 5,\n DOT = -1;\n\nvar FAIL = 0,\n SUCCESS = 2,\n INCOMPLETE = 3;\n\nvar EOF = { },\n PLACEHOLDER = { },\n FAILURE_NODE = { state:FAIL };\n\nfunction Context(aContext, rules)\n{\n this.rules = rules;\n this.incomplete = { };\n this.cache = { };\n this.recursive = { };\n this.index = -1;\n this.placeholderParents = { };\n\n if (aContext)\n {\n this.rules = aContext.rules;\n this.index = aContext.index + 1;\n }\n}\n\n/*\n// r = (bcc / b) cd\nvar rules = {\n 0: { UID:0, type:SEQUENCE, children:[2, 1] },\n 1: { UID:1, type:SEQUENCE, children:[\"c\", \"d\"] },\n 2: { UID:2, type:CHOICE, children:[3, \"b\"] },\n 3: { UID:3, type:SEQUENCE, children:[\"b\", 4] },\n 4: { UID:4, type:SEQUENCE, children:[\"c\", \"c\"] }\n };\nvar source = \"bcd\";\n\n// r = (bc / b) d\nvar rules = {\n 0: { UID:0, type:SEQUENCE, children:[1 ,\"d\"] },\n 1: { UID:1, type:CHOICE, children:[2, \"b\"] },\n 2: { UID:2, type:SEQUENCE, children:[\"b\", \"c\"] }\n };\nvar source = \"bcd\";\n*/\n// A = A a / a\nvar rules = {\n 0: { UID:0, type:NAME, children:[1], name:\"start\" },\n 1: { UID:1, type:CHOICE, children:[2, \"a\"] },\n 2: { UID:2, type:SEQUENCE, children:[1, \"a\"] }\n };\nvar source = \"aaaa\";\n\n/*\nvar rules = {\n 0: { UID:0, type:CHOICE, children:[1, 2] },\n 1: { UID:1, type:SEQUENCE, children:[3, \"b\"] },\n 2: { UID:2, type:SEQUENCE, children:[3, 5] },\n 3: { UID:3, type:SEQUENCE, children:[4, \"a\"] },\n 4: { UID:4, type:SEQUENCE, children:[\"a\", \"a\"] },\n 5: { UID:5, type:AND, children:[6, -1] },\n 6: { UID:6, type:NOT, children:[\"d\"] }\n };\nvar source = \"aaac\";\n*/\n\nvar context = new Context(null, rules);\nvar start = fall(null, 0, context);\n\nvar index = 0,\n count = source.length;\n\nprint_node(start);\nfor (; index < count; ++index)\n{\n console.log(\"+++++DOING \" + source[index]);\n context = parse(context, source[index]);\n //console.log(context);\n print_node(start);\n}\n\nconsole.log(\"+++++DOING EOF\");\ncontext = parse(context, EOF);\nprint_node(start);\n\nfunction print_node(node, indentation, prints)\n{\n indentation = indentation || \"\";\n prints = prints || { };\n\n if (node === PLACEHOLDER)\n return console.log(indentation + \" PLACEHOLDER\");\n\n if (prints[node.UID] === 2)\n return;\n else if (prints[node.UID] === 1)\n prints[node.UID] += 1;\n else\n prints[node.UID] = 1;\n\n var rule = node.rule;\n\n if (typeof rule === \"string\")\n console.log(indentation + rule + \" [\" + node.state + \"]\");\n\n else if (rule === -1)\n console.log(indentation + \"DOT \" + node.UID);\n\n else if (rule.type === CHOICE)\n console.log(indentation + \"CHOICE \" + node.UID + \" [\" + node.state + \"]\");\n\n else if (rule.type === SEQUENCE)\n console.log(indentation + \"SEQUENCE \" + node.UID + \" [\" + node.state + \"]\");\n\n else if (rule.type === NOT)\n console.log(indentation + \"NOT \" + node.UID);\n\n else if (rule.type === AND)\n console.log(indentation + \"AND \" + node.UID);\n\n else if (rule.type === NAME)\n console.log(indentation + \"NAME \" + node.UID + \" \" + node.name);\n\n for (var index = 0, count = node.children.length; index < count; ++index)\n print_node(node.children[index], indentation + \" \", prints);\n\n prints[node.UID]--;\n}\n\nfunction fall(parent, ruleUID, context)\n{\n var UID = ruleUID + \" \" + context.index,\n recursive = context.recursive;\n\n if (recursive[UID])\n {\n context.placeholderParents[parent.UID] = parent;\n\n return PLACEHOLDER;\n }\n\n var rule = context.rules[ruleUID] || ruleUID,\n cache = context.cache,\n node = cache[UID] || { UID:UID, state:INCOMPLETE, rule:rule, parents:{ }, children:[] };\n\n // Only add this parent if we haven't already accounted for it.\n // This accounts for the user doing something silly like A / A\n if (parent && !hasOwnProperty.call(node.parents, parent.UID))\n node.parents[parent.UID] = parent;\n\n // If it's cached, we've already worked this one out.\n if (cache[UID])\n return node;\n\n // Add this to the cache.\n cache[UID] = node;\n\n // If this is a character, there is nothing we can do during the fall stage.\n // Simply store it in the incomplete hash and return.\n if (typeof rule === \"string\" || rule === -1)\n {\n // The empty string always trivially succeeds, and consumes no input.\n if (rule === \"\")\n climb(node, context);\n else\n context.incomplete[UID] = node;\n\n return node;\n }\n\n if (rule.type === NAME)\n node.name = rule.name;\n\n // Before handling our children, make sure we register ourselves so we don't get handled again.\n recursive[UID] = node;\n\n if (rule.type === SEQUENCE)\n node.children[0] = fall(node, rule.children[0], context);\n else\n node.children = rule.children.map(function (child) { return fall(node, child, context); });\n\n // Now unregister ourselves.\n delete recursive[UID];\n\n return node;\n}\n\nfunction climbAllParents(node, context)\n{\n var parents = node.parents;\n\n for (UID in parents)\n if (hasOwnProperty.call(parents, UID))\n climb(parents[UID], context);\n}\n\nfunction climb(node, context)\n{\n if (node.state !== INCOMPLETE)\n return;\n\n var children = node.children,\n rule = node.rule;\n\n if (rule.type === CHOICE)\n {\n var lhs = children[0];\n\n // No matter what, if the first one is incomplete, we can't make a decision.\n if (lhs.state === INCOMPLETE)\n return;\n\n // If not, and this was our ONLY child, or it was successful,\n // then our state is now it's state and we can keep climbing.\n if (children.length === 1 || lhs.state === SUCCESS)\n {\n children.length = 1;\n node.state = lhs.state;\n\n return climbAllParents(node, context);\n }\n\n // Now we know for sure that we have 2 children AND the first was a failure,\n // so its all on rhs.\n var rhs = children[1];\n\n // Same as before, keep waiting.\n if (rhs.state === INCOMPLETE)\n return;\n\n // From now on, we know we have a result, either success of fail.\n node.state = rhs.state;\n\n // If we succeeded, do a little accounting to make rhs our only child.\n if (rhs.state === SUCCESS)\n {\n children[0] = rhs;\n children.length = 1;\n }\n else\n children.length = 0;\n\n return climbAllParents(node, context);\n }\n\n else if (rule.type === AND)\n {\n var lhs = children[0],\n rhs = children[1];\n\n // We have to know the result of both to continue.\n if (lhs.state === INCOMPLETE || rhs.state === INCOMPLETE)\n return;\n\n // If our first child (the \"predicate\") fails, then we fail.\n // Both must succeed to succeed as a whole.\n node.state = (lhs.state === SUCCESS && rhs.state === SUCCESS) ? SUCCESS : FAIL;\n\n children[0] = rhs;\n children.length = 1;\n\n return climbAllParents(node, context);\n }\n\n else if (rule.type === SEQUENCE)\n {\n if (children[0].state === INCOMPLETE)\n return;\n\n // If we have two children, there is no more advancing left to do.\n // We simply have to decide if we succeeded or failed.\n if (children.length === 2)\n {\n node.state = children[1].state;\n\n return climbAllParents(node, context);\n }\n\n // If not, then see whether the first one failed...\n if (children[0].state === FAIL)\n {\n node.state = FAIL;\n\n return climbAllParents(node, context);\n }\n\n // If it succeeded, then fall down again...\n children[1] = fall(node, node.rule.children[1], context);\n }\n\n else if (rule.type === NOT)\n {\n var child = children[0];\n\n if (child.state === INCOMPLETE)\n return;\n\n node.state = (child.state === FAIL ? SUCCESS : FAIL);\n\n return climbAllParents(node, context);\n }\n\n else if (rule.type === NAME)\n {\n var child = children[0];\n\n if (child.state === INCOMPLETE)\n return;\n\n node.state = child.state;\n\n return climbAllParents(node, context);\n }\n}\n\nfunction parse(context, character)\n{\n var incomplete = context.incomplete;\n var placeholderParents = context.placeholderParents;\n var newContext = new Context(context);\n var UID;\n\n for (UID in placeholderParents)\n if (hasOwnProperty.call(placeholderParents, UID))\n {\n var parent = placeholderParents[UID],\n children = parent.children,\n index = 0,\n count = children.length;\n\n for (; index < count; ++index)\n if (children[index] === PLACEHOLDER)\n if (character === EOF)\n children[index] = FAILURE_NODE;\n else\n children[index] = fall(parent, parent.rule.children[index], newContext);\n\n climb(parent, newContext);\n }\n\n for (UID in incomplete)\n if (hasOwnProperty.call(incomplete, UID))\n {\n var node = incomplete[UID];\n\n node.state = node.rule === -1 || character === node.rule ? SUCCESS : FAIL;\n climbAllParents(node, newContext);\n }\n\n return newContext;\n}\n\n/*\n// ADOPTION\n// gotta get up and try and try and try\n//carry onnnn the sound may your touch the ground\n// r = (bc / b) d\n// r = (bc d / b d)\n// r = (;_set) - (choice(bc) d)\n// = - (choice(b) d)\n// algo:\n// (not? pred?)\n// climb to seq take remaining, append.\n// r = choice hold(bc) -> seq _next_\n// hold(b) -> seq _next_\n// a (c / d) b\n// a ((c) b / (d) b)\n/*\n if (rule.type === CHOICE)\n {\n var index = 0,\n count = children.length;\n\n for (; index < count; ++index)\n {\n var child = children[index];\n\n // Can't know yet.\n if (child.state === INCOMPLETE)\n return;\n\n if (child.state === SUCCESS)\n {\n node.state = SUCCESS;\n\n children[0] = child;\n children.length = 1;\n\n return climbAllParents(node, context);\n }\n\n // By this point, there can only be FAILUREs behind us...\n if (child.state === FAILURE && index === count - 1)\n {\n node.state = FAILURE;\n\n children.length = 0;\n\n return climbAllParents(node, context);\n }\n }\n\n return;\n }\n\n if (rule.type === CHOICE)\n {\n var index = 0,\n count = children.length;\n\n for (; index < count; ++index)\n {\n var child = children[index];\n\n // Can't know yet.\n if (child.state === INCOMPLETE)\n return;\n\n if (child.state === SUCCESS)\n {\n node.state = SUCCESS;\n\n children[0] = child;\n children.length = 1;\n\n return climbAllParents(node, context);\n }\n\n // By this point, there can only be FAILUREs behind us...\n if (child.state === FAILURE && index === count - 1)\n {\n node.state = FAILURE;\n\n children.length = 0;\n\n return climbAllParents(node, context);\n }\n }\n\n return;\n }\n\n if (rule.type === SEQUENCE)\n {\n var index = 0,\n count = children.length;\n\n for (; index < count; ++index)\n {\n var child = children[index];\n\n // Can't know yet.\n if (child.state === INCOMPLETE)\n return;\n\n if (child.state === FAILURE)\n {\n node.state = FAILURE;\n children.length = 0;\n\n return climbAllParents(node, context);\n }\n }\n\n node.state = SUCCESS;\n children[0] = children[children.length - 1];\n\n return climbAllParents(node, context);\n }\n\n {\n node.state = SUCCESS;\n children[0] = child;\n children.length = 1;\n\n return climbAllParents(node, context);\n }\n\n // By this point, there can only be FAILUREs behind us...\n if (child.state === FAILURE && index === count - 1)\n {\n node.state = FAILURE;\n children.length = 0;\n\n return climbAllParents(node, context);\n }\n }\n }\n\n*/"},"new_file":{"kind":"string","value":"languages/Objective-J/stab.js"},"old_contents":{"kind":"string","value":"\nvar hasOwnProperty = Object.prototype.hasOwnProperty;\n\n// start = ((\"a\" \"a\") \"a\") \"b\") /\n// ((\"a\" \"a\") \"a\") !\"d\" \"c\")\n\n// A?\n// R = A / \"\"\n// A*\n// U = A / \"\"\n// R = U / R\n// A+\n// \n\nvar CHARACTER = 0,\n CHOICE = 1,\n SEQUENCE = 2,\n NOT = 3,\n AND = 4,\n DOT = -1;\n\nvar FAIL = 0,\n SUCCESS = 2,\n INCOMPLETE = 3;\n\nvar EOF = { },\n PLACEHOLDER = { },\n FAILURE_NODE = { state:FAIL };\n/*\nfunction Context(aContext)\n{\n if (aC\n}*/\n\nvar context =\n{\n rules : {\n 0: { UID:0, type:CHOICE, children:[\"a\", 1] },\n 1: { UID:1, type:SEQUENCE, children:[0, \"a\"] }\n },\n incomplete: { },\n cache: { },\n recursive: { },\n index: -1,\n placeholderParents: { }\n};\n/*\nvar context =\n{\n rules : {\n 0: { UID:0, type:CHOICE, children:[1, 2] },\n 1: { UID:1, type:SEQUENCE, children:[3, \"b\"] },\n 2: { UID:2, type:SEQUENCE, children:[3, 5] },\n 3: { UID:3, type:SEQUENCE, children:[4, \"a\"] },\n 4: { UID:4, type:SEQUENCE, children:[\"a\", \"a\"] },\n 5: { UID:5, type:AND, children:[6, -1] },\n 6: { UID:6, type:NOT, children:[\"d\"] }\n },\n incomplete: { },\n cache: { }\n};*/\n\nvar start = fall(null, 0, context);\n\nvar source = \"aaaa\",\n index = 0,\n count = source.length;\n\nprint_node(start);\nfor (; index < count; ++index)\n{\n console.log(\"+++++DOING \" + source[index]);\n context = parse(context, source[index]);\n //console.log(context);\n print_node(start);\n}\n\nconsole.log(\"+++++DOING EOF\");\ncontext = parse(context, EOF);\nprint_node(start);\n\nfunction print_node(node, indentation, prints)\n{\n indentation = indentation || \"\";\n prints = prints || { };\n\n if (node === PLACEHOLDER)\n return console.log(indentation + \" PLACEHOLDER\");\n\n if (prints[node.UID] === 2)\n return;\n else if (prints[node.UID] === 1)\n prints[node.UID] += 1;\n else\n prints[node.UID] = 1;\n\n var rule = node.rule;\n\n if (typeof rule === \"string\")\n console.log(indentation + rule + \" [\" + node.state + \"]\");\n\n else if (rule === -1)\n console.log(indentation + \"DOT \" + node.UID);\n\n else if (rule.type === CHOICE)\n console.log(indentation + \"CHOICE \" + node.UID + \" [\" + node.state + \"]\");\n\n else if (rule.type === SEQUENCE)\n console.log(indentation + \"SEQUENCE \" + node.UID + \" [\" + node.state + \"]\");\n\n else if (rule.type === NOT)\n console.log(indentation + \"NOT \" + node.UID);\n\n else if (rule.type === AND)\n console.log(indentation + \"AND \" + node.UID);\n\n for (var index = 0, count = node.children.length; index < count; ++index)\n print_node(node.children[index], indentation + \" \", prints);\n\n prints[node.UID]--;\n}\n\nfunction fall(parent, ruleUID, context)\n{\n var UID = ruleUID + \" \" + context.index,\n recursive = context.recursive;\n\n if (recursive[UID])\n {console.log(\"did it...\");\n context.placeholderParents[parent.UID] = parent;\n\n return PLACEHOLDER;\n }\n\n var rule = context.rules[ruleUID] || ruleUID,\n cache = context.cache,\n node = cache[UID] || { UID:UID, state:INCOMPLETE, rule:rule, parents:{ }, children:[] };\n\n // Only add this parent if we haven't already accounted for it.\n // This accounts for the user doing something silly like A / A\n if (parent && !hasOwnProperty.call(node.parents, parent.UID))\n node.parents[parent.UID] = parent;\n\n // If it's cached, we've already worked this one out.\n if (cache[UID])\n return node;\n\n // Add this to the cache.\n cache[UID] = node;\n\n // If this is a character, there is nothing we can do during the fall stage.\n // Simply store it in the incomplete hash and return.\n if (typeof rule === \"string\" || rule === -1)\n {\n // The empty string always trivially succeeds, and consumes no input.\n if (rule === \"\")\n climb(node, context);\n else\n context.incomplete[UID] = node;\n\n return node;\n }\n\n // Before handling our children, make sure we register ourselves so we don't get handled again.\n recursive[UID] = node;\n\n // We always want to fill in the first child.\n node.children[0] = fall(node, node.rule.children[0], context);\n\n // But only the second if this is a CHOICE or and AND.\n if (rule.type === CHOICE || rule.type === AND)\n node.children[1] = fall(node, node.rule.children[1], context);\n\n // Now unregister ourselves.\n delete recursive[UID];\n\n return node;\n}\n\nfunction climbAllParents(node, context)\n{\n var parents = node.parents;\n\n for (UID in parents)\n if (hasOwnProperty.call(parents, UID))\n climb(parents[UID], context);\n}\n\nfunction climb(node, context)\n{\n if (node.state !== INCOMPLETE)\n return;\n\n var children = node.children,\n rule = node.rule;\n\n if (rule.type === CHOICE)\n {\n var lhs = children[0];\n\n // No matter what, if the first one is incomplete, we can't make a decision.\n if (lhs.state === INCOMPLETE)\n return;\n\n // If not, and this was our ONLY child, or it was successful,\n // then our state is now it's state and we can keep climbing.\n if (children.length === 1 || lhs.state === SUCCESS)\n {\n children.length = 1;\n node.state = lhs.state;\n\n return climbAllParents(node, context);\n }\n\n // Now we know for sure that we have 2 children AND the first was a failure,\n // so its all on rhs.\n var rhs = children[1];\n\n // Same as before, keep waiting.\n if (rhs.state === INCOMPLETE)\n return;\n\n // From now on, we know we have a result, either success of fail.\n node.state = rhs.state;\n\n // If we succeeded, do a little accounting to make rhs our only child.\n if (rhs.state === SUCCESS)\n {\n children[0] = rhs;\n children.length = 1;\n }\n else\n children.length = 0;\n\n return climbAllParents(node, context);\n }\n\n else if (rule.type === AND)\n {\n var lhs = children[0],\n rhs = children[1];\n\n // We have to know the result of both to continue.\n if (lhs.state === INCOMPLETE || rhs.state === INCOMPLETE)\n return;\n\n // If our first child (the \"predicate\") fails, then we fail.\n // Both must succeed to succeed as a whole.\n node.state = (lhs.state === SUCCESS && rhs.state === SUCCESS) ? SUCCESS : FAIL;\n\n children[0] = rhs;\n children.length = 1;\n\n return climbAllParents(node, context);\n }\n\n else if (rule.type === SEQUENCE)\n {\n if (children[0].state === INCOMPLETE)\n return;\n\n // If we have two children, there is no more advancing left to do.\n // We simply have to decide if we succeeded or failed.\n if (children.length === 2)\n {\n node.state = children[1].state;\n\n return climbAllParents(node, context);\n }\n\n // If not, then see whether the first one failed...\n if (children[0].state === FAIL)\n {\n node.state = FAIL;\n\n return climbAllParents(node, context);\n }\n\n // If it succeeded, then fall down again...\n children[1] = fall(node, node.rule.children[1], context); \n }\n\n else if (rule.type === NOT)\n {\n var child = children[0];\n\n if (child.state === INCOMPLETE)\n return;\n\n node.state = (child.state === FAIL ? SUCCESS : FAIL);\n\n return climbAllParents(node, context);\n }\n}\n\nfunction parse(context, character)\n{\n var incomplete = context.incomplete;\n var newContext = { rules:context.rules, incomplete:{ }, cache:{ }, index:context.index + 1, recursive:{ }, placeholderParents:{ } };\n var placeholderParents = context.placeholderParents;\n var UID;\n\n for (UID in placeholderParents)\n if (hasOwnProperty.call(placeholderParents, UID))\n {\n var parent = placeholderParents[UID],\n children = parent.children,\n index = 0,\n count = children.length;\n\n for (; index < count; ++index)\n if (children[index] === PLACEHOLDER)\n if (character === EOF)\n children[index] = FAILURE_NODE;\n else\n children[index] = fall(parent, parent.rule.children[index], newContext);\n\n climb(parent, newContext);\n }\n\n for (UID in incomplete)\n if (hasOwnProperty.call(incomplete, UID))\n {\n var node = incomplete[UID];\n\n node.state = node.rule === -1 || character === node.rule ? SUCCESS : FAIL;\n climbAllParents(node, newContext);\n }\n\n return newContext;\n}\n\n"},"message":{"kind":"string","value":"Some cleanup in preparation for more than 2 sequences/choices.\n\nReviewed by @tolmasky.\n"},"old_file":{"kind":"string","value":"languages/Objective-J/stab.js"},"subject":{"kind":"string","value":"Some cleanup in preparation for more than 2 sequences/choices."},"git_diff":{"kind":"string","value":"anguages/Objective-J/stab.js\n // U = A / \"\"\n // R = U / R\n // A+\n// \n//\n \n var CHARACTER = 0,\n CHOICE = 1,\n SEQUENCE = 2,\n NOT = 3,\n AND = 4,\n NAME = 5,\n DOT = -1;\n \n var FAIL = 0,\n var EOF = { },\n PLACEHOLDER = { },\n FAILURE_NODE = { state:FAIL };\n\nfunction Context(aContext, rules)\n{\n this.rules = rules;\n this.incomplete = { };\n this.cache = { };\n this.recursive = { };\n this.index = -1;\n this.placeholderParents = { };\n\n if (aContext)\n {\n this.rules = aContext.rules;\n this.index = aContext.index + 1;\n }\n}\n\n /*\nfunction Context(aContext)\n{\n if (aC\n}*/\n\nvar context =\n{\n rules : {\n 0: { UID:0, type:CHOICE, children:[\"a\", 1] },\n 1: { UID:1, type:SEQUENCE, children:[0, \"a\"] }\n },\n incomplete: { },\n cache: { },\n recursive: { },\n index: -1,\n placeholderParents: { }\n};\n// r = (bcc / b) cd\nvar rules = {\n 0: { UID:0, type:SEQUENCE, children:[2, 1] },\n 1: { UID:1, type:SEQUENCE, children:[\"c\", \"d\"] },\n 2: { UID:2, type:CHOICE, children:[3, \"b\"] },\n 3: { UID:3, type:SEQUENCE, children:[\"b\", 4] },\n 4: { UID:4, type:SEQUENCE, children:[\"c\", \"c\"] }\n };\nvar source = \"bcd\";\n\n// r = (bc / b) d\nvar rules = {\n 0: { UID:0, type:SEQUENCE, children:[1 ,\"d\"] },\n 1: { UID:1, type:CHOICE, children:[2, \"b\"] },\n 2: { UID:2, type:SEQUENCE, children:[\"b\", \"c\"] }\n };\nvar source = \"bcd\";\n*/\n// A = A a / a\nvar rules = {\n 0: { UID:0, type:NAME, children:[1], name:\"start\" },\n 1: { UID:1, type:CHOICE, children:[2, \"a\"] },\n 2: { UID:2, type:SEQUENCE, children:[1, \"a\"] }\n };\nvar source = \"aaaa\";\n\n /*\nvar context =\n{\n rules : {\nvar rules = {\n 0: { UID:0, type:CHOICE, children:[1, 2] },\n 1: { UID:1, type:SEQUENCE, children:[3, \"b\"] },\n