OLD | NEW |
1 """SCons.Tool.JavaCommon | 1 """SCons.Tool.JavaCommon |
2 | 2 |
3 Stuff for processing Java. | 3 Stuff for processing Java. |
4 | 4 |
5 """ | 5 """ |
6 | 6 |
7 # | 7 # |
8 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundat
ion | 8 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundat
ion |
9 # | 9 # |
10 # Permission is hereby granted, free of charge, to any person obtaining | 10 # Permission is hereby granted, free of charge, to any person obtaining |
11 # a copy of this software and associated documentation files (the | 11 # a copy of this software and associated documentation files (the |
12 # "Software"), to deal in the Software without restriction, including | 12 # "Software"), to deal in the Software without restriction, including |
13 # without limitation the rights to use, copy, modify, merge, publish, | 13 # without limitation the rights to use, copy, modify, merge, publish, |
14 # distribute, sublicense, and/or sell copies of the Software, and to | 14 # distribute, sublicense, and/or sell copies of the Software, and to |
15 # permit persons to whom the Software is furnished to do so, subject to | 15 # permit persons to whom the Software is furnished to do so, subject to |
16 # the following conditions: | 16 # the following conditions: |
17 # | 17 # |
18 # The above copyright notice and this permission notice shall be included | 18 # The above copyright notice and this permission notice shall be included |
19 # in all copies or substantial portions of the Software. | 19 # in all copies or substantial portions of the Software. |
20 # | 20 # |
21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | 21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY |
22 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | 22 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE |
23 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | 23 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
24 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | 24 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
25 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | 25 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
26 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | 26 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
27 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 27 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
28 # | 28 # |
29 | 29 |
30 __revision__ = "src/engine/SCons/Tool/JavaCommon.py 3603 2008/10/10 05:46:45 sco
ns" | 30 __revision__ = "src/engine/SCons/Tool/JavaCommon.py 3842 2008/12/20 22:59:52 sco
ns" |
31 | 31 |
32 import os | 32 import os |
33 import os.path | 33 import os.path |
34 import re | 34 import re |
35 import string | 35 import string |
36 | 36 |
37 java_parsing = 1 | 37 java_parsing = 1 |
38 | 38 |
39 default_java_version = '1.4' | 39 default_java_version = '1.4' |
40 | 40 |
(...skipping 27 matching lines...) Expand all Loading... |
68 if not version in ('1.1', '1.2', '1.3','1.4', '1.5', '1.6'): | 68 if not version in ('1.1', '1.2', '1.3','1.4', '1.5', '1.6'): |
69 msg = "Java version %s not supported" % version | 69 msg = "Java version %s not supported" % version |
70 raise NotImplementedError, msg | 70 raise NotImplementedError, msg |
71 | 71 |
72 self.version = version | 72 self.version = version |
73 self.listClasses = [] | 73 self.listClasses = [] |
74 self.listOutputs = [] | 74 self.listOutputs = [] |
75 self.stackBrackets = [] | 75 self.stackBrackets = [] |
76 self.brackets = 0 | 76 self.brackets = 0 |
77 self.nextAnon = 1 | 77 self.nextAnon = 1 |
| 78 self.localClasses = [] |
78 self.stackAnonClassBrackets = [] | 79 self.stackAnonClassBrackets = [] |
79 self.anonStacksStack = [[0]] | 80 self.anonStacksStack = [[0]] |
80 self.package = None | 81 self.package = None |
81 | 82 |
82 def trace(self): | 83 def trace(self): |
83 pass | 84 pass |
84 | 85 |
85 def __getClassState(self): | 86 def __getClassState(self): |
86 try: | 87 try: |
87 return self.classState | 88 return self.classState |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 return self.anonStacksStack[-1] | 120 return self.anonStacksStack[-1] |
120 | 121 |
121 def openBracket(self): | 122 def openBracket(self): |
122 self.brackets = self.brackets + 1 | 123 self.brackets = self.brackets + 1 |
123 | 124 |
124 def closeBracket(self): | 125 def closeBracket(self): |
125 self.brackets = self.brackets - 1 | 126 self.brackets = self.brackets - 1 |
126 if len(self.stackBrackets) and \ | 127 if len(self.stackBrackets) and \ |
127 self.brackets == self.stackBrackets[-1]: | 128 self.brackets == self.stackBrackets[-1]: |
128 self.listOutputs.append(string.join(self.listClasses, '$')) | 129 self.listOutputs.append(string.join(self.listClasses, '$')) |
| 130 self.localClasses.pop() |
129 self.listClasses.pop() | 131 self.listClasses.pop() |
130 self.anonStacksStack.pop() | 132 self.anonStacksStack.pop() |
131 self.stackBrackets.pop() | 133 self.stackBrackets.pop() |
132 if len(self.stackAnonClassBrackets) and \ | 134 if len(self.stackAnonClassBrackets) and \ |
133 self.brackets == self.stackAnonClassBrackets[-1]: | 135 self.brackets == self.stackAnonClassBrackets[-1]: |
134 self.__getAnonStack().pop() | 136 self.__getAnonStack().pop() |
135 self.stackAnonClassBrackets.pop() | 137 self.stackAnonClassBrackets.pop() |
136 | 138 |
137 def parseToken(self, token): | 139 def parseToken(self, token): |
138 if token[:2] == '//': | 140 if token[:2] == '//': |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 235 |
234 class ClassState: | 236 class ClassState: |
235 """A state we go into when we hit a class or interface keyword.""" | 237 """A state we go into when we hit a class or interface keyword.""" |
236 def __init__(self, outer_state): | 238 def __init__(self, outer_state): |
237 # outer_state is always an instance of OuterState | 239 # outer_state is always an instance of OuterState |
238 self.outer_state = outer_state | 240 self.outer_state = outer_state |
239 def parseToken(self, token): | 241 def parseToken(self, token): |
240 # the next non-whitespace token should be the name of the class | 242 # the next non-whitespace token should be the name of the class |
241 if token == '\n': | 243 if token == '\n': |
242 return self | 244 return self |
| 245 # If that's an inner class which is declared in a method, it |
| 246 # requires an index prepended to the class-name, e.g. |
| 247 # 'Foo$1Inner' (Tigris Issue 2087) |
| 248 if self.outer_state.localClasses and \ |
| 249 self.outer_state.stackBrackets[-1] > \ |
| 250 self.outer_state.stackBrackets[-2]+1: |
| 251 locals = self.outer_state.localClasses[-1] |
| 252 try: |
| 253 idx = locals[token] |
| 254 locals[token] = locals[token]+1 |
| 255 except KeyError: |
| 256 locals[token] = 1 |
| 257 token = str(locals[token]) + token |
| 258 self.outer_state.localClasses.append({}) |
243 self.outer_state.listClasses.append(token) | 259 self.outer_state.listClasses.append(token) |
244 self.outer_state.anonStacksStack.append([0]) | 260 self.outer_state.anonStacksStack.append([0]) |
245 return self.outer_state | 261 return self.outer_state |
246 | 262 |
247 class IgnoreState: | 263 class IgnoreState: |
248 """A state that will ignore all tokens until it gets to a | 264 """A state that will ignore all tokens until it gets to a |
249 specified token.""" | 265 specified token.""" |
250 def __init__(self, ignore_until, old_state): | 266 def __init__(self, ignore_until, old_state): |
251 self.ignore_until = ignore_until | 267 self.ignore_until = ignore_until |
252 self.old_state = old_state | 268 self.old_state = old_state |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 # to how long the Java compiler itself seems to take...). | 308 # to how long the Java compiler itself seems to take...). |
293 | 309 |
294 def parse_java_file(fn): | 310 def parse_java_file(fn): |
295 """ "Parse" a .java file. | 311 """ "Parse" a .java file. |
296 | 312 |
297 This actually just splits the file name, so the assumption here | 313 This actually just splits the file name, so the assumption here |
298 is that the file name matches the public class name, and that | 314 is that the file name matches the public class name, and that |
299 the path to the file is the same as the package name. | 315 the path to the file is the same as the package name. |
300 """ | 316 """ |
301 return os.path.split(file) | 317 return os.path.split(file) |
OLD | NEW |