Created
December 8, 2016 18:56
-
-
Save jacobtolar/46f03ced47ce6f15c005e8201ba601e1 to your computer and use it in GitHub Desktop.
Revisions
-
jacobtolar created this gist
Dec 8, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ 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)