From 7f2f5733ef923054158b191a76636735e860bfae Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Wed, 28 Jul 2010 11:21:47 +0400 Subject: [PATCH] EA-19530 - AIOOBE: GroovyVariableValidator.isOKImpl --- .../refactoring/GroovyRefactoringBundle.properties | 3 ++- .../GroovyIntroduceVariableBase.java | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringBundle.properties b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringBundle.properties index 0e947a79f6eb..4a9e38fa2bdc 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringBundle.properties +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringBundle.properties @@ -121,4 +121,5 @@ changing.signature.of.0=Changing signature of {0} refactored.method.will.cover.closure.property=Refactored method will override closure property ''{0}'' in {1} changeSignature.not.throwable.type=Wrong type: ''{0}'' for exception, should extend java.lang.Throwable changeSignature.wrong.type.for.exception=Wrong type: ''{0}'' for exception -changeSignature.no.type.for.exception=Specify a type for exception \ No newline at end of file +changeSignature.no.type.for.exception=Specify a type for exception +no.occurences.found=No occurences found \ No newline at end of file diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduceVariable/GroovyIntroduceVariableBase.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduceVariable/GroovyIntroduceVariableBase.java index 4b44eb03a117..ff90f6e44af1 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduceVariable/GroovyIntroduceVariableBase.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduceVariable/GroovyIntroduceVariableBase.java @@ -38,6 +38,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlo import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrStringInjection; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod; @@ -90,8 +91,9 @@ public abstract class GroovyIntroduceVariableBase implements RefactoringActionHa private boolean invokeImpl(final Project project, final GrExpression selectedExpr, final Editor editor) { - if (selectedExpr == null) { - String message = RefactoringBundle.getCannotRefactorMessage(GroovyRefactoringBundle.message("selected.block.should.represent.an.expression")); + if (selectedExpr == null || (selectedExpr instanceof GrClosableBlock && selectedExpr.getParent() instanceof GrStringInjection)) { + String message = + RefactoringBundle.getCannotRefactorMessage(GroovyRefactoringBundle.message("selected.block.should.represent.an.expression")); showErrorMessage(project, editor, message); return false; } @@ -145,6 +147,12 @@ public abstract class GroovyIntroduceVariableBase implements RefactoringActionHa // Find occurrences final PsiElement[] occurrences = GroovyRefactoringUtil.getExpressionOccurrences(GroovyRefactoringUtil.getUnparenthesizedExpr(selectedExpr), tempContainer); + if (occurrences == null || occurrences.length == 0) { + String message = RefactoringBundle.getCannotRefactorMessage(GroovyRefactoringBundle.message("no.occurences.found")); + showErrorMessage(project, editor, message); + return false; + } + // Getting settings Validator validator = new GroovyVariableValidator(this, project, selectedExpr, occurrences, tempContainer); GroovyIntroduceVariableDialog dialog = getDialog(project, editor, selectedExpr, type, occurrences, false, validator);