IDEA-29993 As well as the intension "Cast to String" offer "Call toString()". WrapExpression intention scope widen.

This commit is contained in:
Danila Ponomarenko
2012-06-20 18:37:40 +04:00
parent 23e1bd0139
commit c14fe14cc4
2 changed files with 14 additions and 14 deletions
@@ -26,7 +26,6 @@ package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.CodeInsightUtilBase;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
@@ -48,7 +48,7 @@ public class WrapExpressionFix implements IntentionAction {
if (type instanceof PsiClassType) {
return (PsiClassType)type;
}
else if (type instanceof PsiPrimitiveType){
else if (type instanceof PsiPrimitiveType) {
return ((PsiPrimitiveType)type).getBoxedType(place.getManager(), GlobalSearchScope.allScope(place.getProject()));
}
return null;
@@ -73,10 +73,11 @@ public class WrapExpressionFix implements IntentionAction {
if (expectedReturnType == null) return null;
PsiMethod[] methods = aClass.getMethods();
for (PsiMethod method : methods) {
if (method.hasModifierProperty(PsiModifier.STATIC) && method.getParameterList().getParametersCount() == 1 &&
method.getParameterList().getParameters()[0].getType().equals(type) &&
method.getReturnType() != null &&
expectedReturnType.equals(method.getReturnType())) {
if (method.hasModifierProperty(PsiModifier.STATIC)
&& method.getParameterList().getParametersCount() == 1
&& method.getParameterList().getParameters()[0].getType().isAssignableFrom(type)
&& method.getReturnType() != null
&& expectedReturnType.equals(method.getReturnType())) {
return method;
}
}
@@ -108,10 +109,10 @@ public class WrapExpressionFix implements IntentionAction {
assert wrapper != null;
PsiElementFactory factory = JavaPsiFacade.getInstance(file.getProject()).getElementFactory();
@NonNls String methodCallText = "Foo." + wrapper.getName() + "()";
PsiMethodCallExpression call = (PsiMethodCallExpression) factory.createExpressionFromText(methodCallText,
null);
PsiMethodCallExpression call = (PsiMethodCallExpression)factory.createExpressionFromText(methodCallText,
null);
call.getArgumentList().add(myExpression);
((PsiReferenceExpression) call.getMethodExpression().getQualifierExpression()).bindToElement(
((PsiReferenceExpression)call.getMethodExpression().getQualifierExpression()).bindToElement(
wrapper.getContainingClass());
myExpression.replace(call);
}
@@ -121,7 +122,7 @@ public class WrapExpressionFix implements IntentionAction {
return true;
}
public static void registerWrapAction (JavaResolveResult[] candidates, PsiExpression[] expressions, HighlightInfo highlightInfo) {
public static void registerWrapAction(JavaResolveResult[] candidates, PsiExpression[] expressions, HighlightInfo highlightInfo) {
PsiType expectedType = null;
PsiExpression expr = null;
@@ -138,17 +139,18 @@ public class WrapExpressionFix implements IntentionAction {
PsiExpression expression = expressions[j];
final PsiType exprType = expression.getType();
if (exprType != null) {
PsiType paramType = parameters[Math.min(j, parameters.length -1)].getType();
PsiType paramType = parameters[Math.min(j, parameters.length - 1)].getType();
if (paramType instanceof PsiEllipsisType) {
paramType = ((PsiEllipsisType)paramType).getComponentType();
}
paramType = substitutor != null ? substitutor.substitute(paramType) : paramType;
if (paramType.isAssignableFrom(exprType)) continue;
//if (paramType.isAssignableFrom(exprType)) continue;
final PsiClassType classType = getClassType(paramType, expression);
if (expectedType == null && classType != null && findWrapper(exprType, classType, paramType instanceof PsiPrimitiveType) != null) {
expectedType = paramType;
expr = expression;
} else {
}
else {
expectedType = null;
expr = null;
continue nextMethod;
@@ -161,5 +163,4 @@ public class WrapExpressionFix implements IntentionAction {
QuickFixAction.registerQuickFixAction(highlightInfo, expr.getTextRange(), new WrapExpressionFix(expectedType, expr));
}
}
}