|
46 | 46 |
|
47 | 47 |
|
48 | 48 | scriptdir = os.path.dirname(os.path.abspath(__file__)) |
49 | | -enableCache = True |
50 | 49 |
|
51 | 50 |
|
52 | 51 | def get_settings(): |
@@ -324,48 +323,52 @@ def find_absolute_of_type(self, data, full_data, type): |
324 | 323 | return type |
325 | 324 | return "%s.%s" % (thispackage, type) |
326 | 325 | outer = type.split("$")[0] |
| 326 | + outer = outer.split(".")[0] |
327 | 327 | regex = "[ \t]*import[ \t]+(.*)\.%s" % outer |
328 | 328 | match = re.search(regex, data) |
329 | 329 | if not match is None: |
330 | | - return "%s.%s" % (match.group(1), type) |
| 330 | + classname = "%s.%s" % (match.group(1), type) |
| 331 | + if cache.get_cached_class_exists(classname): |
| 332 | + return classname |
| 333 | + # Try and see if it's an inner class then |
| 334 | + count = 0 |
| 335 | + while "." in classname and count < 10: |
| 336 | + count += 1 |
| 337 | + classname = "%s$%s" % (classname[:classname.rfind(".")], classname[classname.rfind(".")+1:]) |
| 338 | + print classname |
| 339 | + if cache.get_cached_class_exists(classname): |
| 340 | + return classname |
331 | 341 |
|
332 | 342 | # Couldn't find the absolute name of this class so try to |
333 | 343 | # see if it's in one of the packages imported as |
334 | 344 | # "import package.*;", or in java.lang |
335 | 345 | # |
336 | | - packages = re.findall("[ \t]*import[ \t]+(.*)\.\*;", data) |
337 | | - packages.append("java.lang") |
338 | | - packages.append(thispackage) |
339 | | - if enableCache: |
340 | | - packages.append("") # for int, boolean, etc |
341 | | - for package in packages: |
342 | | - classname = package + "." + type |
343 | | - if cache.get_cached_class_exists(classname): |
344 | | - return classname |
| 346 | + packages = re.findall("[ \t]*import[ \t]+(.*);", data) |
| 347 | + packages.append("java.lang.*") |
| 348 | + packages.append(thispackage + ".*") |
| 349 | + packages.append("") # for int, boolean, etc |
| 350 | + for package in packages: |
| 351 | + classname = type |
| 352 | + if package.endswith(".*"): |
| 353 | + classname = package[:-2] + "." + type |
| 354 | + elif len(package): |
| 355 | + classname = package + "$" + type |
| 356 | + if cache.get_cached_class_exists(classname): |
| 357 | + return classname |
345 | 358 |
|
346 | 359 | # Couldn't find a cached version, invoke java |
347 | | - output = run_java("%s -findclass %s" % (get_cmd(), type), "\n".join(packages)).strip() |
348 | | - if len(output) and enableCache: |
| 360 | + output = run_java("%s -findclass '%s'" % (get_cmd(), type), "\n".join(packages)).strip() |
| 361 | + if len(output): |
349 | 362 | cache.cache_class(output) |
350 | 363 | if len(output) == 0 and "." in type: |
351 | 364 | return self.find_absolute_of_type(data, full_data, type.replace(".", "$")) |
352 | 365 | return output |
353 | 366 |
|
354 | 367 | def complete_class(self, absolute_classname, prefix): |
355 | | - if enableCache: |
356 | | - return cache.complete(absolute_classname, prefix) |
357 | | - else: |
358 | | - stdout = run_java("%s -complete %s %s" % (get_cmd(), absolute_classname, prefix)) |
359 | | - ret = [tuple(line.split(";;--;;")) for line in stdout.split("\n")[:-1]] |
360 | | - return sorted(ret, key=lambda a: a[0]) |
| 368 | + return cache.complete(absolute_classname, prefix) |
361 | 369 |
|
362 | 370 | def get_return_type(self, absolute_classname, prefix): |
363 | | - ret = "" |
364 | | - if enableCache: |
365 | | - ret = cache.get_return_type(absolute_classname, prefix) |
366 | | - else: |
367 | | - stdout = run_java("%s -returntype %s %s" % (get_cmd(), absolute_classname, prefix)) |
368 | | - ret = stdout.strip() |
| 371 | + ret = cache.get_return_type(absolute_classname, prefix) |
369 | 372 | match = re.search("(\[L)?([^;]+)", ret) |
370 | 373 | if match: |
371 | 374 | return match.group(2) |
|
0 commit comments