Fix quickfix and tests

This commit is contained in:
Zalim Bashorov
2015-09-30 23:08:23 +03:00
parent a36e4abf4d
commit 9256682cc5
11 changed files with 25 additions and 14 deletions
@@ -89,7 +89,6 @@ public class KotlinCleanupInspection(): LocalInspectionTool(), CleanupLocalInspe
Errors.USELESS_ELVIS,
ErrorsJvm.POSITIONED_VALUE_ARGUMENT_FOR_JAVA_ANNOTATION,
Errors.DEPRECATED_SYMBOL_WITH_MESSAGE,
Errors.ACCESS_TO_PRIVATE_TOP_LEVEL_FROM_ANOTHER_FILE,
Errors.NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION,
Errors.BACKING_FIELD_SYNTAX_DEPRECATED,
Errors.OPERATOR_MODIFIER_REQUIRED
@@ -19,12 +19,16 @@ package org.jetbrains.kotlin.idea.quickfix
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithVisibility
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory3
import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.psi.JetFile
import org.jetbrains.kotlin.psi.JetModifierListOwner
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.DescriptorUtils
public class ChangePrivateTopLevelToInternalFix(element: JetModifierListOwner, private val elementName: String) : JetIntentionAction<JetModifierListOwner>(element), CleanupFix {
override fun getText() = "Make $elementName internal"
@@ -36,9 +40,15 @@ public class ChangePrivateTopLevelToInternalFix(element: JetModifierListOwner, p
companion object : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
val descriptor = Errors.ACCESS_TO_PRIVATE_TOP_LEVEL_FROM_ANOTHER_FILE.cast(diagnostic).a
@Suppress("UNCHECKED_CAST")
val factory = diagnostic.factory as DiagnosticFactory3<*, DeclarationDescriptor, *, DeclarationDescriptor>
val descriptor = factory.cast(diagnostic).c
if (!DescriptorUtils.isTopLevelDeclaration(descriptor) ||
descriptor !is DeclarationDescriptorWithVisibility ||
descriptor.visibility != Visibilities.PRIVATE) return null
val declaration = DescriptorToSourceUtils.getSourceFromDescriptor(descriptor) as? JetModifierListOwner ?: return null
return ChangePrivateTopLevelToInternalFix(declaration, descriptor.name.asString())
}
}
}
}
@@ -66,8 +66,6 @@ public class QuickFixRegistrar : QuickFixContributor {
ABSTRACT_MEMBER_NOT_IMPLEMENTED.registerFactory(addAbstractModifierFactory)
MANY_IMPL_MEMBER_NOT_IMPLEMENTED.registerFactory(addAbstractModifierFactory)
ACCESS_TO_PRIVATE_TOP_LEVEL_FROM_ANOTHER_FILE.registerFactory(ChangePrivateTopLevelToInternalFix)
val removeFinalModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(FINAL_KEYWORD)
val addAbstractToClassFactory = AddModifierFix.createFactory(ABSTRACT_KEYWORD, javaClass<JetClass>())
ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS.registerFactory(removeAbstractModifierFactory, addAbstractToClassFactory)
@@ -144,6 +142,10 @@ public class QuickFixRegistrar : QuickFixContributor {
CANNOT_CHANGE_ACCESS_PRIVILEGE.registerFactory(ChangeVisibilityModifierFix.createFactory())
CANNOT_WEAKEN_ACCESS_PRIVILEGE.registerFactory(ChangeVisibilityModifierFix.createFactory())
INVISIBLE_REFERENCE.registerFactory(ChangePrivateTopLevelToInternalFix)
INVISIBLE_MEMBER.registerFactory(ChangePrivateTopLevelToInternalFix)
INVISIBLE_SETTER.registerFactory(ChangePrivateTopLevelToInternalFix)
REDUNDANT_NULLABLE.registerFactory(RemoveNullableFix.createFactory(RemoveNullableFix.NullableKind.REDUNDANT))
NULLABLE_SUPERTYPE.registerFactory(RemoveNullableFix.createFactory(RemoveNullableFix.NullableKind.SUPERTYPE))
USELESS_NULLABLE_CHECK.registerFactory(RemoveNullableFix.createFactory(RemoveNullableFix.NullableKind.USELESS))
@@ -1,5 +1,5 @@
// "Make f internal" "true"
// ERROR: Cannot access 'f': it is 'private' in 'privateTopLevelFunInFile.before.Dependency.kt'
// ERROR: Cannot access 'f': it is 'private' in file
package test
@@ -1,5 +1,5 @@
// "Make f internal" "true"
// ERROR: Cannot access 'f': it is 'private' in 'privateTopLevelFunInFile.before.Dependency.kt'
// ERROR: Cannot access 'f': it is 'private' in file
package test
@@ -1,5 +1,5 @@
// "Make prop internal" "true"
// ERROR: Cannot access 'prop': it is 'private' in 'privateTopLevelValInFile.before.Dependency.kt'
// ERROR: Cannot access 'prop': it is 'private' in file
package test
@@ -1,5 +1,5 @@
// "Make prop internal" "true"
// ERROR: Cannot access 'prop': it is 'private' in 'privateTopLevelValInFile.before.Dependency.kt'
// ERROR: Cannot access 'prop': it is 'private' in file
package test
@@ -1,5 +1,5 @@
// "Make prop internal" "true"
// ERROR: Cannot access 'prop': it is 'private' in 'privateTopLevelVarInFile.before.Dependency.kt'
// ERROR: Cannot access 'prop': it is 'private' in file
package test
@@ -1,5 +1,5 @@
// "Make prop internal" "true"
// ERROR: Cannot access 'prop': it is 'private' in 'privateTopLevelVarInFile.before.Dependency.kt'
// ERROR: Cannot access 'prop': it is 'private' in file
package test
@@ -1,5 +1,5 @@
// "Make <set-prop> internal" "true"
// ERROR: Cannot access '<set-prop>': it is 'private' in 'privateTopLevelVarWithSetterInFile.before.Dependency.kt'
// ERROR: Cannot assign to 'prop': the setter is 'private' in file
package test
@@ -1,5 +1,5 @@
// "Make <set-prop> internal" "true"
// ERROR: Cannot access '<set-prop>': it is 'private' in 'privateTopLevelVarWithSetterInFile.before.Dependency.kt'
// ERROR: Cannot assign to 'prop': the setter is 'private' in file
package test