如何仅提取 javadoc 注释的初始描述并使用 python 忽略 javadoc 标记?
How can I extract only the initial description of a javadoc comment and ignore the javadoc tags using python?
我试图在 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;
}
按照您的逻辑,有一个描述部分,然后是一个"tags"部分,然后是一个结束评论标记.
如果你逐行检查是否出现了标签关键字,你将无法处理这一行:
* 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)
我试图在 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;
}
按照您的逻辑,有一个描述部分,然后是一个"tags"部分,然后是一个结束评论标记.
如果你逐行检查是否出现了标签关键字,你将无法处理这一行:
* 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)