All Projects → dnault → therapi-runtime-javadoc

dnault / therapi-runtime-javadoc

Licence: Apache-2.0 License
Read Javadoc comments at run time.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to therapi-runtime-javadoc

openjdk-runtime
Google Cloud Platform OpenJDK Docker image
Stars: ✭ 58 (+16%)
Mutual labels:  runtime
cabasa
Haxe Framework for WebAssembly
Stars: ✭ 30 (-40%)
Mutual labels:  runtime
simple-annotation-processor
Simple annotation processor example. Inspired by the idea of "How ButterKnife works?"
Stars: ✭ 54 (+8%)
Mutual labels:  annotation-processor
maps-app-dotnet
Your organization's suite of cross platform mapping apps built with the ArcGIS Runtime SDK for .NET
Stars: ✭ 20 (-60%)
Mutual labels:  runtime
AppRun
AppDir runtime components
Stars: ✭ 19 (-62%)
Mutual labels:  runtime
ts-browser
🦄 Compile (in worker threads) and run TypeScript in the browser via <script type='text/typescript'>
Stars: ✭ 49 (-2%)
Mutual labels:  runtime
AutoBindings
Set of annotations that aims to make your Android development experience easier along with lint checks.
Stars: ✭ 15 (-70%)
Mutual labels:  annotation-processor
kotlin-cursor
Kotlin Annotation Processor to generate fromCursor and toContentValues of data classes.
Stars: ✭ 34 (-32%)
Mutual labels:  annotation-processor
dagger2-ktx
Kotlin extension bridge library for Dagger2 (proof-of-concept)
Stars: ✭ 41 (-18%)
Mutual labels:  annotation-processor
Corium
Corium is a modern scripting language which combines simple, safe and efficient programming.
Stars: ✭ 18 (-64%)
Mutual labels:  runtime
smartstruct
Dart Code Generator for generating mapper classes
Stars: ✭ 20 (-60%)
Mutual labels:  annotation-processor
CodeDex
CodeDex Android source code, javadoc and github viewer
Stars: ✭ 32 (-36%)
Mutual labels:  javadoc
maps-app-ios
Your organisation's mapping app built with the Runtime SDK for iOS
Stars: ✭ 16 (-68%)
Mutual labels:  runtime
data-collection-ios
Mobile data collection app using the iOS Runtime SDK.
Stars: ✭ 24 (-52%)
Mutual labels:  runtime
WinAnalytics
A light-weight android library that can be quickly integrated into any app to use analytics tools.
Stars: ✭ 23 (-54%)
Mutual labels:  annotation-processor
Arteries
A procedural modeling toolkit base on UE4 blueprint
Stars: ✭ 92 (+84%)
Mutual labels:  runtime
DocDex
JSON API & Discord Bot for Javadocs
Stars: ✭ 31 (-38%)
Mutual labels:  javadoc
Mock.java
This is a framework for generating fake data, similar to Mock.js. 你可以通过这个框架简便的构建一个JavaBean假数据模板并生成假数据,就像Mock.js一样的语法~
Stars: ✭ 32 (-36%)
Mutual labels:  javadoc
typesentry
Python 2.7 & 3.5+ runtime type-checker
Stars: ✭ 19 (-62%)
Mutual labels:  runtime
substrate-tcr
A Parity Substrate runtime implementation of a simple Token Curated Registry (TCR)
Stars: ✭ 45 (-10%)
Mutual labels:  runtime

therapi-runtime-javadoc

Java 1.8+

Bake Javadoc comments into your code

  1. Add an annotation processor to your class path at compile time.
  2. Read Javadoc comments at run time.

The annotation processor copies Javadoc from your source code into class path resources.

The runtime library reads the class path resources, serving up your Javadoc on demand.

Coordinates

Gradle

dependencies {
    annotationProcessor 'com.github.therapi:therapi-runtime-javadoc-scribe:0.13.0'

    // Runtime library
    implementation 'com.github.therapi:therapi-runtime-javadoc:0.13.0'
}

Maven

<!-- Annotation processor -->
<dependency>
    <groupId>com.github.therapi</groupId>
    <artifactId>therapi-runtime-javadoc-scribe</artifactId>
    <version>0.13.0</version>
    <scope>provided</scope>
</dependency>
    
<!-- Runtime library -->
<dependency>
    <groupId>com.github.therapi</groupId>
    <artifactId>therapi-runtime-javadoc</artifactId>
    <version>0.13.0</version>
</dependency>

Usage

Building a JAR with embedded Javadoc

Include the annotation processor JAR in your class path when compiling the code whose Javadoc you want to read later at runtime.

When building in an IDE you may have to explicitly enable annotation processing. In IntelliJ this is done by going to Preferences > Build, Execution, Deployment > Compiler > Annotation Processors and checking the box labeled "Enable annotation processing".

Selective Retention

If you only want to retain the Javadoc from certain packages, use the -A javac argument to pass the javadoc.packages option to the annotation processor. The value is a comma-delimited list of packages whose Javadoc you want to keep. (Subpackages are included, recursively.)

For Gradle that might look like this:

tasks.withType(JavaCompile) {            
  options.compilerArgs << "-Ajavadoc.packages=com.example,org.example"
}

If you don't specify any packages, the default behavior is to retain Javadoc from all packages.

Reading Javadoc comments at runtime

Add the runtime library as a dependency of your project.

Read the Javadoc by calling RuntimeJavadoc.getJavadoc and passing a class literal, a fully-qualified class name, or a java.lang.reflect.Method. Because Javadoc comments may contain inline tags, you'll want to use a CommentFormatter to convert comments to strings.

Here's an example that prints all available documentation for a class:

import com.github.therapi.runtimejavadoc.*;
import java.io.IOException;

public class Example {
    // formatters are reusable and thread-safe
    private static final CommentFormatter formatter = new CommentFormatter();

    public static void printJavadoc(String fullyQualifiedClassName) throws IOException {
        ClassJavadoc classDoc = RuntimeJavadoc.getJavadoc(fullyQualifiedClassName);
        if (classDoc.isEmpty()) { // optionally skip absent documentation
            System.out.println("no documentation for " + fullyQualifiedClassName);
            return;
        }

        System.out.println(classDoc.getName());
        System.out.println(format(classDoc.getComment()));
        System.out.println();

        // @see tags
        for (SeeAlsoJavadoc see : classDoc.getSeeAlso()) {
            System.out.println("See also: " + see.getLink());
        }
        // miscellaneous and custom javadoc tags (@author, etc.)
        for (OtherJavadoc other : classDoc.getOther()) {
            System.out.println(other.getName() + ": " + format(other.getComment()));
        }

        System.out.println();
        System.out.println("CONSTRUCTORS");
        for (MethodJavadoc methodDoc : classDoc.getConstructors()) {
            printMethodJavadoc(methodDoc);
        }

        System.out.println();
        System.out.println("METHODS");
        for (MethodJavadoc methodDoc : classDoc.getMethods()) {
            printMethodJavadoc(methodDoc);
        }
    }

    private static void printMethodJavadoc(MethodJavadoc methodDoc) {
        System.out.println(methodDoc.getName() + methodDoc.getParamTypes());
        System.out.println(format(methodDoc.getComment()));
        
        if (!methodDoc.isConstructor()) {
            System.out.println("  returns " + format(methodDoc.getReturns()));
        }

        for (SeeAlsoJavadoc see : methodDoc.getSeeAlso()) {
            System.out.println("  See also: " + see.getLink());
        }
        for (OtherJavadoc other : methodDoc.getOther()) {
            System.out.println("  " + other.getName() + ": "
                + format(other.getComment()));
        }
        for (ParamJavadoc paramDoc : methodDoc.getParams()) {
            System.out.println("  param " + paramDoc.getName() + " "
                + format(paramDoc.getComment()));
        }
        for (ThrowsJavadoc throwsDoc : methodDoc.getThrows()) {
            System.out.println("  throws " + throwsDoc.getName() + " "
                + format(throwsDoc.getComment()));
        }
        System.out.println();
    }

    private static String format(Comment c) {
        return formatter.format(c);
    }
}

License

Copyright 2015 David Nault and contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Notice

This software includes the following libraries, repackaged to avoid potential dependency conflicts:

  • minimal-json (MIT License) Copyright (c) 2013, 2014 EclipseSource

  • JavaPoet (Apache 2.0 License) Copyright (c) 2015 Square, Inc.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].