Skip to content

Instantly share code, notes, and snippets.

@thvortex
Created March 8, 2012 23:09
Show Gist options
  • Save thvortex/2004037 to your computer and use it in GitHub Desktop.
Save thvortex/2004037 to your computer and use it in GitHub Desktop.
MCP 6.0 commands.py fix to handle Javadoc @ block tags in method/field descriptions
--- commands1.py 2012-03-04 01:56:04.000000000 -0600
+++ commands.py 2012-03-08 17:27:00.040003100 -0600
@@ -1524,6 +1524,7 @@
regexps = {
'field': re.compile(r'^ {4}(?:[\w$.[\]]+ )*(?P<name>field_[0-9]+_[a-zA-Z_]+) *(?:=|;)'),
'method': re.compile(r'^ {4}(?:[\w$.[\]]+ )*(?P<name>func_[0-9]+_[a-zA-Z_]+)\('),
+ 'javadoctag': re.compile(r'\s*(?<!{)@'),
}
wrapper = TextWrapper(width=120)
@@ -1545,8 +1546,8 @@
indent = ' '
name = fielddecl.group('name')
if name in fields:
- desc = fields[name]
- if len(desc) < 70:
+ desc = regexps['javadoctag'].sub('\n@',fields[name])
+ if len(desc) < 70 and desc.find('\n') == -1:
if prev_line != '' and prev_line != '{':
buf_out.append('\n')
buf_out.append(indent + '/** ')
@@ -1558,20 +1559,28 @@
if prev_line != '' and prev_line != '{':
buf_out.append('\n')
buf_out.append(indent + '/**\n')
- buf_out.append(wrapper.fill(desc) + '\n')
+
+ # TextWrapper ignores embedded newlines (added for @ block tags) so split by line
+ for descline in desc.split('\n'):
+ buf_out.append(wrapper.fill(descline) + '\n')
+
buf_out.append(indent + ' */\n')
elif methoddecl:
prev_line = buf_out[-1].strip()
indent = ' '
name = methoddecl.group('name')
if name in methods:
- desc = methods[name]
+ desc = regexps['javadoctag'].sub('\n@',methods[name])
wrapper.initial_indent = indent + ' * '
wrapper.subsequent_indent = indent + ' * '
if prev_line != '' and prev_line != '{':
buf_out.append('\n')
buf_out.append(indent + '/**\n')
- buf_out.append(wrapper.fill(desc) + '\n')
+
+ # TextWrapper ignores embedded newlines (added for @ block tags) so split by line
+ for descline in desc.split('\n'):
+ buf_out.append(wrapper.fill(descline) + '\n')
+
buf_out.append(indent + ' */\n')
buf_out.append(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment