@@ -73,20 +73,15 @@ class CheckedExceptionsDetector : Detector(), Detector.UastScanner {
7373
7474 override fun createUastHandler (context : JavaContext ) = object : UElementHandler () {
7575
76- init {
77- // println(context.uastFile?.asRecursiveLogString())
78- }
79-
8076 override fun visitCallExpression (node : UCallExpression ) {
8177
82- val call = node
83- val method = call.resolve() ? : return
84- val uMethod = context.uastContext.getMethod(method)
78+ val method = node.resolve() ? : return
79+ val uMethod = UastFacade .convertElement(method, null , UMethod ::class .java) as UMethod
8580
8681 var throwsExceptions = HashMap <String , HashSet <String >>()
8782
8883 // Find @Throws in annotation expression
89- for (annotation in uMethod.annotations ) {
84+ for (annotation in uMethod.uAnnotations ) {
9085 if (annotation.qualifiedName != " kotlin.jvm.Throws" ) continue
9186 for (throwsException in findNamedExpressionsInAnnotation(annotation)) {
9287 throwsExceptions[throwsException.canonicalText] = findClassParents(throwsException)
@@ -119,9 +114,9 @@ class CheckedExceptionsDetector : Detector(), Detector.UastScanner {
119114
120115
121116 // Remove catched
122- for (element in call .withContainingElements) {
117+ for (element in node .withContainingElements) {
123118 if (element !is UMethod ) continue
124- for (child in element.annotations ) {
119+ for (child in element.uAnnotations ) {
125120 for (classInAnnotation in findNamedExpressionsInAnnotation(child)) {
126121 throwsExceptions = throwsExceptions.filterTo(HashMap ()) {
127122 ! it.value.contains(classInAnnotation.canonicalText)
@@ -131,7 +126,7 @@ class CheckedExceptionsDetector : Detector(), Detector.UastScanner {
131126 break
132127 }
133128
134- for (element in call .withContainingElements) {
129+ for (element in node .withContainingElements) {
135130 if (element !is UTryExpression ) continue
136131 for (catchCause in element.catchClauses) {
137132 catchCause.types.forEach { catch ->
@@ -145,7 +140,7 @@ class CheckedExceptionsDetector : Detector(), Detector.UastScanner {
145140
146141 for (exceptions in throwsExceptions) {
147142 context.report(
148- ISSUE_PATTERN , call , context.getNameLocation(call ),
143+ ISSUE_PATTERN , node , context.getNameLocation(node ),
149144 " Unhandled exception: ${exceptions.key} "
150145 )
151146 }
0 commit comments