update unusedmethods loplugin to update unused return values

Change-Id: I825d022d09282bc9b6cffd9178e40e4090d335da
This commit is contained in:
Noel Grandin
2016-01-11 08:41:55 +02:00
parent f7c23897a3
commit 86bb6fdf9c
3 changed files with 79 additions and 12 deletions

View File

@@ -7,6 +7,7 @@ import io
definitionSet = set()
definitionToSourceLocationMap = dict()
callSet = set()
returnSet = set()
sourceLocationSet = set()
# things we need to exclude for reasons like :
# - it's a weird template thingy that confuses the plugin
@@ -125,6 +126,9 @@ with io.open(sys.argv[1], "rb", buffering=1024*1024) as txt:
elif line.startswith("call:\t"):
idx1 = line.find("\t",6)
callSet.add((normalizeTypeParams(line[6:idx1]), normalizeTypeParams(line[idx1+1:].strip())))
elif line.startswith("usedReturn:\t"):
idx1 = line.find("\t",12)
returnSet.add((normalizeTypeParams(line[12:idx1]), normalizeTypeParams(line[idx1+1:].strip())))
# Invert the definitionToSourceLocationMap
# If we see more than one method at the same sourceLocation, it's being autogenerated as part of a template
@@ -138,6 +142,10 @@ for k, definitions in sourceLocationToDefinitionMap.iteritems():
for d in definitions:
definitionSet.remove(d)
# -------------------------------------------
# Do the "unused methods" part
# -------------------------------------------
tmp1set = set()
for d in definitionSet:
clazz = d[0] + " " + d[1]
@@ -228,12 +236,45 @@ def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
tmp1list = sorted(tmp1set, key=lambda v: natural_sort_key(v[1]))
# print out the results
for t in tmp1list:
#for t in tmp1list:
# print t[1]
# print " ", t[0]
# -------------------------------------------
# Do the "unused return types" part
# -------------------------------------------
tmp2set = set()
for d in definitionSet:
clazz = d[0] + " " + d[1]
if clazz in exclusionSet:
continue
if d in returnSet:
continue
if d[0] == "void":
continue
# ignore UNO constructor method entrypoints
if "_get_implementation" in d[1]:
continue
# the plugin can't see calls to these
if "operator new" in d[1]:
continue
# unused return type is not a problem here
if "operator=(" in d[1]:
continue
# ignore external code
if definitionToSourceLocationMap[d].startswith("external/"):
continue
tmp2set.add((clazz, definitionToSourceLocationMap[d]))
# sort results by name and line number
tmp2list = sorted(tmp2set, key=lambda v: natural_sort_key(v[1]))
for t in tmp2list:
print t[1]
print " ", t[0]
# add an empty line at the end to make it easier for the unusedmethodsremove plugin to mmap() the output file
print