You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.8 KiB

/*
* Copyright (c) 2017 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package codetoanalyze.java.checkers;
import javax.annotation.concurrent.ThreadSafe;
import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.view.View;
import android.util.DisplayMetrics;
class MyActivity extends Activity {
}
class MyResources extends Resources {
public MyResources(AssetManager assets, DisplayMetrics metrics, Configuration config) {
super(assets, metrics, config);
}
}
class MyView extends View {
boolean mField;
public MyView(Context c) {
super(c);
}
}
@ThreadSafe
public class AndroidModels {
Resources mResources;
MyResources mMyResources;
Object mField;
// assume that some Resources methods are annotated with @Functional
public void resourceMethodFunctionalOk() {
mField = mResources.getString(0);
}
// and subclasses of Resources too
public void customResourceMethodFunctionalOk() {
mField = mResources.getString(0);
}
// but not all of them
public void someResourceMethodsNotFunctionalBad() {
// configuration can change whenever the device rotates
mField = mResources.getConfiguration();
}
public void findViewByIdOk1(MyView view) {
MyView subview = (MyView) view.findViewById(-1);
subview.mField = true; // ok;
}
public void findViewByIdOk2(MyActivity activity) {
MyView view = (MyView) activity.findViewById(-1);
view.mField = true; // ok;
}
}