Skip to content

Commit

Permalink
InCode feature envy replication
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineBarbez committed Jun 5, 2018
1 parent 93b3f75 commit 6673d17
Show file tree
Hide file tree
Showing 13 changed files with 226 additions and 1,436 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified advisors/detection/.DS_Store
Binary file not shown.
Binary file modified advisors/detection/Decor/.DS_Store
Binary file not shown.
137 changes: 137 additions & 0 deletions advisors/detection/InCode/incode_fe_replication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
from __future__ import division

import csv
import re
import sys

sys.path.insert(0, '../')
import evaluate

''' This file is just used to obtain JDeodorant detection results on the test set'''

def normalizeSourceEntity(source_entity):
m1 = re.match('(.+)\((.*)\)', source_entity)

methodName = m1.group(1)
parameters = m1.group(2)
paramList = parameters.split(', ')

normalizedParamList = []
for param in paramList:
normalizedParam = param.split('.')[-1]
m2 = re.match('(\w*)\W*', normalizedParam)

normalizedParamList.append(m2.group(1))

normalizedParamList.sort()

return methodName + '(' + ', '.join(normalizedParamList) + ')'

def feature_envy(systemName):
incodeMetricsFile = '../../metrics_files/feature_envy/InCode/' + systemName + '.csv'

smells = []
currentMethodName = ''
classAttributeDictionnary = {}
i = 0
with open(incodeMetricsFile, 'rb') as csvfile:
nbLines = len(csvfile.readlines()) - 2
csvfile.seek(0)

reader = csv.DictReader(csvfile, delimiter=';')
for row in reader:
methodName = row['Class'] + '.' + row['Method']

if (i == 0):
currentMethodName = methodName

if (currentMethodName != methodName):
enviedClass = getEnviedClasses(currentMethodName, classAttributeDictionnary)
for klass in enviedClass:
smells.append(currentMethodName + ';' + klass)


classAttributeDictionnary = {}
classAttributeDictionnary[row['DeclaringClass']] = int(row['NbFields'])
currentMethodName = methodName
else:
classAttributeDictionnary[row['DeclaringClass']] = int(row['NbFields'])

if (i == nbLines):
currentMethodName = methodName
classAttributeDictionnary[row['DeclaringClass']] = int(row['NbFields'])

enviedClass = getEnviedClasses(currentMethodName, classAttributeDictionnary)
for klass in enviedClass:
smells.append(currentMethodName + ';' + klass)

i = i + 1

return list(set(smells))

def getEnviedClasses(methodName, classAttributeDictionnary):
enviedClass = []

FDP = len(classAttributeDictionnary)

className = methodName.split('.')
className.pop()
className = '.'.join(className)

# ATSD: Access To Self Data
if className in classAttributeDictionnary:
ATSD = classAttributeDictionnary[className]
FDP = FDP - 1
else:
# To avoid division by zero
ATSD = 0.5

for klass in classAttributeDictionnary:
ATFD = int(classAttributeDictionnary[klass])

if ((ATFD > 4) & (ATFD/ATSD > 3.0) & (klass != className)):
enviedClass.append(klass)

if FDP >= 4:
enviedClass = []

return enviedClass

def test(systemName):
print(systemName)
trueFile = '../../../data/labels/Feature_envy/test/' + systemName + '.csv'

# Get Smells occurences
true = []
with open(trueFile, 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter=';')

for row in reader:
print(row[0])
true.append(normalizeSourceEntity(row[0]) + ';' + row[1])

# Get classes detected as God Classes
detected = feature_envy(systemName)
print(detected)

pre = evaluate.precision(detected, true)
rec = evaluate.recall(detected, true)
f_m = evaluate.f_mesure(detected, true)

print('Precision :' + str(pre))
print('Recall :' + str(rec))
print('F-Mesure :' + str(f_m))

return f_m


if __name__ == "__main__":
'''systems = ['apache-tomcat', 'jedit', 'android-platform-support', 'apache-ant']
for system in systems:
test(system)
print("")'''

smel = feature_envy('apache-ant')

print(smel)
8 changes: 5 additions & 3 deletions advisors/detection/JDeodorant/JDeodorant_fe_replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def normalizeSourceEntity(source_entity):
return methodName + '(' + ', '.join(normalizedParamList) + ')'

def feature_envy(systemName):
JDFEFile = '../../results/JDeodorant/Feature_envy/' + systemName + '.txt'
JDFEFile = '../../metrics_files/feature_envy/JDeodorant/' + systemName + '.txt'

smells = []
with open(JDFEFile, 'r') as file:
Expand Down Expand Up @@ -74,8 +74,10 @@ def test(systemName):


if __name__ == "__main__":
systems = ['apache-tomcat', 'jedit', 'android-platform-support', 'apache-ant']
'''systems = ['apache-tomcat', 'jedit', 'android-platform-support', 'apache-ant']
for system in systems:
test(system)
print("")
print("")'''

print(len(feature_envy('jedit')))
1,176 changes: 0 additions & 1,176 deletions advisors/metrics_files/god_class/Decor/android-frameworks-sdk.csv

This file was deleted.

Binary file modified advisors/metrics_files_generators/.DS_Store
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 6673d17

Please sign in to comment.