我正在尝试在python中的Javadoc标签之前提取Javadoc中的文本。到目前为止,我已经能够避免使用参数标签,但是还有其他Javadoc标签可以同时提及。有没有更好的方法可以做到这一点?
parameterTag = "@param"
if (parameterTag in comments):
splitComments = subsentence.split(my_string[my_string.find(start) + 1: my_string.find(parameterTag)])
输入:
/**
* Checks if the given node is inside the graph and
* throws exception if the given node is null
* @param a single node to be check
* @return true if given node is contained in graph,
* return false otherwise
* @requires given node != null
*/
public boolean containsNode(E node){
if(node==null){
throw new IllegalArgumentException();
}
if(graph.containsKey(node)){
return true;
}
return false;
}
输出:
/**
* Checks if the given node is inside the graph and
* throws exception if the given node is null
*/
public boolean containsNode(E node){
if(node==null){
throw new IllegalArgumentException();
}
if(graph.containsKey(node)){
return true;
}
return false;
}
按照您的逻辑,有一个描述部分,然后是"标签"部分,然后是结束注释标记。
如果您逐行检查标签关键字的出现,您将无法处理此行:
* return false otherwise
因此,您需要检测是否从标签部分输入或退出。 下面是一个工作示例:
import re
# Javascript content loading
JSF = open("your_js_file.js", 'r')
js_content = JSF.read()
# We split the script into lines, and then we'll loop through the array
lineiterator = iter(js_content.splitlines())
# This boolean marks if we are or not in a "tags" part
in_tags = False
for line in lineiterator:
# If we matched a line with a word starting with "@",
# Then we entered into a "tags" section
if re.search("@w+", line) is not None :
in_tags = True
# If we matched a closing comment mark, then we left
# The "tags" section (or never entered into it)
if re.search("*/",line) is not None:
in_tags = False
if not in_tags:
print(line)