Skip to content

Commit

Permalink
Handle prefixing imported classes
Browse files Browse the repository at this point in the history
  • Loading branch information
davidliu committed Jun 14, 2024
1 parent 16307b4 commit a6b5eba
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions build/patches/jni_prefix.patch
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,49 @@ index 46d9619789e..4b7e721f716 100644
_name = get_path_info(_name, "name") + "_jni.h"
outputs += [ "$_jni_output_dir/$_name" ]
diff --git a/third_party/jni_zero/parse.py b/third_party/jni_zero/parse.py
index 33203b9848e..f627ed0f8ee 100644
index 33203b9848e..ffd92a2e135 100644
--- a/third_party/jni_zero/parse.py
+++ b/third_party/jni_zero/parse.py
@@ -382,7 +382,10 @@ def _do_parse(filename, *, package_prefix):

if package_prefix:
outer_class = outer_class.make_prefixed(package_prefix)
+ print("inner classes: ")
@@ -342,13 +342,15 @@ _IMPORT_REGEX = re.compile(r'^import\s+([^\s*]+);', flags=re.MULTILINE)
_IMPORT_CLASS_NAME_REGEX = re.compile(r'^(.*?)\.([A-Z].*)')


-def _parse_imports(contents):
+def _parse_imports(contents, package_prefix):
# Regex skips static imports as well as wildcard imports.
names = _IMPORT_REGEX.findall(contents)
for name in names:
m = _IMPORT_CLASS_NAME_REGEX.match(name)
if m:
package, class_name = m.groups()
+ if package.startswith('org.webrtc'):
+ package = package_prefix + '.org.webrtc'
yield java_types.JavaClass(
package.replace('.', '/') + '/' + class_name.replace('.', '$'))

@@ -385,7 +387,7 @@ def _do_parse(filename, *, package_prefix):
nested_classes = [c.make_prefixed(package_prefix) for c in nested_classes]
+ for c in nested_classes:
+ print(c.full_name_with_slashes, c.class_without_prefix.full_name_with_slashes)

type_resolver = java_types.TypeResolver(outer_class)
for java_class in _parse_imports(contents):
- for java_class in _parse_imports(contents):
+ for java_class in _parse_imports(contents, package_prefix):
type_resolver.add_import(java_class)
for java_class in nested_classes:
type_resolver.add_nested_class(java_class)
@@ -415,6 +417,7 @@ def _do_parse(filename, *, package_prefix):


def parse_java_file(filename, *, package_prefix=None):
+ print("parse_java_file: ", filename)
try:
return _do_parse(filename, package_prefix=package_prefix)
except ParseError as e:
@@ -431,6 +434,7 @@ _JAVAP_METHOD_REGEX = re.compile(


def parse_javap(filename, contents):
+ print("parse_javap: ", filename)
contents = _remove_generics(contents)
match = _JAVAP_CLASS_REGEX.search(contents)
if not match:

0 comments on commit a6b5eba

Please sign in to comment.