Skip to content

Commit

Permalink
Ignore anonymous constructor implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
mkevins committed Aug 22, 2023
1 parent 5e807b2 commit dfaedd1
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import com.android.tools.lint.detector.api.isJava
import com.intellij.psi.PsiPrimitiveType
import org.jetbrains.uast.UAnnotated
import org.jetbrains.uast.UAnnotationMethod
import org.jetbrains.uast.UAnonymousClass
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UEnumConstant
import org.jetbrains.uast.UField
import org.jetbrains.uast.UMethod
import org.jetbrains.uast.UParameter
import org.jetbrains.uast.UVariable
import org.jetbrains.uast.getContainingUClass

class MissingNullAnnotationDetector : Detector(), SourceCodeScanner {
override fun getApplicableUastTypes(): List<Class<out UElement>> = listOf(
Expand All @@ -39,6 +41,10 @@ class MissingNullAnnotationDetector : Detector(), SourceCodeScanner {
}

override fun visitMethod(node: UMethod) {
// Ignore anonymous constructor implementations
if (node.isAnonymousConstructor) {
return
}
node.uastParameters.forEach { visitParameter(node, it) }

if (node.requiresNullAnnotation && !node.isNullAnnotated) {
Expand Down Expand Up @@ -108,6 +114,8 @@ private val UMethod.isPrimitive
get() = returnType is PsiPrimitiveType
private val UMethod.requiresNullAnnotation
get() = this !is UAnnotationMethod && !isPrimitive && !isConstructor
private val UMethod.isAnonymousConstructor
get() = isConstructor && getContainingUClass()?.let { it is UAnonymousClass } == true

/* UAnnotated Extensions */
private val UAnnotated.isNullAnnotated
Expand Down

0 comments on commit dfaedd1

Please sign in to comment.