Kategorie szkoleń | Egzaminy | Kontakt
  • 1
  • 4
  • 58

 Witam.

Jakiego narzędzia można użyć do dokumentowania kodu? Fajnie gdyby narzędzie automatycznie pobierało dokumentację z kodu.

Rafał_Kędzierski
  • Zapytał
  • @ Rafał_Kędzierski | 16.02.2016
    • lider
    • laureat
    • 39
    • 6
    • 46

Odpowiedź (1)

  • 2

W JDK można znaleźć narzędzie javadoc. Jest to standardowy program służący do dokumentacji kodu Javy w formacie HTML.

W kodzie wystarczy umieścić specjalne komentarze (kompilator je zignoruje) o postaci:

/** kod dokumentujący (może obejmować wiele wierszy) */

Opisujące klasy i metody. W komentarzach można zawrzeć dowolny tekst, znaczniki HTML oraz adnotacje. Umożliwiają one określenie szczegółów dokumentowanego kodu, np. autora, wersji kodu, opisu parametrów, informacji czy mogą wystąpić wyjątki, zwracanej wartości, itp. Dodatkowo można dzięki nim tworzyć hiperłącza (linki) do innych stron dokumentacji.

Przykładowo taka dokumentacja może wyglądać następująco:

/**
 * Returns an Image object that can then be painted on the screen. 
 * The url argument must specify an absolute {@link URL}. The name
 * argument is a specifier that is relative to the url argument. 
 * <p>
 * This method always returns immediately, whether or not the 
 * image exists. When this applet attempts to draw the image on
 * the screen, the data will be loaded. The graphics primitives 
 * that draw the image will incrementally paint on the screen. 
 *
 * @param  url  an absolute URL giving the base location of the image
 * @param  name the location of the image, relative to the url argument
 * @return      the image at the specified URL
 * @see         Image
 */
 public Image getImage(URL url, String name) {
        try {
            return getImage(new URL(url, name));
        } catch (MalformedURLException e) {
            return null;
        }
 }

Zaletą tego rozwiązania jest także to, że standardowa dokumentacja API Javy została też stworzona w oparciu o to narzędzie - nie ma więc potrzeby nauki innego sposobu wyszukiwania potrzebnych informacji i nawigacji po dokumentacji.\

Pełny opis narzędzia znajduje się poniższym adresem: http://www.oracle.com/technetwork/articles/java/index-137868.html

  • Odpowiedział
  • @ | 16.02.2016
  • TRENER MODERATOR ALTKOM AKADEMII