made getText() work even for invalid action

This commit is contained in:
Alexey Kudravtsev
2011-03-09 12:59:08 +03:00
parent ba9e4f9bf4
commit 7725214e6b
8 changed files with 22 additions and 15 deletions
@@ -91,6 +91,7 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction {
}
private static String formatTypesList(ParameterInfoImpl[] infos, PsiElement context) {
if (infos == null) return null;
String result = "";
try {
for (ParameterInfoImpl info : infos) {
@@ -40,7 +40,7 @@ public class GeneralizeCatchFix implements IntentionAction {
@NotNull
public String getText() {
return QuickFixBundle.message("generalize.catch.text",
HighlightUtil.formatType(myCatchParameter.getType()),
HighlightUtil.formatType(myCatchParameter == null ? null : myCatchParameter.getType()),
HighlightUtil.formatType(myUnhandledException));
}
@@ -30,6 +30,7 @@ import com.intellij.psi.search.PsiElementProcessor;
import com.intellij.psi.search.PsiElementProcessorAdapter;
import com.intellij.psi.search.searches.OverridingMethodsSearch;
import com.intellij.psi.util.PsiFormatUtil;
import com.intellij.psi.util.PsiFormatUtilBase;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.VisibilityUtil;
import com.intellij.util.IncorrectOperationException;
@@ -65,12 +66,12 @@ public class ModifierFix extends IntentionAndQuickFixAction {
@NotNull
public String getName() {
String name = null;
PsiElement parent = myVariable == null ? myModifierList.getParent() : myVariable;
PsiElement parent = myVariable == null ? myModifierList == null ? null : myModifierList.getParent() : myVariable;
if (parent instanceof PsiClass) {
name = ((PsiClass)parent).getName();
}
else {
int options = PsiFormatUtil.SHOW_NAME | (myShowContainingClass ? PsiFormatUtil.SHOW_CONTAINING_CLASS : 0);
int options = PsiFormatUtilBase.SHOW_NAME | (myShowContainingClass ? PsiFormatUtilBase.SHOW_CONTAINING_CLASS : 0);
if (parent instanceof PsiMethod) {
name = PsiFormatUtil.formatMethod((PsiMethod)parent, PsiSubstitutor.EMPTY, options, 0);
}
@@ -101,15 +101,13 @@ public class ReplaceAddAllArrayToCollectionFix implements IntentionAction {
@NonNls
private String getCollectionsMethodCall() {
final PsiExpression qualifierExpression = myMethodCall.getMethodExpression().getQualifierExpression();
PsiExpression[] expressions = myMethodCall.getArgumentList().getExpressions();
return "java.util.Collections.addAll(" +
(qualifierExpression != null ? qualifierExpression.getText() : "this") +
", " +
myMethodCall.getArgumentList().getExpressions()[0]
.getText() +
")";
", " + (expressions.length == 0 ? "" : expressions[0].getText()) + ")";
}
public boolean startInWriteAction() {
return true;
}
}
}
@@ -35,6 +35,7 @@ import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.PsiShortNamesCache;
import com.intellij.psi.util.PsiFormatUtil;
import com.intellij.psi.util.PsiFormatUtilBase;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.proximity.PsiProximityComparator;
import com.intellij.ui.popup.list.ListPopupImpl;
@@ -62,8 +63,10 @@ public class StaticImportMethodFix implements IntentionAction {
@NotNull
public String getText() {
String text = QuickFixBundle.message("static.import.method.text");
if (candidates.size() == 1) {
text += " '" + PsiFormatUtil.formatMethod(candidates.get(0), PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_CONTAINING_CLASS | PsiFormatUtil.SHOW_FQ_NAME, 0)+"'";
if (candidates != null && candidates.size() == 1) {
text += " '" + PsiFormatUtil.formatMethod(candidates.get(0), PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME |
PsiFormatUtilBase.SHOW_CONTAINING_CLASS |
PsiFormatUtilBase.SHOW_FQ_NAME, 0)+"'";
}
else {
text += "...";
@@ -243,7 +246,7 @@ public class StaticImportMethodFix implements IntentionAction {
final PopupListElementRenderer rightArrow = new PopupListElementRenderer(this);
@Override
protected ListCellRenderer getListElementRenderer() {
return new MethodCellRenderer(true, PsiFormatUtil.SHOW_NAME){
return new MethodCellRenderer(true, PsiFormatUtilBase.SHOW_NAME){
@Override
protected DefaultListCellRenderer getRightCellRenderer() {
final DefaultListCellRenderer moduleRenderer = super.getRightCellRenderer();
@@ -70,7 +70,6 @@ public class VariableAccessFromInnerClassFix implements IntentionAction {
case COPY_TO_FINAL:
return QuickFixBundle.message("make.final.copy.to.temp", myVariable.getName());
default:
LOG.error("invalid type "+myFixType);
return "";
}
Collection<PsiVariable> vars = getVariablesToFix();
@@ -56,13 +56,13 @@ public class WrapExpressionFix implements IntentionAction {
@NotNull
public String getText() {
final PsiMethod wrapper = myExpression.isValid() ? findWrapper(myExpression.getType(), myExpectedType, myPrimitiveExpected) : null;
final String methodPresentation = wrapper != null ? (wrapper.getContainingClass().getName() + "." + wrapper.getName()) : "";
final PsiMethod wrapper = myExpression.isValid() && myExpectedType != null ? findWrapper(myExpression.getType(), myExpectedType, myPrimitiveExpected) : null;
final String methodPresentation = wrapper != null ? wrapper.getContainingClass().getName() + "." + wrapper.getName() : "";
return QuickFixBundle.message("wrap.expression.using.static.accessor.text", methodPresentation);
}
@Nullable
private static PsiMethod findWrapper(PsiType type, PsiClassType expectedType, boolean primitiveExpected) {
private static PsiMethod findWrapper(PsiType type, @NotNull PsiClassType expectedType, boolean primitiveExpected) {
PsiClass aClass = expectedType.resolve();
if (aClass != null) {
PsiType expectedReturnType = expectedType;