5

我目前正在测试 Dokka 文档,并且我所做的一些注释没有被呈现。以下是我的发现:

  1. 类不显示@sample,和 html 标签<p></p><h1></h1>:参见 SimpleCalculator类文档
  2. 如果描述在 html 标记下,则不会显示:参见enum class OPERATOR代码文档
  3. 方法不显示@sample并且根本不显示@property:查看所有方法代码文档
  4. @property和之间的混合定义@param。在类声明中, the@param是在 a 中的那个<>(例如Group<T>)。但在方法中,它是参数里面的那个。

请看我的代码:

package example

/**
 * <h1> A Simple Calculator for your daily needs! </h1>
 *
 * <p> This class can help you add, subract, multiply and divide Integers </p>
 *
 * @property firstNumber the first Number you want to use
 * @property secondNumber the second Number you want to use.
 * @constructor Creates a Simple Calculator with the two numbers
 * @sample SimpleCalculator(100,10)
 */
class SimpleCalculator(val firstNumber: Int, val secondNumber: Int) {

    /**
     * <h1> An OPERATOR checker to be used by the Simple Calculator </h1>
     *
     * <p> This class has four enums namely: </p>
     * - ADD
     * - SUB
     * - MUL
     * - DIV
     * @see SimpleCalculator
     */
    enum class OPERATOR { ADD, SUB, MUL, DIV }

    /**
     * Computes with the [firstNumber] and [secondNumber] you have created with [SimpleCalculator].
     * @param operator the required OPERATOR needed for the computation
     * @sample compute(OPERATOR.ADD)
     * @see SimpleCalculator
     * @return the required answer
     */
    fun compute(operator: OPERATOR): Int {
        return when (operator) {
            OPERATOR.ADD -> add(firstNumber, secondNumber)
            OPERATOR.SUB -> sub(firstNumber, secondNumber)
            OPERATOR.MUL -> mul(firstNumber, secondNumber)
            OPERATOR.DIV -> div(firstNumber, secondNumber)
        }
    }

    /**
     * Adds the [firstNumber] and [secondNumber] you have created with [SimpleCalculator].
     * @property firstNumber the first number
     * @property secondNumber the first number
     * @sample add(100, 10)
     * @see SimpleCalculator
     * @return the sum
     * @throws Exception
     */
    fun add(firstNumber: Int, secondNumber: Int): Int = firstNumber + secondNumber

    /**
     * Subtracts the [firstNumber] and [secondNumber] you have created with [SimpleCalculator].
     * Returns the differences
     * @param firstNumber the first number
     * @param secondNumber the second number
     * @sample sub(100, 10)
     * @see SimpleCalculator
     * @return the difference
     * @throws Exception
     */
    fun sub(firstNumber: Int, secondNumber: Int): Int = firstNumber - secondNumber

    /**
     * Multiplies the [firstNumber] and [secondNumber] you have created with [SimpleCalculator].
     * Using [add] as a multiplication factor
     * @sample mul(100, 10)
     * @see add
     * @return the product
     * @throws Exception
     */
    fun mul(firstNumber: Int, secondNumber: Int): Int {
        var result = firstNumber
        var i = 2
        while (i < secondNumber && secondNumber != 0) {
            result += add(result, firstNumber)
            i++
        }

        return result
    }

    /**
     * Divides the [firstNumber] and [secondNumber] you have created with [SimpleCalculator].
     * Using [sub] as a division factor
     * @sample div(100, 10)
     * @see sub
     * @return the dividend
     * @throws Exception
     */
    fun div(firstNumber: Int, secondNumber: Int): Int {
        var result = firstNumber
        var i = 2
        while (i < secondNumber && secondNumber != 0) {
            result -= sub(result, firstNumber)
            i++
        }

        return result
    }

}

我的顶级构建文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.2.0'
    ext.dokka_version = '0.9.15'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.dokka:dokka-gradle-plugin:${dokka_version}"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我的项目构建文件:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'org.jetbrains.dokka'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.hellodokka"
        minSdkVersion 18
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dokka {
    outputFormat = 'html'
    outputDirectory = "$buildDir/html"
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

输出:

简单的计算器

枚举运算符

添加方法

有人可以帮忙吗?

4

0 回答 0