diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/GrLabeledStatement.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/GrLabeledStatement.java index 09977132e1bd..85a0408b723a 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/GrLabeledStatement.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/GrLabeledStatement.java @@ -17,6 +17,7 @@ package org.jetbrains.plugins.groovy.lang.psi.api.statements; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiNameIdentifierOwner; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.psi.GrNamedElement; @@ -24,7 +25,7 @@ import org.jetbrains.plugins.groovy.lang.psi.GrNamedElement; /** * @author ilyas */ -public interface GrLabeledStatement extends GrStatement, GrNamedElement { +public interface GrLabeledStatement extends GrStatement, GrNamedElement, PsiNameIdentifierOwner { @Nullable GrStatement getStatement(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrLabeledStatementImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrLabeledStatementImpl.java index ceb4b228472f..3144cfec6690 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrLabeledStatementImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrLabeledStatementImpl.java @@ -99,4 +99,10 @@ public class GrLabeledStatementImpl extends GroovyPsiElementImpl implements GrLa public PsiElement getNameIdentifierGroovy() { return getLabel(); } + + @Nullable + @Override + public PsiElement getNameIdentifier() { + return getNameIdentifierGroovy(); + } } \ No newline at end of file diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringSupportProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringSupportProvider.java index 4f61d4a8681d..8eee51744d2a 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringSupportProvider.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringSupportProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,11 +18,18 @@ package org.jetbrains.plugins.groovy.refactoring; import com.intellij.lang.refactoring.RefactoringSupportProvider; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.psi.search.LocalSearchScope; +import com.intellij.psi.search.PsiSearchHelper; +import com.intellij.psi.search.SearchScope; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.refactoring.RefactoringActionHandler; import com.intellij.refactoring.changeSignature.ChangeSignatureHandler; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrLabeledStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; import org.jetbrains.plugins.groovy.refactoring.changeSignature.GrChangeSignatureHandler; import org.jetbrains.plugins.groovy.refactoring.extract.method.GroovyExtractMethodHandler; @@ -63,8 +70,28 @@ public class GroovyRefactoringSupportProvider extends RefactoringSupportProvider } @Override - public boolean isInplaceRenameAvailable(PsiElement element, PsiElement context) { - return false; + public boolean isInplaceRenameAvailable(PsiElement elementToRename, PsiElement nameSuggestionContext) { + //local vars & params renames GrVariableInplaceRenameHandler + + if (nameSuggestionContext != null && nameSuggestionContext.getContainingFile() != elementToRename.getContainingFile()) return false; + if (!(elementToRename instanceof GrLabeledStatement)) { + return false; + } + SearchScope useScope = PsiSearchHelper.SERVICE.getInstance(elementToRename.getProject()).getUseScope(elementToRename); + if (!(useScope instanceof LocalSearchScope)) return false; + PsiElement[] scopeElements = ((LocalSearchScope)useScope).getScope(); + if (scopeElements.length > 1) { + return false; + } + + PsiFile containingFile = elementToRename.getContainingFile(); + return PsiTreeUtil.isAncestor(containingFile, scopeElements[0], false); + + } + + @Override + public boolean isMemberInplaceRenameAvailable(PsiElement element, PsiElement context) { + return element instanceof GrMember; } @Override