From: stevenknight Date: Fri, 3 Dec 2004 19:30:28 +0000 (+0000) Subject: Fix Java parsing when creating an array of class instances. X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=26f7ff82aceea63e216eac91fd121039f0e56368;p=scons.git Fix Java parsing when creating an array of class instances. git-svn-id: http://scons.tigris.org/svn/scons/trunk@1182 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 021d1d4e..507245ab 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -10,6 +10,11 @@ RELEASE 0.97 - XXX + From Anonymous: + + - Fix Java parsing to avoid erroneously identifying a new array + of class instances as an anonymous inner class. + From Chad Austin: - Allow Help() to be called multiple times, appending to the help diff --git a/src/engine/SCons/Tool/JavaCommon.py b/src/engine/SCons/Tool/JavaCommon.py index 72196e31..5c462881 100644 --- a/src/engine/SCons/Tool/JavaCommon.py +++ b/src/engine/SCons/Tool/JavaCommon.py @@ -45,10 +45,11 @@ if java_parsing: # A regular expression that will find, in a java file: newlines; # any alphanumeric token (keyword, class name, specifier); open or # close brackets; a single-line comment "//"; the multi-line comment - # begin and end tokens /* and */; single or double quotes; and - # single or double quotes preceeded by a backslash. + # begin and end tokens /* and */; single or double quotes; + # single or double quotes preceeded by a backslash; array + # declarations "[]". _reToken = re.compile(r'(\n|//|\\[\'"]|[\'"\{\}]|[A-Za-z_][\w\.]*|' + - r'/\*|\*/)') + r'/\*|\*/|\[\])') class OuterState: """The initial state for parsing a Java file for classes, diff --git a/src/engine/SCons/Tool/JavaCommonTests.py b/src/engine/SCons/Tool/JavaCommonTests.py index 46d1955c..05d0fad3 100644 --- a/src/engine/SCons/Tool/JavaCommonTests.py +++ b/src/engine/SCons/Tool/JavaCommonTests.py @@ -171,6 +171,22 @@ public class Example1 extends UnicastRemoteObject implements Hello { assert pkg_dir == os.path.join('com', 'sub', 'foo'), pkg_dir assert classes == ['Example1'], classes + def test_arrays(self): + """Test arrays of class instances""" + + pkg_dir, classes = SCons.Tool.JavaCommon.parse_java("""\ +public class Test { + MyClass abc = new MyClass(); + MyClass xyz = new MyClass(); + MyClass _array[] = new MyClass[] { + abc, + xyz + } +} +""") + assert pkg_dir == None, pkg_dir + assert classes == ['Test'], classes + if __name__ == "__main__": suite = unittest.TestSuite() tclasses = [ parse_javaTestCase ]