By Joël Thieffry, under MIT licence.
This Greasemonkey script adds Instant Search function to Javadoc class frame.
NPException
will show NullPointerException
(as in the Eclipse IDE Java's type search).?
to replace one character, *
to replace any number of characters, for example N???P*Exception
.^.*C(li)*p+$
.For use in Mozilla Firefox, you need to install the Greasemonkey plugin. Unless the variable greasemonkey.fileIsGreaseable
is set to true in your about:config
, the script won't run on local files.
In Google Chrome, userscripts support is native since Chrome v4.
?
as "0 or 1 any character" instead of "1 any character".I've just learned Javascript and DOM, this script is my first attempt to use it. I wanted to implement the efficient Eclipse search inside Javadoc.
There were three goals:
Later, I found KOSEKI Kengo's script named Javadoc Incremental Search. This code and webpage inspired me (for example the embedded erase icon comes directly from it), but my implementation is really different: my code is simpler because it does less things.
I've found two formats of generated javadoc:
The modern hierarchy:
html
head
body
h1 (title)
div class="indexContainer"
ul (one for interfaces, one for classes)
li a (for every item)
...
The old hierarchy:
HTML
HEAD
BODY
FONT B (title)
BR
TABLE
TR TD FONT
A BR (for every item)
Given a corresponding page filename, if we find a div whose class is indexContainer
then the modern hierarchy is assumed, otherwise we choose the old hierarchy (which is supported from v0.3).
The search component is a paragraph whose id is javadocInstantSearchElement
. This id is looked for to avoid reinstalling the search component.
The search component is added as a first child of the element whose class is indexContainer
.
The regex transformation from Eclipse model to full regex follows these steps:
regex.replace(/([\\\^\$*+\[\]?{}.=!:(|)])/g, "\\$1")
.^.*
and append .*$
to allow search in any position..*
before all capital letters: regex.replace(/([A-Z])/g, "\.\*$1")
.All regexes are simplified using the following replaces:
regex = regex.replace(/((.[\*\?])+)(?=\2)/g, "") // Replace successive x* and x? to only one
.replace(/((.)\*\2\?)+/g, ".*") // Replace x*x? with x*
.replace(/((.)\?\2\*)+/g, ".*") // Replace x?x* with x*
.replace(/((.)\+\2\*)+/g, ".+") // Replace x+x* with x+
.replace(/((.)\*\2\+)+/g, ".+") // Replace x*x+ with x+
.replace(/((.[\*\?])+)(?=\2)/g, ""); // Replace successive x* and x? to only one