List of usage examples for android.support.v4.app RestrictToEnforcerPositiveCasesApi consumesRestrictedInterface
public static void consumesRestrictedInterface(RestrictedInterface restricted)
From source file:com.google.errorprone.bugpatterns.android.testdata.RestrictToEnforcerPositiveCases.java
void check() { // No bug - restrictto not enforced outside support lib CantUseRestrictToOutsideSupportLib var = null; // No bug - restrictto not enforced outside support lib cantUseRestrictToOutsideSupportLib(); // BUG: Diagnostic contains: RestrictedMethodClass.doSomething() is restricted String string = (String) RestrictedMethodClass.doSomething(); // BUG: Diagnostic contains: RestrictedClass.doSomething() is restricted String string2 = (String) RestrictedClass.doSomething(); ExtendsExtendsRestricted obj = null; // BUG: Diagnostic contains: RestrictedAbstractMethod.restricted() is restricted obj.restricted();//from w ww . j a v a 2 s. co m // no bug - method is not restricted obj.interfaceMethod(); // no bug - method is not restricted UnrestrictedSubclass.doSomething(); // no bug - method is not restricted new UnrestrictedSubclass().instanceMethod(); Runnable unrestricted = new UnrestrictedSubclass()::instanceMethod; // BUG: Diagnostic contains: RestrictedInterface is restricted ((RestrictedInterface) obj).toString(); // BUG: Diagnostic contains: RestrictedInterface is restricted RestrictedInterface obj2 = obj; // BUG: Diagnostic contains: RestrictedInterface is restricted if (obj instanceof RestrictedInterface) { } // BUG: Diagnostic contains: RestrictedInterface.interfaceMethod() is restricted RestrictToEnforcerPositiveCasesApi.returnsRestrictedInterface().interfaceMethod(); RestrictToEnforcerPositiveCasesApi.consumesRestrictedInterface( // BUG: Diagnostic contains: RestrictedInterface is restricted () -> { return; }); // BUG: Diagnostic contains: RestrictedInterface is restricted RestrictToEnforcerPositiveCasesApi.consumesRestrictedInterface(System.out::println); // BUG: Diagnostic contains: RestrictedMethodClass.doSomething() is restricted Runnable runnable = RestrictedMethodClass::doSomething; // No bug - calling method on our own class new ExtendsUnrestrictedRestrictedInterfaceImplementor().interfaceMethod(); // No bug - calling method on our own class Runnable runnable2 = new ExtendsUnrestrictedRestrictedInterfaceImplementor()::interfaceMethod; // BUG: Diagnostic contains: RestrictedOuterClass.UnrestrictedClass.doSomething() is restricted UnrestrictedClass.doSomething(); new RestrictedAbstractMethod() { @Override // BUG: Diagnostic contains: RestrictedAbstractMethod.restricted() is restricted public void restricted() { } @Override public void interfaceMethod() { } }; // BUG: Diagnostic contains: RestrictedClass is restricted AtomicReference<? extends RestrictedClass> ref = new AtomicReference<>(null); // BUG: Diagnostic contains: RestrictedClass.doSomething() is restricted ref.get().doSomething(); // BUG: Diagnostic contains: RestrictedSubClass is restricted RestrictedSubClass subClass = null; // BUG: Diagnostic contains: RestrictedSubClass.superClassMethod() is restricted subClass.superClassMethod(); // BUG: Diagnostic contains: RestrictedConstructor.RestrictedConstructor() is restricted new RestrictedConstructor(); }