Replaced AddReturnTypeFix with SpecifyTypeExplicitlyAction for properties.
This commit is contained in:
@@ -20,17 +20,17 @@ import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.impl.source.tree.LeafPsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil;
|
||||
import org.jetbrains.jet.plugin.refactoring.introduceVariable.JetChangePropertyActions;
|
||||
@@ -41,6 +41,15 @@ import org.jetbrains.jet.plugin.refactoring.introduceVariable.JetChangePropertyA
|
||||
*/
|
||||
public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
|
||||
private JetType targetType;
|
||||
private boolean disabledForError;
|
||||
|
||||
public SpecifyTypeExplicitlyAction() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public SpecifyTypeExplicitlyAction(boolean disabledForError) {
|
||||
this.disabledForError = disabledForError;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -82,6 +91,13 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
|
||||
if (ErrorUtils.isErrorType(targetType)) {
|
||||
return false;
|
||||
}
|
||||
if (disabledForError) {
|
||||
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
|
||||
if (Errors.PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE == diagnostic.getFactory() && property == diagnostic.getPsiElement()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class AddReturnTypeFix extends JetIntentionAction<JetNamedDeclaration> {
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
JetType type = QuickFixUtil.getDeclarationReturnType(element);
|
||||
return super.isAvailable(project, editor, file) && type != null && !ErrorUtils.isErrorType(type);
|
||||
return super.isAvailable(project, editor, file) && type != null && !ErrorUtils.isErrorType(type) && element instanceof JetFunction;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,9 +61,6 @@ public class AddReturnTypeFix extends JetIntentionAction<JetNamedDeclaration> {
|
||||
PsiElement newElement;
|
||||
JetType type = QuickFixUtil.getDeclarationReturnType(element);
|
||||
if (type == null) return;
|
||||
if (element instanceof JetProperty) {
|
||||
newElement = addPropertyType(project, (JetProperty) element, type);
|
||||
}
|
||||
else {
|
||||
assert element instanceof JetFunction;
|
||||
newElement = addFunctionType(project, (JetFunction) element, type);
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.jetbrains.jet.lang.diagnostics.AbstractDiagnosticFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.plugin.codeInsight.ImplementMethodsHandler;
|
||||
import org.jetbrains.jet.plugin.intentions.SpecifyTypeExplicitlyAction;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -137,5 +138,6 @@ public class QuickFixes {
|
||||
|
||||
actions.put(UNNECESSARY_SAFE_CALL, new ReplaceCallFix(false));
|
||||
actions.put(UNSAFE_CALL, new ReplaceCallFix(true));
|
||||
actions.put(PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE, new SpecifyTypeExplicitlyAction(false));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Add return type declaration" "true"
|
||||
// "Specify Type Explicitly" "true"
|
||||
package a
|
||||
|
||||
import java.util.List
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Add return type declaration" "true"
|
||||
// "Specify Type Explicitly" "true"
|
||||
package a
|
||||
|
||||
public val <caret>l = java.util.Collections.emptyList<Int>()
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Add return type declaration" "true"
|
||||
// "Specify Type Explicitly" "true"
|
||||
|
||||
package a
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Add return type declaration" "true"
|
||||
// "Specify Type Explicitly" "true"
|
||||
|
||||
class A() {}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Add return type declaration" "true"
|
||||
// "Specify Type Explicitly" "true"
|
||||
|
||||
package a
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Add return type declaration" "true"
|
||||
// "Specify Type Explicitly" "true"
|
||||
|
||||
class A() {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user