mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-86203 inplace rename for groovy methods (except accessors), classes & labeled statements
This commit is contained in:
+2
-1
@@ -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();
|
||||
|
||||
|
||||
+6
@@ -99,4 +99,10 @@ public class GrLabeledStatementImpl extends GroovyPsiElementImpl implements GrLa
|
||||
public PsiElement getNameIdentifierGroovy() {
|
||||
return getLabel();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement getNameIdentifier() {
|
||||
return getNameIdentifierGroovy();
|
||||
}
|
||||
}
|
||||
+30
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user