diff --git a/base/BUILD.gn b/base/BUILD.gn index 05279f236b410f..245aa9c1b22345 100644 --- a/base/BUILD.gn +++ b/base/BUILD.gn @@ -2894,7 +2894,7 @@ if (is_android) { java_library("jni_java") { supports_android = true java_files = [ - "android/java/src/org/chromium/base/annotations/JniStaticNatives.java", + "android/java/src/org/chromium/base/annotations/NativeMethods.java", "android/java/src/org/chromium/base/JniStaticTestMocker.java", ] } diff --git a/base/android/java/src/org/chromium/base/AnimationFrameTimeHistogram.java b/base/android/java/src/org/chromium/base/AnimationFrameTimeHistogram.java index 7e884ea7dfb49f..1228c52f4bbf2d 100644 --- a/base/android/java/src/org/chromium/base/AnimationFrameTimeHistogram.java +++ b/base/android/java/src/org/chromium/base/AnimationFrameTimeHistogram.java @@ -11,7 +11,7 @@ import android.animation.TimeAnimator.TimeListener; import android.util.Log; -import org.chromium.base.annotations.JniStaticNatives; +import org.chromium.base.annotations.NativeMethods; /** * Record Android animation frame rate and save it to UMA histogram. This is mainly for monitoring @@ -143,7 +143,7 @@ public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) } } - @JniStaticNatives + @NativeMethods interface Natives { void saveHistogram(String histogramName, long[] frameTimesMs, int count); } diff --git a/base/android/java/src/org/chromium/base/JniStaticTestMocker.java b/base/android/java/src/org/chromium/base/JniStaticTestMocker.java index b73be103008702..d3177373ae83e4 100644 --- a/base/android/java/src/org/chromium/base/JniStaticTestMocker.java +++ b/base/android/java/src/org/chromium/base/JniStaticTestMocker.java @@ -7,7 +7,7 @@ /** * Implemented by the TEST_HOOKS field in JNI wrapper classes that are generated * by the JNI annotation processor. Used in tests for setting the mock - * implementation of a {@link org.chromium.base.annotations.JniStaticNatives} interface. - * @param The interface annotated with {@link org.chromium.base.annotations.JniStaticNatives} + * implementation of a {@link org.chromium.base.annotations.NativeMethods} interface. + * @param The interface annotated with {@link org.chromium.base.annotations.NativeMethods} */ public interface JniStaticTestMocker { void setInstanceForTesting(T instance); } diff --git a/base/android/java/src/org/chromium/base/annotations/JCaller.java b/base/android/java/src/org/chromium/base/annotations/JCaller.java index f9c54cddba1c47..4a8e31e975a58d 100644 --- a/base/android/java/src/org/chromium/base/annotations/JCaller.java +++ b/base/android/java/src/org/chromium/base/annotations/JCaller.java @@ -23,7 +23,7 @@ * * static native void nativeFoo(@JCaller A a, long nativeCppClass); * - * @JniStaticNatives + * @NativeMethods * interface Natives { * void foo(@JCaller A a, long nativeCppClass); * } diff --git a/base/android/java/src/org/chromium/base/annotations/JniStaticNatives.java b/base/android/java/src/org/chromium/base/annotations/NativeMethods.java similarity index 91% rename from base/android/java/src/org/chromium/base/annotations/JniStaticNatives.java rename to base/android/java/src/org/chromium/base/annotations/NativeMethods.java index b387854d371d6a..4c98ad21474de0 100644 --- a/base/android/java/src/org/chromium/base/annotations/JniStaticNatives.java +++ b/base/android/java/src/org/chromium/base/annotations/NativeMethods.java @@ -10,4 +10,4 @@ @Target(ElementType.TYPE) @Retention(RetentionPolicy.SOURCE) -public @interface JniStaticNatives {} +public @interface NativeMethods {} diff --git a/base/android/jni_generator/README.md b/base/android/jni_generator/README.md index f1d7b721bea642..35931728d39fdd 100644 --- a/base/android/jni_generator/README.md +++ b/base/android/jni_generator/README.md @@ -69,11 +69,11 @@ There are two ways to call native methods: bindings will automatically generate the appropriate cast and call into C++ code (JNI itself is only C). -**Method 2 - Using an interface annotated with @JniStaticNatives** +**Method 2 - Using an interface annotated with @NativeMethods** - Only works for static methods. - Supports mocking in tests. -- Inner-interfaces annotated with `@JniStaticNatives` defines the native +- Inner-interfaces annotated with `@NativeMethods` defines the native interface. - A companion JNI class is generated which implements this interface with the proper bindings to forward calls to C++ functions (that you must write). @@ -94,7 +94,7 @@ Usage: 1. Enable the JNI processor by adding `annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]` to the Java target. -2. Create an inner-interface annotated with `@JniStaticNatives` that contains +2. Create an inner-interface annotated with `@NativeMethods` that contains the declaration of the corresponding static methods you wish to have implemented. 3. Call native functions using `${OriginalClassName}Jni.get().${method}` e.g. @@ -125,7 +125,7 @@ class A { // Using AJni.get() everywhere has no overhead when running in release with R8. } - @JniStaticNatives + @NativeMethods interface Natives { void foo(); double bar(int a, int b); @@ -133,7 +133,7 @@ class A { } ``` -- If a class contains an interface annotated with `@JniStaticNatives`, the JNI +- If a class contains an interface annotated with `@NativeMethods`, the JNI annotation processor generates a class named `${OriginalClassName}Jni` which has a function `get()` which returns an implementation of the annotated interface (and will call the corresponding static method as if it diff --git a/base/android/jni_generator/java/src/org/chromium/example/jni_generator/SampleForAnnotationProcessor.java b/base/android/jni_generator/java/src/org/chromium/example/jni_generator/SampleForAnnotationProcessor.java index a6af0207556e13..b9e6cd61ba597e 100644 --- a/base/android/jni_generator/java/src/org/chromium/example/jni_generator/SampleForAnnotationProcessor.java +++ b/base/android/jni_generator/java/src/org/chromium/example/jni_generator/SampleForAnnotationProcessor.java @@ -4,7 +4,7 @@ package org.chromium.example.jni_generator; -import org.chromium.base.annotations.JniStaticNatives; +import org.chromium.base.annotations.NativeMethods; /** * Sample class that uses the JNI annotation processor for static methods. @@ -22,7 +22,7 @@ class TestStruct { * with the name SampleForAnnotationProcessorJni which will implement * Natives. */ - @JniStaticNatives + @NativeMethods interface Natives { void foo(); SampleForAnnotationProcessor bar(SampleForAnnotationProcessor sample); diff --git a/base/android/jni_generator/java/src/org/chromium/jni_generator/JniProcessor.java b/base/android/jni_generator/java/src/org/chromium/jni_generator/JniProcessor.java index 587746e68d74d5..01ce5b90dafa63 100644 --- a/base/android/jni_generator/java/src/org/chromium/jni_generator/JniProcessor.java +++ b/base/android/jni_generator/java/src/org/chromium/jni_generator/JniProcessor.java @@ -21,7 +21,7 @@ import com.squareup.javapoet.TypeSpec; import org.chromium.base.JniStaticTestMocker; -import org.chromium.base.annotations.JniStaticNatives; +import org.chromium.base.annotations.NativeMethods; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -49,17 +49,17 @@ /** * Annotation processor that finds inner interfaces annotated with - * {@link JniStaticNatives} and generates a class with native bindings + * {@link NativeMethods} and generates a class with native bindings * (GEN_JNI) and a class specific wrapper class with name (classnameJni) * * NativeClass - refers to the class that contains all native declarations. * NativeWrapperClass - refers to the class that is generated for each class - * containing an interface annotated with JniStaticNatives. + * containing an interface annotated with NativeMethods. * */ @AutoService(Processor.class) public class JniProcessor extends AbstractProcessor { - private static final Class JNI_STATIC_NATIVES_CLASS = JniStaticNatives.class; + private static final Class JNI_STATIC_NATIVES_CLASS = NativeMethods.class; private static final String NATIVE_WRAPPER_CLASS_POSTFIX = "Jni"; @@ -164,11 +164,11 @@ public boolean process( List writeQueue = Lists.newArrayList(); for (Element e : roundEnvironment.getElementsAnnotatedWith(JNI_STATIC_NATIVES_CLASS)) { - // @JniStaticNatives can only annotate types so this is safe. + // @NativeMethods can only annotate types so this is safe. TypeElement type = (TypeElement) e; if (!e.getKind().isInterface()) { - printError("@JniStaticNatives must annotate an interface", e); + printError("@NativeMethods must annotate an interface", e); } // Interface must be nested within a class. @@ -208,7 +208,7 @@ public boolean process( // Queue this file for writing. // Can't write right now because the wrapper class depends on NativeClass - // to be written and we can't write NativeClass until all @JniStaticNatives + // to be written and we can't write NativeClass until all @NativeMethods // interfaces are processed because each will add new native methods. JavaFile file = JavaFile.builder(packageName, nativeWrapperClassSpec).build(); writeQueue.add(file); @@ -274,8 +274,8 @@ String getNativeMethodName(String packageName, String className, String oldMetho /** * Creates method specs for the native methods of NativeClass given - * the method declarations from a {@link JniStaticNatives} annotated interface - * @param interfaceMethods method declarations from a {@link JniStaticNatives} annotated + * the method declarations from a {@link NativeMethods} annotated interface + * @param interfaceMethods method declarations from a {@link NativeMethods} annotated * interface * @param outerType ClassName of class that contains the annotated interface * @return map from old method name to new native method specification @@ -318,11 +318,11 @@ void printError(String s) { void printError(String s, Element e) { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, - String.format("Error processing @JniStaticNatives interface: %s", s), e); + String.format("Error processing @NativeMethods interface: %s", s), e); } /** - * Creates a class spec for an implementation of an {@link JniStaticNatives} annotated interface + * Creates a class spec for an implementation of an {@link NativeMethods} annotated interface * that will wrap calls to the NativesClass which contains the actual native method * declarations. * @@ -336,7 +336,7 @@ void printError(String s, Element e) { * * @param name name of the wrapper class. * @param isPublic if true, a public modifier will be added to this native wrapper. - * @param nativeInterface the {@link JniStaticNatives} annotated type that this native wrapper + * @param nativeInterface the {@link NativeMethods} annotated type that this native wrapper * will implement. * @param methodMap a map from the old method name to the new method spec in NativeClass. * */ @@ -355,7 +355,7 @@ TypeSpec createNativeWrapperClassSpec(String name, boolean isPublic, // Start by adding all the native method wrappers. for (Element enclosed : nativeInterface.getEnclosedElements()) { if (enclosed.getKind() != ElementKind.METHOD) { - printError("Cannot have a non-method in a @JniStaticNatives annotated interface", + printError("Cannot have a non-method in a @NativeMethods annotated interface", enclosed); } @@ -452,7 +452,7 @@ TypeSpec createNativeWrapperClassSpec(String name, boolean isPublic, /** * Creates a wrapper method that overrides interfaceMethod and calls staticNativeMethod. - * @param interfaceMethod method that will be overridden in a {@link JniStaticNatives} annotated + * @param interfaceMethod method that will be overridden in a {@link NativeMethods} annotated * interface. * @param staticNativeMethod method that will be called in NativeClass. */ diff --git a/base/android/jni_generator/jni_generator.py b/base/android/jni_generator/jni_generator.py index 9311d98eb879e7..d9c025495a22c3 100755 --- a/base/android/jni_generator/jni_generator.py +++ b/base/android/jni_generator/jni_generator.py @@ -57,7 +57,7 @@ flags=re.DOTALL) _NATIVE_PROXY_EXTRACTION_REGEX = re.compile( - r'@JniStaticNatives\s*(public|private)*\s*interface\s*' + r'@NativeMethods\s*(public|private)*\s*interface\s*' r'(?P\w*)\s*(?P{(\s*.*)+?\s*})') # Use 100 columns rather than 80 because it makes many lines more readable. @@ -837,7 +837,7 @@ def CreateFromClass(class_file, options): return jni_from_javap -# 'Proxy' native methods are declared in an @JniStaticNatives interface without +# 'Proxy' native methods are declared in an @NativeMethods interface without # a native qualifier and indicate that the JNI annotation processor should # generate code to link between the equivalent native method as if it were # declared statically. diff --git a/base/android/jni_generator/jni_generator_tests.py b/base/android/jni_generator/jni_generator_tests.py index b50bc0e598a7f3..bc99a7a6058417 100755 --- a/base/android/jni_generator/jni_generator_tests.py +++ b/base/android/jni_generator/jni_generator_tests.py @@ -1244,7 +1244,7 @@ def testProxyNativesWithNatives(self): class Foo { - @JniStaticNatives + @NativeMethods interface Natives { void foo(); String bar(String s, int y, char x, short z); @@ -1267,7 +1267,7 @@ class Foo { def testEscapingProxyNatives(self): test_data = """ class SampleProxyJni { - @JniStaticNatives + @NativeMethods interface Natives { void foo_bar(); void foo__bar(); @@ -1306,7 +1306,7 @@ def testProxyNativesMainDex(self): test_data = """ @MainDex class Foo() { - @JniStaticNatives + @NativeMethods interface Natives { void thisismaindex(); } @@ -1318,7 +1318,7 @@ class Foo() { non_main_dex_test_data = """ class Bar() { - @JniStaticNatives + @NativeMethods interface Natives { void foo(); void bar(); @@ -1382,7 +1382,7 @@ def testProxyNatives(self): test_data = """ class SampleProxyJni { private void do_not_match(); - @JniStaticNatives + @NativeMethods interface Natives { void foo(); int bar(int x, int y); @@ -1396,7 +1396,7 @@ class SampleProxyJni { bad_spaced_test_data = """ class SampleProxyJni{ - @JniStaticNatives interface + @NativeMethods interface Natives diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/JniMocker.java b/base/test/android/javatests/src/org/chromium/base/test/util/JniMocker.java index 5b0edebab2224a..f995309bf0ee59 100644 --- a/base/test/android/javatests/src/org/chromium/base/test/util/JniMocker.java +++ b/base/test/android/javatests/src/org/chromium/base/test/util/JniMocker.java @@ -7,7 +7,7 @@ import org.junit.rules.ExternalResource; import org.chromium.base.JniStaticTestMocker; -import org.chromium.base.annotations.JniStaticNatives; +import org.chromium.base.annotations.NativeMethods; import java.util.ArrayList; @@ -23,7 +23,7 @@ public class JniMocker extends ExternalResource { * All TEST_HOOKS set with this function will have their test instance * set to null after each test is run. * - * @param T Interface type that implements {@link JniStaticNatives} + * @param T Interface type that implements {@link NativeMethods} * @param hook Instance of the corresponding JniStaticTestMocker in the * wrapper class generated by the JNI annotation processor * @param testInst Mock instance of type T which will be set as the