From fa29e75add49662d3f3c4815629ae11d0fdc2e6c Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 26 May 2015 16:39:04 +0300 Subject: [PATCH] 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 --- .../inspections/KotlinCleanupInspection.kt | 6 +----- .../quickfix/ReplaceObsoleteLabelSyntaxFix.kt | 19 +++++++++---------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt index ded013a166f..bba46649841 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt @@ -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() ?: return false - return annotationEntry.looksLikeObsoleteLabel() + return ReplaceObsoleteLabelSyntaxFix.looksLikeObsoleteLabel(annotationEntry) } private fun Diagnostic.toProblemDescriptor(file: JetFile, manager: InspectionManager): ProblemDescriptor? { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceObsoleteLabelSyntaxFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceObsoleteLabelSyntaxFix.kt index 1c64b66948b..879d5bb0c32 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceObsoleteLabelSyntaxFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceObsoleteLabelSyntaxFix.kt @@ -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() ?: 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