在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));
}
在此示例中,我使用了关键字“弃用”,但找不到可用关键字的完整列表。
有人发现了吗?
谢谢!
答案 0 :(得分:18)
我终于成功从这个Github source code获取了关键字列表。
我把它贴在这里以防万一:
"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 <keyword>
并不是一直有效。
为了能够使用关键字UnusedDeclaration
,我必须在变量声明之前写下这一行:
/** @noinspection UnusedDeclaration */
private static final String TAG = "DateTools";
答案 1 :(得分:3)
我可能错了,但我认为最接近的是Android Studio设置中的Inspections
视图。按 Ctrl + Alt + S ,选择Editor
- &gt; Inspections
。
它不会显示可用的noinspection
个关键字列表,但它会为您提供Android Studio中可用的检查的完整列表。