Loading tools/lint/checks/src/com/android/bluetooth/lint/LogEnforcementVariableCreationDetector.kt +2 −1 Original line number Diff line number Diff line Loading @@ -135,7 +135,8 @@ class LogEnforcementVariableCreationDetector : Detector(), SourceCodeScanner { val fieldType = field.getType() val fieldName = field.getName() val fieldInitializer = field.uastInitializer?.skipParenthesizedExprDown() return fieldType.canonicalText.lowercase() == "boolean" && return (fieldType.canonicalText == "boolean" || fieldType.canonicalText == "java.lang.Boolean") && (isLogEnforcementVariable(fieldName) || (fieldInitializer != null && (checkExpressionForIsLoggableUsages(fieldInitializer) || Loading tools/lint/checks/tests/com/android/bluetooth/lint/test/LogEnforcementVariableCreationDetectorTest.kt +32 −0 Original line number Diff line number Diff line Loading @@ -779,6 +779,38 @@ class LogEnforcementVariableCreationDetectorTest : LintDetectorTest() { .expectClean() } @Test fun testVariableCreationWithBooleanWrapperClass_issuesFound() { lint() .files( java( """ package com.android.bluetooth; import android.util.Log; public final class Foo { private static final String TAG = Foo.class.getSimpleName(); private static final Boolean WHYYYY_DBG = true; public Foo() { Log.d(TAG, "created Foo without an enforcement variable"); } } """ ) .indented(), *stubs ) .issues(LogEnforcementVariableCreationDetector.ISSUE) .run() .expectContains( LogEnforcementVariableCreationDetector.LOG_ENFORCEMENT_VARIABLE_USAGE_ERROR ) .expectContains(createErrorCountString(1, 0)) .expectFixDiffs(createFixDiff(7, " private static final Boolean WHYYYY_DBG = true;")) } private val logFramework: TestFile = java( """ Loading Loading
tools/lint/checks/src/com/android/bluetooth/lint/LogEnforcementVariableCreationDetector.kt +2 −1 Original line number Diff line number Diff line Loading @@ -135,7 +135,8 @@ class LogEnforcementVariableCreationDetector : Detector(), SourceCodeScanner { val fieldType = field.getType() val fieldName = field.getName() val fieldInitializer = field.uastInitializer?.skipParenthesizedExprDown() return fieldType.canonicalText.lowercase() == "boolean" && return (fieldType.canonicalText == "boolean" || fieldType.canonicalText == "java.lang.Boolean") && (isLogEnforcementVariable(fieldName) || (fieldInitializer != null && (checkExpressionForIsLoggableUsages(fieldInitializer) || Loading
tools/lint/checks/tests/com/android/bluetooth/lint/test/LogEnforcementVariableCreationDetectorTest.kt +32 −0 Original line number Diff line number Diff line Loading @@ -779,6 +779,38 @@ class LogEnforcementVariableCreationDetectorTest : LintDetectorTest() { .expectClean() } @Test fun testVariableCreationWithBooleanWrapperClass_issuesFound() { lint() .files( java( """ package com.android.bluetooth; import android.util.Log; public final class Foo { private static final String TAG = Foo.class.getSimpleName(); private static final Boolean WHYYYY_DBG = true; public Foo() { Log.d(TAG, "created Foo without an enforcement variable"); } } """ ) .indented(), *stubs ) .issues(LogEnforcementVariableCreationDetector.ISSUE) .run() .expectContains( LogEnforcementVariableCreationDetector.LOG_ENFORCEMENT_VARIABLE_USAGE_ERROR ) .expectContains(createErrorCountString(1, 0)) .expectFixDiffs(createFixDiff(7, " private static final Boolean WHYYYY_DBG = true;")) } private val logFramework: TestFile = java( """ Loading