public class JavaDocUtil extends Object
Get urls to function, class, and object targets.
aliteralmind __DASH__ github __AT__ yahoo __DOT__ com), dual-licensed under the LGPL (version 3.0 or later) or the ASL (version 2.0). See source code for details. http://codelet.aliteralmind.com, https://github.com/aliteralmind/codelet| Modifier and Type | Method and Description |
|---|---|
static StringBuilder |
appendClassNameForParams(StringBuilder to_appendTo,
Class<?>[] classes,
VarArgs var_args)
Append the comma-separated list of JavaDoc parameters for a method or constructor.
|
static StringBuilder |
appendUrlToClass(StringBuilder to_appendTo,
String url_toDocRoot,
Class<?> target)
Append the url to a class.
|
static StringBuilder |
appendUrlToConstructor(StringBuilder to_appendTo,
String url_toDocRoot,
Constructor<?> target)
Append the url to a constructor.
|
static StringBuilder |
appendUrlToField(StringBuilder to_appendTo,
String url_toDocRoot,
Field target)
Append the url to a field.
|
static StringBuilder |
appendUrlToMethod(StringBuilder to_appendTo,
String url_toDocRoot,
Method target)
Append the url to a function.
|
static String |
getClassNameForParams(Class<?>[] classes,
VarArgs var_args)
Append the comma-separated list of JavaDoc parameters for a method or constructor.
|
static String |
getEllipsisArrayLastParam(Class<?> cls)
For the final parameter in a
variable-argument method or constructor, that is known to be an array-ellipsis ("..."), get its JavaDoc-url parameter name. |
static String |
getRelativeUrlToDocRoot(String package_containingLink)
Get the url from a link-source file's package to doc-root.
|
static String |
getUrlToClass(String url_toDocRoot,
Class<?> target)
Get the url to a class.
|
static String |
getUrlToClassViaDocRoot(String url_toDocRoot,
Class<?> target)
Get the url from a link-source to the target class file.
|
static String |
getUrlToConstructor(String url_toDocRoot,
Constructor target)
Get the url to a constructor.
|
static String |
getUrlToField(String url_toDocRoot,
Field target)
Get the url to a field.
|
static String |
getUrlToMethod(String url_toDocRoot,
Method target)
Get the url to a function.
|
public static final String getUrlToClass(String url_toDocRoot, Class<?> target)
Get the url to a class.
appendUrlToClass((new StringBuilder()), url_toDocRoot, target).toString()public static final StringBuilder appendUrlToClass(StringBuilder to_appendTo, String url_toDocRoot, Class<?> target)
Append the url to a class.
to_appendTo - May not be null.url_toDocRoot - The url to {@docRoot} for the link target-file. Which must end with a slash "/", and should not be null.. This is also the directory in which the package-list files exists. For local files, this is a relative directory (such as "../../") otherwise this is the full url to the external doc-root directory.target - May not be null.to_appendTo.append(url_toDocRoot).
append(target.getName.replace(".", "/")).append(".html")getUrlToClass(String, Class)public static final String getUrlToConstructor(String url_toDocRoot, Constructor target)
Get the url to a constructor.
appendUrlToConstructor((new StringBuilder()), url_toDocRoot, target).toString()public static final StringBuilder appendUrlToConstructor(StringBuilder to_appendTo, String url_toDocRoot, Constructor<?> target)
Append the url to a constructor.
to_appendTo - May not be null.url_toDocRoot - The url to {@docRoot} for the link target-file. Which must end with a slash "/", and should not be null.. This is also the directory in which the package-list files exists. For local files, this is a relative directory (such as "../../") otherwise this is the full url to the external doc-root directory.target - May not be null.to_appendTogetUrlToConstructor,
appendUrlToMethod,
appendUrlToClass,
appendClassNameForParamspublic static final String getUrlToMethod(String url_toDocRoot, Method target)
Get the url to a function.
appendUrlToConstructor((new StringBuilder()), url_toDocRoot, target).toString()public static final StringBuilder appendUrlToMethod(StringBuilder to_appendTo, String url_toDocRoot, Method target)
Append the url to a function.
import com.github.aliteralmind.codelet.util.JavaDocUtil;
import java.lang.reflect.Method;
import java.lang.reflect.Constructor;
import com.github.xbn.lang.reflect.Declared;
import com.github.xbn.lang.reflect.ReflectRtxUtil;
public class FunctionConstructorJavaDocLink {
public static final void main(String[] ignored) {
testConstructor();
testConstructor(String.class, int[].class, int[].class);
testMethod(int.class);
testMethod(String.class, int[].class);
}
private static final void testConstructor(Class<?>... param_types) {
Constructor c = ReflectRtxUtil.getConstructor(
FunctionConstructorJavaDocLink.class, Declared.NO, null,
(Class<?>[])param_types);
System.out.println(JavaDocUtil.getUrlToConstructor("../", c));
}
private static final void testMethod(Class<?>... param_types) {
Method m = ReflectRtxUtil.getMethod(FunctionConstructorJavaDocLink.class,
"doSomething", Declared.NO, null, (Class<?>[])param_types);
System.out.println(JavaDocUtil.getUrlToMethod("../../", m));
}
public FunctionConstructorJavaDocLink() {
}
public FunctionConstructorJavaDocLink(String s, int[] ai, int... ai2) {
}
public void doSomething(int i) {
}
public void doSomething(String s, int[] ai) {
}
}
Output:
../com/github/aliteralmind/codelet/examples/util/FunctionConstructorJavaDocLink.html#FunctionConstructorJavaDocLink() ../com/github/aliteralmind/codelet/examples/util/FunctionConstructorJavaDocLink.html#FunctionConstructorJavaDocLink(java.lang.String, int[], int...) ../../com/github/aliteralmind/codelet/examples/util/FunctionConstructorJavaDocLink.html#doSomething(int) ../../com/github/aliteralmind/codelet/examples/util/FunctionConstructorJavaDocLink.html#doSomething(java.lang.String, int[])
to_appendTo - May not be null.url_toDocRoot - The url to {@docRoot} for the link target-file. Which must end with a slash "/", and should not be null.. This is also the directory in which the package-list files exists. For local files, this is a relative directory (such as "../../") otherwise this is the full url to the external doc-root directory.target - May not be null.to_appendTogetUrlToMethod,
appendUrlToMethod,
appendUrlToClass,
appendClassNameForParamspublic static final String getUrlToField(String url_toDocRoot, Field target)
Get the url to a field.
appendUrlToField((new StringBuilder()), url_toDocRoot, target).toString()public static final StringBuilder appendUrlToField(StringBuilder to_appendTo, String url_toDocRoot, Field target)
Append the url to a field.
appendUrlToClass(to_appendTo, url_toDocRoot, target.getDeclaringClass()).
append("#").append(target.Field#getName())getUrlToField(String, Field)public static final String getRelativeUrlToDocRoot(String package_containingLink)
Get the url from a link-source file's package to doc-root.
packageElementMtchr.reset(package_containingLink).replaceAll("../")
packageElementMtchr is initalized to
Pattern.compile(JavaRegexes.IDENTIFIER + "\\.?").matcher("")public static final String getUrlToClassViaDocRoot(String url_toDocRoot, Class<?> target)
Get the url from a link-source to the target class file. This always goes entirely down to {@docRoot}, and then back to the target file.
url_toDocRoot - The url to {@docRoot} for the link target-file. Which must end with a slash "/", and should not be null.. This is also the directory in which the package-list files exists. For local files, this is a relative directory (such as "../../") otherwise this is the full url to the external doc-root directory.target - May not be null.packageElementMtchr.reset(target.getName()).replaceAll("../")
packageElementMtchr is initalized to
Pattern.compile(".", Pattern.LITERAL).matcher("")public static final String getEllipsisArrayLastParam(Class<?> cls)
For the final parameter in a variable-argument method or constructor, that is known to be an array-ellipsis ("..."), get its JavaDoc-url parameter name.
import com.github.aliteralmind.codelet.util.JavaDocUtil;
public class JavaDocUtilGetEllipsisArrayLastParamXmpl {
public static final void main(String[] ignored) {
try {
System.out.print("int: ");
JavaDocUtil.getEllipsisArrayLastParam(int.class);
} catch(IllegalArgumentException iax) {
System.out.println(iax);
}
System.out.println("int[]: " + JavaDocUtil.getEllipsisArrayLastParam(int[].class));
System.out.println("int[][]: " + JavaDocUtil.getEllipsisArrayLastParam(int[][].class));
System.out.println("String[]: " + JavaDocUtil.getEllipsisArrayLastParam(String[].class));
System.out.println("String[][]: " + JavaDocUtil.getEllipsisArrayLastParam(String[][].class));
}
}
Output:
int: java.lang.IllegalArgumentException: cls.isArray() is false. int[]: int... int[][]: int[]... String[]: java.lang.String... String[][]: java.lang.String[]...
cls - May not be null."[]") is replaced with an ellipsis ("...").IllegalArgumentException - If cls is not an array.appendClassNameForParams(StringBuilder, Class[], VarArgs),
Class#getCanonicalName(),
Class.getCanonicalName()public static final String getClassNameForParams(Class<?>[] classes, VarArgs var_args)
Append the comma-separated list of JavaDoc parameters for a method or constructor.
appendClassNameForParams((new StringBuilder()), classes, is_varArgs).toString()public static final StringBuilder appendClassNameForParams(StringBuilder to_appendTo, Class<?>[] classes, VarArgs var_args)
Append the comma-separated list of JavaDoc parameters for a method or constructor. This does not include the surrounding parentheses.
This appends the canonical name of each class. If is_varArgs is true, the final parameter is output with getEllipsisArrayLastParam.
to_appendTo - May not be null.classes - May not be null, and is_varArgs is true, the final element must be an array (and classes.length should be non-empty).var_args - If YES, this is a variable-argument method or constructor, meaning the final parameter is an ellipsis array: "...". This parameter value may not be null.to_appendTogetClassNameForParams(Class[], VarArgs),
appendUrlToConstructor,
appendUrlToMethod,
lang.reflect.ReflectRtxUtil#appendClassNamesCopyright 2014, Jeff Epstein, All Rights Reserved. See top of source code files for copyright notice.
https://github.com/aliteralmind/codelet