Suppressing unused parameter annotation when function is entry point.

This commit is contained in:
Evgeny Gerashchenko
2015-02-17 21:23:01 +03:00
parent 943131b7b0
commit b1840ebd99
7 changed files with 91 additions and 27 deletions
@@ -48,6 +48,6 @@ public class DuplicateJvmSignatureAnnotator implements Annotator {
Diagnostics diagnostics = AsJavaPackage.getJvmSignatureDiagnostics(element, otherDiagnostics, moduleScope);
if (diagnostics == null) return;
JetPsiChecker.annotateElement(element, holder, diagnostics);
new JetPsiChecker().annotateElement(element, holder, diagnostics);
}
}
@@ -45,6 +45,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.*
import org.jetbrains.kotlin.idea.quickfix.QuickFixes
import kotlin.platform.platformStatic
import org.jetbrains.kotlin.idea.kdoc.KDocHighlightingVisitor
import org.jetbrains.kotlin.psi.JetParameter
public open class JetPsiChecker : Annotator, HighlightRangeExtension {
@@ -71,7 +72,18 @@ public open class JetPsiChecker : Annotator, HighlightRangeExtension {
return file is JetFile
}
private class ElementAnnotator(private val element: PsiElement, private val holder: AnnotationHolder) {
open protected fun shouldSuppressUnusedParameter(parameter: JetParameter): Boolean = false
fun annotateElement(element: PsiElement, holder: AnnotationHolder, diagnostics: Diagnostics) {
if (ProjectRootsUtil.isInProjectSource(element) || element.getContainingFile() is JetCodeFragment) {
val elementAnnotator = ElementAnnotator(element, holder)
for (diagnostic in diagnostics.forElement(element)) {
elementAnnotator.registerDiagnosticAnnotations(diagnostic)
}
}
}
private inner class ElementAnnotator(private val element: PsiElement, private val holder: AnnotationHolder) {
private var isMarkedWithRedeclaration = false
fun registerDiagnosticAnnotations(diagnostic: Diagnostic) {
@@ -130,6 +142,9 @@ public open class JetPsiChecker : Annotator, HighlightRangeExtension {
}
}
Severity.WARNING -> {
if (factory == Errors.UNUSED_PARAMETER && shouldSuppressUnusedParameter(diagnostic.getPsiElement() as JetParameter)) {
return
}
for (textRange in textRanges) {
val annotation = holder.createWarningAnnotation(textRange, getDefaultMessage(diagnostic))
setUpAnnotation(diagnostic, annotation, if (factory in Errors.UNUSED_ELEMENT_DIAGNOSTICS)
@@ -227,14 +242,5 @@ public open class JetPsiChecker : Annotator, HighlightRangeExtension {
DeprecatedAnnotationVisitor(holder, bindingContext)
)
platformStatic fun annotateElement(element: PsiElement, holder: AnnotationHolder, diagnostics: Diagnostics) {
if (ProjectRootsUtil.isInProjectSource(element) || element.getContainingFile() is JetCodeFragment) {
val elementAnnotator = ElementAnnotator(element, holder)
for (diagnostic in diagnostics.forElement(element)) {
elementAnnotator.registerDiagnosticAnnotations(diagnostic)
}
}
}
}
}