2009-11-03 2 views
247

Есть ли способ добавить ссылки на один или несколько параметров метода из тела документации метода? Что-то вроде:Как добавить ссылку на параметр метода в 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) 
{...} 

ответ

290

Насколько я могу судить после чтения the docs for javadoc такой функции нет.

Не используйте <code>foo</code>, как рекомендовано в других ответах; вы можете использовать {@code foo}. Это особенно полезно знать, когда вы ссылаетесь на общий тип, такой как {@code Iterator<String>} - он выглядит лучше, чем <code>Iterator&lt;String&gt;</code>, не так ли!

8

Я думаю, вы могли бы написать свой собственный доклет или taglet поддерживать такое поведение.

Taglet Overview

Doclet Overview

+13

И сделать запрос тянуть к Javadoc :) –

53

Как вы можете видеть в Java Source класса 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); 
} 

ссылки параметров окружены <code></code> тегов, что означает, что Синтаксис Javadoc не дает никакого способа сделать такую ​​вещь. (Я думаю, что String.class - хороший пример использования javadoc).

+22

Это старое. Строка документирована с помощью {@code foo} –

+2

Тег не ссылается на определенный параметр. Он форматирует слово «String» в текст «code look». – Naxos84

10

Правильный способ обращения к параметру методы, как это:

enter image description here

+0

Это ничего не добавляет к существующим ответам. Пожалуйста, удалите его. – suriv

+7

Он не только отвечает на вопрос, но и визуально объясняет, как изменить Javadoc с помощью параметра, использующего IDE, например Intellij. Это будет полезно для искателей, которые ищут ответ. –

+0

На Eclipse он не работает. Но это хороший ответ, тем не менее –

Смежные вопросы