Android - Hiding methods from Javadoc

      Android platform's javadoc uses a custom doclet (com.google.doclava.Doclava) to support a custom tag @hide. This ensures that the methods, classes marked as hidden isn't included in the generated javadoc and this is how android ensures internal and non-public APIs aren't documented.

      3rd party library developers often have a similar need to generate their library's documentation. Fortunately, yWorks comes to rescue. yWorks is a javadoc extension known early as yDoc. This offers a custom doclet to hide methods, classes from the generated docs.

Prerequisites

   1) Download and unzip the community edition at http://www.yworks.com/en/products_download.php?file=yworks-uml-doclet-3.0_02-jdk1.5.zip

   2) Refer to man pages for yWorks at http://www.yworks.com/products/yDoc/doc/usersguide.html#install

   3) Specify tag @y.exclude for non-public methods and classes

/**
         * Internal non-public API
         *
         * @y.exclude
*/  
        public boolean internalAPI( )
        {
          return true;
        }

   4) Add and execute the following javadoc task to the library project in Android Studio

android.libraryVariants.all { variant ->

    task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
        source = variant.javaCompile.source

        // Specify Doclet Path and doclet class
        File customDoclet = file("/Volumes/Android/yworks-uml-doclet-3.0_02-jdk1.5/lib/ydoc.jar")
        assert customDoclet.exists()
        File resources = file("/Volumes/Android/yworks-uml-doclet-3.0_02-jdk1.5/resources")
        assert resources.exists()
        List<File> docletList = new ArrayList<File>()
        docletList.add( customDoclet )
        docletList.add( resources )
        options.setDocletpath( docletList )
        options.doclet = "ydoc.doclets.YStandard"

        // Specify filter options.
        CoreJavadocOptions coreOptions = options as CoreJavadocOptions
        coreOptions.addStringOption("filter", "ydoc.filters.ExcludeFilter")
        coreOptions.addStringOption("filterpath", "/Volumes/Android/yworks-uml-doclet-3.0_02-jdk1.5/lib/ydoc.jar")

        options.links("http://docs.oracle.com/javase/7/docs/api/");
        options.linksOffline("http://d.android.com/reference", "${android.sdkDirectory}/docs/reference")
        ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
        classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
        exclude '**/BuildConfig.java'
        exclude '**/R.java'
    }

}

No comments: