developer tip

javadoc에서 메소드를 참조하는 방법은 무엇입니까?

optionbox 2020. 9. 29. 07:40
반응형

javadoc에서 메소드를 참조하는 방법은 무엇입니까?


@link태그를 사용하여 메소드에 연결하려면 어떻게해야합니까?

나는 바꾸고 싶다

/**
 * Returns the Baz object owned by the Bar object owned by Foo owned by this.
 * A convenience method, equivalent to getFoo().getBar().getBaz()
 * @return baz
 */
public Baz fooBarBaz()

...에

/**
 * Returns the Baz object owned by the Bar object owned by Foo owned by this.
 * A convenience method, equivalent to {@link getFoo()}.{@link getBar()}.{@link getBaz()}
 * @return baz
 */
public Baz fooBarBaz()

하지만 @link태그 형식을 올바르게 지정 하는 방법을 모르겠습니다 .


표준 Doclet에 대한 문서 주석 사양 에서 JavaDoc에 대한 많은 정보를 찾을 수 있습니다.

{@link package.class # member label}

태그 (당신이 찾고있는 것). 문서의 해당 예는 다음과 같습니다.

예를 들어, 다음은 getComponentAt (int, int) 메서드를 참조하는 주석입니다.

Use the {@link #getComponentAt(int, int) getComponentAt} method.

package.class참조한 방법은 현재 클래스의 경우 부분 ommited 수있다.


JavaDoc에 대한 기타 유용한 링크는 다음과 같습니다.


javadoc 문서@link 섹션에있는 일반 형식 은 다음과 같습니다.

{@link package.class # member label}

같은 클래스의 메서드 :

/** See also {@link #myMethod(String)}. */
void foo() { ... }

동일한 패키지에 있거나 가져온 다른 클래스의 메소드 :

/** See also {@link MyOtherClass#myMethod(String)}. */
void foo() { ... }

다른 패키지에 있고 가져 오지 않은 메소드 :

/** See also {@link com.mypackage.YetAnotherClass#myMethod(String)}. */
void foo() { ... }

메서드에 연결된 레이블, 코드 글꼴이 아닌 일반 텍스트 :

/** See also this {@linkplain #myMethod(String) implementation}. */
void foo() { ... }

귀하의 질문에서 같이 일련의 메서드 호출 . 이 클래스 외부의 메서드에 대한 링크에 대한 레이블을 지정해야합니다 getFoo().Foo.getBar().Bar.getBaz(). 그렇지 않으면 . 그러나 이러한 레이블은 깨지기 쉽습니다. 아래의 "라벨"을 참조하십시오.

/**
 * A convenience method, equivalent to 
 * {@link #getFoo()}.{@link Foo#getBar() getBar()}.{@link Bar#getBaz() getBaz()}.
 * @return baz
 */
public Baz fooBarBaz()

라벨

자동화 된 리팩토링은 레이블에 영향을주지 않을 수 있습니다. 여기에는 메서드, 클래스 또는 패키지의 이름 변경이 포함됩니다. 및 메소드 서명 변경.

따라서 기본값과 다른 텍스트를 원하는 경우 에만 레이블을 제공하십시오 .

예를 들어, 인간 언어에서 코드로 링크 할 수 있습니다.

/** You can also {@linkplain #getFoo() get the current foo}. */
void setFoo( Foo foo ) { ... }

또는 위의 "A chain of method calls"에 표시된대로 기본값과 다른 텍스트로 코드 샘플에서 링크 할 수 있습니다. 그러나 이는 API가 진화하는 동안 취약 할 수 있습니다.

삭제 및 #member 입력

메소드 서명에 매개 변수화 된 유형이 포함 된 경우 javadoc @link에서 해당 유형의 삭제를 사용하십시오. 예를 들면 :

int bar( Collection<Integer> receiver ) { ... }

/** See also {@link #bar(Collection)}. */
void foo() { ... }

다음과 같이 사용할 수 있습니다 @see.

견본:

interface View {
        /**
         * @return true: have read contact and call log permissions, else otherwise
         * @see #requestReadContactAndCallLogPermissions()
         */
        boolean haveReadContactAndCallLogPermissions();

        /**
         * if not have permissions, request to user for allow
         * @see #haveReadContactAndCallLogPermissions()
         */
        void requestReadContactAndCallLogPermissions();
    }

참고 URL : https://stackoverflow.com/questions/5915992/how-to-reference-a-method-in-javadoc

반응형