package test.pkg;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.view.ViewDebug;

import static android.os.Build.VERSION_CODES.KITKAT_WATCH;
import static android.os.Build.VERSION_CODES.LOLLIPOP;

@SuppressWarnings({"unused", "StatementWithEmptyBody"})
public class VersionConditional3 {
    public void test(ViewDebug.ExportedProperty property) {
        // Test short circuit evaluation
        if (Build.VERSION.SDK_INT > 18 && property.hasAdjacentMapping()) { // ERROR
        }
        if (Build.VERSION.SDK_INT > 19 && property.hasAdjacentMapping()) { // ERROR
        }
        if (Build.VERSION.SDK_INT > 20 && property.hasAdjacentMapping()) { // OK
        }
        if (Build.VERSION.SDK_INT > 21 && property.hasAdjacentMapping()) { // OK
        }
        if (Build.VERSION.SDK_INT > 22 && property.hasAdjacentMapping()) { // OK
        }

        if (Build.VERSION.SDK_INT >= 18 && property.hasAdjacentMapping()) { // ERROR
        }
        if (Build.VERSION.SDK_INT >= 19 && property.hasAdjacentMapping()) { // ERROR
        }
        if (Build.VERSION.SDK_INT >= 20 && property.hasAdjacentMapping()) { // ERROR
        }
        if (Build.VERSION.SDK_INT >= 21 && property.hasAdjacentMapping()) { // OK
        }
        if (Build.VERSION.SDK_INT >= 22 && property.hasAdjacentMapping()) { // OK
        }

        if (Build.VERSION.SDK_INT == 18 && property.hasAdjacentMapping()) { // ERROR
        }
        if (Build.VERSION.SDK_INT == 19 && property.hasAdjacentMapping()) { // ERROR
        }
        if (Build.VERSION.SDK_INT == 20 && property.hasAdjacentMapping()) { // ERROR
        }
        if (Build.VERSION.SDK_INT == 21 && property.hasAdjacentMapping()) { // OK
        }
        if (Build.VERSION.SDK_INT == 22 && property.hasAdjacentMapping()) { // OK
        }

        if (Build.VERSION.SDK_INT < 18 && property.hasAdjacentMapping()) { // ERROR
        }
        if (Build.VERSION.SDK_INT < 22 && property.hasAdjacentMapping()) { // ERROR
        }
        if (Build.VERSION.SDK_INT <= 18 && property.hasAdjacentMapping()) { // ERROR
        }
        if (Build.VERSION.SDK_INT <= 22 && property.hasAdjacentMapping()) { // ERROR
        }

        // Symbolic names instead
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD && property.hasAdjacentMapping()) { // ERROR
        }
        if (Build.VERSION.SDK_INT > VERSION_CODES.KITKAT && property.hasAdjacentMapping()) { // ERROR
        }
        if (Build.VERSION.SDK_INT > KITKAT_WATCH && property.hasAdjacentMapping()) { // OK
        }
        if (Build.VERSION.SDK_INT > LOLLIPOP && property.hasAdjacentMapping()) { // OK
        }

        // Wrong operator
        if (Build.VERSION.SDK_INT > 21 || property.hasAdjacentMapping()) { // ERROR
        }

        // Test multiple conditions in short circuit evaluation
        if (Build.VERSION.SDK_INT > 21 &&
                System.getProperty("something") != null &&
                property.hasAdjacentMapping()) { // OK
        }

        // Test order (still before call)
        if (System.getProperty("something") != null &&
                Build.VERSION.SDK_INT > 21 &&
                property.hasAdjacentMapping()) { // OK
        }

        // Test order (after call)
        if (System.getProperty("something") != null &&
                property.hasAdjacentMapping() && // ERROR
                Build.VERSION.SDK_INT > 21) {
        }

        if (Build.VERSION.SDK_INT > 21 && System.getProperty("something") == null) { // OK
            boolean p = property.hasAdjacentMapping(); // OK
        }
    }
}