在 javadoc 中将长 URL 分成几行
Breaking a long URL to several line in javadoc
如果我正在使用一段代码或从其他互联网获取的资源,我想在 class 或功能文档中指出这一点,并提供 link 到原始来源。但是,为了更好的可读性,我也想在编写代码时坚持每行最多 80 个字符的原则。有没有办法将源代码中的长 URL 解析为多行,并且在像 Eclipse 一样使用 IDE 中的 javadoc 时仍然保持原始地址可用?可用的意思是单击 javadoc 工具提示中的 URL 会打开正确的页面。
例如,您将如何格式化以下内容:
/**
* Class to do some cool stuff
* Original source:
* http://whosebug.com/questions/and-huge-amouts-of-URL-address-which-does-not-fit-to-80-chars
*/
public class ExampleClass {
}
您可以使用以下内容
@see <a href = "https://whosebug.com/questions/and-huge-amouts-of-URL-address-which-does-not-fit-to-80-chars"> SO Link </a>
并且它将呈现为:
See Also:
SO Link
来源:javadoc
如果您不想使用 URL 缩写词,您可以用 <pre></pre>
标签包围您的 url,如下所示:
/**
* Class to do some cool stuff
* Original source:
* <pre>
* See <a href="http://whosebug.com/questions/
and-huge-amouts-of-URL-address-which-does-not-fit-to-80-chars">NameOfyourLink</a>
* </pre>
*/
例如,这将满足 checkstyle 并让您保留原始 URL。
我发现的另一个解决方案是只断开行并确保连续的行完全遵循 URL(中间没有任何其他字符)。
例如:
/**
* Link to <a href="https://developer.android.com/reference/android/app/Service#
startForeground(int,%20android.app.Notification)">startForeground(..)</a>
*/
如果我正在使用一段代码或从其他互联网获取的资源,我想在 class 或功能文档中指出这一点,并提供 link 到原始来源。但是,为了更好的可读性,我也想在编写代码时坚持每行最多 80 个字符的原则。有没有办法将源代码中的长 URL 解析为多行,并且在像 Eclipse 一样使用 IDE 中的 javadoc 时仍然保持原始地址可用?可用的意思是单击 javadoc 工具提示中的 URL 会打开正确的页面。
例如,您将如何格式化以下内容:
/**
* Class to do some cool stuff
* Original source:
* http://whosebug.com/questions/and-huge-amouts-of-URL-address-which-does-not-fit-to-80-chars
*/
public class ExampleClass {
}
您可以使用以下内容
@see <a href = "https://whosebug.com/questions/and-huge-amouts-of-URL-address-which-does-not-fit-to-80-chars"> SO Link </a>
并且它将呈现为:
See Also: SO Link
来源:javadoc
如果您不想使用 URL 缩写词,您可以用 <pre></pre>
标签包围您的 url,如下所示:
/**
* Class to do some cool stuff
* Original source:
* <pre>
* See <a href="http://whosebug.com/questions/
and-huge-amouts-of-URL-address-which-does-not-fit-to-80-chars">NameOfyourLink</a>
* </pre>
*/
例如,这将满足 checkstyle 并让您保留原始 URL。
我发现的另一个解决方案是只断开行并确保连续的行完全遵循 URL(中间没有任何其他字符)。
例如:
/**
* Link to <a href="https://developer.android.com/reference/android/app/Service#
startForeground(int,%20android.app.Notification)">startForeground(..)</a>
*/