Refactoring: return not-null from doCreateActions()
This commit is contained in:
+2
-2
@@ -24,12 +24,12 @@ import java.util.Collections
|
||||
// TODO: Replace with trait when all subclasses are translated to Kotlin
|
||||
public abstract class JetIntentionActionsFactory {
|
||||
protected open fun isApplicableForCodeFragment(): Boolean = false
|
||||
protected abstract fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>?
|
||||
protected abstract fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>
|
||||
|
||||
public fun createActions(diagnostic: Diagnostic): List<IntentionAction> {
|
||||
if (diagnostic.getPsiElement().getContainingFile() is JetCodeFragment && !isApplicableForCodeFragment()) {
|
||||
return emptyList()
|
||||
}
|
||||
return doCreateActions(diagnostic) ?: emptyList()
|
||||
return doCreateActions(diagnostic)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElement
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
|
||||
public object KotlinAddOrderEntryActionFactory : JetIntentionActionsFactory() {
|
||||
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>? {
|
||||
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction> {
|
||||
val simpleExpression = diagnostic.psiElement as? JetSimpleNameExpression ?: return emptyList()
|
||||
val refElement = simpleExpression.getQualifiedElement()
|
||||
|
||||
@@ -52,6 +52,7 @@ public object KotlinAddOrderEntryActionFactory : JetIntentionActionsFactory() {
|
||||
return simpleExpression.mainReference.bindToElement(element, ShorteningMode.FORCED_SHORTENING)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return OrderEntryFix.registerFixes(QuickFixActionRegistrarImpl(null), reference) as List<IntentionAction>? ?: emptyList()
|
||||
}
|
||||
|
||||
+2
-2
@@ -62,10 +62,10 @@ abstract class KotlinIntentionActionFactoryWithDelegate<E : JetElement, D : Any>
|
||||
|
||||
protected abstract fun extractFixData(element: E, diagnostic: Diagnostic): D?
|
||||
|
||||
override final fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>? {
|
||||
override final fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction> {
|
||||
val diagnosticMessage = DefaultErrorMessages.render(diagnostic)
|
||||
val diagnosticElementPointer = diagnostic.psiElement.createSmartPointer()
|
||||
val originalElement = getElementOfInterest(diagnostic) ?: return null
|
||||
val originalElement = getElementOfInterest(diagnostic) ?: return emptyList()
|
||||
val originalElementPointer = originalElement.createSmartPointer()
|
||||
|
||||
val file = originalElement.containingFile
|
||||
|
||||
@@ -48,18 +48,18 @@ import java.util.*
|
||||
public object SuperClassNotInitialized : JetIntentionActionsFactory() {
|
||||
private val DISPLAY_MAX_PARAMS = 5
|
||||
|
||||
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>? {
|
||||
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction> {
|
||||
val delegator = diagnostic.getPsiElement() as JetDelegatorToSuperClass
|
||||
val classOrObjectDeclaration = delegator.getParent().getParent() as? JetClassOrObject ?: return null
|
||||
val classOrObjectDeclaration = delegator.getParent().getParent() as? JetClassOrObject ?: return emptyList()
|
||||
|
||||
val typeRef = delegator.getTypeReference() ?: return null
|
||||
val type = typeRef.analyze()[BindingContext.TYPE, typeRef] ?: return null
|
||||
if (type.isError()) return null
|
||||
val typeRef = delegator.getTypeReference() ?: return emptyList()
|
||||
val type = typeRef.analyze()[BindingContext.TYPE, typeRef] ?: return emptyList()
|
||||
if (type.isError()) return emptyList()
|
||||
|
||||
val superClass = (type.getConstructor().getDeclarationDescriptor() as? ClassDescriptor) ?: return null
|
||||
val superClass = (type.getConstructor().getDeclarationDescriptor() as? ClassDescriptor) ?: return emptyList()
|
||||
val classDescriptor = delegator.getResolutionFacade().resolveToDescriptor(classOrObjectDeclaration) as ClassDescriptor
|
||||
val constructors = superClass.getConstructors().filter { it.isVisible(classDescriptor) }
|
||||
if (constructors.isEmpty()) return null // no accessible constructor
|
||||
if (constructors.isEmpty()) return emptyList() // no accessible constructor
|
||||
|
||||
val fixes = ArrayList<IntentionAction>()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user