This commit is contained in:
Maxim.Medvedev
2012-02-20 11:41:52 +04:00
parent b54086f079
commit d8e59ff645
4 changed files with 9 additions and 14 deletions
@@ -197,8 +197,8 @@ public abstract class GroovyRefactoringUtil {
});
}
public static boolean isLocalVariable(GrVariable variable) {
return !(variable instanceof GrField || variable instanceof GrParameter);
public static boolean isLocalVariable(PsiElement variable) {
return variable instanceof GrVariable && !(variable instanceof GrField || variable instanceof GrParameter);
}
@@ -210,8 +210,7 @@ public class ExtractUtil {
@Override
public void visitReferenceExpression(GrReferenceExpression ref) {
final PsiElement resolved = ref.resolve();
if ((resolved instanceof GrParameter ||
resolved instanceof GrVariable && GroovyRefactoringUtil.isLocalVariable((GrVariable)resolved)) && resolved.isPhysical()) {
if ((resolved instanceof GrParameter || GroovyRefactoringUtil.isLocalVariable(resolved)) && resolved.isPhysical()) {
final int offset = resolved.getTextRange().getStartOffset();
//var is declared outside of selected code
if (offset < start || end <= offset) {
@@ -59,7 +59,7 @@ public class GroovyInlineLocalHandler extends InlineActionHandler {
@Override
public boolean canInlineElement(PsiElement element) {
return element instanceof GrVariable && GroovyRefactoringUtil.isLocalVariable((GrVariable)element);
return GroovyRefactoringUtil.isLocalVariable(element);
}
@Override
@@ -332,10 +332,8 @@ public class GrIntroduceFieldDialog extends DialogWrapper implements GrIntroduce
private static String getInvokedOnLocalVar(GrExpression expression) {
if (expression instanceof GrReferenceExpression) {
final PsiElement resolved = ((GrReferenceExpression)expression).resolve();
if (resolved instanceof GrVariable) {
if (GroovyRefactoringUtil.isLocalVariable((GrVariable)resolved)) {
return ((GrVariable)resolved).getName();
}
if (GroovyRefactoringUtil.isLocalVariable(resolved)) {
return ((GrVariable)resolved).getName();
}
}
return null;
@@ -348,11 +346,9 @@ public class GrIntroduceFieldDialog extends DialogWrapper implements GrIntroduce
if (expression instanceof GrReferenceExpression) {
final PsiElement resolved = ((GrReferenceExpression)expression).resolve();
if (resolved instanceof GrVariable) {
if (GroovyRefactoringUtil.isLocalVariable((GrVariable)resolved)) {
expression = ((GrVariable)resolved).getInitializerGroovy();
if (expression == null) return false;
}
if (GroovyRefactoringUtil.isLocalVariable(resolved)) {
expression = ((GrVariable)resolved).getInitializerGroovy();
if (expression == null) return false;
}
}