2009-11-03 20 views
247

Esiste un modo per aggiungere riferimenti a uno o più parametri di un metodo dal corpo della documentazione del metodo? Qualcosa di simile:Come aggiungere riferimento a un parametro di metodo in javadoc?

/** 
* When {@paramref a} is null, we rely on b for the discombobulation. 
* 
* @param a this is one of the parameters 
* @param b another param 
*/ 
void foo(String a, int b) 
{...} 

risposta

290

Per quanto ne so, dopo aver letto the docs for javadoc non esiste tale funzione.

Non utilizzare <code>foo</code> come consigliato in altre risposte; puoi usare {@code foo}. Questo è particolarmente utile quando si fa riferimento a un tipo generico come {@code Iterator<String>} - sicuramente sembra più bello di <code>Iterator&lt;String&gt;</code>, no?

8

Credo che si potrebbe scrivere il proprio doclet o taglet per sostenere questo comportamento.

Taglet Overview

Doclet Overview

+13

e fare una richiesta di pull a javadoc :) –

53

Come si può vedere nel sorgente Java della classe java.lang.String:

/** 
* Allocates a new <code>String</code> that contains characters from 
* a subarray of the character array argument. The <code>offset</code> 
* argument is the index of the first character of the subarray and 
* the <code>count</code> argument specifies the length of the 
* subarray. The contents of the subarray are copied; subsequent 
* modification of the character array does not affect the newly 
* created string. 
* 
* @param  value array that is the source of characters. 
* @param  offset the initial offset. 
* @param  count the length. 
* @exception IndexOutOfBoundsException if the <code>offset</code> 
*    and <code>count</code> arguments index characters outside 
*    the bounds of the <code>value</code> array. 
*/ 
public String(char value[], int offset, int count) { 
    if (offset < 0) { 
     throw new StringIndexOutOfBoundsException(offset); 
    } 
    if (count < 0) { 
     throw new StringIndexOutOfBoundsException(count); 
    } 
    // Note: offset or count might be near -1>>>1. 
    if (offset > value.length - count) { 
     throw new StringIndexOutOfBoundsException(offset + count); 
    } 

    this.value = new char[count]; 
    this.count = count; 
    System.arraycopy(value, offset, this.value, 0, count); 
} 

riferimenti parametri sono circondati da <code></code> tag, il che significa che il La sintassi Javadoc non fornisce alcun modo per fare una cosa del genere. (Penso che String.class sia un buon esempio di utilizzo di javadoc).

+22

Questo è vecchio. La stringa è documentata con {@code foo} –

+2

Il tag non fa riferimento a un parametro specifico. Sta formattando la parola "String" nel testo "code look". – Naxos84

10

Il modo corretto di fare riferimento a un parametro del metodo è come questo:

enter image description here

+0

Questo non aggiunge nulla alle risposte esistenti. Per favore cancellalo. – suriv

+7

Non solo risponde alla domanda, ma spiega visivamente come modificare Javadoc con un parametro utilizzando un IDE come Intellij. Questo sarà utile per i ricercatori che stanno cercando una risposta. –

+0

Su Eclipse non funziona. Ma è comunque una bella risposta –

Problemi correlati