Created
December 8, 2016 18:56
-
-
Save jacobtolar/46f03ced47ce6f15c005e8201ba601e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
exts = set(['.java', '.groovy']) | |
BEGIN_JAVADOC = re.compile('^\s*\/\*\*.*') | |
END_JAVADOC = re.compile('^\s*\*\/.*') | |
MISSING_PARAGRAPH = re.compile('^(\s*)\*\s*$') | |
class State(object): | |
NO_COMMENT = 1 | |
IN_COMMENT = 2 | |
def fixup(p): | |
result = [] | |
with open(p) as fh: | |
state = State.NO_COMMENT | |
for line in fh: | |
if state == State.NO_COMMENT: | |
result.append(line) | |
m = BEGIN_JAVADOC.match(line) | |
if m: | |
if line.find('*/') == -1: # Also ends the comment | |
state = State.IN_COMMENT | |
elif state == State.IN_COMMENT: | |
match_end = END_JAVADOC.match(line) | |
match_missing = MISSING_PARAGRAPH.match(line) | |
if match_end: | |
result.append(line) | |
state = State.NO_COMMENT | |
elif match_missing: | |
result.append(match_missing.group(1) + '* <p>\n') | |
else: | |
result.append(line) | |
else: | |
raise Exception('Unknown state') | |
with open(p, 'w') as fh: | |
fh.write(''.join(result)) | |
for dirpath, dnames, files in os.walk("./"): | |
for f in (f for f in files if os.path.splitext(f)[1] in exts): | |
p = os.path.join(dirpath, f) | |
print 'fixup {}'.format(p) | |
fixup(p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment