mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1049105: Remove generateStatic option from JNI wrapper generator r=kats
This commit is contained in:
parent
c5ac3dc2cf
commit
6c62798b21
@ -9,15 +9,13 @@ package org.mozilla.gecko.annotationProcessors;
|
||||
*/
|
||||
public class AnnotationInfo {
|
||||
public final String wrapperName;
|
||||
public final boolean isStatic;
|
||||
public final boolean isMultithreaded;
|
||||
public final boolean noThrow;
|
||||
public final boolean narrowChars;
|
||||
|
||||
public AnnotationInfo(String aWrapperName, boolean aIsStatic, boolean aIsMultithreaded,
|
||||
public AnnotationInfo(String aWrapperName, boolean aIsMultithreaded,
|
||||
boolean aNoThrow, boolean aNarrowChars) {
|
||||
wrapperName = aWrapperName;
|
||||
isStatic = aIsStatic;
|
||||
isMultithreaded = aIsMultithreaded;
|
||||
noThrow = aNoThrow;
|
||||
narrowChars = aNarrowChars;
|
||||
|
@ -12,7 +12,6 @@ import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Member;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
@ -97,24 +96,22 @@ public class CodeGenerator {
|
||||
generateMemberCommon(theMethod, CMethodName, mClassToWrap);
|
||||
|
||||
boolean isFieldStatic = Utils.isMemberStatic(theMethod);
|
||||
boolean shallGenerateStatic = isFieldStatic || aMethodTuple.mAnnotationInfo.isStatic;
|
||||
|
||||
Class<?>[] parameterTypes = theMethod.getParameterTypes();
|
||||
Class<?> returnType = theMethod.getReturnType();
|
||||
|
||||
// Get the C++ method signature for this method.
|
||||
String implementationSignature = Utils.getCImplementationMethodSignature(parameterTypes, returnType, CMethodName, mCClassName, aMethodTuple.mAnnotationInfo.narrowChars);
|
||||
String headerSignature = Utils.getCHeaderMethodSignature(parameterTypes, theMethod.getParameterAnnotations(), returnType, CMethodName, mCClassName, shallGenerateStatic, aMethodTuple.mAnnotationInfo.narrowChars);
|
||||
String headerSignature = Utils.getCHeaderMethodSignature(parameterTypes, theMethod.getParameterAnnotations(), returnType, CMethodName, mCClassName, isFieldStatic, aMethodTuple.mAnnotationInfo.narrowChars);
|
||||
|
||||
// Add the header signature to the header file.
|
||||
writeSignatureToHeader(headerSignature);
|
||||
|
||||
// Use the implementation signature to generate the method body...
|
||||
writeMethodBody(implementationSignature, CMethodName, theMethod, mClassToWrap,
|
||||
aMethodTuple.mAnnotationInfo.isStatic,
|
||||
aMethodTuple.mAnnotationInfo.isMultithreaded,
|
||||
aMethodTuple.mAnnotationInfo.noThrow,
|
||||
aMethodTuple.mAnnotationInfo.narrowChars);
|
||||
writeMethodBody(implementationSignature, theMethod, mClassToWrap,
|
||||
aMethodTuple.mAnnotationInfo.isMultithreaded,
|
||||
aMethodTuple.mAnnotationInfo.noThrow,
|
||||
aMethodTuple.mAnnotationInfo.narrowChars);
|
||||
}
|
||||
|
||||
private void generateGetterOrSetterBody(Class<?> aFieldType, String aFieldName, boolean aIsFieldStatic, boolean isSetter, boolean aNarrowChars) {
|
||||
@ -182,15 +179,14 @@ public class CodeGenerator {
|
||||
|
||||
boolean isFieldStatic = Utils.isMemberStatic(theField);
|
||||
boolean isFieldFinal = Utils.isMemberFinal(theField);
|
||||
boolean shallGenerateStatic = isFieldStatic || aFieldTuple.mAnnotationInfo.isStatic;
|
||||
|
||||
String getterName = "get" + CFieldName;
|
||||
String getterSignature = Utils.getCImplementationMethodSignature(EMPTY_CLASS_ARRAY, fieldType, getterName, mCClassName, aFieldTuple.mAnnotationInfo.narrowChars);
|
||||
String getterHeaderSignature = Utils.getCHeaderMethodSignature(EMPTY_CLASS_ARRAY, GETTER_ARGUMENT_ANNOTATIONS, fieldType, getterName, mCClassName, shallGenerateStatic, aFieldTuple.mAnnotationInfo.narrowChars);
|
||||
String getterHeaderSignature = Utils.getCHeaderMethodSignature(EMPTY_CLASS_ARRAY, GETTER_ARGUMENT_ANNOTATIONS, fieldType, getterName, mCClassName, isFieldStatic, aFieldTuple.mAnnotationInfo.narrowChars);
|
||||
|
||||
writeSignatureToHeader(getterHeaderSignature);
|
||||
|
||||
writeFunctionStartupBoilerPlate(getterSignature, fieldType, isFieldStatic, true);
|
||||
writeFunctionStartupBoilerPlate(getterSignature, true);
|
||||
|
||||
generateGetterOrSetterBody(fieldType, CFieldName, isFieldStatic, false, aFieldTuple.mAnnotationInfo.narrowChars);
|
||||
|
||||
@ -201,11 +197,11 @@ public class CodeGenerator {
|
||||
Class<?>[] setterArguments = new Class<?>[]{fieldType};
|
||||
|
||||
String setterSignature = Utils.getCImplementationMethodSignature(setterArguments, Void.class, setterName, mCClassName, aFieldTuple.mAnnotationInfo.narrowChars);
|
||||
String setterHeaderSignature = Utils.getCHeaderMethodSignature(setterArguments, SETTER_ARGUMENT_ANNOTATIONS, Void.class, setterName, mCClassName, shallGenerateStatic, aFieldTuple.mAnnotationInfo.narrowChars);
|
||||
String setterHeaderSignature = Utils.getCHeaderMethodSignature(setterArguments, SETTER_ARGUMENT_ANNOTATIONS, Void.class, setterName, mCClassName, isFieldStatic, aFieldTuple.mAnnotationInfo.narrowChars);
|
||||
|
||||
writeSignatureToHeader(setterHeaderSignature);
|
||||
|
||||
writeFunctionStartupBoilerPlate(setterSignature, Void.class, isFieldStatic, true);
|
||||
writeFunctionStartupBoilerPlate(setterSignature, true);
|
||||
|
||||
generateGetterOrSetterBody(fieldType, CFieldName, isFieldStatic, true, aFieldTuple.mAnnotationInfo.narrowChars);
|
||||
}
|
||||
@ -269,14 +265,9 @@ public class CodeGenerator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Write out the function startup boilerplate for the method described. Check for environment
|
||||
* existence,
|
||||
* @param methodSignature
|
||||
* @param returnType
|
||||
* @param aIsStatic
|
||||
* @param aIsThreaded
|
||||
* Writes code for getting the JNIEnv instance.
|
||||
*/
|
||||
private void writeFunctionStartupBoilerPlate(String methodSignature, Class<?> returnType, boolean aIsStatic, boolean aIsThreaded) {
|
||||
private void writeFunctionStartupBoilerPlate(String methodSignature, boolean aIsThreaded) {
|
||||
// The start-of-function boilerplate. Does the bridge exist? Does the env exist? etc.
|
||||
wrapperMethodBodies.append('\n')
|
||||
.append(methodSignature)
|
||||
@ -384,7 +375,7 @@ public class CodeGenerator {
|
||||
boolean aIsThreaded, boolean aNoThrow) {
|
||||
Class<?>[] argumentTypes = theCtor.getParameterTypes();
|
||||
|
||||
writeFunctionStartupBoilerPlate(implementationSignature, Void.class, false, aIsThreaded);
|
||||
writeFunctionStartupBoilerPlate(implementationSignature, aIsThreaded);
|
||||
|
||||
writeFramePushBoilerplate(theCtor, false, aNoThrow);
|
||||
|
||||
@ -421,17 +412,16 @@ public class CodeGenerator {
|
||||
*
|
||||
* @param methodSignature The previously-generated C++ method signature for the method to be
|
||||
* generated.
|
||||
* @param aCMethodName The C++ method name for the method to be generated.
|
||||
* @param aMethod The Java method to be wrapped by the C++ method being generated.
|
||||
* @param aClass The Java class to which the method belongs.
|
||||
*/
|
||||
private void writeMethodBody(String methodSignature, String aCMethodName, Method aMethod,
|
||||
Class<?> aClass, boolean aIsStaticBridgeMethod, boolean aIsMultithreaded,
|
||||
boolean aNoThrow, boolean aNarrowChars) {
|
||||
private void writeMethodBody(String methodSignature, Method aMethod,
|
||||
Class<?> aClass, boolean aIsMultithreaded,
|
||||
boolean aNoThrow, boolean aNarrowChars) {
|
||||
Class<?>[] argumentTypes = aMethod.getParameterTypes();
|
||||
Class<?> returnType = aMethod.getReturnType();
|
||||
|
||||
writeFunctionStartupBoilerPlate(methodSignature, returnType, aIsStaticBridgeMethod, aIsMultithreaded);
|
||||
writeFunctionStartupBoilerPlate(methodSignature, aIsMultithreaded);
|
||||
|
||||
boolean isObjectReturningMethod = !returnType.getCanonicalName().equals("void") && Utils.isObjectType(returnType);
|
||||
|
||||
|
@ -73,7 +73,6 @@ public class GeneratableElementIterator implements Iterator<AnnotatableEntity> {
|
||||
final String annotationTypeName = annotationType.getName();
|
||||
if (annotationTypeName.equals("org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI")) {
|
||||
String stubName = null;
|
||||
boolean isStaticStub = false;
|
||||
boolean isMultithreadedStub = false;
|
||||
boolean noThrow = false;
|
||||
boolean narrowChars = false;
|
||||
@ -83,11 +82,6 @@ public class GeneratableElementIterator implements Iterator<AnnotatableEntity> {
|
||||
stubNameMethod.setAccessible(true);
|
||||
stubName = (String) stubNameMethod.invoke(annotation);
|
||||
|
||||
// Detemine if the generated stub should be static.
|
||||
final Method staticStubMethod = annotationType.getDeclaredMethod("generateStatic");
|
||||
staticStubMethod.setAccessible(true);
|
||||
isStaticStub = (Boolean) staticStubMethod.invoke(annotation);
|
||||
|
||||
// Determine if the generated stub is to allow calls from multiple threads.
|
||||
final Method multithreadedStubMethod = annotationType.getDeclaredMethod("allowMultithread");
|
||||
multithreadedStubMethod.setAccessible(true);
|
||||
@ -124,7 +118,7 @@ public class GeneratableElementIterator implements Iterator<AnnotatableEntity> {
|
||||
}
|
||||
|
||||
AnnotationInfo annotationInfo = new AnnotationInfo(
|
||||
stubName, isStaticStub, isMultithreadedStub, noThrow, narrowChars);
|
||||
stubName, isMultithreadedStub, noThrow, narrowChars);
|
||||
mNextReturnValue = new AnnotatableEntity(candidateElement, annotationInfo);
|
||||
return;
|
||||
}
|
||||
@ -134,7 +128,7 @@ public class GeneratableElementIterator implements Iterator<AnnotatableEntity> {
|
||||
// thanks to the "Generate everything" annotation.
|
||||
if (mIterateEveryEntry) {
|
||||
AnnotationInfo annotationInfo = new AnnotationInfo(
|
||||
candidateElement.getName(), false, false, false, false);
|
||||
candidateElement.getName(), false, false, false);
|
||||
mNextReturnValue = new AnnotatableEntity(candidateElement, annotationInfo);
|
||||
return;
|
||||
}
|
||||
|
@ -411,7 +411,7 @@ public class GeckoAppShell
|
||||
* The Gecko-side API: API methods that Gecko calls
|
||||
*/
|
||||
|
||||
@WrapElementForJNI(allowMultithread = true, generateStatic = true, noThrow = true)
|
||||
@WrapElementForJNI(allowMultithread = true, noThrow = true)
|
||||
public static void handleUncaughtException(Thread thread, Throwable e) {
|
||||
if (GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoExited)) {
|
||||
// We've called System.exit. All exceptions after this point are Android
|
||||
@ -452,14 +452,14 @@ public class GeckoAppShell
|
||||
}
|
||||
}
|
||||
|
||||
@WrapElementForJNI(generateStatic = true)
|
||||
@WrapElementForJNI
|
||||
public static void notifyIME(int type) {
|
||||
if (editableListener != null) {
|
||||
editableListener.notifyIME(type);
|
||||
}
|
||||
}
|
||||
|
||||
@WrapElementForJNI(generateStatic = true)
|
||||
@WrapElementForJNI
|
||||
public static void notifyIMEContext(int state, String typeHint,
|
||||
String modeHint, String actionHint) {
|
||||
if (editableListener != null) {
|
||||
@ -468,7 +468,7 @@ public class GeckoAppShell
|
||||
}
|
||||
}
|
||||
|
||||
@WrapElementForJNI(generateStatic = true)
|
||||
@WrapElementForJNI
|
||||
public static void notifyIMEChange(String text, int start, int end, int newEnd) {
|
||||
if (newEnd < 0) { // Selection change
|
||||
editableListener.onSelectionChange(start, end);
|
||||
|
@ -26,10 +26,6 @@ public @interface WrapElementForJNI {
|
||||
// of the Java method will be used.
|
||||
String stubName() default "";
|
||||
|
||||
// Optional parameter specifying if the generated method should be a static member of AndroidBridge
|
||||
// By default, an instance member is produced. This is almost always what is wanted.
|
||||
boolean generateStatic() default false;
|
||||
|
||||
/**
|
||||
* If set, the generated method stub will support being called from any thread via the use of
|
||||
* GetJNIForThread. This is rarely useful, at time of writing, as well as possibly risky.
|
||||
|
Loading…
Reference in New Issue
Block a user