Example #1
0
def getRenameMaps(srgFiles, mcpConfDir, lvRangeMapFile, dumpRenameMap, srcRoot, excFiles):
    maps = {}
    importMaps = {}

    # CB -> packaged MCP class/field/method
    _notReallyThePackageMap, classMap, fieldMap, methodMap, methodSigMap = srglib.readMultipleSrgs(srgFiles)
    for old,new in classMap.iteritems():
        maps["class "+old]=srglib.splitBaseName(new) 
        importMaps["class "+old]=srglib.internalName2Source(new)  # when renaming class, need to import it, too
    for old,new in fieldMap.iteritems():
        maps["field "+old]=srglib.splitBaseName(new)
    for old,new in methodMap.iteritems():
        maps["method "+old]=srglib.splitBaseName(new)

    # CB class -> MCP package name
    for cbClass, mcpClass in classMap.iteritems():
        cbFile = "src/main/java/"+cbClass+".java"
        mcpPackage = srglib.splitPackageName(mcpClass)
        maps["package "+cbClass] = srglib.internalName2Source(mcpPackage)

    # Read parameter map from MCP.. it comes from MCP with MCP namings, so have to remap to CB 
    invMethodMap, invMethodSigMap = srglib.invertMethodMap(methodMap, methodSigMap)
    invClassMap = srglib.invertDict(classMap)
    if mcpConfDir is not None:
        mcpParamMap = srglib.readParameterMap(mcpConfDir, apply_map = False)
        cbParamMap, removedParamMap = srglib.remapParameterMap(mcpParamMap, invMethodMap, invMethodSigMap, invClassMap)
        if not excFiles is None:
            for file in excFiles:
                tmp = srglib.readParameterMap(mcpConfDir, file, apply_map = False)
                tmp_clean, _ = srglib.remapParameterMap(tmp, invMethodMap, invMethodSigMap, invClassMap, keep_missing=True)
                pprint(tmp_clean)
                cbParamMap.update(tmp_clean)
        # removedParamMap = methods in FML/MCP repackaged+joined but not CB = client-only methods

    else:
        # don't rename any parameters
        mcpParamMap = {}
        cbParamMap = {}
        removedParamMap = {}

    for old,new in cbParamMap.iteritems():
        for i in range(0,len(new)):
            maps["param %s %s" % (old, i)] = new[i]

    # Local variable map - position in source -> name; derived from MCP rangemap
    if lvRangeMapFile is not None:
        readLocalVariableMap(lvRangeMapFile, maps, invClassMap, invMethodMap, invMethodSigMap, srcRoot)

    if dumpRenameMap:
        for key in sorted(maps.keys()):
            newName = maps[key]
            print "RENAME MAP: %s -> %s" % (key, newName)

    return maps, importMaps
def getRenameMaps(srgFiles, mcpConfDir, lvRangeMapFile, dumpRenameMap, srcRoot):
    maps = {}
    importMaps = {}

    # CB -> packaged MCP class/field/method
    _notReallyThePackageMap, classMap, fieldMap, methodMap, methodSigMap = srglib.readMultipleSrgs(srgFiles)
    for old,new in classMap.iteritems():
        maps["class "+old]=srglib.splitBaseName(new) 
        importMaps["class "+old]=srglib.internalName2Source(new)  # when renaming class, need to import it, too
    for old,new in fieldMap.iteritems():
        maps["field "+old]=srglib.splitBaseName(new)
    for old,new in methodMap.iteritems():
        maps["method "+old]=srglib.splitBaseName(new)

    # CB class -> MCP package name
    for cbClass, mcpClass in classMap.iteritems():
        cbFile = "src/main/java/"+cbClass+".java"
        mcpPackage = srglib.splitPackageName(mcpClass)
        maps["package "+cbClass] = srglib.internalName2Source(mcpPackage)

    # Read parameter map from MCP.. it comes from MCP with MCP namings, so have to remap to CB 
    invMethodMap, invMethodSigMap = srglib.invertMethodMap(methodMap, methodSigMap)
    invClassMap = srglib.invertDict(classMap)
    if mcpConfDir is not None:
        mcpParamMap = srglib.readParameterMap(mcpConfDir)
        cbParamMap, removedParamMap = srglib.remapParameterMap(mcpParamMap, invMethodMap, invMethodSigMap, invClassMap)
        # removedParamMap = methods in FML/MCP repackaged+joined but not CB = client-only methods

    else:
        # don't rename any parameters
        mcpParamMap = {}
        cbParamMap = {}
        removedParamMap = {}

    for old,new in cbParamMap.iteritems():
        for i in range(0,len(new)):
            maps["param %s %s" % (old, i)] = new[i]

    # Local variable map - position in source -> name; derived from MCP rangemap
    if lvRangeMapFile is not None:
        readLocalVariableMap(lvRangeMapFile, maps, invClassMap, invMethodMap, invMethodSigMap, srcRoot)

    if dumpRenameMap:
        for key in sorted(maps.keys()):
            newName = maps[key]
            print "RENAME MAP: %s -> %s" % (key, newName)

    return maps, importMaps
def getRenameMaps(srgFiles, mcpConfDir, mcpRangeMapFile, dumpRenameMap, srcRoot):
    maps = {}
    importMaps = {}

    # CB -> packaged MCP class/field/method
    _notReallyThePackageMap, classMap, fieldMap, methodMap, methodSigMap = srglib.readMultipleSrgs(srgFiles)
    for old, new in classMap.iteritems():
        maps["class " + old] = srglib.splitBaseName(new)
        importMaps["class " + old] = srglib.internalName2Source(new)  # when renaming class, need to import it, too
    for old, new in fieldMap.iteritems():
        maps["field " + old] = srglib.splitBaseName(new)
    for old, new in methodMap.iteritems():
        maps["method " + old] = srglib.splitBaseName(new)

    # CB class -> MCP package name
    for cbClass, mcpClass in classMap.iteritems():
        cbFile = "src/main/java/" + cbClass + ".java"
        mcpPackage = srglib.splitPackageName(mcpClass)
        maps["package " + cbClass] = srglib.internalName2Source(mcpPackage)

    # Read parameter map.. it comes from MCP with MCP namings, so have to remap to CB
    mcpParamMap = srglib.readParameterMap(mcpConfDir)
    invMethodMap, invMethodSigMap = srglib.invertMethodMap(methodMap, methodSigMap)
    invClassMap = srglib.invertDict(classMap)
    cbParamMap, removedParamMap = srglib.remapParameterMap(mcpParamMap, invMethodMap, invMethodSigMap, invClassMap)
    # removedParamMap = methods in FML/MCP repackaged+joined but not CB = client-only methods

    for old, new in cbParamMap.iteritems():
        for i in range(0, len(new)):
            maps["param %s %s" % (old, i)] = new[i]

    # Local variable map - position in source -> name; derived from MCP rangemap
    readLocalVariableMap(mcpRangeMapFile, maps, invClassMap, invMethodMap, invMethodSigMap, srcRoot)

    if dumpRenameMap:
        for key in sorted(maps.keys()):
            newName = maps[key]
            print "RENAME MAP: %s -> %s" % (key, newName)

    return maps, importMaps