Move JetCodeFragment-related logic to JetIntentionActionsFactory
This commit is contained in:
+13
-2
@@ -18,7 +18,18 @@ package org.jetbrains.jet.plugin.quickfix
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic
|
||||
import org.jetbrains.jet.lang.psi.JetCodeFragment
|
||||
import java.util.Collections
|
||||
|
||||
public trait JetIntentionActionsFactory {
|
||||
public fun createActions(diagnostic: Diagnostic): List<IntentionAction>
|
||||
// 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>
|
||||
|
||||
public fun createActions(diagnostic: Diagnostic): List<IntentionAction> {
|
||||
if (diagnostic.getPsiElement().getContainingFile() is JetCodeFragment && !isApplicableForCodeFragment()) {
|
||||
return Collections.emptyList()
|
||||
}
|
||||
return doCreateActions(diagnostic)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
|
||||
return new JetIntentionActionsFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<IntentionAction> createActions(@NotNull Diagnostic diagnostic) {
|
||||
protected List<IntentionAction> doCreateActions(@NotNull Diagnostic diagnostic) {
|
||||
List<IntentionAction> actions = new LinkedList<IntentionAction>();
|
||||
|
||||
JetFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetFunction.class);
|
||||
|
||||
@@ -128,7 +128,7 @@ public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclara
|
||||
return new JetIntentionActionsFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<IntentionAction> createActions(@NotNull Diagnostic diagnostic) {
|
||||
protected List<IntentionAction> doCreateActions(@NotNull Diagnostic diagnostic) {
|
||||
List<IntentionAction> actions = new LinkedList<IntentionAction>();
|
||||
|
||||
JetProperty property = QuickFixUtil.getParentElementOfType(diagnostic, JetProperty.class);
|
||||
|
||||
@@ -18,20 +18,11 @@ package org.jetbrains.jet.plugin.quickfix
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic
|
||||
import org.jetbrains.jet.lang.psi.JetCodeFragment
|
||||
|
||||
import java.util.Collections
|
||||
import org.jetbrains.jet.utils.addToStdlib.singletonOrEmptyList
|
||||
|
||||
public abstract class JetSingleIntentionActionFactory : JetIntentionActionsFactory {
|
||||
public abstract fun createAction(diagnostic: Diagnostic): IntentionAction?
|
||||
public abstract class JetSingleIntentionActionFactory : JetIntentionActionsFactory() {
|
||||
protected abstract fun createAction(diagnostic: Diagnostic): IntentionAction?
|
||||
|
||||
override fun createActions(diagnostic: Diagnostic): List<IntentionAction> {
|
||||
if (diagnostic.getPsiElement().getContainingFile() is JetCodeFragment && !isApplicableForCodeFragment()) {
|
||||
return Collections.emptyList()
|
||||
}
|
||||
return createAction(diagnostic).singletonOrEmptyList()
|
||||
}
|
||||
|
||||
public fun isApplicableForCodeFragment(): Boolean = false
|
||||
final override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction> = createAction(diagnostic).singletonOrEmptyList()
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
//TODO: should use change signature to deal with cases of multiple overridden descriptors
|
||||
public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsFactory {
|
||||
public class QuickFixFactoryForTypeMismatchError extends JetIntentionActionsFactory {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<IntentionAction> createActions(@NotNull Diagnostic diagnostic) {
|
||||
protected List<IntentionAction> doCreateActions(@NotNull Diagnostic diagnostic) {
|
||||
List<IntentionAction> actions = new LinkedList<IntentionAction>();
|
||||
|
||||
DiagnosticWithParameters2<JetExpression, JetType, JetType> diagnosticWithParameters = Errors.TYPE_MISMATCH.cast(diagnostic);
|
||||
|
||||
Reference in New Issue
Block a user