IDEA-99663 Groovy: method inlining with parameters of same package type

This commit is contained in:
Max Medvedev
2013-02-22 16:17:14 +04:00
parent fed00071af
commit 6cece786ce
4 changed files with 32 additions and 6 deletions
@@ -16,7 +16,7 @@
package org.jetbrains.plugins.groovy.refactoring.inline;
import com.intellij.codeInsight.TargetElementUtil;
import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.lang.refactoring.InlineHandler;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
@@ -25,7 +25,7 @@ import com.intellij.openapi.help.HelpManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.LocalSearchScope;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.refactoring.HelpID;
@@ -81,7 +81,7 @@ public class GroovyInlineMethodUtil {
}
if (invokedOnReference) {
PsiReference reference = editor != null ? TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset()) : null;
PsiReference reference = editor != null ? TargetElementUtilBase.findReference(editor, editor.getCaretModel().getOffset()) : null;
if (reference == null) return InlineHandler.Settings.CANNOT_INLINE_SETTINGS;
PsiElement element = reference.getElement();
@@ -534,8 +534,7 @@ public class GroovyInlineMethodUtil {
GrCallExpression call,
GrExpression oldExpression,
GrParameter parameter) {
Collection<PsiReference> refs =
ReferencesSearch.search(parameter, GlobalSearchScope.projectScope(parameter.getProject()), false).findAll();
Collection<PsiReference> refs = ReferencesSearch.search(parameter, new LocalSearchScope(method), false).findAll();
final GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(call.getProject());
GrExpression expression = elementFactory.createExpressionFromText(oldExpression.getText());
@@ -352,7 +352,7 @@ public class GroovyMethodInliner implements InlineHandler.Inliner {
method = ((GrReflectedMethod)method).getBaseMethod();
}
GrMethod newMethod = factory.createMethodFromText(method.getText());
GrMethod newMethod = factory.createMethodFromText(method.getText(), call);
if (qualifier != null) {
Collection<GroovyInlineMethodUtil.ReferenceExpressionInfo> infos = GroovyInlineMethodUtil.collectReferenceInfo(method);
GroovyInlineMethodUtil.addQualifiersToInnerReferences(newMethod, infos, qualifier);
@@ -100,6 +100,10 @@ public class InlineMethodTest extends LightCodeInsightFixtureTestCase {
public void testVarargs() {doTest();}
public void testTypeParameterDeclaredInFile() {
doTest()
}
public void testInlineAll() {
doTest(new GroovyInlineHandler() {
@Override
@@ -0,0 +1,23 @@
class X {
interface GrAnnotation {}
static void getResolvedAnnotations(GrAnnotation annotation) {
<selection>coll</selection>(annotation)
}
static void coll(GrAnnotation alias) {
alias
}
}
-----
class X {
interface GrAnnotation {}
static void getResolvedAnnotations(GrAnnotation annotation) {
annotation
}
static void coll(GrAnnotation alias) {
alias
}
}