Editing Eclipse Javadoc ${tags} Variable
版本:Luna Service Release 2(4.4.2)
我通常使用" / **"方法在我的方法上插入Javadoc。 Eclipse为所有args插入
1 2 3 4 5 6 7 8 | /** * * @param criteria * @param filters * @return */ protected static String getColumnNameFromCriteria(SelectedCriteria criteria, List<SelectionFilter> filters) |
第一个问题是:在Eclipse中是否有一个开关可以使它在添加Javadoc时自动插入方法返回类型?
我找不到一个,于是我抬起头来:偏好设置-> java->代码样式->代码模板->方法
在该模板上,我看到了变量
第二个问题是:有没有一种方法可以编辑
我希望能够键入
1 2 3 4 5 6 7 8 | /** * * @param criteria * @param filters * @return String */ protected static String getColumnNameFromCriteria(SelectedCriteria criteria, List<SelectionFilter> filters) |
您尝试过jautodoc插件吗?看看它可能会帮助您。它比alt-shift-j中内置的eclipse更好
http://jautodoc.sourceforge.net/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | private static void insertTag(IDocument textBuffer, int offset, int length, String[] paramNames, String[] exceptionNames, String returnType, String[] typeParameterNames, boolean isDeprecated, String lineDelimiter) throws BadLocationException { IRegion region= textBuffer.getLineInformationOfOffset(offset); if (region == null) { return; } String lineStart= textBuffer.get(region.getOffset(), offset - region.getOffset()); StringBuffer buf= new StringBuffer(); for (int i= 0; i < typeParameterNames.length; i++) { if (buf.length() > 0) { buf.append(lineDelimiter).append(lineStart); } buf.append("@param <").append(typeParameterNames[i]).append('>'); //$NON-NLS-1$ } for (int i= 0; i < paramNames.length; i++) { if (buf.length() > 0) { buf.append(lineDelimiter).append(lineStart); } buf.append("@param").append(paramNames[i]); //$NON-NLS-1$ } if (returnType != null && !returnType.equals("void")) { //$NON-NLS-1$ if (buf.length() > 0) { buf.append(lineDelimiter).append(lineStart); } buf.append("@return"); //$NON-NLS-1$ } if (exceptionNames != null) { for (int i= 0; i < exceptionNames.length; i++) { if (buf.length() > 0) { buf.append(lineDelimiter).append(lineStart); } buf.append("@throws").append(exceptionNames[i]); //$NON-NLS-1$ } } ... |
请注意,没有任何方法可以附加返回类型。模板中仅插入
至少有一种非常怪异的方法。您仍然可以通过以下方法更新模板:转到窗口->首选项-> Java->代码样式->代码模板->注释,然后选择编辑以编辑注释模板。然后,您可以将模板更改为:
1 2 3 4 | /** * ${tags} * @return ${return_type} */ |
有关可用变量,请参见http://help.eclipse.org/mars/topic/org.eclipse.jdt.doc.user/concepts/concept-template-variables.htm。
但这会导致添加两个
根据您的问题,Eclipse中尚未配置(允许您修改此配置)。这是因为javadoc中的注释必须使用自动生成类javadoc HTML的工具进行投诉。如果允许更改它,则
您不必担心,因为此标记
采取这种方法,例如:
1 2 3 4 5 6 7 8 9 | /** * This is an example of a documentation of a method with a return type. * Note that there isn't a type on the `@return` tag * * @return the someAttribute */ public String getSomeAttribute() { return someAttribute; } |
在Eclipse中,当您将鼠标指针停在此方法上时,它将显示以下内容:
请注意图像上该文档的第一行。它说:
当您通过
您可以在"修饰符和类型"列中看到方法的返回类型。如果查看其中一个方法的源代码,例如图像
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | /** * Returns the <wyn>char</wyn> value at the * specified index. An index ranges from <wyn>0</wyn> to * <wyn>length() - 1</wyn>. The first <wyn>char</wyn> value of the sequence * is at index <wyn>0</wyn>, the next at index <wyn>1</wyn>, * and so on, as for array indexing. * * <p> If the <wyn>char</wyn> value specified by the index is a * surrogate, the surrogate * value is returned. * * @param index the index of the <wyn>char</wyn> value. * @return the <wyn>char</wyn> value at the specified index of this string. * The first <wyn>char</wyn> value is at index <wyn>0</wyn>. * @exception IndexOutOfBoundsException if the <wyn>index</wyn> * argument is negative or not less than the length of this * string. */ public char charAt(int index) { if ((index < 0) || (index >= value.length)) { throw new StringIndexOutOfBoundsException(index); } return value[index]; } |
希望它可以帮助您了解该标签。