diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringUtil.java index f502a90e5c2b..961cd88bb34a 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringUtil.java @@ -53,6 +53,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrContinueSta import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrCaseSection; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.*; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrCallExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; @@ -65,6 +66,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeArgumentList; import org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner; import org.jetbrains.plugins.groovy.lang.psi.api.util.GrVariableDeclarationOwner; import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; +import org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo; import java.util.*; @@ -105,12 +107,29 @@ public abstract class GroovyRefactoringUtil { final PsiElement commonParent = PsiTreeUtil.findCommonParent(element1, element2); assert commonParent != null; final T element = ReflectionUtil.isAssignable(klass, commonParent.getClass()) ? (T) commonParent : PsiTreeUtil.getParentOfType(commonParent, klass); - if (element == null || element.getTextRange().getStartOffset() != startOffset) { + if (element == null) { return null; } + + if (!checkRanges(element, startOffset, endOffset)) { + return null; + } + return element; } + private static boolean checkRanges(@NotNull PsiElement element, int startOffset, int endOffset) { + if (element instanceof GrLiteral && StringPartInfo.isWholeLiteralContentSelected((GrLiteral)element, startOffset, endOffset)) { + return true; + } + + if (element.getTextRange().getStartOffset() == startOffset) { + return true; + } + + return false; + } + public static PsiElement[] getExpressionOccurrences(@NotNull PsiElement expr, @NotNull PsiElement scope) { ArrayList occurrences = new ArrayList(); Comparator comparator = new Comparator() {