New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate calls to Shadow.invokeConstructor and ReflectionHelpers.callConstructor to reflector #8873
Comments
@hoisie Also Is there any Similar Migration that has already took place ? |
@shashankiitbhu there are some commits here that migrate ReflectionHelpers (and other things) to reflector. One example is in here in ShadowLegacyTypeface: There are calls such as This can be migrated to reflector, something like: interface TypefaceReflector {
@Constructor
Typeface newTypeface(long fontId);
} And then you could just invoke:
Anywhere
|
So Just to make sure I am getting this Right: This is current approach: if (getApiLevel() >= LOLLIPOP) {
return ReflectionHelpers.callConstructor(
Typeface.class, ClassParameter.from(long.class, thisFontId));
} After Creating TypefaceReflector above : protected static Typeface createUnderlyingTypeface(String familyName, int style) {
long thisFontId = nextFontId.getAndIncrement();
FONTS.put(thisFontId, new FontDesc(familyName, style));
TypefaceReflector reflector = Reflector.reflector(TypefaceReflector.class);
return reflector.newTypeface(thisFontId);
} This is similar to how I was thinking about approaching this, thanks. |
@hoisie Maybe we can Introduce a New Annotation. For example, |
In Robolectric there are a lot of calls to
Shadow.invokeConstructor
andReflectionHelpers.callConstructor
in shadow code. Any call to Shadow.invokeConstructor and ReflectionHelpers.callConstructor will end up using reflection.Ideally all of these should be migrated to reflector. This will still be using reflection but it will be faster.
Shadow.invokeConstructor
should be migrated to@Direct @Constructor
andReflectionHelpers.callConstructor
can be migrated to@Constructor
. Note that@Direct @Constructor
may not actually be supported at the moment.The text was updated successfully, but these errors were encountered: