<commit_before>'''
Created on Mar 12, 2014

@author: tangliuxiang
'''
import SmaliLib
import SmaliEntry
import Smali
import string
import SmaliMethod
import sys
import SmaliParser
import os
import getopt
import SAutoCom

sys.path.append('%s/autopatch' %os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from log import Log

class Options(object): pass
OPTIONS = Options()
OPTIONS.autoComplete = False

OPTIONS.formatSmali = False
OPTIONS.libraryPath = None
OPTIONS.filterOutDir = []

OPTIONS.replaceMethod = False

MAX_CHECK_INVOKE_DEEP = 50
class SCheck(object):
    '''
    classdocs
    '''


    def __init__(self, vendorDir, aospDir, bospDir, mergedDir):
        '''
        Constructor
        '''
        self.mVSLib = SmaliLib.SmaliLib(vendorDir)
        self.mASLib = SmaliLib.SmaliLib(aospDir)
        self.mBSLib = SmaliLib.SmaliLib(bospDir)
        self.mMSLib = SmaliLib.SmaliLib(mergedDir)
    
    def autoComplete(self, smali):
        unImplementMethods = self.getUnImplementMethods(smali)
        canReplaceEntryList = []
        canNotReplaceEntryList = []
        if unImplementMethods is not None and len(unImplementMethods) > 0:
            vSmali = self.mVSLib.getSmali(smali.getClassName())
            if vSmali is None:
                Log.e("Can't get smali %s from vendor: %s"  %(smali.getClassName(), string.join(unImplementMethods)))
                return canReplaceEntryList
            
            unImplMethodEntryList = getEntryListByNameList(vSmali, SmaliEntry.METHOD, unImplementMethods)
            (canReplaceEntryList, canNotReplaceEntryList) = getCanReplaceMethods(self.mMSLib, self.mVSLib, smali.getClassName(), unImplMethodEntryList)
        
            for entry in canReplaceEntryList:
                Log.d("   Can Replace: %s" %(entry.getSimpleString()))

            for entry in canNotReplaceEntryList:
                Log.d("   Can not Replace: %s" %(entry.getSimpleString()))

        return (canReplaceEntryList, canNotReplaceEntryList)
        
    def getUnImplementMethods(self, smali):
        return getUnImplementMethods(self.mASLib, self.mMSLib, smali)
        
    def getCanReplaceToBaiduMethods(self, smali, methodEntryList):
        return getCanReplaceMethods(self.mMSLib, self.mBSLib, smali.getClassName(), methodEntryList)
    
def getEntryListByNameList(smali, type, nameList):
    outList = []<commit_msg>[R47]: fix the error when doesn't have smali in vendor<commit_after>'''
Created on Mar 12, 2014

@author: tangliuxiang
'''
import SmaliLib
import SmaliEntry
import Smali
import string
import SmaliMethod
import sys
import SmaliParser
import os
import getopt
import SAutoCom

sys.path.append('%s/autopatch' %os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from log import Log

class Options(object): pass
OPTIONS = Options()
OPTIONS.autoComplete = False

OPTIONS.formatSmali = False
OPTIONS.libraryPath = None
OPTIONS.filterOutDir = []

OPTIONS.replaceMethod = False

MAX_CHECK_INVOKE_DEEP = 50
class SCheck(object):
    '''
    classdocs
    '''


    def __init__(self, vendorDir, aospDir, bospDir, mergedDir):
        '''
        Constructor
        '''
        self.mVSLib = SmaliLib.SmaliLib(vendorDir)
        self.mASLib = SmaliLib.SmaliLib(aospDir)
        self.mBSLib = SmaliLib.SmaliLib(bospDir)
        self.mMSLib = SmaliLib.SmaliLib(mergedDir)
    
    def autoComplete(self, smali):
        unImplementMethods = self.getUnImplementMethods(smali)
        canReplaceEntryList = []
        canNotReplaceEntryList = []
        if unImplementMethods is not None and len(unImplementMethods) > 0:
            vSmali = self.mVSLib.getSmali(smali.getClassName())
            if vSmali is None:
                Log.e("Can't get smali %s from vendor: %s"  %(smali.getClassName(), string.join(unImplementMethods)))
                return (canReplaceEntryList, canNotReplaceEntryList)
            
            unImplMethodEntryList = getEntryListByNameList(vSmali, SmaliEntry.METHOD, unImplementMethods)
            (canReplaceEntryList, canNotReplaceEntryList) = getCanReplaceMethods(self.mMSLib, self.mVSLib, smali.getClassName(), unImplMethodEntryList)
        
            for entry in canReplaceEntryList:
                Log.d("   Can Replace: %s" %(entry.getSimpleString()))

            for entry in canNotReplaceEntryList:
                Log.d("   Can not Replace: %s" %(entry.getSimpleString()))

        return (canReplaceEntryList, canNotReplaceEntryList)
        
    def getUnImplementMethods(self, smali):
        return getUnImplementMethods(self.mASLib, self.mMSLib, smali)
        
    def getCanReplaceToBaiduMethods(self, smali, methodEntryList):
        return getCanReplaceMethods(self.mMSLib, self.mBSLib, smali.getClassName(), methodEntryList)
    
def getEntryListByNameList(smali, type, nameList):
    outList = []
{'fraction_non_alphanumeric': 0.09402769167183303, 'fraction_numerical': 0.0041330853482124405, 'mean_word_length': 3.2270742358078603, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3180133', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1479, 'n_words': 316}