• Post Reply Bookmark Topic Watch Topic
  • New Topic

Utility: Adding a word index to jdk-8-doc api  RSS feed

 
Carey Brown
Bartender
Posts: 3022
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a tool I built a number of years ago to enhance the JDK JavaDocs to include an index of words used in class names. For instance, if I wanted to find "ThreadLocalRandom" but all I could remember is that it had the word "Random" in it, I could use this enhanced index to look up "random" and it will show all the class names that contain the word "random" and provides links to the classes within the docs.

How does it work: First you have to download the java docs from Oracle. Then run this program on the api directory. The program does a crude scrape of the api docs and finds class names. Class names are written in camel case so it extracts relative words based on parsing the camel case. For instance: "ThreadLocalRandom" will find the words "Thread", "Local", and "Random". These words are then used to build an additional HTML file (index-words.html) and modifies the header of the overview summary page to include a link called "Words" in that page. Lastly I set a bookmark in my browser to point to the javadocs now on my hard drive (file:///c:/tools/jdk-8-doc/docs/api/index.html).

This program has worked successfully for Java versions 6, 7, and 8.




 
Stephan van Hulst
Saloon Keeper
Posts: 7821
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great effort Carey, have a cow!

I have a few remarks:

  • You're declaring a lot of variables of types that are too specific for your needs. For instance, don't use TreeMap if Map will do.
  • When you declare a variable, you can use the diamond operator to initialize generic types.
  • Don't use File, use Path instead.
  • You're not closing your files. Use try-with-resources.
  • Use Files.walkFileTree() with a SimpleFileVisitor to walk through the documentation folder.
  • Instead of outputting all HTML manually, use a templating engine, such as Thymeleaf.
  • From your signature quote I can tell that you don't like regular expression, but your camelCaseToWords method just begs for a regular expression engine:
  •  
    Carey Brown
    Bartender
    Posts: 3022
    46
    Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Stephan for the cow and the remarks. As I said, I wrote this many years ago and would have done a much better job on it today. I find this utility so useful that perhaps it may be time to refactor it. I will take your remarks to heart.
     
    Rob Spoor
    Sheriff
    Posts: 21095
    85
    Chrome Eclipse IDE Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Doesn't Ctrl+F work just as well for class names? That's what I always use...
     
    Carey Brown
    Bartender
    Posts: 3022
    46
    Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I took some time to refactor the code. Ditching the hand built camel-case parser and using Stephan's regex was a big improvement. Also: try-with-resources, and replaced File with Path in a number of places. Looked briefly at Thymeleaf. I may use it some day but it looked like it had a learning curve that I didn't have time for right now.

    Regarding the use of Ctrl-F for searching, I use that as well but I also like having an index. Ctrl-F works well when you only have a handful of matches.


     
    Carey Brown
    Bartender
    Posts: 3022
    46
    Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I just noticed that some of the HTML got corrupted when I posted it to coderanch so here's a URL for the source code.
    http://inasphere.com/files/Javadoc2Words.java
     
    Liutauras Vilda
    Marshal
    Posts: 4668
    320
    BSD
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    This feature is so good and missed, that Oracle announced it is going to be released along with JDK 9. Full featured built-in search functionality within Java 9 API page.
     
    Liutauras Vilda
    Marshal
    Posts: 4668
    320
    BSD
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    https://community.oracle.com/community/java/javaone

    watch from 18:00
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!