From c14fe14cc44a6855570a5f5533396572e0e3a131 Mon Sep 17 00:00:00 2001 From: Danila Ponomarenko Date: Wed, 20 Jun 2012 18:30:22 +0400 Subject: [PATCH] IDEA-29993 As well as the intension "Cast to String" offer "Call toString()". WrapExpression intention scope widen. --- .../daemon/impl/quickfix/AddTypeCastFix.java | 1 - .../impl/quickfix/WrapExpressionFix.java | 27 ++++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddTypeCastFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddTypeCastFix.java index 5966fbf38d36..28d0b986e4e7 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddTypeCastFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddTypeCastFix.java @@ -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; diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/WrapExpressionFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/WrapExpressionFix.java index e03214da210f..e327a9bb0ab4 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/WrapExpressionFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/WrapExpressionFix.java @@ -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)); } } - }