Improved the comments module yet again.

It should now be able to handle multi-line comments that are only on one line.
Furthermore, it should also handle multi-line comments from languages such as
python (where the identifiers for comment begining/end are identical).
This commit is contained in:
Adam Waldenberg 2012-05-16 04:14:48 +02:00
parent 842ca6b87c
commit 676cb5c114
3 changed files with 15 additions and 15 deletions

View File

@ -48,14 +48,15 @@ class Blame:
if self.blames.get(author, None) == None:
self.blames[author] = BlameEntry()
if comment.has_comment_begining(FileDiff.get_extension(i), content):
is_inside_comment = True
if comment.is_comment(FileDiff.get_extension(i), content) or is_inside_comment:
if comment.is_comment(FileDiff.get_extension(i), content):
self.blames[author].comments += 1
if comment.has_comment_end(FileDiff.get_extension(i), content):
is_inside_comment = False
if is_inside_comment:
if comment.has_comment_end(FileDiff.get_extension(i), content):
is_inside_comment = False
else:
self.blames[author].comments += 1
elif comment.has_comment_begining(FileDiff.get_extension(i), content):
is_inside_comment = True
self.blames[author].rows += 1

View File

@ -27,9 +27,9 @@ __comment__ = {"java": "//", "c": "//", "cpp": "//", "h": "//", "hpp": "//", "py
"rb": "#", "js": "//", "sql": "--"}
def is_comment(extension, string):
if __comment_begining__.get(extension, None) != None and string.strip().startswith(__comment__[extension]):
if __comment_begining__.get(extension, None) != None and string.strip().startswith(__comment_begining__[extension]):
return True
if __comment_end__.get(extension, None) != None and string.strip().endswith(__comment__[extension]):
if __comment_end__.get(extension, None) != None and string.strip().endswith(__comment_end__[extension]):
return True
if __comment__.get(extension, None) != None and string.strip().startswith(__comment__[extension]):
return True
@ -37,7 +37,7 @@ def is_comment(extension, string):
return False
def has_comment_begining(extension, string):
if __comment_begining__.get(extension, None) != None:
if __comment_begining__.get(extension, None) != None and string.find(__comment_end__[extension], 2) == -1:
return string.find(__comment_begining__[extension]) != -1
else:
return False

View File

@ -46,15 +46,14 @@ class Metrics:
eloc_counter = 0
for j in file_r.readlines():
if comment.has_comment_begining(extension, j):
if is_inside_comment and comment.has_comment_end(extension, j):
is_inside_comment = False
elif comment.has_comment_begining(extension, j):
is_inside_comment = True
if not comment.is_comment(extension, j) and not is_inside_comment:
if not is_inside_comment and not comment.is_comment(extension, j):
eloc_counter += 1
if comment.has_comment_end(extension, j):
is_inside_comment = False
return eloc_counter
def output(repo, hard):