mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Groovy: in-place introduce field from local var
This commit is contained in:
+25
-16
@@ -125,26 +125,35 @@ public class GrIntroduceFieldProcessor {
|
||||
updateCaretPosition(occurrence);
|
||||
return Collections.singletonList(occurrence);
|
||||
}
|
||||
else {
|
||||
if (mySettings.replaceAllOccurrences()) {
|
||||
GroovyRefactoringUtil.sortOccurrences(myContext.getOccurrences());
|
||||
ArrayList<PsiElement> result = ContainerUtil.newArrayList();
|
||||
for (PsiElement occurrence : myContext.getOccurrences()) {
|
||||
result.add(replaceOccurrence(field, occurrence, targetClass));
|
||||
}
|
||||
return result;
|
||||
|
||||
if (mySettings.replaceAllOccurrences()) {
|
||||
GroovyRefactoringUtil.sortOccurrences(myContext.getOccurrences());
|
||||
ArrayList<PsiElement> result = ContainerUtil.newArrayList();
|
||||
for (PsiElement occurrence : myContext.getOccurrences()) {
|
||||
result.add(replaceOccurrence(field, occurrence, targetClass));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
GrVariable var = myContext.getVar();
|
||||
if (var != null) {
|
||||
GrExpression initializer = var.getInitializerGroovy();
|
||||
if (initializer != null) {
|
||||
return Collections.singletonList(replaceOccurrence(field, initializer, targetClass));
|
||||
}
|
||||
else {
|
||||
final GrExpression expression = myContext.getExpression();
|
||||
assert expression != null;
|
||||
if (PsiUtil.isExpressionStatement(expression)) {
|
||||
return Collections.<PsiElement>singletonList(expression);
|
||||
}
|
||||
else {
|
||||
return Collections.singletonList(replaceOccurrence(field, expression, targetClass));
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
final GrExpression expression = myContext.getExpression();
|
||||
assert expression != null;
|
||||
if (PsiUtil.isExpressionStatement(expression)) {
|
||||
return Collections.<PsiElement>singletonList(expression);
|
||||
}
|
||||
else {
|
||||
return Collections.singletonList(replaceOccurrence(field, expression, targetClass));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCaretPosition(@NotNull PsiElement occurrence) {
|
||||
|
||||
+18
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -328,6 +328,23 @@ class A {
|
||||
''', false, false, false, CUR_METHOD, false, null)
|
||||
}
|
||||
|
||||
void testFromVar() {
|
||||
doTest('''\
|
||||
class A {
|
||||
def foo() {
|
||||
def <selection>a = 5</selection>
|
||||
print a
|
||||
}
|
||||
}''', '''\
|
||||
class A {
|
||||
def f = 5
|
||||
|
||||
def foo() {
|
||||
print f
|
||||
}
|
||||
}''', false, true, false, FIELD_DECLARATION, true, null)
|
||||
}
|
||||
|
||||
|
||||
private void doTest(final boolean isStatic,
|
||||
final boolean removeLocal,
|
||||
|
||||
Reference in New Issue
Block a user