diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/BindFieldsFromParametersAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/BindFieldsFromParametersAction.java index 735f1ea5102a..380d185e649b 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/BindFieldsFromParametersAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/BindFieldsFromParametersAction.java @@ -30,7 +30,6 @@ import com.intellij.openapi.util.Key; import com.intellij.psi.*; import com.intellij.psi.codeStyle.*; import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.util.Function; import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; @@ -153,9 +152,9 @@ public class BindFieldsFromParametersAction extends BaseIntentionAction implemen } private static void invoke(final Project project, Editor editor, PsiFile file, boolean isInteractive) { - PsiParameter myParameter = FieldFromParameterUtils.findParameterAtCursor(file, editor); + PsiParameter psiParameter = FieldFromParameterUtils.findParameterAtCursor(file, editor); if (!FileModificationService.getInstance().prepareFileForWrite(file)) return; - final PsiMethod method = myParameter != null ? (PsiMethod)myParameter.getDeclarationScope() : PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PsiMethod.class); + final PsiMethod method = psiParameter != null ? (PsiMethod)psiParameter.getDeclarationScope() : PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PsiMethod.class); LOG.assertTrue(method != null); final HashSet usedNames = new HashSet(); @@ -260,16 +259,18 @@ public class BindFieldsFromParametersAction extends BaseIntentionAction implemen } private static void processParameter(final Project project, - final PsiParameter myParameter, + final PsiParameter parameter, final Set usedNames) { IdeDocumentHistory.getInstance(project).includeCurrentPlaceAsChangePlace(); - final PsiType type = FieldFromParameterUtils.getSubstitutedType(myParameter); + final PsiType type = FieldFromParameterUtils.getSubstitutedType(parameter); final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project); - final String parameterName = myParameter.getName(); + final String parameterName = parameter.getName(); String propertyName = styleManager.variableNameToPropertyName(parameterName, VariableKind.PARAMETER); - final PsiClass targetClass = PsiTreeUtil.getParentOfType(myParameter, PsiClass.class); - final PsiMethod method = (PsiMethod)myParameter.getDeclarationScope(); + final PsiClass targetClass = PsiTreeUtil.getParentOfType(parameter, PsiClass.class); + final PsiElement declarationScope = parameter.getDeclarationScope(); + if (!(declarationScope instanceof PsiMethod)) return; + final PsiMethod method = (PsiMethod)declarationScope; final boolean isMethodStatic = method.hasModifierProperty(PsiModifier.STATIC); @@ -298,7 +299,7 @@ public class BindFieldsFromParametersAction extends BaseIntentionAction implemen } final String fieldName = usedNames.add(name) ? name - : JavaCodeStyleManager.getInstance(project).suggestUniqueVariableName(name, myParameter, true); + : JavaCodeStyleManager.getInstance(project).suggestUniqueVariableName(name, parameter, true); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override @@ -308,7 +309,7 @@ public class BindFieldsFromParametersAction extends BaseIntentionAction implemen project, targetClass, method, - myParameter, + parameter, type, fieldName, isMethodStatic, diff --git a/platform/platform-resources-en/src/messages/CodeInsightBundle.properties b/platform/platform-resources-en/src/messages/CodeInsightBundle.properties index 86141c214bbd..32fe7e463cc0 100644 --- a/platform/platform-resources-en/src/messages/CodeInsightBundle.properties +++ b/platform/platform-resources-en/src/messages/CodeInsightBundle.properties @@ -210,7 +210,7 @@ intention.assign.field.from.parameter.family=Assign Parameter to Field intention.create.field.from.parameter.text=Create field for parameter ''{0}'' intention.create.field.from.parameter.family=Create field for parameter intention.bind.fields.from.parameters.text=Bind {0} parameters to fields -intention.bind.fields.from.parameters.family=Bind Parameters to Fields +intention.bind.fields.from.parameters.family=Bind parameters to fields intention.implement.abstract.method.searching.for.descendants.progress=Searching For Descendants... intention.implement.abstract.method.error.no.classes.message=There are no classes found where this method can be implemented intention.implement.abstract.method.error.no.classes.title=No Classes Found