source

javadoc에서 메서드 파라미터에 참조를 추가하는 방법

goodcode 2022. 8. 31. 22:40
반응형

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)
{...}

javadoc 문서를 읽어본 결과 그런 기능은 없는 것으로 나타났습니다.

사용하지 않다<code>foo</code>다른 답변에서 권장하는 바와 같이, 사용할 수 있습니다.{@code foo}이것은, 다음과 같은 범용 타입을 참조할 경우에 특히 도움이 됩니다.{@code Iterator<String>}-- 확실히 보다 멋져 보인다.<code>Iterator&lt;String&gt;</code>안 그래?

메서드 파라미터를 올바르게 참조하는 방법은 다음과 같습니다.

여기에 이미지 설명 입력

의 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 사용의 좋은 예라고 생각합니다).

이 행동을 뒷받침하는 자기 자신의 문서나 태그렛을 쓸 수 있을 것 같아요.

태그렛의 개요

문서의 개요

Eclipse Temurin JDK 8 소스에는 다음과 같이 기술되어 있습니다.

여기에 이미지 설명 입력

실제로 인텔리J 아이디어에서는 적어도 {@link #<param_name_here>}과 같은 패턴을 사용할 수 있을 것 같습니다.

언급URL : https://stackoverflow.com/questions/1667212/how-to-add-reference-to-a-method-parameter-in-javadoc

반응형