Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can one use variables in JAVADOC comments?

Tags:

java

javadoc

I wish to refer to a particular URL in JAVADOC comments in a project. However, I know that the URL may change in the near future. So, I was looking for a functionality that allows one to use a single variable in place of this URL throughout the project. So that if needed, it can easily be changed, but I could not find one.

Is there a way to achieve this?

like image 594
piedpiper Avatar asked Jul 09 '13 12:07

piedpiper


People also ask

How do you comment variables in Javadoc?

Writing Javadoc Comments In general, Javadoc comments are any multi-line comments (" /** ... */ ") that are placed before class, field, or method declarations. They must begin with a slash and two stars, and they can include special tags to describe characteristics like method parameters or return values.

How do you write comments for the Javadoc tool?

In order to create a Javadoc comment, place the cursor before a class declaration, a method, or a variable declaration. Then, add a comment. A Javadoc comment starts with a slash and two asterisks, and you can create it easily by typing those characters, slash, asterisk, asterisk, and then pressing enter or return.

What is the use of Javadoc comments?

This is a documentation comment and in general its called doc comment. The JDK javadoc tool uses doc comments when preparing automatically generated documentation.

Can you use HTML tags in Javadoc comments?

General FormattingA Javadoc comment is written in HTML and can therefore use common HTML tags. A JavaDoc comment is made up of two parts, the description followed by block tags. Keep in mind that Javadoc is often read in it's source form, so it should be easy to read and understand without the generated web frontend.


2 Answers

By looking into javadoc specification doc I see this tag : {@value}

Displays the value of a constant, which must be a static field.

So if you create a class for example DocLinksHolder and declare static fields there, then you can refer to them in javadoc.

{@value DocLinksHolder#fieldName}
like image 146
Tala Avatar answered Oct 06 '22 22:10

Tala


If you are using maven, you can use its filtering feature.

With this in your pom :

<resources>
  <resource>
    <directory>src/main/java</directory>
    <filtering>true</filtering>
  </resource>
</resources>

Maven will find all string which match ${something} and replace them with values coming from your pom.

For example, you can put

/**
 * URL is ${url}.
 */

and in your pom :

<properties>
  <url>myUrl.com</url>
</properties> 
like image 33
Arnaud Denoyelle Avatar answered Oct 06 '22 21:10

Arnaud Denoyelle