# Path: SmellDetector/FileOperations.py
# def countPuppetFiles(folder):
# 
# Path: SmellDetector/Utilities.py
# def myPrint(msg):
# def reportSmell(outputFile, fileName, smellName, reason):
# def intersection(list1, list2):
# def summation(list1, list2):


import os
import Graph.GR_Constants as GRCONSTS
import Graph.Graph
import Graph.GraphNode
import Graph.Resource
import SmellDetector.Constants as CONSTS
import SourceModel.SM_File
from SmellDetector import FileOperations, Utilities

def detectUnstructuredMod(folder, outputFile):
    detectUnstructuredModForm1(folder, outputFile)
    detectUnstructuredModForm2(folder, outputFile)
    detectUnstructuredModForm3(folder, outputFile)

def detectTightlyCoupledMod(folder, outputFile):
    for root, dirs, files in os.walk(folder):
        for file in files:
            if file.endswith(".pp") and not os.path.islink(os.path.join(root, file)):
                fileObj = SourceModel.SM_File.SM_File(os.path.join(root, file))
                detectTCMod(fileObj, outputFile)

def detectHairballStrAndWeakendMod(folder, outputFile):
    graph = getGraph(folder)
    detectHaiStr(graph, folder, outputFile) #Excessive avg dependency
    detectWeakendMod(graph, folder, outputFile) #modularity ratio

#Form 1 - If a file contains declaration of more than one class/define
def detectInsufficientModForm1(folder, outputFile):
    for root, dirs, files in os.walk(folder):
        for file in files:
            if file.endswith(".pp") and not os.path.islink(os.path.join(root, file)):
                fileObj = SourceModel.SM_File.SM_File(os.path.join(root, file))
                detectInsModForm1(fileObj, outputFile)


def detectInsModForm1(fileObj, outputFile):
    classDefineDeclCount = len(fileObj.getOuterClassList()) + len(fileObj.getOuterDefineList())
    if classDefineDeclCount > 1:

# Path: SmellDetector/FileOperations.py
# def countPuppetFiles(folder):
# 
# Path: SmellDetector/Utilities.py
# def myPrint(msg):
# def reportSmell(outputFile, fileName, smellName, reason):
# def intersection(list1, list2):
# def summation(list1, list2):


# Path: SmellDetector/ModSmellDectector.py
import os
import Graph.GR_Constants as GRCONSTS
import Graph.Graph
import Graph.GraphNode
import Graph.Resource
import SmellDetector.Constants as CONSTS
import SourceModel.SM_File
from SmellDetector import FileOperations, Utilities


def detectUnstructuredMod(folder, outputFile):
    detectUnstructuredModForm1(folder, outputFile)
    detectUnstructuredModForm2(folder, outputFile)
    detectUnstructuredModForm3(folder, outputFile)

def detectTightlyCoupledMod(folder, outputFile):
    for root, dirs, files in os.walk(folder):
        for file in files:
            if file.endswith(".pp") and not os.path.islink(os.path.join(root, file)):
                fileObj = SourceModel.SM_File.SM_File(os.path.join(root, file))
                detectTCMod(fileObj, outputFile)

def detectHairballStrAndWeakendMod(folder, outputFile):
    graph = getGraph(folder)
    detectHaiStr(graph, folder, outputFile) #Excessive avg dependency
    detectWeakendMod(graph, folder, outputFile) #modularity ratio

#Form 1 - If a file contains declaration of more than one class/define
def detectInsufficientModForm1(folder, outputFile):
    for root, dirs, files in os.walk(folder):
        for file in files:
            if file.endswith(".pp") and not os.path.islink(os.path.join(root, file)):
                fileObj = SourceModel.SM_File.SM_File(os.path.join(root, file))
                detectInsModForm1(fileObj, outputFile)


def detectInsModForm1(fileObj, outputFile):
    classDefineDeclCount = len(fileObj.getOuterClassList()) + len(fileObj.getOuterDefineList())
    if classDefineDeclCount > 1:

        Utilities.reportSmell(outputFile, fileObj.fileName, CONSTS.SMELL_INS_MOD_1, CONSTS.FILE_RES)