diff --git a/.classpath b/.classpath deleted file mode 100644 index 4810bd5..0000000 --- a/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/.project b/.project deleted file mode 100644 index b649233..0000000 --- a/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - Thininginjava - - - - - - org.python.pydev.PyDevBuilder - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - org.python.pydev.pythonNature - - diff --git a/.pydevproject b/.pydevproject deleted file mode 100644 index 40e9f40..0000000 --- a/.pydevproject +++ /dev/null @@ -1,5 +0,0 @@ - - -Default -python 2.7 - diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 7341ab1..0000000 --- a/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,11 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.7 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.7 diff --git a/Blips.out b/Blips.out deleted file mode 100644 index 8c2ed85..0000000 Binary files a/Blips.out and /dev/null differ diff --git a/People.xml b/People.xml deleted file mode 100644 index f2c5b97..0000000 --- a/People.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - Dr. Bunsen - Honeydew - - - Gonzo - The Great - - - Phillip J. - Fry - - diff --git a/README.md b/README.md index 234f8eb..bb58a39 100644 --- a/README.md +++ b/README.md @@ -1,2 +1 @@ -《Java编程思想》第四版书中程序示例 -注:仅为代码管理方便,非开源项目。 +ThinkingInJava-ExampleCode diff --git a/data.txt b/data.txt deleted file mode 100644 index 6dc5df6..0000000 --- a/data.txt +++ /dev/null @@ -1 +0,0 @@ -Some text Some more \ No newline at end of file diff --git a/lib/xom-1.2.10.jar b/lib/xom-1.2.10.jar deleted file mode 100644 index 4eb88da..0000000 Binary files a/lib/xom-1.2.10.jar and /dev/null differ diff --git a/src/Copyright.txt b/src/Copyright.txt deleted file mode 100644 index 7833890..0000000 --- a/src/Copyright.txt +++ /dev/null @@ -1,66 +0,0 @@ -This computer source code is Copyright (c)2006 MindView, Inc. -All Rights Reserved. - -Permission to use, copy, modify, and distribute this -computer source code (Source Code) and its documentation -without fee and without a written agreement for the -purposes set forth below is hereby granted, provided that -the above copyright notice, this paragraph and the -following five numbered paragraphs appear in all copies. - -1. Permission is granted to compile the Source Code and to -include the compiled code, in executable format only, in -personal and commercial software programs. - -2. Permission is granted to use the Source Code without -modification in classroom situations, including in -presentation materials, provided that the book "Thinking in -Java" is cited as the origin. - -3. Permission to incorporate the Source Code into printed -media may be obtained by contacting: - -MindView, Inc. 5343 Valle Vista La Mesa, California 91941 -Wayne@MindView.net - -4. The Source Code and documentation are copyrighted by -MindView, Inc. The Source code is provided without express -or implied warranty of any kind, including any implied -warranty of merchantability, fitness for a particular -purpose or non-infringement. MindView, Inc. does not -warrant that the operation of any program that includes the Source Code will be uninterrupted or error-free. MindView, -Inc. makes no representation about the suitability of the -Source Code or of any software that includes the Source -Code for any purpose. The entire risk as to the quality -and performance of any program that includes the Source -Code is with the user of the Source Code. The user -understands that the Source Code was developed for research and instructional purposes and is advised not to rely -exclusively for any reason on the Source Code or any -program that includes the Source Code. Should the Source -Code or any resulting software prove defective, the user -assumes the cost of all necessary servicing, repair, or -correction. - -5. IN NO EVENT SHALL MINDVIEW, INC., OR ITS PUBLISHER BE -LIABLE TO ANY PARTY UNDER ANY LEGAL THEORY FOR DIRECT, -INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -INCLUDING LOST PROFITS, BUSINESS INTERRUPTION, LOSS OF -BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS, OR FOR -PERSONAL INJURIES, ARISING OUT OF THE USE OF THIS SOURCE -CODE AND ITS DOCUMENTATION, OR ARISING OUT OF THE INABILITY TO USE ANY RESULTING PROGRAM, EVEN IF MINDVIEW, INC., OR -ITS PUBLISHER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGE. MINDVIEW, INC. SPECIFICALLY DISCLAIMS ANY -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE SOURCE CODE AND DOCUMENTATION PROVIDED -HEREUNDER IS ON AN "AS IS" BASIS, WITHOUT ANY ACCOMPANYING -SERVICES FROM MINDVIEW, INC., AND MINDVIEW, INC. HAS NO -OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, -ENHANCEMENTS, OR MODIFICATIONS. - -Please note that MindView, Inc. maintains a Web site which -is the sole distribution point for electronic copies of the Source Code, http://www.MindView.net (and official mirror -sites), where it is freely available under the terms stated above. - -If you think you've found an error in the Source Code, -please submit a correction using the feedback system that you will find at http://www.MindView.net. diff --git a/src/DEclipse.py b/src/DEclipse.py deleted file mode 100644 index fc787fe..0000000 --- a/src/DEclipse.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/python -""" -DEclipse.py by Bruce Eckel, for Thinking in Java 4e - -Undoes the effect of Eclipse.py, so that Ant can be used -again to build the code tree. - -You must have Python 2.3 installed to run this program. See www.python.org. -""" -import os - -for path, dirs, files in os.walk('.'): - for file in files: - if file.endswith(".java"): - filepath = path + os.sep + file - code = open(filepath).readlines() - found = False - for n, line in enumerate(code): - if line.find(" /* Added by Eclipse.py */") != -1: - del code[n] - open(filepath, 'w').writelines(code) - - -print "Project ready to be built with Ant." - \ No newline at end of file diff --git a/src/Eclipse.py b/src/Eclipse.py deleted file mode 100644 index 65c4203..0000000 --- a/src/Eclipse.py +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/python -""" -Eclipse.py by Bruce Eckel, for Thinking in Java 4e -Modify or insert package statments so that Eclipse is happy with the code tree. -Run this with no arguments from the root of the code tree. - -The Ant build will not work once you run this program! - -You may also want to modify the dotproject and dotclasspath text below. - -You must have Python 2.3 installed to run this program. See www.python.org. -""" -import os - -os.remove("reusing/Lisa.java"); - -for path, dirs, files in os.walk('.'): - for file in files: - if file.endswith(".java"): - filepath = path + os.sep + file - firstLine = open(filepath).readline().strip() - tagPath = firstLine.split()[1] - tagPath = ".".join(tagPath.split('/')[:-1]) - packageStatement = "package " + tagPath + ";" - code = open(filepath).readlines() - found = False - for line in code: - if line.startswith("package "): - found = True - if not found: - code.insert(1, packageStatement + " /* Added by Eclipse.py */\n") - open(filepath, 'w').writelines(code) - -here = os.path.abspath('.').replace("\\", "/") -if here.startswith("/cygdrive/"): # If using cygwin - here = here.replace("/cygdrive/", "", 1) - here = here[0] + ":" + here[1:] -print "here", here -open(".classpath", 'w').write(\ -""" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -""") # % (here, here)) - -open(".project", 'w').write(\ -""" - - TIJ4 - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - - -""") - -if not os.path.exists(".settings"): - os.mkdir(".settings") -os.chdir(".settings") -open("org.eclipse.jdt.core.prefs", 'w').write(\ -"""#Fri Jan 14 11:03:37 MST 2005 -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.source=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -""") - -print """Project ready to be opened with Eclipse (see www.Eclipse.org) -Use DEclipse.py if you want to go back to building with Ant.""" - \ No newline at end of file diff --git a/src/FindBugsExcluder.py b/src/FindBugsExcluder.py deleted file mode 100644 index e094854..0000000 --- a/src/FindBugsExcluder.py +++ /dev/null @@ -1,53 +0,0 @@ -"""FindBugsExcluder.py -Creates a filter file from the xml and text output of FindBugs -To prepare, you must run -findbugs -textui .> findbugs.txt -findbugs -textui -xml .> findbugs.xml -Once you've run this program you can then run -findbugs -textui -exclude FindBugsFilter-auto.xml . -To exclude the bugs that have been discovered. - -The program includes the suggested changes with each exclusion, -so you can go through FindBugsFilter-auto.xml and decide -to fix things and remove their "Match" nodes. -""" -from xml.dom.minidom import parse -import xml.dom -import os, sys, re, pprint - -xml_buglist = 'findbugs.xml' #'D:\\aaa-TIJ4\\code\\findbugs.xml' -text_buglist = 'findbugs.txt' # 'D:\\aaa-TIJ4\\code\\findbugs.txt' -findbugs_filter = 'FindBugsFilter-auto.xml' # 'D:\\aaa-TIJ4\\code\\FindBugsFilter-auto.xml' - -def main(): - textbugs = [bug.split(':', 1) for bug in file(text_buglist) - if bug.startswith("M ") or bug.startswith("H ")] - textbugs = [(bug[0].split()[2], bug[1].strip()) for bug in textbugs] - dom1 = parse(xml_buglist) - dom2 = xml.dom.getDOMImplementation().createDocument( - None, "FindBugsFilter", None) - bugsDone = [] - for bugNode in [bug for bug in dom1.firstChild.childNodes - if bug.nodeName == "BugInstance"]: - for child in bugNode.childNodes: - if child.nodeName == "Class": - classname = child.attributes.item(0).value - bugtype = bugNode.attributes.item(2).value - if (bugtype, classname) in bugsDone: - continue - else: - bugsDone.append((bugtype, classname)) - match = dom2.createElement("Match") - match.setAttribute("class", classname) - bugCode = dom2.createElement("BugCode") - bugCode.setAttribute("name", bugtype) - match.appendChild(bugCode) - for textbug in textbugs: - if textbug[0] == bugtype and classname in textbug[1]: - match.appendChild(dom2.createComment(textbug[1])) - dom2.documentElement.appendChild(match) - break # out of inner for loop - file(findbugs_filter, 'w').write(dom2.toprettyxml(' ', '\n')) - -if __name__ == "__main__": main() - diff --git a/src/FindBugsFilter.xml b/src/FindBugsFilter.xml deleted file mode 100644 index e394446..0000000 --- a/src/FindBugsFilter.xml +++ /dev/null @@ -1,547 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/JavaLint.py b/src/JavaLint.py deleted file mode 100644 index 4774e0f..0000000 --- a/src/JavaLint.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/python -""" -Runs javac -Xlint on all files in all subdirectories. -Collects results into JavaLint.txt -""" -import os - -outputfile = "JavaLint.txt" - -javadirs = [] -for path, dirs, files in os.walk('.'): - for file in files: - if file.endswith(".java"): - javadirs.append(path) - break - -start = os.getcwd() - -for jd in javadirs: - os.chdir(jd) - print jd - os.system("javac -source 1.5 -Xlint -Xlint:-serial *.java -Xstdout " + outputfile) - os.chdir(start) - -results = open(start + os.sep + outputfile, 'w') - -for jd in javadirs: - messages = open(jd + os.sep + outputfile).read() - if len(messages): - print>>results, '='*40 + "\n" + jd + "\n" + '='*40 + "\n" + messages - \ No newline at end of file diff --git a/src/OutputGenerator.py b/src/OutputGenerator.py deleted file mode 100644 index 9861141..0000000 --- a/src/OutputGenerator.py +++ /dev/null @@ -1,133 +0,0 @@ -#!/usr/bin/python -""" -Runs a Java program, appends output if it's not there - --force as first argument when doing batch files forces overwrite - -""" -import os, re, sys - -argTag = '// {Args: ' -oldOutput = re.compile("/* Output:.*?\n(.*)\n\*///:~(?s)") - -def makeOutputIncludedFile(path, fileName, changeReport, force = False): - oldDir = os.getcwd() - os.chdir(path) - base = fileName.split('.')[0] - package = '' - args = '' - command = None - for line in file(fileName): - if line.startswith("} /*"): - break # Out of for loop - if line.startswith("package"): - words = line.strip().split() - package = words[1][:-1] + '.' # remove ';' - if line.startswith(argTag): - args = line[len(argTag):].strip() - assert args.rfind('}') != -1, "%s, %s" % (args, fileName) - args = " " +args[:args.rfind('}')] - if line.startswith("// {main:"): - base = line.split()[-1] - base = base[:-1] - if line.startswith("// {Exec:"): - command = line.split(':', 1)[1].strip()[:-1] - if not command: - command = "java " + package + base + args - command += "> " + base + "-output.txt" - print command - result = os.system(command) - if(result != 0): - raise Exception, "Command returned nonzero value: " + str(result) - # Read output file that was just generated: - results = file(base + "-output.txt").read().strip() - # Strip off trailing spaces on each line: - results = "\n".join([line.rstrip() for line in results.split("\n")]) - results = results.replace('\t', ' ') - if results: - if force or not oldOutput.findall(file(fileName).read()): - processedText = createProcessedJavaText(results, fileName) - open(fileName, 'w').write(processedText + "\n") - if changeReport: - changeReport.write(os.path.join(path, fileName) + "\n") - return # Don't need to try for error output - ##### Duplicate for standard error output: - command += " 2> " + base + "-erroroutput.txt" - print command - result = os.system(command) - if(result != 0): - raise Exception, "Command returned nonzero value: " + str(result) - # Read error file that was just generated: - results = file(base + "-erroroutput.txt").read().strip() - # Strip off trailing spaces on each line: - results = "\n".join([line.rstrip() for line in results.split("\n")]) - results = results.replace('\t', ' ') - if results: - if force or not oldOutput.findall(file(fileName).read()): - processedText = createProcessedJavaText(results, fileName) - open(fileName, 'w').write(processedText + "\n") - if changeReport: - changeReport.write(os.path.join(path, fileName) + "\n") - os.chdir(oldDir) - -def createProcessedJavaText(results, fileName): - processedJava = '' - for line in [line.rstrip() for line in file(fileName)]: - if line.startswith("} ///:~"): - processedJava += "} /* Output:\n" + results + "\n*///:~" - return processedJava - if line.startswith("} /* Output:"): - processedJava += line + "\n" + results + "\n*///:~" # Preserve modifiers - return processedJava - processedJava += line + "\n" - raise Exception, "No marker found at end of file " + path + " " + fileName - -class ReportFile: - def __init__(self, filePath): - self.filePath = filePath - self.file = None - def write(self, line): - if not self.file: - self.file = file(self.filePath, 'w') - self.file.write(line) - print line - def close(self): - if self.file: - self.file.close() - -if __name__ == "__main__": - start = os.getcwd() - args = sys.argv[1:] - forceFlag = False - if len(args): - if args[0] == "-force": - forceFlag = True - print "forceFlag = ", forceFlag - del args[0] - if len(args)> 0: - for javaSource in args: - if javaSource.endswith("."): javaSource = javaSource[:-1] - if not javaSource.endswith(".java"): javaSource += ".java" - os.system("javac " + javaSource) - makeOutputIncludedFile(os.getcwd(), javaSource, None, force = True) - else: - changeReport = ReportFile(os.path.join(start, "Changes.txt")) - for root, dirs, files in os.walk('.'): - if (os.sep + "gui") in root: continue - path = os.path.normpath(os.path.join(start,root)) - print path - for name in [name for name in files if name.endswith(".java")]: - java = file(os.path.join(path, name)).read() - if "public static void main(String" in java and \ - not "{RunByHand}" in java and \ - not "{ThrowsException}" in java and \ - not "/* (Execute to see output) *///:~" in java and \ - not "} /* Same output as" in java: - if forceFlag or not "} /* Output:" in java: - print "\t", name - makeOutputIncludedFile(path, name, changeReport, force = forceFlag) - changeReport.close() - os.system("uedit32 /f Changes.txt &") - - - \ No newline at end of file diff --git a/src/OutputVerifier.py b/src/OutputVerifier.py deleted file mode 100644 index 4300b54..0000000 --- a/src/OutputVerifier.py +++ /dev/null @@ -1,200 +0,0 @@ -#!/usr/bin/python -""" -To do: - -3) command-line argument (to test a single file) - -- What about exceptions and aborts? - --If ...is embedded anywhere in a line, that portion becomes a .*? regexp - ---------------- -Find files with -/* Output: - -Run the programs and capture the output, compare with anticipated output. - -/* Output: (80% match) - -For files that vary from run to run - -Complete punt: -/* Output: (Sample) - -(More elaborate design in SimpleTest1.py) -""" -import os, re, glob, sys, string, codecs -from difflib import SequenceMatcher - -argTag = '// {Args: ' -targetOutput = re.compile("/* Output:(.*?)\n(.*)\n\*///:~", re.DOTALL) - -class SimpleTest: - - def __init__(self, fileName, text, referencePath, reportFile): - self.fileName = fileName - self.normalOutput = self.fileName + "-output.txt" - self.errorOutput = self.fileName + "-erroroutput.txt" - self.text = text - self.referencePath = referencePath - self.reportFile = reportFile - self.package = "" - self.args = "" - self.runTest = True - self.insertOutput = True - self.EmbeddedComparisonOutput = False - self.comparisonFile = None - self.lines = self.text.split("\n") - for line in self.lines: - if "{RunByHand}" in line or \ - line.startswith("import javax.swing.*;") or \ - "c12:ZipCompress.java" in line or \ - "/* (Execute to see output) *///:~" in line: - self.runTest = False - if line.startswith("package"): - self.package = line.split()[1][:-1] + "." - if line.startswith(argTag): - self.args = line[len(argTag):].strip() - assert self.args.rfind('}') != -1, "%s, %s" % (self.args, referencePath) - self.args = self.args[:self.args.rfind('}')] - if line.startswith("// {main:"): - self.fileName = line.split()[-1][:-1] - if line.startswith("// {Exec:"): - self.command = line.split(':', 1)[1].strip()[:-1] - if "/* Output:" in line: - self.EmbeddedComparisonOutput = True - if line.startswith("} /*"): - break # Out of for loop - #if "} ///:~" in line: # Extra space - # self.insertOutput = False - - def run(self): - if not self.runTest: return - if not hasattr(self, "command"): - self.command = "java " + self.package + self.fileName + " " + self.args - # Capture standard output into a local file. - self.command = self.command + "> " + self.normalOutput - print self.command - os.system(self.command) - if os.stat(self.normalOutput).st_size: - return self.compareResults(self.normalOutput) - # Capture error output into a local file. - # The '2>' requires cygwin under Windows, or *nix: - self.command = self.command + " 2> " + self.errorOutput - print self.command - os.system(self.command) - return self.compareResults(self.errorOutput) - - def compareResults(self, fileName): - # Read output file that was just generated: - results = makePrintable(file(fileName).read()) - results = results.replace('\t', ' ') - results = results.strip() - file("Generated.txt",'w').write(results) - # Strip off trailing spaces on each line: - results = "\n".join([line.rstrip() for line in results.split("\n")]) - controlSample = self.getControlSample() - ratio = 1.0 - if controlSample: - controlOutput = controlSample.group(2).rstrip() - if "\n..." in controlOutput: - controlLines = controlOutput.split("\n")[:-1] - resultLines = results.split("\n")[:len(controlLines)] - controlOutput = "\n".join(controlLines) - results = "\n".join(resultLines) - file("controlOutput.txt",'w').write(controlOutput) - modifier = controlSample.group(1) - if "match" in modifier: - ratio = float(re.findall("\d+", modifier)[0]) / 100 - print "Looking for", ratio, "match" - if "Sample" in modifier: - ratio = 0.0 - actualRatio = SequenceMatcher(None, controlOutput, results).ratio() - if actualRatio < ratio: - self.reportFile.write("mismatch in " + self.referencePath + "\n") - self.reportFile.write("Actual ratio " + str(actualRatio) + "\n") - self.reportFile.write("expected:\n") - self.reportFile.write(controlOutput + "\n") - self.reportFile.write("----------actual:----------\n") - self.reportFile.write(results + "\n") - file(self.fileName + "-control.txt", 'w').write(controlOutput) - file(self.fileName + "-results.txt", 'w').write(results) - self.reportFile.write("---------------------------\n") - os.system("cmp " + self.fileName + "-control.txt " - + self.fileName + "-results.txt" - + "> cmp-out.txt") - self.reportFile.write(file("cmp-out.txt").read()) - self.reportFile.write("=" * 40 + "\n") - - else: - pass #!!! No control sample, create initial one here - - def appendOutput(self): - if self.insertOutput: - # Rewrite the tail of the source file if the result is nonzero - self.lines[-2] = '}' - self.lines[-1] = "/* Output:" - for tline in file(self.fileName + "-output.txt"): - self.lines.append(tline.rstrip()) - self.lines.append("*///:~") - self.lines.append("") - file(self.fileName + ".java", 'w').write("\n".join(self.lines)) - - def getControlSample(self): - """Finds the control sample, returns an re group - First element is the arguments, second is the actual data""" - if self.EmbeddedComparisonOutput: - self.sourceOutput = targetOutput.search(self.text) - else: - return None - return self.sourceOutput - -def makePrintable(s): - for c in s: - if c not in string.printable: return _makePrintable(s) - return s - -def _makePrintable(s): - result = '' - for c in s: - if c not in string.printable: result += ' ' - else: result += c - return result - -class ReportFile: - def __init__(self, filePath): - self.filePath = filePath - self.file = None - def write(self, line): - if not self.file: - self.file = file(self.filePath, 'w') - self.file.write(line) - print line - def close(self): - if self.file: - self.file.close() - -if __name__ == "__main__": - if len(sys.argv)> 1: - javaSource = sys.argv[1] - if javaSource.endswith("."): javaSource = javaSource[:-1] - if not javaSource.endswith(".java"): javaSource += ".java" - os.system("javac " + javaSource) - SimpleTest(javaSource.split('.')[0], file(javaSource).read(), javaSource, sys.stdout).run() - sys.exit() - start = os.getcwd() - reportFile = ReportFile(start + os.sep + "OutputErrors.txt") - for root, dirs, files in os.walk('.'): - print root - os.chdir(root) - for f in [name.split('.')[0] for name in files if name.endswith(".java")]: - text = file(f + ".java").read() - # Only perform verification if there is an output tag: - if text.find("/* Output:") != -1: - referencePath = os.path.join(root, f + ".java") - SimpleTest(f, text, referencePath, reportFile).run() - os.chdir(start) - reportFile.close() - if reportFile.file: - print "Errors in OutputErrors.txt" - diff --git a/src/RedundantImportDetector.py b/src/RedundantImportDetector.py deleted file mode 100644 index 8215196..0000000 --- a/src/RedundantImportDetector.py +++ /dev/null @@ -1,54 +0,0 @@ -"""RedundantImportDetector.py -Discover redundant java imports using brute force. -Requires Python 2.3""" -import os, sys, re -from glob import glob - -reportFile = file("RedundantImports.txt", 'w') - -startDir = 'D:\\aaa-TIJ4\\code' - -# Regular expression to find the block of import statements: -findImports = re.compile("\n(?:import .*?\n)+") - -baseDir = os.path.abspath(".") - -print "basDir:", baseDir - -def main(): - for javaFile in glob("*.java") + glob("**/*.java"): - print javaFile - checkImports(os.path.join(baseDir, javaFile)) - -def checkImports(javaFile): - java = file(javaFile).read() - imports = findImports.search(java) - if imports: - imports = [f for f in imports.group(0).split('\n') if f != ''] - fileParts = findImports.split(java) - assert len(fileParts) == 2 - for mutated in mutateImports(imports): - file(javaFile, 'w').write(fileParts[0] + mutated + fileParts[1]) - print "changing to", os.path.dirname(javaFile) - os.chdir(os.path.dirname(javaFile)) - if os.system("javac " + os.path.basename(javaFile)) == 0: - print>>reportFile, javaFile + "\n" + mutated - redundantRemoved = "\n".join( - [m for m in mutated.split("\n") - if not m.startswith("//")]) - print>>reportFile, redundantRemoved - file(javaFile, 'w').write(fileParts[0] + - redundantRemoved + fileParts[1]) - return # No further attempts - file(javaFile, 'w').write(java) # Restore original file - -def mutateImports(imports): - '''Generates different versions of imports, each with a - different line commented out''' - for i in range(len(imports)): - mutated = imports[:] - mutated[i] = '//' + mutated[i] - yield "\n".join([''] + mutated + ['']) - -if __name__ == "__main__": main() - diff --git a/src/build.xml b/src/build.xml deleted file mode 100644 index 272ed2a..0000000 --- a/src/build.xml +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - Main build.xml for the source code for - Thinking in Java, 4th Edition by Bruce Eckel - Code available at http://www.MindView.net - See copyright notice in CopyRight.txt - - Ant available from: http://jakarta.apache.org/ant - - To see options, type: ant -p - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/chapterOrder.xml b/src/chapterOrder.xml deleted file mode 100644 index 4f5a16e..0000000 --- a/src/chapterOrder.xml +++ /dev/null @@ -1,28 +0,0 @@ - \ No newline at end of file diff --git a/worm.out b/worm.out deleted file mode 100644 index 85f9371..0000000 Binary files a/worm.out and /dev/null differ

AltStyle によって変換されたページ (->オリジナル) /