Fix Java parsing when creating an array of class instances.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 3 Dec 2004 19:30:28 +0000 (19:30 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 3 Dec 2004 19:30:28 +0000 (19:30 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1182 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Tool/JavaCommon.py
src/engine/SCons/Tool/JavaCommonTests.py

index 021d1d4e33e00dc4b1c9e2f10896287903b2735d..507245abc405fff255b8415395af30c9cd8bd49a 100644 (file)
 
 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
index 72196e315d0936b88957ecf0093c6b158371bb24..5c46288161a6ace6f476fd117ce8fb3aa12c0477 100644 (file)
@@ -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,
index 46d1955c732feb945761358e633b8bb366458dfd..05d0fad345faaefaec9773b382fa1c8f2eab71f3 100644 (file)
@@ -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 ]