Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ad1e20b7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Discourage methods that use resource reflection"

parents f9a3f5cd 8c2c82d3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -13462,7 +13462,7 @@ package android.content.res {
    method public float getFloat(@DimenRes int);
    method @NonNull public android.graphics.Typeface getFont(@FontRes int) throws android.content.res.Resources.NotFoundException;
    method public float getFraction(@FractionRes int, int, int);
    method public int getIdentifier(String, String, String);
    method @Discouraged(message="Use of this function is discouraged because resource reflection makes it harder to perform build optimizations and compile-time verification of code. It is much more efficient to retrieve resources by identifier (e.g. `R.foo.bar`) than by name (e.g. `getIdentifier(\"bar\", \"foo\", null)`).") public int getIdentifier(String, String, String);
    method @NonNull public int[] getIntArray(@ArrayRes int) throws android.content.res.Resources.NotFoundException;
    method public int getInteger(@IntegerRes int) throws android.content.res.Resources.NotFoundException;
    method @NonNull public android.content.res.XmlResourceParser getLayout(@LayoutRes int) throws android.content.res.Resources.NotFoundException;
@@ -13482,7 +13482,7 @@ package android.content.res {
    method public CharSequence getText(@StringRes int, CharSequence);
    method @NonNull public CharSequence[] getTextArray(@ArrayRes int) throws android.content.res.Resources.NotFoundException;
    method public void getValue(@AnyRes int, android.util.TypedValue, boolean) throws android.content.res.Resources.NotFoundException;
    method public void getValue(String, android.util.TypedValue, boolean) throws android.content.res.Resources.NotFoundException;
    method @Discouraged(message="Use of this function is discouraged because it makes internal calls to `getIdentifier()`, which uses resource reflection. Reflection makes it harder to perform build optimizations and compile-time verification of code. It is much more efficient to retrieve resource values by identifier (e.g. `getValue(R.foo.bar, outValue, true)`) than by name (e.g. `getValue(\"foo\", outvalue, true)`).") public void getValue(String, android.util.TypedValue, boolean) throws android.content.res.Resources.NotFoundException;
    method public void getValueForDensity(@AnyRes int, int, android.util.TypedValue, boolean) throws android.content.res.Resources.NotFoundException;
    method @NonNull public android.content.res.XmlResourceParser getXml(@XmlRes int) throws android.content.res.Resources.NotFoundException;
    method public final android.content.res.Resources.Theme newTheme();
+12 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.annotation.BoolRes;
import android.annotation.ColorInt;
import android.annotation.ColorRes;
import android.annotation.DimenRes;
import android.annotation.Discouraged;
import android.annotation.DrawableRes;
import android.annotation.FontRes;
import android.annotation.FractionRes;
@@ -1466,6 +1467,12 @@ public class Resources {
     * @throws NotFoundException Throws NotFoundException if the given ID does not exist.
     *
     */
    @Discouraged(message = "Use of this function is discouraged because it makes internal calls to "
                         + "`getIdentifier()`, which uses resource reflection. Reflection makes it "
                         + "harder to perform build optimizations and compile-time verification of "
                         + "code. It is much more efficient to retrieve resource values by "
                         + "identifier (e.g. `getValue(R.foo.bar, outValue, true)`) than by name "
                         + "(e.g. `getValue(\"foo\", outvalue, true)`).")
    public void getValue(String name, TypedValue outValue, boolean resolveRefs)
            throws NotFoundException {
        mResourcesImpl.getValue(name, outValue, resolveRefs);
@@ -2198,6 +2205,11 @@ public class Resources {
     * @return int The associated resource identifier.  Returns 0 if no such
     *         resource was found.  (0 is not a valid resource ID.)
     */
    @Discouraged(message = "Use of this function is discouraged because resource reflection makes "
                         + "it harder to perform build optimizations and compile-time "
                         + "verification of code. It is much more efficient to retrieve "
                         + "resources by identifier (e.g. `R.foo.bar`) than by name (e.g. "
                         + "`getIdentifier(\"bar\", \"foo\", null)`).")
    public int getIdentifier(String name, String defType, String defPackage) {
        return mResourcesImpl.getIdentifier(name, defType, defPackage);
    }