コード例 #1
0
ファイル: javadocxfer.py プロジェクト: Lrns123/Srg2Source
def readJavadoc(mcpFilenamePath):
    readingJavadoc = False
    readingIdentifyingLine = False
    javadocLines = []
    javadoc = {}
    expectBlankLineBefore = {}
    lineBeforeJavadoc = None
    for mcpLine in file(mcpFilenamePath).readlines():
        if readingIdentifyingLine:
            # The line after the javadoc is what it refers to
            identifier = srglib.killWhitespace(mcpLine)
            assert len(identifier) != 0, "Nothing associated with javadoc '%s' in %s" % (javadocLines, mcpFilenamePath)
            assert not javadoc.has_key(identifier), "Duplicate javadoc for '%s' in %s: %s" % (identifier, mcpFilenamePath, javadocLines)
            javadoc[identifier] = javadocLines
            expectBlankLineBefore[identifier] = isBlank(lineBeforeJavadoc)
            javadocLines = []
            readingIdentifyingLine = False
        if "/**" in mcpLine:
            readingJavadoc = True
        if readingJavadoc:
            # javadoc is enclosed in /** ... */
            javadocLines.append(mcpLine)
            if "*/" in mcpLine:
                readingJavadoc = False
                readingIdentifyingLine = True 
        if not readingJavadoc and not readingIdentifyingLine:
            lineBeforeJavadoc = mcpLine

    assert not readingJavadoc, "Failed to find end of javadoc %s in %s" % (javadocLines, mcpFilenamePath)
    assert not readingIdentifyingLine, "Failed to find javadoc identifier for %s in %s" % (javadocLines, mcpFilenamePath)

    return javadoc, expectBlankLineBefore
コード例 #2
0
def readJavadoc(mcpFilenamePath):
    readingJavadoc = False
    readingIdentifyingLine = False
    javadocLines = []
    javadoc = {}
    expectBlankLineBefore = {}
    lineBeforeJavadoc = None
    for mcpLine in file(mcpFilenamePath).readlines():
        if readingIdentifyingLine:
            # The line after the javadoc is what it refers to
            identifier = srglib.killWhitespace(mcpLine)
            assert len(identifier
                       ) != 0, "Nothing associated with javadoc '%s' in %s" % (
                           javadocLines, mcpFilenamePath)
            assert not javadoc.has_key(
                identifier), "Duplicate javadoc for '%s' in %s: %s" % (
                    identifier, mcpFilenamePath, javadocLines)
            javadoc[identifier] = javadocLines
            expectBlankLineBefore[identifier] = isBlank(lineBeforeJavadoc)
            javadocLines = []
            readingIdentifyingLine = False
        if "/**" in mcpLine:
            readingJavadoc = True
        if readingJavadoc:
            # javadoc is enclosed in /** ... */
            javadocLines.append(mcpLine)
            if "*/" in mcpLine:
                readingJavadoc = False
                readingIdentifyingLine = True
        if not readingJavadoc and not readingIdentifyingLine:
            lineBeforeJavadoc = mcpLine

    assert not readingJavadoc, "Failed to find end of javadoc %s in %s" % (
        javadocLines, mcpFilenamePath)
    assert not readingIdentifyingLine, "Failed to find javadoc identifier for %s in %s" % (
        javadocLines, mcpFilenamePath)

    return javadoc, expectBlankLineBefore
コード例 #3
0
ファイル: javadocxfer.py プロジェクト: Lrns123/Srg2Source
def addJavadoc(cbFilenamePath, mcpFilenamePath, className):
    javadoc, expectBlankLineBefore = readJavadoc(mcpFilenamePath)
    #pprint.pprint(javadoc)

    newLines = []
    found = 0
    previousLine = None
    for line in file(cbFilenamePath).readlines():
        identifier = srglib.killWhitespace(line)
        if javadoc.has_key(identifier):
            # This line has associated javadoc
            found += 1
            
            if expectBlankLineBefore[identifier]:
                # Add missing blank
                if not isBlank(previousLine):
                    newLines.append("\n")
            else:
                # Remove extra blank
                if isBlank(previousLine):
                    newLines = newLines[:-1]

            newLines.extend(javadoc[identifier])

        newLines.append(line)
        previousLine = line

    newData = "".join(newLines)
    if rewriteFiles:
        file(cbFilenamePath, "w").write(newData)

    missing = len(javadoc) - found
    if found != 0:
        print "Added %s javadoc to %s" % (found, className)
    if missing != 0:
        print "Skipping %s javadoc in %s" % (missing, className)
コード例 #4
0
def addJavadoc(cbFilenamePath, mcpFilenamePath, className):
    javadoc, expectBlankLineBefore = readJavadoc(mcpFilenamePath)
    #pprint.pprint(javadoc)

    newLines = []
    found = 0
    previousLine = None
    for line in file(cbFilenamePath).readlines():
        identifier = srglib.killWhitespace(line)
        if javadoc.has_key(identifier):
            # This line has associated javadoc
            found += 1

            if expectBlankLineBefore[identifier]:
                # Add missing blank
                if not isBlank(previousLine):
                    newLines.append("\n")
            else:
                # Remove extra blank
                if isBlank(previousLine):
                    newLines = newLines[:-1]

            newLines.extend(javadoc[identifier])

        newLines.append(line)
        previousLine = line

    newData = "".join(newLines)
    if rewriteFiles:
        file(cbFilenamePath, "w").write(newData)

    missing = len(javadoc) - found
    if found != 0:
        print "Added %s javadoc to %s" % (found, className)
    if missing != 0:
        print "Skipping %s javadoc in %s" % (missing, className)
コード例 #5
0
def isBlank(line):
    return len(srglib.killWhitespace(line)) == 0
コード例 #6
0
def removeNonPrefixWhitespace(s):
    prefix, rest = re.match(r"(\s*)(.*)", s).groups()
    return prefix + srglib.killWhitespace(rest)
コード例 #7
0
def isBlank(line):
    return len(srglib.killWhitespace(line)) == 0
コード例 #8
0
def removeNonPrefixWhitespace(s):
    prefix, rest = re.match(r"(\s*)(.*)", s).groups()
    return prefix + srglib.killWhitespace(rest)