当前位置:  开发笔记 > Android > 正文

Android Studio中的"noinspection"关键字列表

如何解决《AndroidStudio中的"noinspection"关键字列表》经验,为你挑选了1个好方法。

在Android Studio中,我有时会使用这种注释来禁用我已经处理的特定代码行上的检查警告,例如:

if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
    //noinspection deprecation
    textView.setBackgroundDrawable(ContextCompat.getDrawable(mContext, R.drawable.calendar_item_separator));
} else {
    textView.setBackground(ContextCompat.getDrawable(mContext, R.drawable.calendar_item_separator));
}

在这个例子中,我使用了关键字"deprecation",但我找不到可用关键字的完整列表.

有人发现了吗?

谢谢!



1> Yoann Hercou..:

我终于成功从这个Github 源代码中获取了关键字列表.

我把它贴在这里以防万一:

"localInspection": [
    {
        "language": "JAVA",
        "shortName": "UndesirableClassUsage",
        "displayName": "Undesirable class usage",
        "groupName": "IntelliJ IDEA Platform Inspections",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.internal.UndesirableClassUsageInspection"
    },
    {
        "language": "JAVA",
        "shortName": "FileEqualsUsage",
        "displayName": "File.equals() usage",
        "groupName": "IntelliJ IDEA Platform Inspections",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.internal.FileEqualsUsageInspection"
    },
    {
        "language": "JAVA",
        "shortName": "GtkPreferredJComboBoxRenderer",
        "displayName": "Preferred JComboBox renderer",
        "groupName": "IntelliJ IDEA Platform Inspections",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.internal.GtkPreferredJComboBoxRendererInspection"
    },
    {
        "language": "JAVA",
        "shortName": "UnsafeVfsRecursion",
        "displayName": "Unsafe VFS recursion",
        "groupName": "IntelliJ IDEA Platform Inspections",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.internal.UnsafeVfsRecursionInspection"
    },
    {
        "language": "JAVA",
        "shortName": "ConstantConditions",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.data.flow.display.name",
        "groupName": "Probable bugs",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.dataFlow.DataFlowInspection"
    },
    {
        "language": "JAVA",
        "shortName": "UnusedAssignment",
        "displayName": "Unused assignment",
        "groupName": "Probable bugs",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.defUse.DefUseInspection"
    },
    {
        "language": "JAVA",
        "shortName": "NumericOverflow",
        "displayName": "Numeric overflow",
        "groupName": "Numeric issues",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.NumericOverflowInspection"
    },
    {
        "language": "JAVA",
        "shortName": "RedundantCast",
        "displayName": "Redundant type cast",
        "groupName": "Verbose or redundant code constructs",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.redundantCast.RedundantCastInspection"
    },
    {
        "language": "JAVA",
        "shortName": "RedundantTypeArguments",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.redundant.type.display.name",
        "groupName": "Verbose or redundant code constructs",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.miscGenerics.RedundantTypeArgsInspection"
    },
    {
        "language": "JAVA",
        "shortName": "RedundantArrayCreation",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.redundant.array.creation.display.name",
        "groupName": "Verbose or redundant code constructs",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.miscGenerics.RedundantArrayForVarargsCallInspection"
    },
    {
        "language": "JAVA",
        "shortName": "SuspiciousMethodCalls",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.suspicious.collections.method.calls.display.name",
        "groupName": "Probable bugs",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.miscGenerics.SuspiciousCollectionsMethodCallsInspection"
    },
    {
        "language": "JAVA",
        "shortName": "LocalCanBeFinal",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.local.can.be.final.display.name",
        "groupName": "Code style issues",
        "enabledByDefault": "false",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.localCanBeFinal.LocalCanBeFinal"
    },
    {
        "language": "JAVA",
        "shortName": "JavaDoc",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.javadoc.display.name",
        "groupKey": "group.names.javadoc.issues",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.javaDoc.JavaDocLocalInspection"
    },
    {
        "language": "JAVA",
        "shortName": "JavadocReference",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.javadoc.ref.display.name",
        "groupKey": "group.names.javadoc.issues",
        "enabledByDefault": "true",
        "level": "ERROR",
        "implementationClass": "com.intellij.codeInspection.javaDoc.JavaDocReferenceInspection"
    },
    {
        "language": "JAVA",
        "suppressId": "deprecation",
        "shortName": "Deprecation",
        "displayName": "Deprecated API usage",
        "groupName": "",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.deprecation.DeprecationInspection"
    },
    {
        "language": "JAVA",
        "suppressId": "extensionSyntax",
        "bundle": "messages.InspectionsBundle",
        "key": "deprecated.defender.syntax.description",
        "groupName": "",
        "enabledByDefault": "true",
        "level": "ERROR",
        "implementationClass": "com.intellij.codeInspection.deprecation.DeprecatedDefenderSyntaxInspection"
    },
    {
        "language": "XML",
        "shortName": "DeprecatedClassUsageInspection",
        "displayName": "Deprecated API usage in XML",
        "groupName": "XML",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.util.xml.DeprecatedClassUsageInspection"
    },
    {
        "language": "JAVA",
        "shortName": "EqualsAndHashcode",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.equals.hashcode.display.name",
        "groupName": "",
        "enabledByDefault": "false",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.equalsAndHashcode.EqualsAndHashcode"
    },
    {
        "language": "JAVA",
        "shortName": "Since15",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.1.5.display.name",
        "groupName": "Java language level migration aids",
        "enabledByDefault": "false",
        "level": "ERROR",
        "implementationClass": "com.intellij.codeInspection.java15api.Java15APIUsageInspection"
    },
    {
        "language": "JAVA",
        "shortName": "Dependency",
        "displayName": "Illegal package dependencies",
        "groupName": "",
        "enabledByDefault": "true",
        "level": "ERROR",
        "implementationClass": "com.intellij.codeInspection.dependencyViolation.DependencyInspection"
    },
    {
        "language": "JAVA",
        "shortName": "FieldCanBeLocal",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.field.can.be.local.display.name",
        "groupName": "Class structure",
        "enabledByDefault": "true",
        "level": "WARNING",
        "runForWholeFile": "true",
        "implementationClass": "com.intellij.codeInspection.varScopeCanBeNarrowed.FieldCanBeLocalInspection"
    },
    {
        "language": "JAVA",
        "shortName": "ParameterCanBeLocal",
        "key": "inspection.parameter.can.be.local.display.name",
        "groupName": "Class structure",
        "enabledByDefault": "true",
        "level": "WARNING",
        "bundle": "messages.InspectionsBundle",
        "implementationClass": "com.intellij.codeInspection.varScopeCanBeNarrowed.ParameterCanBeLocalInspection"
    },
    {
        "language": "JAVA",
        "shortName": "NullableProblems",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.nullable.problems.display.name",
        "groupName": "Probable bugs",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.nullable.NullableStuffInspection"
    },
    {
        "language": "JAVA",
        "shortName": "TestOnlyProblems",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.test.only.problems.display.name",
        "groupName": "General",
        "enabledByDefault": "false",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.testOnly.TestOnlyInspection"
    },
    {
        "language": "JAVA",
        "shortName": "WrongPackageStatement",
        "bundle": "messages.InspectionsBundle",
        "key": "wrong.package.statement",
        "groupName": "",
        "enabledByDefault": "true",
        "level": "ERROR",
        "implementationClass": "com.intellij.codeInspection.wrongPackageStatement.WrongPackageStatementInspection"
    },
    {
        "language": "JAVA",
        "shortName": "SillyAssignment",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.variable.assigned.to.itself.display.name",
        "groupName": "",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.sillyAssignment.SillyAssignmentInspection"
    },
    {
        "language": "JAVA",
        "shortName": "RedundantThrowsDeclaration",
        "bundle": "messages.InspectionsBundle",
        "key": "redundant.throws.declaration",
        "groupName": "Declaration redundancy",
        "enabledByDefault": "false",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.unneededThrows.RedundantThrowsDeclaration"
    },
    {
        "language": "JAVA",
        "shortName": "AccessStaticViaInstance",
        "bundle": "messages.InspectionsBundle",
        "key": "access.static.via.instance",
        "groupName": "",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.accessStaticViaInstance.AccessStaticViaInstance"
    },
    {
        "shortName": "DefaultFileTemplate",
        "bundle": "messages.InspectionsBundle",
        "key": "default.file.template.display.name",
        "groupName": "General",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.defaultFileTemplateUsage.DefaultFileTemplateUsageInspection"
    },
    {
        "language": "JAVA",
        "suppressId": "UnusedDeclaration",
        "alternativeId": "unused",
        "shortName": "UNUSED_SYMBOL",
        "displayName": "Unused symbol",
        "groupName": "Declaration redundancy",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection",
        "unfair": "true"
    },
    {
        "language": "JAVA",
        "shortName": "UNUSED_IMPORT",
        "displayName": "Unused import (editor light)",
        "groupName": "Imports",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.unusedImport.UnusedImportLocalInspection"
    },
    {
        "language": "JAVA",
        "suppressId": "unchecked",
        "shortName": "UNCHECKED_WARNING",
        "displayName": "Unchecked warning",
        "groupName": "",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection"
    },
    {
        "language": "JAVA",
        "shortName": "SuspiciousNameCombination",
        "bundle": "messages.InspectionsBundle",
        "key": "suspicious.name.combination.display.name",
        "groupName": "Probable bugs",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.suspiciousNameCombination.SuspiciousNameCombinationInspection"
    },
    {
        "language": "JAVA",
        "shortName": "DuplicateThrows",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.duplicate.throws.display.name",
        "groupName": "Declaration redundancy",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.duplicateThrows.DuplicateThrowsInspection"
    },
    {
        "language": "JAVA",
        "shortName": "FieldAccessNotGuarded",
        "displayName": "Unguarded field access",
        "groupName": "Concurrency annotation issues",
        "enabledByDefault": "false",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.concurrencyAnnotations.FieldAccessNotGuardedInspection"
    },
    {
        "language": "JAVA",
        "shortName": "InstanceGuardedByStatic",
        "displayName": "Instance member guarded by static field",
        "groupName": "Concurrency annotation issues",
        "enabledByDefault": "false",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.concurrencyAnnotations.InstanceGuardedByStaticInspection"
    },
    {
        "language": "JAVA",
        "shortName": "NonFinalFieldInImmutable",
        "displayName": "Non-final field in @Immutable class",
        "groupName": "Concurrency annotation issues",
        "enabledByDefault": "false",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.concurrencyAnnotations.NonFinalFieldInImmutableInspection"
    },
    {
        "language": "JAVA",
        "shortName": "NonFinalGuard",
        "displayName": "Non-final @GuardedBy field",
        "groupName": "Concurrency annotation issues",
        "enabledByDefault": "false",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.concurrencyAnnotations.NonFinalGuardInspection"
    },
    {
        "language": "JAVA",
        "shortName": "StaticGuardedByInstance",
        "displayName": "Static member guarded by instance field or this",
        "groupName": "Concurrency annotation issues",
        "enabledByDefault": "false",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.concurrencyAnnotations.StaticGuardedByInstanceInspection"
    },
    {
        "language": "JAVA",
        "shortName": "UnknownGuard",
        "displayName": "Unknown @GuardedBy field",
        "groupName": "Concurrency annotation issues",
        "enabledByDefault": "false",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.concurrencyAnnotations.UnknownGuardInspection"
    },
    {
        "language": "JAVA",
        "shortName": "Convert2Diamond",
        "displayName": "Explicit type can be replaced with <>",
        "groupName": "Java language level migration aids",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.ExplicitTypeCanBeDiamondInspection"
    },
    {
        "language": "JAVA",
        "shortName": "Convert2Lambda",
        "displayName": "Anonymous type can be replaced with lambda",
        "groupName": "Java language level migration aids",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.AnonymousCanBeLambdaInspection"
    },
    {
        "language": "JAVA",
        "shortName": "Anonymous2MethodRef",
        "displayName": "Anonymous type can be replaced with method reference",
        "groupName": "Java language level migration aids",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.AnonymousCanBeMethodReferenceInspection"
    },
    {
        "language": "JAVA",
        "shortName": "Convert2MethodRef",
        "displayName": "Lambda can be replaced with method reference",
        "groupName": "Java language level migration aids",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.LambdaCanBeMethReferenceInspection"
    },
    {
        "language": "JAVA",
        "shortName": "CodeBlock2Expr",
        "displayName": "Lambda code block can be replaced with expression",
        "groupName": "Java language level migration aids",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.RedundantLambdaCodeBlockInspection"
    },
    {
        "language": "JAVA",
        "suppressId": "unchecked",
        "shortName": "SafeVarargsDetector",
        "displayName": "Possible heap pollution from parameterized vararg type",
        "groupName": "Java language level migration aids",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.PossibleHeapPollutionVarargsInspection"
    },
    {
        "language": "JAVA",
        "shortName": "JavacQuirks",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.compiler.javac.quirks.name",
        "groupName": "Compiler issues",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.compiler.JavacQuirksInspection"
    },
    {
        "language": "JAVA",
        "shortName": "MagicConstant",
        "displayName": "Magic Constant",
        "groupName": "Probable bugs",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.magicConstant.MagicConstantInspection"
    }
],
"globalInspection": [
    {
        "shortName": "WeakerAccess",
        "displayName": "Declaration access can be weaker",
        "groupName": "Declaration redundancy",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.visibility.VisibilityInspection"
    },
    {
        "shortName": "CanBeFinal",
        "displayName": "Declaration can have final modifier",
        "groupName": "Declaration redundancy",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.canBeFinal.CanBeFinalInspection"
    },
    {
        "shortName": "UnusedParameters",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.unused.parameter.display.name",
        "groupName": "Declaration redundancy",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.unusedParameters.UnusedParametersInspection"
    },
    {
        "shortName": "SameParameterValue",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.same.parameter.display.name",
        "groupName": "Declaration redundancy",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.sameParameterValue.SameParameterValueInspection"
    },
    {
        "shortName": "UnusedReturnValue",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.unused.return.value.display.name",
        "groupName": "Declaration redundancy",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.unusedReturnValue.UnusedReturnValue"
    },
    {
        "shortName": "SameReturnValue",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.same.return.value.display.name",
        "groupName": "Declaration redundancy",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.sameReturnValue.SameReturnValueInspection"
    },
    {
        "shortName": "EmptyMethod",
        "displayName": "Empty method",
        "groupName": "Declaration redundancy",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.emptyMethod.EmptyMethodInspection"
    },
    {
        "shortName": "RedundantThrows",
        "displayName": "Redundant throws clause",
        "groupName": "Declaration redundancy",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.unneededThrows.RedundantThrows"
    },
    {
        "shortName": "UnnecessaryModuleDependencyInspection",
        "bundle": "messages.InspectionsBundle",
        "key": "unnecessary.module.dependency.display.name",
        "groupName": "Declaration redundancy",
        "enabledByDefault": "true",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.unnecessaryModuleDependency.UnnecessaryModuleDependencyInspection"
    },
    {
        "shortName": "RedundantSuppression",
        "bundle": "messages.InspectionsBundle",
        "key": "inspection.redundant.suppression.name",
        "groupName": "Declaration redundancy",
        "enabledByDefault": "false",
        "level": "WARNING",
        "implementationClass": "com.intellij.codeInspection.RedundantSuppressInspection"
    }
]

由于我仍然不知道的原因,评论的使用//noinspection 并不是一直有效.

为了能够使用关键字,UnusedDeclaration我必须在变量声明之前写这行:

/** @noinspection UnusedDeclaration */
private static final String TAG = "DateTools";

推荐阅读
pan2502851807
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有