Minor, move top level function to companion object
Package 'org.jetbrains.kotlin.idea.quickfix' already contains top level functions in module 'idea-analysis' and top level functions in another module cause compilation errors because of package facade class clash
This commit is contained in:
@@ -16,21 +16,17 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.inspections
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
import com.intellij.codeInspection.*
|
||||
import com.intellij.openapi.progress.ProcessCanceledException
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult
|
||||
import org.jetbrains.kotlin.idea.highlighter.JetPsiChecker
|
||||
import org.jetbrains.kotlin.idea.quickfix.CleanupFix
|
||||
import org.jetbrains.kotlin.idea.quickfix.JetWholeProjectModalAction
|
||||
import org.jetbrains.kotlin.idea.quickfix.ReplaceObsoleteLabelSyntaxFix
|
||||
import org.jetbrains.kotlin.idea.quickfix.looksLikeObsoleteLabel
|
||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
|
||||
import org.jetbrains.kotlin.psi.JetAnnotationEntry
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
@@ -85,7 +81,7 @@ public class KotlinCleanupInspection(): LocalInspectionTool(), CleanupLocalInspe
|
||||
|
||||
private fun Diagnostic.isObsoleteLabel(): Boolean {
|
||||
val annotationEntry = getPsiElement().getNonStrictParentOfType<JetAnnotationEntry>() ?: return false
|
||||
return annotationEntry.looksLikeObsoleteLabel()
|
||||
return ReplaceObsoleteLabelSyntaxFix.looksLikeObsoleteLabel(annotationEntry)
|
||||
}
|
||||
|
||||
private fun Diagnostic.toProblemDescriptor(file: JetFile, manager: InspectionManager): ProblemDescriptor? {
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.createIntentionFactory
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.anyDescendantOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespaceAndComments
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
|
||||
@@ -40,7 +39,7 @@ public class ReplaceObsoleteLabelSyntaxFix(element: JetAnnotationEntry?) : JetIn
|
||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||
val annotationEntry = diagnostic.getPsiElement().getNonStrictParentOfType<JetAnnotationEntry>() ?: return null
|
||||
|
||||
if (!annotationEntry.looksLikeObsoleteLabel()) return null
|
||||
if (!looksLikeObsoleteLabel(annotationEntry)) return null
|
||||
|
||||
return ReplaceObsoleteLabelSyntaxFix(annotationEntry)
|
||||
}
|
||||
@@ -64,7 +63,7 @@ public class ReplaceObsoleteLabelSyntaxFix(element: JetAnnotationEntry?) : JetIn
|
||||
expression.getAnnotationEntries().filter { it.looksLikeObsoleteLabelWithReferencesInCode() }
|
||||
|
||||
private fun JetAnnotationEntry.looksLikeObsoleteLabelWithReferencesInCode(): Boolean {
|
||||
if (!looksLikeObsoleteLabel()) return false
|
||||
if (!looksLikeObsoleteLabel(this)) return false
|
||||
|
||||
val baseExpression = (getParent() as? JetAnnotatedExpression)?.getBaseExpression() ?: return false
|
||||
|
||||
@@ -78,6 +77,13 @@ public class ReplaceObsoleteLabelSyntaxFix(element: JetAnnotationEntry?) : JetIn
|
||||
} && analyze().getDiagnostics().forElement(nameExpression).any { it.getFactory() == Errors.UNRESOLVED_REFERENCE }
|
||||
}
|
||||
|
||||
public fun looksLikeObsoleteLabel(entry: JetAnnotationEntry): Boolean =
|
||||
entry.getAtSymbol() != null &&
|
||||
entry.getParent() is JetAnnotatedExpression &&
|
||||
(entry.getParent() as JetAnnotatedExpression).getAnnotationEntries().size() == 1 &&
|
||||
entry.getValueArgumentList() == null &&
|
||||
entry.getCalleeExpression()?.getConstructorReferenceExpression()?.getIdentifier() != null
|
||||
|
||||
private fun replaceWithLabel(annotation: JetAnnotationEntry) {
|
||||
val labelName = annotation.getCalleeExpression()?.getConstructorReferenceExpression()?.getReferencedName() ?: return
|
||||
val annotatedExpression = annotation.getParent() as? JetAnnotatedExpression ?: return
|
||||
@@ -96,10 +102,3 @@ public class ReplaceObsoleteLabelSyntaxFix(element: JetAnnotationEntry?) : JetIn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public fun JetAnnotationEntry.looksLikeObsoleteLabel(): Boolean =
|
||||
getAtSymbol() != null &&
|
||||
getParent() is JetAnnotatedExpression &&
|
||||
(getParent() as JetAnnotatedExpression).getAnnotationEntries().size() == 1 &&
|
||||
getValueArgumentList() == null &&
|
||||
getCalleeExpression()?.getConstructorReferenceExpression()?.getIdentifier() != null
|
||||
|
||||
Reference in New Issue
Block a user